From patchwork Thu Jul 11 15:53:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 33678 Received: (qmail 68105 invoked by alias); 11 Jul 2019 15:53:19 -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 67909 invoked by uid 89); 11 Jul 2019 15:53:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 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=HX-Spam-Relays-External:209.85.221.67, H*RU:209.85.221.67 X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Jul 2019 15:53:08 +0000 Received: by mail-wr1-f67.google.com with SMTP id n9so6876842wrr.4 for ; Thu, 11 Jul 2019 08:53:08 -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=xhsz0H/PCrbfgr+hKowD4JdLy1U1N9i3H2xHlVE6g5Q=; b=NLrkeyLYKkkueiPXgbIaEJfn+AeRyIlWb3BtiZqx+5+gcwCgdn/ajvR07r8r3Wemma X0RLviLdgI/UyDk89IHg6rvEb6iiD7ct4gBKT07cBjhcJNwPwF91O1FlwlM1Q5sHKBvV 73JMUxm97K9b+/SwlsSWL4JEixRdL0BgM6waR/pfpWZJ7VujBuThd1wOUr3OwtTgDZiG obCObkqv5ecP/T7gCwpEbTSTowb0QJ35u3wJ1qRZkiN/ihezQuzXt1tIe4+a5VLA+byg qsSmfN/k0GIOZ58ryTpRKCNW2TjdCd8q4o2THii/z/3R5XSUMUZCiaT0oGhJTYXfau5/ Ua1g== Return-Path: Received: from localhost (host86-128-12-99.range86-128.btcentralplus.com. [86.128.12.99]) by smtp.gmail.com with ESMTPSA id w14sm5129774wrk.44.2019.07.11.08.53.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jul 2019 08:53:06 -0700 (PDT) Date: Thu, 11 Jul 2019 16:53:05 +0100 From: Andrew Burgess To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 0/2] Make use of gdb::options for info variabels|functions|args|locals Message-ID: <20190711155305.GO23204@embecosm.com> References: <306a840c-719a-0398-26cd-34142ba05167@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <306a840c-719a-0398-26cd-34142ba05167@redhat.com> X-Fortune: Linux, because we don't need no steenkin' Blue Screen of Death! X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes * Pedro Alves [2019-07-11 14:36:23 +0100]: > On 7/11/19 2:20 PM, Andrew Burgess wrote: > > Additional use of the gdb::options framework. > > > > -- > > > > Andrew Burgess (2): > > gdb: Allow quoting around string options in the gdb::option framework > > Ahaha, that didn't take long. Thanks for doing this. LGTM. > > > gdb: Make use of gdb::option framework for some info commands > > This LGTM to me too, but, I was surprised to find this doesn't add > completers at the same time? Something like this, maybe? Thanks, Andrew --- [PATCH] gdb: Add command completers for some info commands 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'. --- gdb/ChangeLog | 11 +++++++++++ gdb/cli/cli-utils.c | 19 +++++++++++++++++++ gdb/cli/cli-utils.h | 13 +++++++++++++ gdb/stack.c | 10 ++++++---- gdb/symtab.c | 19 +++++++++++++------ 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index cd3dfe65a2b..be830ee9f9d 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -473,3 +473,22 @@ 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); + return; +} + diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index a3826be6824..17cdd842b2f 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -20,6 +20,10 @@ #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. */ diff --git a/gdb/stack.c b/gdb/stack.c index 175f2116a5b..9b1d1a68568 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -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, _("\ diff --git a/gdb/symtab.c b/gdb/symtab.c index 46691122187..41898992c19 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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).