开发者

C/C++ mixed programming: gdb segmentation fault frequently

I always meet gdb crash when I try to print a definitely valid structure/variable. And it often crash if I tried to call another function in gdb. I found this could happen only if the code is C/C++ mixed.

For example,

%> p anotherFunction()
Segmentation fault

Here is a small example which is my typical scenario:

example.cc:

class foo(){
    public void bar();
};

void foo::bar(){
    int i=12345;
    printf("%d", i);
}

foo * pfoo;

extern "C" call_foo(){
     pfoo = new foo();
     pfoo->bar();
}

in the example, if I stop at the printf and try to execute "p i" in gdb, it will leads to crash.

Please note this is just an example, please don't look for bug in the example. Such crash happens everywhere but sometime everything is OK.

I guess this is because I debugged from C code (call_foo in this example) to C++ code and gdb has some problem to switch the context.

Please help if you have any idea. It really affects my productivity much :(....

BTW, I already tried different version of gdb. It seems the problem exists in each version include the latest one. And I have also tried purify/valgrind to verify my programs and 开发者_如何学JAVAI did't see any error with the program.


Any crash in GDB is a bug in GDB. Please file the bugs in GDB bugzilla.

If multiple versions of GDB crash on your example, the problem may be with your compiler (but even then GDB should not crash).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜