aboutsummaryrefslogtreecommitdiff
path: root/gdb/completer.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-12-27 18:31:09 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2020-03-19 08:23:30 +0000
commit19a2740f7f2ea0f65745a3c00cf8a64647378aa3 (patch)
treed391f702c3054eb50db729a7936908ff2ef1b72d /gdb/completer.c
parent724fd9ba432a20ef2e3f2c0d6060bff131226816 (diff)
downloadgdb-19a2740f7f2ea0f65745a3c00cf8a64647378aa3.zip
gdb-19a2740f7f2ea0f65745a3c00cf8a64647378aa3.tar.gz
gdb-19a2740f7f2ea0f65745a3c00cf8a64647378aa3.tar.bz2
gdb: Remove C++ symbol aliases from completion list
Consider debugging the following C++ program: struct object { int a; }; typedef object *object_p; static int get_value (object_p obj) { return obj->a; } int main () { object obj; obj.a = 0; return get_value (&obj); } Now in a GDB session: (gdb) complete break get_value break get_value(object*) break get_value(object_p) Or: (gdb) break get_va<TAB> (gdb) break get_value(object<RETURN> Function "get_value(object" not defined. Make breakpoint pending on future shared library load? (y or [n]) n The reason this happens is that we add completions based on the msymbol names and on the symbol names. For C++ both of these names include the parameter list, however, the msymbol names have some differences from the symbol names, for example: + typedefs are resolved, + whitespace rules are different around pointers, + the 'const' keyword is placed differently. What this means is that the msymbol names and symbol names appear to be completely different to GDB's completion tracker, and therefore to readline when it offers the completions. This commit builds on the previous commit which reworked the completion_tracker class. It is now trivial to add a remove_completion member function, this is then used along with cp_canonicalize_string_no_typedefs to remove the msymbol aliases from the completion tracker as we add the symbol names. Now, for the above program GDB only presents a single completion for 'get_value', which is 'get_value(object_p)'. It is still possible to reference the symbol using the msymbol name, so a user can manually type out 'break get_value (object *)' if they wish and will get the expected behaviour. I did consider adding an option to make this alias exclusion optional, in the end I didn't bother as I didn't think it would be very useful, but I can easily add such an option if people think it would be useful. gdb/ChangeLog: * completer.c (completion_tracker::remove_completion): Define new function. * completer.h (completion_tracker::remove_completion): Declare new function. * symtab.c (completion_list_add_symbol): Remove aliasing msymbols when adding a C++ function symbol. gdb/testsuite/ChangeLog: * gdb.linespec/cp-completion-aliases.cc: New file. * gdb.linespec/cp-completion-aliases.exp: New file. Change-Id: Ie5c7c9fc8ecf973072cfb4a9650867104bf7f50c
Diffstat (limited to 'gdb/completer.c')
-rw-r--r--gdb/completer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/gdb/completer.c b/gdb/completer.c
index 14c7a57..67dce30 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1678,6 +1678,20 @@ completion_tracker::add_completions (completion_list &&list)
add_completion (std::move (candidate));
}
+/* See completer.h. */
+
+void
+completion_tracker::remove_completion (const char *name)
+{
+ hashval_t hash = htab_hash_string (name);
+ if (htab_find_slot_with_hash (m_entries_hash, name, hash, NO_INSERT)
+ != NULL)
+ {
+ htab_remove_elt_with_hash (m_entries_hash, name, hash);
+ m_lowest_common_denominator_valid = false;
+ }
+}
+
/* Helper for the make_completion_match_str overloads. Returns NULL
as an indication that we want MATCH_NAME exactly. It is up to the
caller to xstrdup that string if desired. */