Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 1/3] gdb: Switch "info types" over to use the gdb::options framework
Date: Fri, 12 Jul 2019 11:37:00 -0000	[thread overview]
Message-ID: <c93fe4d308adbad677d2f2c473d26f9d1c094e7f.1562931337.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1562931337.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1562931337.git.andrew.burgess@embecosm.com>

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       | 11 +++++++++
 gdb/NEWS            |  4 ++++
 gdb/doc/ChangeLog   |  5 +++++
 gdb/doc/gdb.texinfo |  6 +++--
 gdb/symtab.c        | 64 +++++++++++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 4e479bf738b..cc1d58520d4 100644
--- 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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index eddd939869a..777a412df67 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18428,8 +18428,7 @@
 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,9 @@
 @code{whatis}, it does not print a detailed description; second, it
 lists all source files and line numbers where a type is defined.
 
+The optional flag @samp{-q}, which stands for @samp{quiet}, disables
+printing header information.
+
 @kindex info type-printers
 @item info type-printers
 Versions of @value{GDBN} that ship with Python scripting enabled may
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 41898992c19..7b7f1298419 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4769,11 +4769,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.  */
@@ -6035,8 +6086,13 @@ 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 some headers\n\
+and messages."));
+  set_cmd_completer_handle_brkchars (c, info_types_command_completer);
 
   add_info ("sources", info_sources_command,
 	    _("Source files in the program."));
-- 
2.14.5


  reply	other threads:[~2019-07-12 11:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12 11:37 [PATCH 0/3] Improving "info types" command Andrew Burgess
2019-07-12 11:37 ` Andrew Burgess [this message]
2019-07-12 12:48   ` [PATCH 1/3] gdb: Switch "info types" over to use the gdb::options framework Eli Zaretskii
2019-07-19 14:50     ` Andrew Burgess
2019-07-18 20:07   ` Pedro Alves
2019-07-12 11:37 ` [PATCH 2/3] gdb: Improve output from "info types" commad Andrew Burgess
2019-07-18 20:07   ` Pedro Alves
2019-07-19 19:43     ` Andrew Burgess
2019-07-19 19:54       ` Pedro Alves
2019-07-20 13:47       ` Pedro Alves
2019-07-12 11:37 ` [PATCH 3/3] gdb: Show type summary for anonymous structures from c_print_typedef Andrew Burgess
2019-07-19 12:38   ` Pedro Alves
2019-07-19 21:06     ` Andrew Burgess
2019-07-20 13:47       ` Pedro Alves
2019-07-22 14:10         ` Tom Tromey

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=c93fe4d308adbad677d2f2c473d26f9d1c094e7f.1562931337.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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