Mac 上的 gcc 4.7.3 和 gdb 7.6 - 奇怪的步进问题
Posted
技术标签:
【中文标题】Mac 上的 gcc 4.7.3 和 gdb 7.6 - 奇怪的步进问题【英文标题】:gcc 4.7.3 and gdb 7.6 on Mac - strange stepping problems 【发布时间】:2013-05-26 06:57:43 【问题描述】:我最近通过 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
编译,如果从void test()
调用,GDB 会进入 testMethod。从主要方面来说,步进仍然不起作用。但是,现在,我可以通过仅指定方法名称来设置断点。
此外,一旦我在 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.
我知道以下问题:
Debugging Problems,
Weird GDB messages,
GDB error message,
GDB fails on Mountain Lion,
但他们没有帮助我。指定 -gdwarf-2 -gstrict-dwarf
也无济于事。
-编辑-
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 上运行?
【问题讨论】:
找到解决方案了吗?我遇到了非常相似的问题 (***.com/questions/22581645/…) 不,对不起。我最终放弃了。 【参考方案1】:我试过这样编译......它工作正常...... 您可以单独尝试使用 -g 选项吗?
例如:g++ -g test.cpp -o test
【讨论】:
不幸的是,这无济于事。结果与使用 -ggdb 编译时相同。你是如何安装 GCC/GDB 的? 对不起....我在 GCC 4.5.3 中为 CYGWIN 尝试了你的代码。您是否在二进制文件上尝试了 nm 命令以查看符号是否存在? 我在问题中添加了nm
输出。我对nm
不是很熟悉,但是,我认为这些符号是存在的。至少,GDB 完成了它们。另外,我认为这不是一般的 GCC/GDB 问题,更多的是 Mac 上的问题。在 Ubuntu 上,一切正常。以上是关于Mac 上的 gcc 4.7.3 和 gdb 7.6 - 奇怪的步进问题的主要内容,如果未能解决你的问题,请参考以下文章