gdb: Add command completers for some info commands
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 11 Jul 2019 14:39:55 +0000 (15:39 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 11 Jul 2019 19:19:24 +0000 (20:19 +0100)
Add command completion for info variables, functions, args, and
locals.  This completer only completes the command line options as
these commands all take a regexp which GDB can't really offer
completions for.

gdb/ChangeLog:

* cli/cli-utils.c (info_print_command_completer): New function.
* cli/cli-utils.h: Add 'completer.h' include, and forward
declaration for 'struct cmd_list_element'.
(info_print_command_completer): Declare.
* stack.c (_initialize_stack): Add completer for 'info locals' and
'info args'.
* symtab.c (_initialize_symtab): Add completer for 'info
variables' and 'info functions'.
* NEWS: Mention completion for additional info commands.

gdb/ChangeLog
gdb/NEWS
gdb/cli/cli-utils.c
gdb/cli/cli-utils.h
gdb/stack.c
gdb/symtab.c

index f330fb5f7508e67e52fc835adc71fdc9c9b568b7..90af6d38b57c8d7c60a58f4cd9e2580018666071 100644 (file)
@@ -1,3 +1,15 @@
+2019-07-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * cli/cli-utils.c (info_print_command_completer): New function.
+       * cli/cli-utils.h: Add 'completer.h' include, and forward
+       declaration for 'struct cmd_list_element'.
+       (info_print_command_completer): Declare.
+       * stack.c (_initialize_stack): Add completer for 'info locals' and
+       'info args'.
+       * symtab.c (_initialize_symtab): Add completer for 'info
+       variables' and 'info functions'.
+       * NEWS: Mention completion for additional info commands.
+
 2019-07-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * cli/cli-utils.c (extract_info_print_args): Delete.
index f7b6b88a220f214b941fb7d9b394adf8d0e6216a..4e479bf738bbff1e99e2fe0a35c56bd536fdc63d 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -217,7 +217,9 @@ maint show test-options-completion-result
      "taas" commands, and their "-ascending" option can now be
      abbreviated.
 
-  ** GDB can now complete the options of the "info threads" command.
+  ** GDB can now complete the options of the "info threads", "info
+     functions", "info variables", "info locals", and "info args"
+     commands.
 
   ** GDB can now complete the options of the "compile file" and
      "compile code" commands.  The "compile file" command now
index cd3dfe65a2b63b0d4bdf9f8e2fb0d1b91ad64ffe..c6405505d99141d77526564bfc61cb798d668373 100644 (file)
@@ -473,3 +473,20 @@ extract_info_print_options (info_print_options *opts,
   if (*args != nullptr && **args == '\0')
     *args = nullptr;
 }
+
+/* See documentation in cli-utils.h.  */
+
+void
+info_print_command_completer (struct cmd_list_element *ignore,
+                             completion_tracker &tracker,
+                             const char *text, const char * /* word */)
+{
+  const auto group
+    = make_info_print_options_def_group (nullptr);
+  if (gdb::option::complete_options
+      (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
+    return;
+
+  const char *word = advance_to_expression_complete_word_point (tracker, text);
+  symbol_completer (ignore, tracker, text, word);
+}
index a3826be68247a6e517d042b43318bf34062d05be..17cdd842b2f0936e34f102d80ccd8b557b34fdf2 100644 (file)
 #ifndef CLI_CLI_UTILS_H
 #define CLI_CLI_UTILS_H
 
+#include "completer.h"
+
+struct cmd_list_element;
+
 /* *PP is a string denoting a number.  Get the number.  Advance *PP
    after the string and any trailing whitespace.
 
@@ -66,6 +70,15 @@ struct info_print_options
 extern void extract_info_print_options (info_print_options *opts,
                                        const char **args);
 
+/* Function that can be used as a command completer for 'info variable'
+   and friends.  This offers command option completion as well as symbol
+   completion.  At the moment all symbols are offered for all commands.  */
+
+extern void info_print_command_completer (struct cmd_list_element *ignore,
+                                         completion_tracker &tracker,
+                                         const char *text,
+                                         const char * /* word */);
+
 /* Throws an error telling the user that ARGS starts with an option
    unrecognized by COMMAND.  */
 
index 175f2116a5bf1a226a2c328f7b50d8846dd484fc..9b1d1a6856884f24282320d52d706ec173e8b2d3 100644 (file)
@@ -3423,18 +3423,20 @@ Print information about a stack frame selected by level.\n\
 Usage: info frame level LEVEL"),
           &info_frame_cmd_list);
 
-  add_info ("locals", info_locals_command,
-           info_print_args_help (_("\
+  cmd = add_info ("locals", info_locals_command,
+                 info_print_args_help (_("\
 All local variables of current stack frame or those matching REGEXPs.\n\
 Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
 Prints the local variables of the current stack frame.\n"),
                                  _("local variables")));
-  add_info ("args", info_args_command,
-           info_print_args_help (_("\
+  set_cmd_completer_handle_brkchars (cmd, info_print_command_completer);
+  cmd = add_info ("args", info_args_command,
+                 info_print_args_help (_("\
 All argument variables of current stack frame or those matching REGEXPs.\n\
 Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
 Prints the argument variables of the current stack frame.\n"),
                                  _("argument variables")));
+  set_cmd_completer_handle_brkchars (cmd, info_print_command_completer);
 
   if (dbx_commands)
     add_com ("func", class_stack, func_command, _("\
index 466911221870b49d4a958fb4d02544db6079ced8..41898992c190745519535a5f15cd2f14a7363a67 100644 (file)
@@ -5997,28 +5997,35 @@ symbol_set_symtab (struct symbol *symbol, struct symtab *symtab)
 void
 _initialize_symtab (void)
 {
+  cmd_list_element *c;
+
   initialize_ordinary_address_classes ();
 
-  add_info ("variables", info_variables_command,
-           info_print_args_help (_("\
+  c = add_info ("variables", info_variables_command,
+               info_print_args_help (_("\
 All global and static variable names or those matching REGEXPs.\n\
 Usage: info variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
 Prints the global and static variables.\n"),
                                  _("global and static variables")));
+  set_cmd_completer_handle_brkchars (c, info_print_command_completer);
   if (dbx_commands)
-    add_com ("whereis", class_info, info_variables_command,
-            info_print_args_help (_("\
+    {
+      c = add_com ("whereis", class_info, info_variables_command,
+                  info_print_args_help (_("\
 All global and static variable names, or those matching REGEXPs.\n\
 Usage: whereis [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
 Prints the global and static variables.\n"),
                                   _("global and static variables")));
+      set_cmd_completer_handle_brkchars (c, info_print_command_completer);
+    }
 
-  add_info ("functions", info_functions_command,
-           info_print_args_help (_("\
+  c = add_info ("functions", info_functions_command,
+               info_print_args_help (_("\
 All function names or those matching REGEXPs.\n\
 Usage: info functions [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
 Prints the functions.\n"),
                                  _("functions")));
+  set_cmd_completer_handle_brkchars (c, info_print_command_completer);
 
   /* FIXME:  This command has at least the following problems:
      1.  It prints builtin types (in a very strange and confusing fashion).