To set a breakpoint for all instances, use:
gdb> rbreak Foo<.*>
To set only a breakpoint in a known instance
gdb> break Foo<int>
You can also use rbreak Foo<int> , but it doesn't make sense to use a call that evaluates regular expressions, but you don't give it rbreak Foo<int>
Code example:
#include <iostream> #include <string> template < typename T> T Foo(T t) { return t; } int main() { std::cout << Foo<int>(1) << std::endl; std::cout << Foo<std::string>("Hallo") << std::endl; }
Just compile with debug info:
g++ main.cpp -g -o go
Run gdb:
gdb go
And the test:
gdb> rbreak Foo<int> gdb> run gdb> backtrace gdb> cont
As you can see: only one instance of the template is affected.
In the opposite direction, you can see which instance of the template is being called:
#0 Foo<int> (t=1) at main.cpp:5 #1 0x0000000000400b69 in main () at main.cpp:9
As you can see, here is Foo<int> .
Klaus source share