diff mbox

[RFA] candidates for ambiguous command in upper case

Message ID 20170111153724.GG27546@adacore.com
State New
Headers show

Commit Message

Jerome Guitton Jan. 11, 2017, 3:37 p.m. UTC
Pedro Alves (palves@redhat.com):

> In my branch I've completely changed how GDB hands over

> completion matches to readline, and I've had to make

> sure to preserve that behavior, as caught by some test.


Interesting! When do you think that this branch would be merged in
master? Still interested in my patch in the meantime? I guess that
the new tests would be useful in any case.

Last version in attachment. There was already a test for "info sysq",
I've added "info T" and "info TERMINA".
diff mbox

Patch

commit 0eec4d84f57d5a214e00f3186f38d3af07584d86
Author: Jerome Guitton <guitton@adacore.com>
Date:   Tue Jan 10 15:10:08 2017 +0100

    [RFA] candidates for ambiguous command in upper case
    
    If you type an ambiguous command in lower case, gdb tells the command
    is ambiguous and tells you which one could match. If you type the same
    but in upper case, gdb also says it is ambiguous, but shows an empty
    list of commands:
    
     (gdb) ex
     Ambiguous command "ex": exec-file, expression.
     (gdb) EX
     Ambiguous command "EX": .
    
    The same issue with completion.
    
      (gdb) inf<tab><tab>
    
    shows "inferior  info", but
    
      (gdb) INF<tab><tab>
    
    shows nothing.
    
    Simple fix in attachment, with an additional test.
    Tested on x86-linux. OK to apply?
    
    gdb/ChangeLog:
    
    	* cli-decode.c (lookup_cmd): case insensitive match when looking
    	up candidates for ambiguous command.
    	(complete_on_cmdlist): Ditto.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/completion.exp: Add tests for completion of upper case
    	commands.

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index d3be93c..dbd874e 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1550,7 +1550,7 @@  lookup_cmd (const char **line, struct cmd_list_element *list, char *cmdtype,
 
 	  ambbuf[0] = 0;
 	  for (c = local_list; c; c = c->next)
-	    if (!strncmp (*line, c->name, amb_len))
+	    if (!strncasecmp (*line, c->name, amb_len))
 	      {
 		if (strlen (ambbuf) + strlen (c->name) + 6
 		    < (int) sizeof ambbuf)
@@ -1800,7 +1800,7 @@  complete_on_cmdlist (struct cmd_list_element *list,
   for (pass = 0; matchlist == 0 && pass < 2; ++pass)
     {
       for (ptr = list; ptr; ptr = ptr->next)
-	if (!strncmp (ptr->name, text, textlen)
+	if (!strncasecmp (ptr->name, text, textlen)
 	    && !ptr->abbrev_flag
 	    && (!ignore_help_classes || ptr->func
 		|| ptr->prefixlist))
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 4a3ee4b..cae45ae 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -30,6 +30,8 @@ 
 #   "info t foo" no completions
 #   "info t " no completions
 #   "info t" ambiguous ("info target", "info terminal", etc.)
+#   "info T" ambiguous ("info target", "info terminal", etc.)
+#   "info TERMINA" unambiguous (completes to "info terminal")
 #   "info ajksdlfk" no completions
 #   "info ajksdlfk " no completions
 #   "info" " "
@@ -265,6 +267,32 @@  gdb_test_multiple "" "$test" {
     }
 }
 
+set test "complete 'info T '"
+send_gdb "info T \t"
+gdb_test_multiple "" "$test" {
+    -re "^info T \\\x07$" {
+	send_gdb "\n"
+	gdb_test_multiple "" "$test" {
+	    -re "Ambiguous info command \"T \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
+		pass "$test"
+	    }
+	}
+    }
+}
+
+set test "complete 'info TERMINA'"
+send_gdb "info TERMINA\t"
+gdb_test_multiple "" "$test" {
+    -re "^info TERMINAterminal $" {
+	send_gdb "\n"
+	gdb_test_multiple "" "$test" {
+	    -re "Inferior's terminal status.*$gdb_prompt $" {
+		pass "$test"
+	    }
+	}
+    }
+}
+
 set test "complete 'info t '"
 send_gdb "info t \t"
 gdb_test_multiple "" "$test" {