首页 > 解决方案 > macOS Mojave 10.14.2 上的 gdb

问题描述

  1. 操作系统版本:macOS Mojave 10.14.2
  2. gdb:8.2.1(使用 brew install gdb 安装)
  3. 我成功地进行了代码设计

    codesign --entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)

  4. 我有这样的简单代码:

    int main(int argc, char *argv[]) { std::cout << "你好,世界" << std::endl; 返回0;}

  5. 然后 gdb 挂起

    zhifandeMacBook-Pro:cpp-quick-start zhifan$ g++ -g main.cpp

    zhifandeMacBook-Pro:cpp-quick-start zhifan$ gdb ./a.out
    GNU gdb (GDB) 8.2.1
    Copyright (C) 2018 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-darwin18.2.0".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from ./a.out...Reading symbols from /Users/zhifan/github/cpp-quick-start/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
    done.
    (gdb) start
    Temporary breakpoint 1 at 0x100000f54: file main.cpp, line 5.
    Starting program: /Users/zhifan/github/cpp-quick-start/a.out
    [New Thread 0x1903 of process 11780]
    [New Thread 0x1a03 of process 11780]
    During startup program terminated with signal ?, Unknown signal.
    (gdb) set startup-with-shell off
    (gdb) start
    Temporary breakpoint 2 at 0x100000f54: file main.cpp, line 5.
    Starting program: /Users/zhifan/github/cpp-quick-start/a.out
    [New Thread 0x2707 of process 11806]

我的 gdb 一直挂在这里([进程 11806 的新线程 0x2707])。

我不能使用 8.0.1,因为问题未知加载命令 0x32

我还可以做些什么?

标签: macosgdb

解决方案


好的,根据我过去两年使用 MacBook Pro 编码的经验。我从来没有成功让 gdb 正常工作。macOS 使用 Xcode Developer 工具进行编译。这些工具包括与 gdb 非常相似的 lldb。

这是一个可以帮助您做到这一点的网站。 https://lldb.llvm.org/lldb-gdb.html 这是一张直接展示gdb工具和lldb工具的图。希望这可以帮助。


推荐阅读