diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-12-27 18:31:09 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-03-19 08:23:30 +0000 |
commit | 19a2740f7f2ea0f65745a3c00cf8a64647378aa3 (patch) | |
tree | d391f702c3054eb50db729a7936908ff2ef1b72d /gdb/testsuite | |
parent | 724fd9ba432a20ef2e3f2c0d6060bff131226816 (diff) | |
download | gdb-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/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.linespec/cp-completion-aliases.cc | 73 | ||||
-rw-r--r-- | gdb/testsuite/gdb.linespec/cp-completion-aliases.exp | 54 |
3 files changed, 132 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0588fe6..6574270e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-19 Andrew Burgess <andrew.burgess@embecosm.com> + + * gdb.linespec/cp-completion-aliases.cc: New file. + * gdb.linespec/cp-completion-aliases.exp: New file. + 2020-03-19 Tom de Vries <tdevries@suse.de> * gdb.opt/inline-locals.exp: Add kfail PR number. Make kfail matching diff --git a/gdb/testsuite/gdb.linespec/cp-completion-aliases.cc b/gdb/testsuite/gdb.linespec/cp-completion-aliases.cc new file mode 100644 index 0000000..5f2fb5c --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cp-completion-aliases.cc @@ -0,0 +1,73 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <cstring> + +template<typename T> +struct magic +{ + T x; +}; + +struct object +{ + int a; +}; + +typedef magic<int> int_magic_t; + +typedef object *object_p; + +typedef const char *my_string_t; + +static int +get_value (object_p obj) +{ + return obj->a; +} + +static int +get_something (object_p obj) +{ + return obj->a; +} + +static int +get_something (my_string_t msg) +{ + return strlen (msg); +} + +static int +grab_it (int_magic_t *var) +{ + return var->x; +} + +int +main () +{ + magic<int> m; + m.x = 4; + + object obj; + obj.a = 0; + + int val = (get_value (&obj) + get_something (&obj) + + get_something ("abc") + grab_it (&m)); + return val; +} diff --git a/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp b/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp new file mode 100644 index 0000000..313ff84 --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cp-completion-aliases.exp @@ -0,0 +1,54 @@ +# Copyright 2019-2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file tests GDB's ability to remove symbol aliases from the +# completion list in C++. + +load_lib completion-support.exp + +standard_testfile .cc + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} { + return -1 +} + +# Tests below are about tab-completion, which doesn't work if readline +# library isn't used. Check it first. + +if { ![readline_is_used] } { + untested "no tab completion support without readline" + return -1 +} + +# Disable the completion limit for the whole testcase. +gdb_test_no_output "set max-completions unlimited" + +test_gdb_complete_tab_unique "break get_v" \ + "break get_value\\(object_p\\)" " " + +test_gdb_complete_cmd_unique "break get_v" \ + "break get_value\\(object_p\\)" + +test_gdb_complete_tab_unique "break gr" \ + "break grab_it\\(int_magic_t\\*\\)" " " + +test_gdb_complete_cmd_unique "break gr" \ + "break grab_it\\(int_magic_t\\*\\)" + +test_gdb_complete_tab_multiple "break get_som" "ething(" \ + { "get_something(my_string_t)" "get_something(object_p)" } + +test_gdb_complete_cmd_multiple "break " "get_som" \ + { "get_something(my_string_t)" "get_something(object_p)" } |