gcc 4.7.3 and gdb 7.6 on Mac - strange stepping problems

陌路散爱 提交于 2020-01-01 09:42:04

问题


I recently installed GCC 4.7.3 and GDB 7.6 on my OS X 10.7 system via MacPorts to be able to compile C++11 code. I cannot use Apple's selfmade clang++ and gdb since it doesn't allow me to debug standard template library code properly (for example, if I dereference a list iterator, the program crashes).

Now, with the new GCC / GDB combination I have some weird problems with stepping into functions. Take this minimal example:

#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;
}

If I compile the code with g++ -O0 -ggdb test.cpp, GDB does not step into A::testMethod at all. I can set a breakpoint by specifying the code line inside A::testMethod, but not by specifying the method name (b A::testMethod()).

More strangely, if I compile with g++ -O0 -ggdb -std=c++11 test.cpp, GDB steps into testMethod if called from void test(). From the main, stepping still doesn't work. However, now, I can set a breakpoint by specifying just the method name.

Further, as soon as I start the program in GDB, I get GDB warnings, as described in related questions. These warnings appear regardless of whether I specify -std=c++11 or not.

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.

I am aware of the following questions: Debugging Problems, Weird GDB messages, GDB error message, GDB fails on Mountain Lion, yet they didn't help me. Specifying -gdwarf-2 -gstrict-dwarf does not help either.

-EDIT- The output of nm is the same in both cases:

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

Has anyone managed to get GCC 4.7 and some appropriate debugger working on OS X Lion?


回答1:


I tried compiling like this....It is working fine.... Could you just try with -g option alone?

E.g: g++ -g test.cpp -o test



来源:https://stackoverflow.com/questions/16756911/gcc-4-7-3-and-gdb-7-6-on-mac-strange-stepping-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!