I was wondering if it is possible to use gdb print command to evaluate results of c++ template functions. In the following code with a simple id function, I tried to print results of id(x), but it's as if id or id<t> never existed. The code I use is below, compiled with g++ -std=c++11 -g test7.cpp:
template<typename T>
T id(T x) {return x;}
int main() {
int i = 0;
i = i + 1;
}
In GDB, I tried to print as follows:
Breakpoint 1, main () at test7.cpp:6
6 i = i + 1;
(gdb) print i
$1 = 0
(gdb) print id(i)
No symbol "id" in current context.
(gdb) print id<int>(i)
No symbol "id<int>" in current context.
As you can see, I always get "No symbol id".
There is a related post about GDB not allowing stepping into template functions in OSX. In the answers there, the template function can at least be disassembled. In my case, even disassemble gives nothing:
(gdb) disassemble id<int>
No symbol "id<int>" in current context.
Is it possible to evaluate template functions at all?
P.S. I am using GDB 7.6.1 coming from TDM-GCC (4.8.1-2).
Thanks.