views:

300

answers:

1

Hi all. My gdb is GNU gdb Red Hat Linux (6.3.0.0-1.162.el4rh). And I can't debug templates. Can anybody help me? How can I debug templates with this debugger? Thanks.

+3  A: 

if your problem is just about placing breakpoint in your code. here is a little snipet

ex: main.cpp

#include <iostream>

template <typename T>
void coin(T v)
{
    std::cout << v << std::endl;
}

template<typename T>
class Foo
{
public:

    T bar(T c)
    {
        return c * 2;
    }
};

int main(int argc, char** argv)
{
    Foo<int> f;
    coin(f.bar(21));
}

compile with g++ -O0 -g main.cpp

gdb ./a.out
(gdb) b Foo<int>::bar(int)
Breakpoint 2 at 0x804871d: file main.cpp, line 16.
(gdb) b void coin<int>(int)
Breakpoint 1 at 0x804872a: file main.cpp, line 6.
(gdb) r
... debuging start

otherwise you could just use

(gdb) b main.cpp:16
chub