Currently "b foo[TAB]" offers data symbols as completion candidates.
This doesn't make sense, since you can't set a breakpoint on data
symbols, only on code symbols.
(gdb) b globa[TAB]
(gdb) b global [ENTER]
Function "global" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) info symbol global
global in section .rodata
So this patch makes linespec completion ignore data symbols.
gdb/ChangeLog:
2017-11-08 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_make_symbol_completion_list): Use
completion_skip_symbol.
* symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
(symbol_is_function_or_method(symbol*)): New.
(add_symtab_completions): Add complete_symbol_mode parameter. Use
completion_skip_symbol.
(default_collect_symbol_completion_matches_break_on): Use
completion_skip_symbol. Pass down mode.
(collect_file_symbol_completion_matches): Pass down mode.
* symtab.h (symbol_is_function_or_method): New declarations.
(completion_skip_symbol): New template function.
2017-11-08 Pedro Alves <palves@redhat.com>
+ * ada-lang.c (ada_make_symbol_completion_list): Use
+ completion_skip_symbol.
+ * symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
+ (symbol_is_function_or_method(symbol*)): New.
+ (add_symtab_completions): Add complete_symbol_mode parameter. Use
+ completion_skip_symbol.
+ (default_collect_symbol_completion_matches_break_on): Use
+ completion_skip_symbol. Pass down mode.
+ (collect_file_symbol_completion_matches): Pass down mode.
+ * symtab.h (symbol_is_function_or_method): New declarations.
+ (completion_skip_symbol): New template function.
+
+2017-11-08 Pedro Alves <palves@redhat.com>
+
* linespec.c (iterate_over_all_matching_symtabs): Add
search_domain parameter. Pass it down to expand_symtabs_matching.
(decode_objc): Request FUNCTIONS_DOMAIN symbols only.
{
QUIT;
+ if (completion_skip_symbol (mode, msymbol))
+ continue;
+
completion_list_add_name (tracker,
MSYMBOL_LANGUAGE (msymbol),
MSYMBOL_LINKAGE_NAME (msymbol),
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
+ if (completion_skip_symbol (mode, sym))
+ continue;
+
completion_list_add_name (tracker,
SYMBOL_LANGUAGE (sym),
SYMBOL_LINKAGE_NAME (sym),
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
+ if (completion_skip_symbol (mode, sym))
+ continue;
+
completion_list_add_name (tracker,
SYMBOL_LANGUAGE (sym),
SYMBOL_LINKAGE_NAME (sym),
continue;
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
+ if (completion_skip_symbol (mode, sym))
+ continue;
+
completion_list_add_name (tracker,
SYMBOL_LANGUAGE (sym),
SYMBOL_LINKAGE_NAME (sym),
}
}
+/* See symtab.h. */
+
+bool
+symbol_is_function_or_method (symbol *sym)
+{
+ switch (TYPE_CODE (SYMBOL_TYPE (sym)))
+ {
+ case TYPE_CODE_FUNC:
+ case TYPE_CODE_METHOD:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* See symtab.h. */
+
+bool
+symbol_is_function_or_method (minimal_symbol *msymbol)
+{
+ switch (MSYMBOL_TYPE (msymbol))
+ {
+ case mst_text:
+ case mst_text_gnu_ifunc:
+ case mst_solib_trampoline:
+ case mst_file_text:
+ return true;
+ default:
+ return false;
+ }
+}
+
/* Add matching symbols from SYMTAB to the current completion list. */
static void
add_symtab_completions (struct compunit_symtab *cust,
completion_tracker &tracker,
+ complete_symbol_mode mode,
const lookup_name_info &lookup_name,
const char *text, const char *word,
enum type_code code)
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), i);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
+ if (completion_skip_symbol (mode, sym))
+ continue;
+
if (code == TYPE_CODE_UNDEF
|| (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
&& TYPE_CODE (SYMBOL_TYPE (sym)) == code))
{
QUIT;
+ if (completion_skip_symbol (mode, msymbol))
+ continue;
+
completion_list_add_msymbol (tracker, msymbol, lookup_name,
sym_text, word);
/* Add completions for all currently loaded symbol tables. */
ALL_COMPUNITS (objfile, cust)
- add_symtab_completions (cust, tracker, lookup_name,
+ add_symtab_completions (cust, tracker, mode, lookup_name,
sym_text, word, code);
/* Look through the partial symtabs for all symbols which begin by
[&] (compunit_symtab *symtab) /* expansion notify */
{
add_symtab_completions (symtab,
- tracker, lookup_name,
+ tracker, mode, lookup_name,
sym_text, word, code);
},
ALL_DOMAIN);
iterate_over_symtabs (srcfile, [&] (symtab *s)
{
add_symtab_completions (SYMTAB_COMPUNIT (s),
- tracker, lookup_name,
+ tracker, mode, lookup_name,
sym_text, word, TYPE_CODE_UNDEF);
return false;
});
extern completion_list
make_source_files_completion_list (const char *, const char *);
+/* Return whether SYM is a function/method, as opposed to a data symbol. */
+
+extern bool symbol_is_function_or_method (symbol *sym);
+
+/* Return whether MSYMBOL is a function/method, as opposed to a data
+ symbol */
+
+extern bool symbol_is_function_or_method (minimal_symbol *msymbol);
+
+/* Return whether SYM should be skipped in completion mode MODE. In
+ linespec mode, we're only interested in functions/methods. */
+
+template<typename Symbol>
+static bool
+completion_skip_symbol (complete_symbol_mode mode, Symbol *sym)
+{
+ return (mode == complete_symbol_mode::LINESPEC
+ && !symbol_is_function_or_method (sym));
+}
+
/* symtab.c */
int matching_obj_sections (struct obj_section *, struct obj_section *);