我最近通过MacPorts在我的OS X 10.7系统上安装了GCC 4.7.3和GDB 7.6,以便能够编译C++ 11代码.我不能使用Apple的自制clang ++和gdb,因为它不允许我正确调试标准模板库代码(例如,如果我取消引用列表迭代器,程序崩溃).
现在,通过新的GCC/GDB组合,我在进入函数时遇到了一些奇怪的问题.拿这个最小的例子:
#include <stdio.h>
class A {
public:
virtual void testMethod() {
printf("test in A\n");
}
};
void test(A &a) {
printf("asdf\n");
a.testMethod(); // here, stepping works with -std=c++11
}
int main() {
A a;
a.testMethod();
test(a);
a.testMethod();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我编译代码g++ -O0 -ggdb test.cpp,GDB根本不会介入A::testMethod.我可以通过指定内部的代码行来设置断点A::testMethod,但不能通过指定方法名称(b A::testMethod())来设置断点.
更奇怪的是,如果我编译,如果g++ -O0 -ggdb -std=c++11 test.cpp从中调用,GDB会进入testMethod void test().从主要的,踩踏仍然不起作用.但是,现在,我可以通过仅指定方法名称来设置断点.
此外,一旦我在GDB中启动程序,我就会收到GDB警告,如相关问题中所述.无论是否指定,都会显示这些警告-std=c++11.
warning: Could not …Run Code Online (Sandbox Code Playgroud)