From 4acfdd20c9ef3c0368868b4221554f0abef04196 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Mon, 22 Jul 2019 16:53:06 +0100 Subject: gdb: Add new -n flag to some info commands The 'info variables', its alias 'whereis', and 'info functions' all include non-debug symbols in the output by default. The list of non-debug symbols can sometimes be quite long, resulting in the debug symbol based results being scrolled off the screen. This commit adds a '-n' flag to all of the commands listed above that excludes the non-debug symbols from the results, leaving just the debug symbol based results. gdb/ChangeLog: * cli/cli-utils.c (info_print_options_defs): Delete. (make_info_print_options_def_group): Delete. (extract_info_print_options): Delete. (info_print_command_completer): Delete. (info_print_args_help): Add extra parameter, and optionally include text about -n flag. * cli/cli-utils.h (struct info_print_options): Delete. (extract_info_print_options): Delete declaration. (info_print_command_completer): Delete declaration. (info_print_args_help): Add extra parameter, extend header comment. * python/python.c (gdbpy_rbreak): Pass additional parameter to search_symbols. * stack.c (struct info_print_options): New type. (info_print_options_defs): New file scoped variable. (make_info_print_options_def_group): New static function. (info_print_command_completer): New static function. (info_locals_command): Update to use new local functions. (info_args_command): Likewise. (_initialize_stack): Add extra parameter to calls to info_print_args_help. * symtab.c (search_symbols): Add extra parameter, use this to possibly excluse non-debug symbols. (symtab_symbol_info): Add extra parameter, which is passed on to search_symbols. (struct info_print_options): New type. (info_print_options_defs): New file scoped variable. (make_info_print_options_def_group): New static function. (info_print_command_completer): New static function. (info_variables_command): Update to use local functions, and pass extra parameter through to symtab_symbol_info. (info_functions_command): Likewise. (info_types_command): Pass additional argument through to symtab_symbol_info. (rbreak_command): Pass extra argument to search_symbols. (_initialize_symtab): Add extra arguments for calls to info_print_args_help, and update help text for 'info variables', 'whereis', and 'info functions' commands. * symtab.h (search_symbols): Add extra argument to declaration. * NEWS: Mention new flags. gdb/doc/ChangeLog: * gdb.texinfo (Symbols): Add information about the -n flag to "info variables" and "info functions". gdb/testsuite/ChangeLog: * gdb.base/info-fun.exp: Extend to test the -n flag for 'info functions'. Reindent as needed. * gdb.base/info-var-f1.c: New file. * gdb.base/info-var-f2.c: New file. * gdb.base/info-var.exp: New file. * gdb.base/info-var.h: New file. --- gdb/cli/cli-utils.c | 65 ++++++----------------------------------------------- gdb/cli/cli-utils.h | 39 +++++--------------------------- 2 files changed, 12 insertions(+), 92 deletions(-) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index c640550..b6b21c9 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -194,7 +194,8 @@ report_unrecognized_option_error (const char *command, const char *args) const char * info_print_args_help (const char *prefix, - const char *entity_kind) + const char *entity_kind, + bool document_n_flag) { return xstrprintf (_("\ %sIf NAMEREGEXP is provided, only prints the %s whose name\n\ @@ -204,8 +205,11 @@ matches TYPEREGEXP. Note that the matching is done with the type\n\ printed by the 'whatis' command.\n\ By default, the command might produce headers and/or messages indicating\n\ why no %s can be printed.\n\ -The flag -q disables the production of these headers and messages."), - prefix, entity_kind, entity_kind, entity_kind); +The flag -q disables the production of these headers and messages.%s"), + prefix, entity_kind, entity_kind, entity_kind, + (document_n_flag ? _("\n\ +By default, the command will include non-debug symbols in the output;\n\ +these can be excluded using the -n flag.") : "")); } /* See documentation in cli-utils.h. */ @@ -435,58 +439,3 @@ validate_flags_qcs (const char *which_command, qcs_flags *flags) error (_("%s: -c and -s are mutually exclusive"), which_command); } -/* The options used by the 'info variables' commands and similar. */ - -static const gdb::option::option_def info_print_options_defs[] = { - gdb::option::boolean_option_def { - "q", - [] (info_print_options *opt) { return &opt->quiet; }, - nullptr, /* show_cmd_cb */ - nullptr /* set_doc */ - }, - - gdb::option::string_option_def { - "t", - [] (info_print_options *opt) { return &opt->type_regexp; }, - nullptr, /* show_cmd_cb */ - nullptr /* set_doc */ - } -}; - -/* Returns the option group used by 'info variables' and similar. */ - -static gdb::option::option_def_group -make_info_print_options_def_group (info_print_options *opts) -{ - return {{info_print_options_defs}, opts}; -} - -/* See documentation in cli-utils.h. */ - -void -extract_info_print_options (info_print_options *opts, - const char **args) -{ - auto grp = make_info_print_options_def_group (opts); - gdb::option::process_options - (args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); - 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); -} diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index 17cdd84..cbe8ff6 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -47,38 +47,6 @@ extern int get_number (char **); error instead of returning 0. */ extern ULONGEST get_ulongest (const char **pp, int trailer = '\0'); -/* Structure to hold the values of the options used by the 'info - variables' command and other similar commands. These correspond to the - -q and -t options. */ - -struct info_print_options -{ - int quiet = false; - char *type_regexp = nullptr; - - ~info_print_options () - { - xfree (type_regexp); - } -}; - -/* Extract options from ARGS for commands like 'info variables', placing - the options into OPTS. ARGS is updated to point to the first character - after the options, or, if there is nothing after the options, then ARGS - is set to nullptr. */ - -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. */ @@ -87,10 +55,13 @@ extern void report_unrecognized_option_error (const char *command, /* Builds the help string for a command documented by PREFIX, - followed by the extract_info_print_args help for ENTITY_KIND. */ + followed by the extract_info_print_args help for ENTITY_KIND. If + DOCUMENT_N_FLAG is true then help text descibing the -n flag is also + included. */ const char *info_print_args_help (const char *prefix, - const char *entity_kind); + const char *entity_kind, + bool document_n_flag); /* Parse a number or a range. A number will be of the form handled by get_number. -- cgit v1.1