Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: <guitton@adacore.com>
Subject: Re: [PATCH] define_command: Don't convert command name to lower case
Date: Mon, 28 Aug 2017 21:20:00 -0000	[thread overview]
Message-ID: <e1265b13-9086-7cdf-f436-79f19acc9efc@ericsson.com> (raw)
In-Reply-To: <f84b2460-df75-9da2-638b-76d903169962@ericsson.com>

On 2017-07-24 11:54 PM, Simon Marchi wrote:
> On 2017-07-24 11:47 PM, Simon Marchi wrote:
>> 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.
> 
> I forgot to mention but this would be a candidate for the 8.0 branch as well,
> since it's a regression.
> 
> Simon
> 

This is now pushed to master and gdb-8.0-branch.  I made a small change to the test,
in order to test that multiple commands whose names differ only by case don't
interfere.


From fd437cbc432d5421492a5b0e371750de104cce93 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Mon, 28 Aug 2017 23:05:04 +0200
Subject: [PATCH] define_command: Don't convert command name to lower case

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/ChangeLog                       |  5 +++++
 gdb/cli/cli-script.c                |  6 ------
 gdb/testsuite/ChangeLog             |  5 +++++
 gdb/testsuite/gdb.base/commands.exp | 30 ++++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 39ff4ed..73106bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-08-28  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* cli/cli-script.c (define_command): Don't convert command name
+	to lower case.
+
 2017-08-25  Joel Brobecker  <brobecker@adacore.com>

 	* ada-lang.c (ada_lookup_struct_elt_type): Remove parameter "dispp".
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 4b8ae0b..64b4c2b 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1478,12 +1478,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/ChangeLog b/gdb/testsuite/ChangeLog
index 56ff191..83261df 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-08-28  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* gdb.base/commands.exp (user_defined_command_case_sensitivity):
+	New proc, call it from toplevel.
+
 2017-08-23  Sergio Durigan Junior  <sergiodj@redhat.com>

 	PR remote/21852
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 4963743..4cd5f46 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -352,6 +352,35 @@ 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 {} {
+    # Define a first command with mixed case name.
+    set test "define Homer-Simpson"
+    gdb_test_multiple $test $test {
+	    -re "End with"  {
+		pass $test
+	    }
+	}
+
+    gdb_test "print 123\nend" "" "enter commands 1"
+
+    # Define a second command, same name but different case.
+    set test "define HomeR-SimpsoN"
+    gdb_test_multiple $test $test {
+	    -re "End with"  {
+		pass $test
+	    }
+	}
+
+    gdb_test "print 456\nend" "" "enter commands 2"
+
+    gdb_test "Homer-Simpson" " = 123" "execute command"
+    gdb_test "HomeR-SimpsoN" " = 456" "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 +1081,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



  reply	other threads:[~2017-08-28 21:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1484058324-5368-1-git-send-email-guitton@adacore.com>
2017-01-10 15:07 ` [RFA] candidates for ambiguous command in upper case Yao Qi
2017-01-10 15:19   ` Jerome Guitton
2017-01-10 15:28     ` Simon Marchi
2017-01-10 15:40       ` Jerome Guitton
2017-01-10 17:00       ` Pedro Alves
2017-01-11 15:37         ` Jerome Guitton
2017-01-11 17:26         ` Yao Qi
2017-01-11 17:35           ` Luis Machado
2017-01-11 20:24           ` Pedro Alves
2017-01-12 10:18             ` Jerome Guitton
2017-01-12 16:37               ` Pedro Alves
2017-01-16 16:32                 ` Jerome Guitton
2017-01-17  1:58                   ` Pedro Alves
2017-01-17 16:29                     ` Luis Machado
2017-01-17 16:35                       ` Pedro Alves
2017-01-17 16:51                         ` Luis Machado
2017-01-17 17:04                           ` Pedro Alves
2017-01-17 17:13                             ` Luis Machado
2017-01-31 14:39                       ` Jerome Guitton
2017-01-31 15:20                         ` Pedro Alves
2017-02-08 18:05                           ` Jerome Guitton
2017-07-24 21:17                             ` Simon Marchi
2017-07-24 21:48                               ` [PATCH] define_command: Don't convert command name to lower case Simon Marchi
2017-07-24 21:54                                 ` Simon Marchi
2017-08-28 21:20                                   ` Simon Marchi [this message]
2017-07-26 12:42                                 ` Jerome Guitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1265b13-9086-7cdf-f436-79f19acc9efc@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guitton@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox