diff options
author | Keith Seitz <keiths@redhat.com> | 2022-02-24 16:42:22 -0800 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2022-02-24 16:42:22 -0800 |
commit | 64a9760601d3d8761fcf0aae121e69ca0cae1a9c (patch) | |
tree | 568bdb8fd5255e7824d6912582baf7f7d93e5292 /gdb/testsuite/gdb.cp | |
parent | b05752c223b79f3b42fb2a506377fc12adaf8aeb (diff) | |
download | gdb-64a9760601d3d8761fcf0aae121e69ca0cae1a9c.zip gdb-64a9760601d3d8761fcf0aae121e69ca0cae1a9c.tar.gz gdb-64a9760601d3d8761fcf0aae121e69ca0cae1a9c.tar.bz2 |
Support template lookups in strncmp_iw_with_mode
This patch adds support for wild template parameter list matches, similar
to how ABI tags or function overloads are now handled.
With this patch, users will be able to "gloss over" the details of matching
template parameter lists. This is accomplished by adding (yet more) logic
to strncmp_iw_with_mode to skip parameter lists if none is explicitly given
by the user.
Here's a simple example using gdb.linespec/cpls-ops.exp:
Before
------
(gdb) ptype test_op_call
type = struct test_op_call {
public:
void operator()(void);
void operator()(int);
void operator()(long);
void operator()<int>(int *);
}
(gdb) b test_op_call::operator()
Breakpoint 1 at 0x400583: test_op_call::operator(). (3 locations)
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x400583 in test_op_call::operator()(int)
at cpls-ops.cc:43
1.2 y 0x40058e in test_op_call::operator()()
at cpls-ops.cc:47
1.3 y 0x40059e in test_op_call::operator()(long)
at cpls-ops.cc:51
The breakpoint at test_op_call::operator()<int> was never set.
After
-----
(gdb) b test_op_call::operator()
Breakpoint 1 at 0x400583: test_op_call::operator(). (4 locations)
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x400583 in test_op_call::operator()(int)
at cpls-ops.cc:43
1.2 y 0x40058e in test_op_call::operator()()
at cpls-ops.cc:47
1.3 y 0x40059e in test_op_call::operator()(long)
at cpls-ops.cc:51
1.4 y 0x4008d0 in test_op_call::operator()<int>(int*)
at cpls-ops.cc:57
Similar to how scope lookups work, passing "-qualified" to the break command
will cause a literal lookup of the symbol. In the example immediately above,
this will cause GDB to only find the three non-template functions.
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/templates.cc | 47 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/templates.exp | 67 |
2 files changed, 114 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/templates.cc b/gdb/testsuite/gdb.cp/templates.cc index d5b24af..1b9a2d4 100644 --- a/gdb/testsuite/gdb.cp/templates.cc +++ b/gdb/testsuite/gdb.cp/templates.cc @@ -742,6 +742,34 @@ template<class C> int FunctionArg<C>::method(Empty<void (FunctionArg<C>)> &arg) Empty<void(FunctionArg<int>)> empty; FunctionArg<int> arg; +template <typename T1> +struct Foozle +{ + int x; + T1 t; + template <typename T2> + T2 fogey (T2 plop); +}; + +template <typename T1> +template <typename T2> +T2 Foozle<T1>::fogey (T2 plop) +{ + return plop; +} + +template <typename T> +int operator< (T &lhs, T &rhs) +{ + return 0; +} + +template <typename T> +int operator<< (T &obj, T &val) +{ + return 1; +}; + int main() { int i; @@ -815,5 +843,24 @@ int main() arg.method(empty); + Empty<int> e; + Foozle<int> fzi; + x = fzi.fogey (0); + c = fzi.fogey<char> ('a'); + e = fzi.fogey<Empty<int>> (e); + Foozle<char> fzc; + c = fzc.fogey ('b'); + x = fzc.fogey<int> (0); + e = fzc.fogey<Empty<int>> (e); + Foozle<Empty<int>> fze; + e = fze.fogey (e); + c = fze.fogey<char> ('c'); + x = fze.fogey<int> (0); + + z = e < e; + z += e << e; + z += fzi < fzi; + z += fzi << fzi; + return 0; /* Final breakpoint. */ } diff --git a/gdb/testsuite/gdb.cp/templates.exp b/gdb/testsuite/gdb.cp/templates.exp index 885fb86..a798054 100644 --- a/gdb/testsuite/gdb.cp/templates.exp +++ b/gdb/testsuite/gdb.cp/templates.exp @@ -614,3 +614,70 @@ gdb_test "print Garply<Garply<char> >::garply" \ # Now should work fine gdb_test "break Garply<Garply<char> >::garply" \ "Breakpoint \[0-9\]* at $hex: file .*templates.cc, line.*" + +# +# Template wild-matching tests +# + +# Turn off "ask" when multiple symbols are seen. +gdb_test_no_output "set multiple-symbols all" + +# Test setting breakpoints in a method of all class template instantiations, +# including overloads. +gdb_test "break Foo::foo" "Breakpoint.*at.* \\(3 locations\\)" +foreach t [list "int" "char" "volatile char *"] { + gdb_breakpoint "Foo<$t>::foo (int, $t)" + gdb_breakpoint "Foo::foo (int, $t)" +} + +gdb_test "break Bar::bar" "Breakpoint.*at.* \\(2 locations\\)" +gdb_test "break Bar::bar (int, int)" "Breakpoint.*at.* \\(2 locations\\)" +foreach val [list 1 33] { + gdb_breakpoint "Bar<int, $val>::bar (int, int)" +} + +# Test setting breakpoints in a member function template of a class template, +# including overloads. +gdb_test "break Foozle::fogey" "Breakpoint.*at.* \\(9 locations\\)" \ + "break at template method fogey" +foreach t [list "int" "char" "Empty<int>"] { + gdb_test "break Foozle::fogey ($t)" "Breakpoint.*at.* \\(3 locations\\)" + gdb_test "break Foozle::fogey<$t>" "Breakpoint.*at.* \\(3 locations\\)" + foreach u [list "int" "char" "Empty<int>"] { + gdb_breakpoint "Foozle<$t>::fogey<$u>" message + gdb_breakpoint "Foozle<$t>::fogey<$u> ($u)" message + } +} + +# Test templated operators < and <<. Restrict results to only the test +# source file. +# operator<: +# 1. operator< (const T2&, const T2&) +# 2. operator< (const T2&, char) +# 3. operator< <Empty<int>> +# 4. operator< <Foozle<in>> +# +# operator<<: +# 1. operator<< <Empty<int>> +# 2. operator<< <Foozle<int>> +gdb_test "break -source $srcfile -func operator<" \ + "Breakpoint.*at.* \\(4 locations\\)" +gdb_test "break -source $srcfile -func operator<<" \ + "Breakpoint.*at.* \\(2 locations\\)" +foreach t [list "Empty" "Foozle"] { + set tt "$t<int>" + gdb_breakpoint "operator< <$tt>" message + gdb_breakpoint "operator<< <$tt>" message + + # Try a specific instance, both with and without whitespace + # after the template-template parameter. + gdb_breakpoint "operator< <$tt> ($tt&, $tt&)" message + gdb_breakpoint "operator< <$tt > ($tt&, $tt&)" message + gdb_breakpoint "operator<< <$tt> ($tt&, $tt&)" message + gdb_breakpoint "operator<< <$tt > ($tt&, $tt&)" message +} + +# Test that "-qualified" finds no matching locations. +gdb_test_no_output "set breakpoint pending off" +gdb_test "break -qualified Foozle::fogey" \ + "Function \"Foozle::fogey\" not defined." |