7

GCC 4.7 MacPorts ビルドでコンパイルされたプログラムの読み取り可能なデバッグ出力を取得できないようです。

GDB 6.3 と GDB 7.3 の両方で試しましたが、それぞれに問題があります。

GDB 7.3 (MacPorts) で試す

GDB 7.3 では、起動時に次の出力が得られます。

$ ggdb ./test
GNU gdb (GDB) 7.3
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin11.4.0".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
Reading symbols from /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test...Reading symbols from /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test.dSYM/Contents/Resources/DWARF/test...done.
done.

アサーションを実行してトリガーすると、読み取り不能なスタック トレースが発生します。

(gdb) r
Starting program: /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test 
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x26
main
Assertion failed: (false), function lock, file main.cpp, line 168.

Program received signal SIGABRT, Aborted.
0x00007fff8ede282a in ?? ()

(gdb) bt
#0  0x00007fff8ede282a in ?? ()
#1  0x00007fff9a273a9c in ?? ()
#2  0x00007fff6af00690 in ?? ()
#3  0x0000003000000030 in ?? ()
#4  0x00007fffffffffdf in ?? ()
#5  0x000000010b305840 in ?? ()
#6  0x00007fff6af006d0 in ?? ()
#7  0x00007fff9a2a65de in ?? ()
#8  0x0000000000000000 in ?? ()

GDB 6.3 (ビルトイン) で試す

この回答によると、 GDB 6.3 を使用する必要があります。しかし、それは別の問題につながります。起動中に一連のエラーが発生します。

GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .
warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility.cc".


warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility-debug_list.cc".

warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_mports_dports_lang_gcc47/gcc47/work/build/x86_64-apple-darwin11/libstdc++-v3/src/.libs/compatibility-debug_list-2.o" - no debug information available for "../../../../gcc-4.7.1/libstdc++-v3/src/c++98/compatibility-debug_list-2.cc".

これは、アサーションがトリガーされ、バックトレースを取得しようとした場合に表示されるものです。

Assertion failed: (false), function lock, file main.cpp, line 168.

Program received signal SIGABRT, Aborted.
0x00007fff8ede282a in __kill ()
(gdb) bt
#0  0x00007fff8ede282a in __kill ()
#1  0x00007fff9a273a9c in abort ()
#2  0x00007fff9a2a65de in __assert_rtn ()
Die: DW_TAG_unspecified_type (abbrev = 19, offset = 423)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_strp) string: "decltype(nullptr)"
Die: DW_TAG_unspecified_type (abbrev = 19, offset = 423)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_strp) string: "decltype(nullptr)"
Dwarf Error: Cannot find type of die [in module /Users/StackedCrooked/programming/projects/stacked-crooked/Playground/LockOrderChecker/test.dSYM/Contents/Resources/DWARF/test]

この回答(GCC 4.5マニュアルを引用)によると、-gdwarf-2 -gstrict-dwarfオプションを使用する必要があります。

私はこのアドバイスに従いました。私のビルドコマンドは次のようになります:

g++ -o run-test -std=c++0x -Wall -Wextra -Werror -gdwarf-2 -gstrict-dwarf -g2 -O0 -I/opt/local/include main.cpp

ただし、前述の問題は解決されません。

記録のために:私はOS X Lionを使用しています。

これを修正する方法を知っている人はいますか?

4

2 に答える 2

2

g++ のマニュアル ページによると、-ggdb を使用して gdb のデバッグ シンボルを生成する必要があります。ところで、 -g を使用するだけで、私の経験では常に gdb の適切なシンボルが生成されました(Linux、Windows(mingw)、およびMac)。

于 2012-09-26T13:39:45.503 に答える
0

MacPorts gdb 7.3 セッションからの警告は、ロード コマンド 0x24 (LC_VERSION_MIN_MACOSX) および 0x26 (LC_FUNCTION_STARTS) に対するものです。これらは新しいロード コマンドですが、デバッグには必須ではありません。警告は無害です。セッションにシンボリック情報がないのは、おそらく ASLR が原因ですか? ユーザーランドのデバッグ用にシステムに導入されてから何年も経ちますが、実行時にすべてがメモリ内を移動したことを認識していない場合、デバッガーの出力はこのようになります。

lldb を使ってみましたか? Xcode 4.5 で提供されるバージョンは、非常に優れています。これは、Apple が現在積極的にサポートおよび開発しているデバッガであり、最新のコンパイラによる DWARF 出力で正しく動作するはずです。コマンド構文は gdb とは少し異なります (ただし、gdb ユーザーになじみのあるコマンド ショートカットが多数提供されています) 。 gdb.html。試してみてください。気に入るかもしれません。

于 2012-10-01T19:09:28.517 に答える