This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] define_command: Don't convert command name to lower case


I think this won't be too controversial, so I went ahead and made a patch for
it.

Commit

  Command names: make them case sensitive
  3d7b173c29900879c9a5958dd6029fd36666e57c

made command name lookup case sensitive.  However, define_command, used
when creating a user-defined command, converts the command name to
lowercase, assuming that the command name lookup works in a case
insensitive way.  This causes user-defined commands with capital letters
in their name to only be callable with a lowercase version:

  (gdb) define Foo
  Type commands for definition of "Foo".
  End with a line saying just "end".
  >print 1
  >end
  (gdb) Foo
  Undefined command: "Foo".  Try "help".
  (gdb) foo
  $1 = 1

This patch removes that conversion to lowercase, so that the user can
call the command with the same name they provided.

gdb/ChangeLog:

	* cli/cli-script.c (define_command): Don't convert command name
	to lower case.

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp (user_defined_command_case_sensitivity):
	New proc, call it from toplevel.
---
 gdb/cli/cli-script.c                |  6 ------
 gdb/testsuite/gdb.base/commands.exp | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 5674404..481cc01 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1499,12 +1499,6 @@ define_command (char *comname, int from_tty)
 
   comname = xstrdup (comname);
 
-  /* If the rest of the commands will be case insensitive, this one
-     should behave in the same manner.  */
-  for (tem = comname; *tem; tem++)
-    if (isupper (*tem))
-      *tem = tolower (*tem);
-
   xsnprintf (tmpbuf, sizeof (tmpbuf),
 	     "Type commands for definition of \"%s\".", comfull);
   command_line_up cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0);
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 4963743..3ccd8b1 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -352,6 +352,25 @@ proc_with_prefix user_defined_command_test {} {
 	"display user-defined empty command"
 }
 
+# Test that the case with which the command was defined is preserved.
+
+proc_with_prefix user_defined_command_case_sensitivity {} {
+    global gdb_prompt
+
+    set test "define Homer-Simpson"
+    gdb_test_multiple $test $test {
+	    -re "End with"  {
+		pass $test
+	    }
+	}
+
+    gdb_test "print 123\nend" "" "enter commands"
+
+    gdb_test "Homer-Simpson" " = 123" "execute command"
+    gdb_test "HOMER-SIMPSON" "Undefined command.*" "try to call in upper case"
+    gdb_test "homer-simpson" "Undefined command.*" "try to call in lower case"
+}
+
 # Test that "eval" in a user-defined command expands $argc/$argN.
 
 proc_with_prefix user_defined_command_args_eval {} {
@@ -1052,6 +1071,7 @@ if_while_breakpoint_command_test
 infrun_breakpoint_command_test
 breakpoint_command_test
 user_defined_command_test
+user_defined_command_case_sensitivity
 user_defined_command_args_eval
 user_defined_command_args_stack_test
 user_defined_command_manyargs_test
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]