From: Joel Brobecker Date: Thu, 3 Apr 2008 21:39:16 +0000 (+0000) Subject: * symtab.c (multiple_symbols_ask, multiple_symbols_all) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=717d2f5a05d436766fb431411e7768a2886bca42;p=binutils-gdb.git * symtab.c (multiple_symbols_ask, multiple_symbols_all) (multiple_symbols_cancel): New constants. (multiple_symbols_modes, multiple_symbols_mode): New static globals. (multiple_symbols_select_mode): New function. (_initialize_symtab): Add new set/show multiple-symbols commands. * symtab.h (multiple_symbols_ask, multiple_symbols_all) (multiple_symbols_cancel, multiple_symbols_select_mode): Declare. * ada-lang.c (user_select_syms): Add handling of new multiple-symbols setting. * linespec.c (decode_line_2): Likewise. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5c30714640a..e47a277f609 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2008-04-03 Joel Brobecker + + * symtab.c (multiple_symbols_ask, multiple_symbols_all) + (multiple_symbols_cancel): New constants. + (multiple_symbols_modes, multiple_symbols_mode): New static globals. + (multiple_symbols_select_mode): New function. + (_initialize_symtab): Add new set/show multiple-symbols commands. + * symtab.h (multiple_symbols_ask, multiple_symbols_all) + (multiple_symbols_cancel, multiple_symbols_select_mode): Declare. + * ada-lang.c (user_select_syms): Add handling of new multiple-symbols + setting. + * linespec.c (decode_line_2): Likewise. + 2008-04-03 Doug Evans * symtab.h (enum free_code): Delete free_contents, unused. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 2f0f55f5fb8..6e829f057d2 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3312,12 +3312,24 @@ user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results) int *chosen = (int *) alloca (sizeof (int) * nsyms); int n_chosen; int first_choice = (max_results == 1) ? 1 : 2; + const char *select_mode = multiple_symbols_select_mode (); if (max_results < 1) error (_("Request to select 0 symbols!")); if (nsyms <= 1) return nsyms; + if (select_mode == multiple_symbols_cancel) + error (_("\ +canceled because the command is ambiguous\n\ +See set/show multiple-symbol.")); + + /* If select_mode is "all", then return all possible symbols. + Only do that if more than one symbol can be selected, of course. + Otherwise, display the menu as usual. */ + if (select_mode == multiple_symbols_all && max_results > 1) + return nsyms; + printf_unfiltered (_("[0] cancel\n")); if (max_results > 1) printf_unfiltered (_("[1] all\n")); diff --git a/gdb/linespec.c b/gdb/linespec.c index b3a46b46a23..f78a681406d 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -491,7 +491,13 @@ decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline, char *symname; struct cleanup *old_chain; char **canonical_arr = (char **) NULL; + const char *select_mode = multiple_symbols_select_mode (); + if (select_mode == multiple_symbols_cancel) + error (_("\ +canceled because the command is ambiguous\n\ +See set/show multiple-symbol.")); + values.sals = (struct symtab_and_line *) alloca (nelts * sizeof (struct symtab_and_line)); return_values.sals = (struct symtab_and_line *) @@ -507,38 +513,52 @@ decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline, } i = 0; - printf_unfiltered (_("[0] cancel\n[1] all\n")); while (i < nelts) { init_sal (&return_values.sals[i]); /* Initialize to zeroes. */ init_sal (&values.sals[i]); if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) - { - values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline); - if (values.sals[i].symtab) - printf_unfiltered ("[%d] %s at %s:%d\n", - (i + 2), - SYMBOL_PRINT_NAME (sym_arr[i]), - values.sals[i].symtab->filename, - values.sals[i].line); - else - printf_unfiltered (_("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n"), - (i + 2), - SYMBOL_PRINT_NAME (sym_arr[i]), - values.sals[i].line); - - } - else - printf_unfiltered (_("?HERE\n")); + values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline); i++; } - prompt = getenv ("PS2"); - if (prompt == NULL) + /* If select_mode is "all", then do not print the multiple-choice + menu and act as if the user had chosen choice "1" (all). */ + if (select_mode == multiple_symbols_all) + args = "1"; + else { - prompt = "> "; + i = 0; + printf_unfiltered (_("[0] cancel\n[1] all\n")); + while (i < nelts) + { + if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) + { + if (values.sals[i].symtab) + printf_unfiltered ("[%d] %s at %s:%d\n", + (i + 2), + SYMBOL_PRINT_NAME (sym_arr[i]), + values.sals[i].symtab->filename, + values.sals[i].line); + else + printf_unfiltered (_("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n"), + (i + 2), + SYMBOL_PRINT_NAME (sym_arr[i]), + values.sals[i].line); + + } + else + printf_unfiltered (_("?HERE\n")); + i++; + } + + prompt = getenv ("PS2"); + if (prompt == NULL) + { + prompt = "> "; + } + args = command_line_input (prompt, 0, "overload-choice"); } - args = command_line_input (prompt, 0, "overload-choice"); if (args == 0 || *args == 0) error_no_arg (_("one or more choice numbers")); diff --git a/gdb/symtab.c b/gdb/symtab.c index ddd2310165d..aa401ad034e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -124,6 +124,30 @@ void _initialize_symtab (void); /* */ +/* Allow the user to configure the debugger behavior with respect + to multiple-choice menus when more than one symbol matches during + a symbol lookup. */ + +const char const multiple_symbols_ask[] = "ask"; +const char const multiple_symbols_all[] = "all"; +const char const multiple_symbols_cancel[] = "cancel"; +static const char *multiple_symbols_modes[] = +{ + multiple_symbols_ask, + multiple_symbols_all, + multiple_symbols_cancel, + NULL +}; +static const char *multiple_symbols_mode = multiple_symbols_all; + +/* Read-only accessor to AUTO_SELECT_MODE. */ + +const char * +multiple_symbols_select_mode (void) +{ + return multiple_symbols_mode; +} + /* The single non-language-specific builtin type */ struct type *builtin_type_error; @@ -4422,6 +4446,15 @@ All global and static variable names, or those matching REGEXP.")); All global and static variable names, or those matching REGEXP.")); } + add_setshow_enum_cmd ("multiple-symbols", no_class, + multiple_symbols_modes, &multiple_symbols_mode, + _("\ +Set the debugger behavior when more than one symbol are possible matches\n\ +in an expression."), _("\ +Show how the debugger handles ambiguities in expressions."), _("\ +Valid values are \"ask\", \"all\", \"cancel\", and the default is \"all\"."), + NULL, NULL, &setlist, &showlist); + /* Initialize the one built-in type that isn't language dependent... */ builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "", (struct objfile *) NULL); diff --git a/gdb/symtab.h b/gdb/symtab.h index 9fec2e79fb3..65b1cb4edf1 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -998,6 +998,12 @@ extern int asm_demangle; /* symtab.c lookup functions */ +extern const char const multiple_symbols_ask[]; +extern const char const multiple_symbols_all[]; +extern const char const multiple_symbols_cancel[]; + +const char *multiple_symbols_select_mode (void); + /* lookup a symbol table by source file name */ extern struct symtab *lookup_symtab (const char *);