]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Expression completer should not match explicit location options
authorPedro Alves <palves@redhat.com>
Thu, 29 Jun 2017 14:52:38 +0000 (15:52 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 29 Jun 2017 14:53:48 +0000 (15:53 +0100)
This commit fixes a mismatch between what "print" command completer
thinks the command understands, and what the command actually
understands.

The explicit location options are understood by commands that take
(linespecs and) explicit locations as argument.  I.e, breakpoint
commands, and "list".  For example:

 (gdb) b -source file.c -function my_func

So for those commands, it makes sense that the completer
completes:

 "b -sour[TAB]" -> "b -source "
 "b -functi[TAB]" -> "b -function "

etc.

However, completion for commands that take expressions (not
linespecs/locations) as arguments, such as the "print" command, also
completes the explicit location options, even though those switches
aren't really understood by these commands.  Instead, "-foo" is
understood as an expression applying unary minus on a symbol named
"foo" (think "print -1"):

 (gdb) p -func[TAB]
 (gdb) p -function [RET]
 No symbol "function" in current context.

The patch fixes this by having the expression_completer function
bypass the function that completes explicit locations.

New regression tests included.

gdb/ChangeLog:
2017-06-29  Pedro Alves  <palves@redhat.com>

* completer.c (expression_completer): Call
linespec_location_completer instead of location_completer.

gdb/testsuite/ChangeLog:
2017-06-29  Pedro Alves  <palves@redhat.com>

* gdb.base/printcmds.exp: Add tests.

gdb/ChangeLog
gdb/completer.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/printcmds.exp

index c76158faf2a1fed9bde6847ca706150937b80159..b47226bcc3958de3bbf00caadeacc632d081d1e4 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-29  Pedro Alves  <palves@redhat.com>
+
+       * completer.c (expression_completer): Call
+       linespec_location_completer instead of location_completer.
+
 2017-06-29  Pedro Alves  <palves@redhat.com>
 
        * completer.c (expression_completer): Remove code that recomputes
index f152dd5fadc9063b5a15f17a65188f29fbafbbb9..68e68eb8d68c0fae85eacc86d37a80a6518675ea 100644 (file)
@@ -635,7 +635,7 @@ expression_completer (struct cmd_list_element *ignore,
   xfree (fieldname);
 
   /* Not ideal but it is what we used to do before...  */
-  return location_completer (ignore, text, word);
+  return linespec_location_completer (ignore, text, word);
 }
 
 /* See definition in completer.h.  */
index b7462a5cdcbf859e6c2b1adbd159d760e76e6e38..41c5434052c6650301d7f40e8aa7b6257b136c00 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-29  Pedro Alves  <palves@redhat.com>
+
+       * gdb.base/printcmds.exp: Add tests.
+
 2017-06-28  Doug Gilmore  <Doug.Gilmore@imgtec.com>
 
        PR gdb/21337
index d949b309bf688902257655c73ed39a21fd096896..323ca7307720473233546dc6b8dc875dbba57f5b 100644 (file)
@@ -931,6 +931,12 @@ gdb_test "ptype \"abc\"" " = char \\\[4\\\]"
 gdb_test "print \$cvar = \"abc\"" " = \"abc\""
 gdb_test "print sizeof (\$cvar)" " = 4"
 
+# GDB used to complete the explicit location options even when
+# printing expressions.
+gdb_test_no_output "complete p -function"
+gdb_test_no_output "complete p -line"
+gdb_test_no_output "complete p -source"
+
 gdb_file_cmd ${binfile}
 
 gdb_test "print \$pc" "No registers\\." "print \$pc (with file)"