【发布时间】:2015-07-25 04:44:14
【问题描述】:
在成功使用 x86 GDB 15 年后,第一次尝试在四核 Xeon 上进行调试。
Linux DellT3500 3.16.0-23-generic #31-Ubuntu SMP Tue Oct 21 17:56:17 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvs
g++ 编译器标志:
-Wall -Wwrite-strings -Wchar-subscripts -Wparentheses -gstabs+ -DLINUX -O0
在某个类成员函数中设置断点在断点发生时显示this=0x0和其他参数错误。但是在代码中插入一个 printf 表明 this 和参数实际上设置正确:
Breakpoint 1, PlayGamePage::actionPerformed (this=0x0, inTarget=0x7fffffffdf90)
at PlayGamePage.cpp:725
725 printf( "hey, this = %x, inTarget = %x\n", this );
(gdb) next
hey, this = b6cc50, inTarget = b6ce18
727 if( inTarget == &mCommitButton &&
(gdb) print this
$1 = (PlayGamePage * const) 0x0
(gdb) print inTarget
$2 = (GUIComponent *) 0x7fffffffdf90
(gdb)
但是您可以看到 GDB 甚至无法正确打印这些值,即使它们是由带有 printf 的代码设置和打印的。这是一个大问题,因为 GDB 无法访问打印成员变量。
此外,函数体的其余部分广泛使用 this 和 inTarget(访问类成员和测试 inTarget),并且代码按预期运行。没有崩溃或错误行为,因此在代码中设置正确,但 GDB 看不到。
上栈:
(gdb) up
#1 0x000000000040a11f in ActionListenerList::fireActionPerformed (
this=0xb6cf98, inTarget=0xb6cf48)
at ../../minorGems/ui/event/ActionListenerList.h:134
134 listener->actionPerformed( inTarget );
看到 inTarget 匹配 printf 在 actionPerformed 函数体中看到的内容。此外,此时 gdb 可以很好地打印这些值:
(gdb) print inTarget
$5 = (GUIComponent *) 0xb6cf48
(gdb) print listener
$6 = (ActionListener *) 0xb6ce18
listener 应该匹配函数体中的 this,它根据 printf 执行,但 gdb 看到的是 this=0x0。
是的,这是一个被调用的虚函数(PlayGamePage 实现了 ActionListener 接口,覆盖了 actionPerformed 虚函数)。
我刚刚在 32 位 x86 上的 GDB 中完全相同的代码中放置了一个断点,它可以正确地看到 this 和 inTarget 并且可以正确打印它们,其值与代码的 printf 显示的值匹配。
【问题讨论】: