我最近通过 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;
}
如果我用 编译代码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 open OSO archive file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/./gcc/libgcc_eh.a"
warning: Could not open OSO archive file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/../libsupc++/.libs/libsupc++convenience.a"
warning: Could not open OSO archive file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/../src/c++11/.libs/libc++11convenience.a"
warning: Could not open OSO archive file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/../src/c++98/.libs/libc++98convenience.a"
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-atomic-c++0x.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-c++0x.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list-2.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-thread-c++0x.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc49/libstdcxx-devel/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/_muldi3_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/addtf3_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/darwin-64_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/divtf3_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/emutls_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/enable-execute-stack_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/eqtf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/extenddftf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/extendsftf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/extendxftf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixtfdi_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixtfsi_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixtfti_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixunstfdi_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixunstfsi_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/fixunstfti_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floatditf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floatsitf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floattitf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floatunditf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floatunsitf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/floatuntitf_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/getf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/letf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/multf3_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/negtf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/subtf3_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/trunctfdf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/trunctfsf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/trunctfxf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/unordtf2_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/unwind-c_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/unwind-dw2-fde-darwin_s.o': can't open to read symbols: No such file or directory.
warning: `/opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libgcc/unwind-dw2_s.o': can't open to read symbols: No such file or directory.
我知道以下问题:
调试问题、
奇怪的 GDB 消息、
GDB 错误消息、
GDB 在 Mountain Lion 上失败,但他们没有帮助我。指定-gdwarf-2 -gstrict-dwarf
也无济于事。
-EDIT- 的输出nm
在两种情况下都是相同的:
0000000100001068 s GCC_except_table0
00000001000010c0 S _NXArgc
00000001000010c8 S _NXArgv
U __Unwind_Resume
0000000100000e34 T __Z4testR1A
0000000100000eae T __ZN1A10testMethodEv
00000001000010b0 S __ZTI1A
0000000100000f1d S __ZTS1A
0000000100001090 S __ZTV1A
U __ZTVN10__cxxabiv117__class_type_infoE
U ___gxx_personality_v0
00000001000010d8 S ___progname
0000000100000000 T __mh_execute_header
00000001000010d0 S _environ
U _exit
0000000100000e61 T _main
U _puts
0000000100001000 s _pvars
U dyld_stub_binder
0000000100000df8 T start
有没有人设法让 GCC 4.7 和一些合适的调试器在 OS X Lion 上工作?