gdb终止了信号?,未知信号

我只是想在Mac OSX版本10.12上使用gdb调试代码,但在gdb中启动程序时总是会遇到此未知错误。

我在安装后对gdb进行了编码,并使用-g标志编译了我的代码。

这就是发生的事情:

computer:hello user$ gdb a.out GNU gdb (GDB) 7.12 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later  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-darwin16.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...Reading symbols from /Users/user/Documents/Programming/hello/a.out.dSYM/Contents/Resources/DWARF/a.out...done. done. (gdb) r Starting program: /Users/user/Documents/Programming/hello/a.out During startup program terminated with signal ?, Unknown signal. 

临时我得到了SIGTRAP信号,但我无法弄清楚为什么它现在再次抛出未知信号。

适用于Mac OS X 10.12.5及更高版本的解决方案

在home-direcetory中创建一个.gdbinit文件,并在其中写入“set startup-with-shell off”。

可以使用vi ~/.gdbinit创建文件。

打开一个新的终端,gdb将工作。

如果您仍在寻找解决方案,这对我有用:

  • 在恢复模式下重启机器,打开终端并输入以下内容

    $ csrutil enable --without debug

    重新启动机器,gdb应该照常工作(完整的线程在这里: http : //sourceware-org.1504.n7.nabble.com/gdb-on-macOS-10-12-quot-Sierra-quot-td415708.html #a415940 )

这是因为您使用的是最新版本的OSX 10.12或10.12.1。 降级或等待OSX / GDB修复似乎是最好的选择。 我整天都在弄清楚这一点。 不要浪费你的时间尝试与Sierra一起解决它!