gdb: Switch "info types" over to use the gdb::options framework
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 11 Jul 2019 20:02:59 +0000 (21:02 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 22 Jul 2019 09:43:00 +0000 (10:43 +0100)
Adds a new -q flag to "info types" using the gdb::option framework.
This -q flag is similar to the -q flag already present for "info
variables" and "info functions".

gdb/ChangeLog:

* NEWS: Mention adding -q option to "info types".
* symtab.c (struct info_types_options): New struct.
(info_types_options_defs): New variable.
(make_info_types_options_def_group): New function.
(info_types_command): Use gdb::option framework to parse options.
(info_types_command_completer): New function.
(_initialize_symtab): Extend the help text on "info types" and
register command completer.

gdb/doc/ChangeLog:

* gdb.texinfo (Symbols): Add information about -q flag to "info
types".

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/symtab.c

index 63f6fa90d101718c528cf820147e9e6aad5745e5..18987b0de405c04af3fa5b79b3f7d0ceb4dbb8a3 100644 (file)
@@ -1,3 +1,14 @@
+2019-07-22  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * NEWS: Mention adding -q option to "info types".
+       * symtab.c (struct info_types_options): New struct.
+       (info_types_options_defs): New variable.
+       (make_info_types_options_def_group): New function.
+       (info_types_command): Use gdb::option framework to parse options.
+       (info_types_command_completer): New function.
+       (_initialize_symtab): Extend the help text on "info types" and
+       register command completer.
+
 2019-07-21  Christian Biesinger  <cbiesinger@google.com>
 
        * symtab.c (lookup_symbol_in_objfile_symtabs): Change int to block_enum.
index 4e479bf738bbff1e99e2fe0a35c56bd536fdc63d..cc1d58520d4bfe3ee59ac0d315051dda19a9c16d 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -211,6 +211,10 @@ maint show test-options-completion-result
 
     (gdb) print -raw -pretty -object off -- *myptr
 
+  ** The "info types" command now supports the '-q' flag to disable
+     printing of some header information in a similar fashion to "info
+     variables" and "info functions".
+
 * Completion improvements
 
   ** GDB can now complete the options of the "thread apply all" and
index 948b2b2c04bce043a61b1f7fe930f819b82602f2..ca0e3ee1155aa16db48cadde268139e0bc16ef33 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-22  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.texinfo (Symbols): Add information about -q flag to "info
+       types".
+
 2019-07-20  Kevin Buettner  <kevinb@redhat.com>
 
        * python.texi (python command): Revise example to match
index eddd939869a7e310296428aee9a7715ae9f651bc..be65d528d28fdd796af25049eec7adf42184f854 100644 (file)
@@ -18428,8 +18428,7 @@ information.  Inspecting the type of a (global) variable for which
 of such variables.
 
 @kindex info types
-@item info types @var{regexp}
-@itemx info types
+@item info types [-q] [@var{regexp}]
 Print a brief description of all types whose names match the regular
 expression @var{regexp} (or all types in your program, if you supply
 no argument).  Each complete typename is matched as though it were a
@@ -18449,6 +18448,11 @@ This command differs from @code{ptype} in two ways: first, like
 @code{whatis}, it does not print a detailed description; second, it
 lists all source files and line numbers where a type is defined.
 
+The output from @samp{into types} is proceeded with a header line
+describing what types are being listed.  The optional flag @samp{-q},
+which stands for @samp{quiet}, disables printing this header
+information.
+
 @kindex info type-printers
 @item info type-printers
 Versions of @value{GDBN} that ship with Python scripting enabled may
index ce1cdcf9e70e4faa38a2b01da20ef28fd049b26b..ea2b813f293ad5851f0d862477b213861456f4c9 100644 (file)
@@ -4773,11 +4773,62 @@ info_functions_command (const char *args, int from_tty)
                      opts.type_regexp, from_tty);
 }
 
+/* Holds the -q option for the 'info types' command.  */
+
+struct info_types_options
+{
+  int quiet = false;
+};
+
+/* The options used by the 'info types' command.  */
+
+static const gdb::option::option_def info_types_options_defs[] = {
+  gdb::option::boolean_option_def<info_types_options> {
+    "q",
+    [] (info_types_options *opt) { return &opt->quiet; },
+    nullptr, /* show_cmd_cb */
+    nullptr /* set_doc */
+  }
+};
+
+/* Returns the option group used by 'info types'.  */
+
+static gdb::option::option_def_group
+make_info_types_options_def_group (info_types_options *opts)
+{
+  return {{info_types_options_defs}, opts};
+}
+
+/* Implement the 'info types' command.  */
 
 static void
-info_types_command (const char *regexp, int from_tty)
+info_types_command (const char *args, int from_tty)
 {
-  symtab_symbol_info (false, regexp, TYPES_DOMAIN, NULL, from_tty);
+  info_types_options opts;
+
+  auto grp = make_info_types_options_def_group (&opts);
+  gdb::option::process_options
+    (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
+  if (args != nullptr && *args == '\0')
+    args = nullptr;
+  symtab_symbol_info (opts.quiet, args, TYPES_DOMAIN, NULL, from_tty);
+}
+
+/* Command completer for 'info types' command.  */
+
+static void
+info_types_command_completer (struct cmd_list_element *ignore,
+                             completion_tracker &tracker,
+                             const char *text, const char * /* word */)
+{
+  const auto group
+    = make_info_types_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);
 }
 
 /* Breakpoint all functions matching regular expression.  */
@@ -6041,8 +6092,12 @@ Prints the functions.\n"),
      print "struct foo *".
      I also think "ptype" or "whatis" is more likely to be useful (but if
      there is much disagreement "info types" can be fixed).  */
-  add_info ("types", info_types_command,
-           _("All type names, or those matching REGEXP."));
+  c = add_info ("types", info_types_command, _("\
+All type names, or those matching REGEXP.\n\
+Usage: info types [-q] [REGEXP]\n\
+Print information about all types matching REGEXP, or all types if no\n\
+REGEXP is given.  The optional flag -q disables printing of headers."));
+  set_cmd_completer_handle_brkchars (c, info_types_command_completer);
 
   add_info ("sources", info_sources_command,
            _("Source files in the program."));
This page took 0.05604 seconds and 4 git commands to generate.