From patchwork Fri Jul 19 14:50:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 33740 Received: (qmail 5165 invoked by alias); 19 Jul 2019 14:50:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5156 invoked by uid 89); 19 Jul 2019 14:50:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=reality X-HELO: mail-wm1-f42.google.com Received: from mail-wm1-f42.google.com (HELO mail-wm1-f42.google.com) (209.85.128.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Jul 2019 14:50:52 +0000 Received: by mail-wm1-f42.google.com with SMTP id s3so29087286wms.2 for ; Fri, 19 Jul 2019 07:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gfqAatST0hveLXcKZR9WPG+KdS4bjLy7N1bryXRLr5s=; b=dAxOgZ/slVuEKhPs4N1++VFFFWntdETS2v2pTsVl4qlu9I8DXPKhOkYRfo51xy3h+V CFUgAK2zl3Apk+14rM8IVFw/4n9fBBokEQoqQUbAlMpy2Vfxu76RYZcg9ruv2+ClbtzA 5lM48iAJ8OlpIVYeskfeakmJ72KCBCsVsaQPKeZG6Z95atxeR+4ejXJqLjrtL5fk03Xc +fJ4E8fc1vXKRqfWdd1oC2p63HN5VTiQe68u4Ch0qTO9sXSzWKvs3+hMNbCxNT/owxuO JyWf6MADfsYxJjtx/SVaCkJODK+gQN4u9ztN4x6XYUrM+jQ09Ag4gLn8GVvX7GW2QUVP Z8Qg== Return-Path: Received: from localhost (host86-171-250-129.range86-171.btcentralplus.com. [86.171.250.129]) by smtp.gmail.com with ESMTPSA id w23sm31779956wmi.45.2019.07.19.07.50.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jul 2019 07:50:49 -0700 (PDT) Date: Fri, 19 Jul 2019 15:50:48 +0100 From: Andrew Burgess To: Eli Zaretskii Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 1/3] gdb: Switch "info types" over to use the gdb::options framework Message-ID: <20190719145048.GA23204@embecosm.com> References: <83lfx32zbt.fsf@gnu.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <83lfx32zbt.fsf@gnu.org> X-Fortune: Fly me away to the bright side of the moon ... X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes * Eli Zaretskii [2019-07-12 15:48:38 +0300]: > > From: Andrew Burgess > > Cc: Andrew Burgess > > Date: Fri, 12 Jul 2019 12:37:04 +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". > > Thanks. > > > 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". > > + > > This part is OK. > > > +@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. > > I don't see "headers" described anywhere in the preceding text, so > "disables printing header information" here is not clear enough. > Besides, the command's doc string says "some headers and messages", > which seems to imply more than just "headers" is suppressed by this > switch. > > Can you please make the effect of this switch more clear? Thanks for your feedback. Part of the problem here is that many of the commands in this area are similarly poorly documented, and I more or less copied the description over. I've simplified the command help text to actually reflect reality (only headers are suppressed) and extended the manual text to mention the headers before describing that the -q flag disables them. Hopefully this all makes more sense. Thanks, Andrew --- gdb: Switch "info types" over to use the gdb::options framework 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". 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..be65d528d28 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,11 @@ @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 diff --git a/gdb/symtab.c b/gdb/symtab.c index 719e5b2ee9a..16861e2bc92 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 { + "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. */ @@ -6037,8 +6088,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."));