From 61d3b7c315f2621f913c28c5d3b2819994d07c12 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 27 May 2020 19:31:48 +0100 Subject: [PATCH 2/2] rough testcase --- .../gdb.linespec/cp-completion-aliases-2.cc | 132 +++++++++++++++++++++ .../gdb.linespec/cp-completion-aliases-2.exp | 64 ++++++++++ 2 files changed, 196 insertions(+) create mode 100644 gdb/testsuite/gdb.linespec/cp-completion-aliases-2.cc create mode 100644 gdb/testsuite/gdb.linespec/cp-completion-aliases-2.exp diff --git a/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.cc b/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.cc new file mode 100644 index 00000000000..cc1eb0505b8 --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.cc @@ -0,0 +1,132 @@ +/* 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 . */ + +#include + +namespace NS1 { + +namespace NS2 { + +struct object +{ + int a; + + object (); +}; + +object::object () +{ +} + +typedef object *object_p; + +typedef const char *my_string_t; + +template +struct magic +{ + T x; + + magic (object_p) + { + } + + template + static void + foo (object_p) + { + } +}; + +template +struct tragic +{ + T t; + U u; + + tragic (object_p) + { + } + + template + static void + foo (object_p) + { + } +}; + +template using partial = tragic; + +typedef partial int_tragic_t; + +typedef magic int_magic_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; +} + +} + +} + +/* These typedefs have the same name as some of the components within + NS1, on purpose, to try to confuse GDB. */ +using NS2 = int; +using object = NS1::NS2::object; +using magic = NS1::NS2::magic; + +NS2 ns2_int = 0; +object o; +magic m (0); +NS1::NS2::int_tragic_t trag (0); + +int +main () +{ + NS1::NS2::magic ns_m (0); + NS1::NS2::magic::foo (0); + NS1::NS2::partial::foo (0); + ns_m.x = 4; + + NS1::NS2::object ns_obj; + ns_obj.a = 0; + + int ns_val = (NS1::NS2::get_value (&ns_obj) + NS1::NS2::get_something (&ns_obj) + + NS1::NS2::get_something ("abc") + NS1::NS2::grab_it (&ns_m)); + + return ns_val; +} diff --git a/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.exp b/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.exp new file mode 100644 index 00000000000..b09cd6490e8 --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cp-completion-aliases-2.exp @@ -0,0 +1,64 @@ +# 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 . + +# 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 +} + +# Disable the completion limit for the whole testcase. +gdb_test_no_output "set max-completions unlimited" + +# This is what I think should happen, but instead, we lose the +# object_p typedef somewhere. +test_gdb_complete_unique \ + "break -q NS1::NS2::get_v" \ + "break -q NS1::NS2::get_value(NS1::NS2::object_p)" + +# Keith's patch fixes this one: +test_gdb_complete_unique \ + "break -q NS1::NS2::magic::mag" \ + "break -q NS1::NS2::magic::magic(NS1::NS2::object*)" + +# This works: +gdb_test "b NS1::NS2::magic::foo(NS1::NS2::object*)" "Breakpoint .* at .*" + +# This works too. Note that there's a "NS2" typedef in the global +# namespace. +gdb_test "b NS1::NS2::magic::foo(NS1::NS2::object*)" "Breakpoint .* at .*" + +# But this does not work with Keith's patch. We never get to replace +# the "NS2" typedef in "foo". +gdb_test "b NS1::NS2::magic::foo(NS1::NS2::object*)" "Breakpoint .* at .*" + +# These work. +gdb_test "b NS1::NS2::tragic::foo(NS1::NS2::object*)" "Breakpoint .* at .*" +gdb_test "b NS1::NS2::tragic::foo(NS1::NS2::object_p)" "Breakpoint .* at .*" + +# These don't work because GDB doesn't understand the partial +# alias template. +gdb_test "b NS1::NS2::partial::foo(NS1::NS2::object*)" "Breakpoint .* at .*" +gdb_test "b NS1::NS2::partial::foo(NS1::NS2::object_p)" "Breakpoint .* at .*" + +# These crash GDB with recursion around "magic". There's a "magic" +# typedef in the global namespace. +gdb_test "b NS1::NS2::grab_it(NS1::NS2::int_magic_t*)" "Breakpoint .* at .*" +gdb_test "b NS1::NS2::grab_it(NS1::NS2::magic*)" "Breakpoint .* at .*" -- 2.14.5