开发者

debugging templates with GDB

My gdb is GNU gdb Red Hat Linux (6.3.0.0-1.162.el4rh) and I can't debug templates. How can I debug te开发者_StackOverflow中文版mplates with this debugger?


if your problem is just about placing breakpoint in your code. Here is a little snippet

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
... debugging start

otherwise you could just use

(gdb) b main.cpp:16


I was having a hard time trying to get gdb debugging to work with templates code using gdb 6.8 with code compiled with gcc version 4.4.1

After ripping my hair for a while, I found that it magically started working perfectly when I add the -fPIC switch to the g++ compile arguments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜