【问题标题】:Debugging problems with MacPorts GCC on OS X在 OS X 上调试 MacPorts GCC 的问题
【发布时间】:2012-09-07 23:59:25
【问题描述】:

对于使用 GCC 4.7 MacPorts build 编译的程序,我似乎无法获得可读的调试输出。

我已经尝试过 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(内置)

根据this answer 我应该使用 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]

根据this answer(引用 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。

有谁知道如何解决这个问题?

【问题讨论】:

  • @Walter 我猜 gdb 是 gcc 的调试器?
  • 是的,我使用的是 MacPorts 提供的命令行工具 g++ 和 gdb。
  • 我试图建议放弃使用调试器的想法。或者你可以在调试器中运行调试器lol
  • 我在 StackOverflow 上阅读了有关网络和其他主题的信息,有人认为这是 gdb 7.3 的一个错误,并且已经解决了升级到 gdb 7.4 的问题,我不知道这个主题是否有帮助你:stackoverflow.com/questions/11093392/gdb-7-3-1-on-osx-lion
  • 您使用 MacPorts 中的 GCC/GDB 而非 XCode 工具有什么原因吗?

标签: c++ macos gcc gdb


【解决方案1】:

来自 MacPorts gdb 7.3 会话的警告针对加载命令 0x24 (LC_VERSION_MIN_MACOSX) 和 0x26 (LC_FUNCTION_STARTS)。这些是新的加载命令,但对于调试不是必需的 - 警告是无害的。您的会话缺少任何符号信息的事实可能是因为 ASLR?自从它被引入系统进行用户空间调试以来已经有好几年了,但如果它不知道所有东西在运行时都在内存中滑动,这就是调试器输出的样子。

您是否尝试过使用 lldb? Xcode 4.5 中提供的版本真的很不错。它是 Apple 目前正在积极支持和开发的调试器,它应该可以正确地与更新的编译器的 DWARF 输出一起使用。命令语法与 gdb 略有不同(尽管提供了许多命令快捷方式,使 gdb 用户熟悉它),http://lldb.llvm.org/lldb-gdb.html 提供了一个 gdb/lldb 命令等效表。试试看,你可能会喜欢。

【讨论】:

    【解决方案2】:

    根据 g++ 手册页,您应该使用 -ggdb 为 gdb 生成调试符号。顺便说一句,根据我的经验(在 linux、windows (mingw) 和 mac 上),仅使用 -g 总是为 gdb 生成好的符号。

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 2012-03-07
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      相关资源
      最近更新 更多