diff -urpN src/gdb/linespec.c dev/gdb/linespec.c --- src/gdb/linespec.c 2008-01-01 23:53:11.000000000 +0100 +++ dev/gdb/linespec.c 2008-01-08 15:33:48.000000000 +0100 @@ -36,6 +36,7 @@ #include "linespec.h" #include "exceptions.h" #include "language.h" +#include "gdbcmd.h" /* We share this one with symtab.c, but it is not exported widely. */ @@ -140,6 +141,16 @@ static struct symtabs_and_lines minsym_found (int funfirstline, struct minimal_symbol *msymbol); +static int symbol_user_choice = 0; + +static void +show_symbol_user_choice (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("User choice for multiple symbols is %s.\n"), + value); +} + /* Helper functions. */ /* Issue a helpful hint on using the command completion feature on @@ -1725,9 +1736,35 @@ decode_variable (char *copy, int funfirs struct symbol *sym; /* The symtab that SYM was found in. */ struct symtab *sym_symtab; - struct minimal_symbol *msymbol; + if (symbol_user_choice && !file_symtab) + { + int nelts; + struct symbol_search *symbols, *p; + struct cleanup *chain; + struct symbol **sym_arr; + + search_symbols (copy, FUNCTIONS_DOMAIN, 0, (char **) NULL, &symbols); + chain = make_cleanup_free_search_symbols (symbols); + + nelts = count_symbols (symbols); + if (nelts) + { + int idx = 0; + sym_arr = xmalloc ((nelts) * sizeof (struct symbol *)); + make_cleanup (xfree, sym_arr); + + for (p = symbols; p != NULL; p = p->next) + if (p->symbol) + sym_arr[idx++] = p->symbol; + + return decode_line_2 (sym_arr, idx, funfirstline, + canonical); + } + } + + sym = lookup_symbol (copy, (file_symtab ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), @@ -1856,3 +1893,18 @@ minsym_found (int funfirstline, struct m values.nelts = 1; return values; } + + +void +_initialize_linespec (void) +{ + + /* Toggle wheter or not to let the user choose multiple defined symbols. */ + add_setshow_boolean_cmd ("symbol-user-choice", class_support, + &symbol_user_choice, + _("Set whether the user is to choose a symbol when multiple symbols are defined."), + _("Show whether the user is to choose a symbol when multiple symbols are defined."), + _("Use \"on\" to let the user choose a symbol when multiple symbols are defined. Use \"off\" to pick the first of those symbols by default."), + NULL, show_symbol_user_choice, &setlist, &showlist); + +} diff -urpN src/gdb/Makefile.in dev/gdb/Makefile.in --- src/gdb/Makefile.in 2008-01-08 11:22:24.000000000 +0100 +++ dev/gdb/Makefile.in 2008-01-08 15:33:48.000000000 +0100 @@ -2331,7 +2331,7 @@ libunwind-frame.o: libunwind-frame.c $(d $(gdb_string_h) $(libunwind_frame_h) $(complaints_h) linespec.o: linespec.c $(defs_h) $(symtab_h) $(frame_h) $(command_h) \ $(symfile_h) $(objfiles_h) $(source_h) $(demangle_h) $(value_h) \ - $(completer_h) $(cp_abi_h) $(parser_defs_h) $(block_h) \ + $(completer_h) $(cp_abi_h) $(parser_defs_h) $(block_h) $(gdbcmd_h)\ $(objc_lang_h) $(linespec_h) $(exceptions_h) $(language_h) linux-fork.o: linux-fork.c $(defs_h) $(inferior_h) $(regcache_h) $(gdbcmd_h) \ $(infcall_h) $(gdb_assert_h) $(gdb_string_h) $(linux_fork_h) \ diff -urpN src/gdb/symtab.c dev/gdb/symtab.c --- src/gdb/symtab.c 2008-01-03 22:30:13.000000000 +0100 +++ dev/gdb/symtab.c 2008-01-08 15:33:48.000000000 +0100 @@ -2778,6 +2778,21 @@ file_matches (char *file, char *files[], return 0; } + +/* Returns number of elements in search reusult SYMBOLS. */ + +int +count_symbols (struct symbol_search *symbols) +{ + struct symbol_search *p; + int nr = 0; + + for (p = symbols; p != NULL; p = p->next) + nr++; + + return nr; +} + /* Free any memory associated with a search. */ void free_search_symbols (struct symbol_search *symbols) diff -urpN src/gdb/symtab.h dev/gdb/symtab.h --- src/gdb/symtab.h 2008-01-01 23:53:13.000000000 +0100 +++ dev/gdb/symtab.h 2008-01-08 15:33:48.000000000 +0100 @@ -1385,6 +1385,7 @@ struct symbol_search extern void search_symbols (char *, domain_enum, int, char **, struct symbol_search **); +extern int count_symbols (struct symbol_search *); extern void free_search_symbols (struct symbol_search *); extern struct cleanup *make_cleanup_free_search_symbols (struct symbol_search *);