我的应用运行正常,但gdb无法使用以下错误进行调试
(gdb) run
Starting program: /path/to/app
Unable to find Mach task port for process-id 83767: (os/kern) failure (0x5).
我在OS X Lion上。 GDB版本是
$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1752) (Sat Jan 28 03:02:46 UTC 2012)
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".
答案 0 :(得分:115)
当我改为sudo gdb executableFileName
时,它会起作用! :)
答案 1 :(得分:55)
在Snow Leopard和后来的Mac OS版本中,仅对gdb
可执行文件进行编码是不够的。
您必须遵循本指南才能发挥作用:http://www.opensource.apple.com/source/lldb/lldb-69/docs/code-signing.txt
该指南介绍了如何为lldb
执行此操作,但gdb
的过程完全相同。
答案 2 :(得分:30)
您需要创建证书并签署gdb:
最后你可以签署gdb:
sudo codesign -s gdb-cert /usr/local/bin/ggdb
sudo ggdb ./myprog
答案 3 :(得分:13)
问题是您没有以root用户身份登录(您不想要)。您需要为gdb创建一个允许访问的证书。按照本教程,你应该很高兴...
http://sourceware.org/gdb/wiki/BuildingOnDarwin
如果所有其他方法都失败了,只需使用:sudo gdb executableFileName
答案 4 :(得分:6)
This link有一个最清晰,最详细的步骤,让这个错误消失了。
在我的情况下,我必须将密钥作为“系统”密钥,否则它不起作用(并非每个网址都提到)。
同样杀死taskgated
是必须重启的可行(且更快)的替代方案。
在开始此过程之前我还uninstalled MacPorts并使用brew uninstall gdb
卸载了当前的gdb。
答案 5 :(得分:2)
我需要这个命令才能让它在El Capitan上运行:
sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/gdb-cert.cer
答案 6 :(得分:1)
我按照this教程,一切正常。
答案 7 :(得分:1)
在MacOSX上,lldb需要进行代码签名。使用名为lldb_codesign的代码签名证书将Debug和Release构建设置为代码签名。
If you don't have one yet you will need to:
- Launch /Applications/Utilities/Keychain Access.app
- In Keychain Access select the "login" keychain in the "Keychains"
list in the upper left hand corner of the window.
- Select the following menu item:
Keychain Access->Certificate Assistant->Create a Certificate...
- Set the following settings
Name = lldb_codesign
Identity Type = Self Signed Root
Certificate Type = Code Signing
- Click Continue
- Click Continue
- Click Done
- Click on the "My Certificates"
- Double click on your new lldb_codesign certificate
- Turn down the "Trust" disclosure triangle
Change:
When using this certificate: Always Trust
- Enter your login password to confirm and make it trusted
The next steps are necessary on SnowLeopard, but are probably because of a bug
how Keychain Access makes certificates.
- Option-drag the new lldb_codesign certificate from the login keychain to
the System keychain in the Keychains pane of the main Keychain Access window
to make a copy of this certificate in the System keychain. You'll have to
authorize a few more times, set it to be "Always trusted" when asked.
- Switch to the System keychain, and drag the copy of lldb_codesign you just
made there onto the desktop.
- Switch to Terminal, and run the following:
sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/lldb_codesign.cer
- Right click on the "lldb_codesign" certificate in the "System" keychain (NOT
"login", but the one in "System"), and select "Delete" to delete it from
the "System" keychain.
- Reboot
- Clean and rebuild lldb and you should be able to debug.
That should do it.
[注意: - lldb在mac中用作gdb。]
答案 8 :(得分:1)
这是一个非常有用的guide,它解决了我的问题(OSX 10.13.6)。
codesign -fs gdbc /usr/local/bin/gdb
:这要求输入root密码答案 9 :(得分:0)
这些说明适用于OSX High Sierra,并避免以root身份运行gdb(哎呀!)。我最近从OSX 10.13.2更新到10.3.3。我想这是gdb 8.0.1(安装w / homebrew)开始失败的时候。
我对其他人的指示很困难。经过不同的指示,一切都很乱。所以我开始新鲜了。我或多或少地遵循了这些instructions。
清理混乱:
brew uninstall --force gdb # This deletes _all_ versions of gdb on the machine
Applications
- > Utilities
- > Keychain Access
,我删除了所有以前的gdb证书和密钥(确保你知道你在这里做了什么!)。目前还不清楚这是否有必要,但由于我试图使用其他指令创建这些证书和密钥,我无论如何都要删除它们。我在登录和系统中都有密钥和证书。现在重新安装gdb。
brew install gdb
Keychain Access
内,转到菜单Keychain Access
- > Certificate Assistant
- > Create a Certificate
Name : gdb-cert Identity Type: Self Signed Root Certificate Type : Code Signing [X] Let me override defaults
Serial Number : 1 Validity Period (days): 3650
在第二个证书信息页面上,我将所有字段留空,但已填写的字段除外。
在“密钥对信息”页面上,我保留了默认值
Key Size : 2048 Algorithm : RSA
[X] Include Key Usage Extension [X] This extension is critical Capabilities: [X] Signature
[X] Include Extended Key Usage Extension [X] This extension is critical Capabilities: [X] Code Signing
在基本约束扩展页面上,未检查任何内容(默认)。
在主题备用名称扩展页面上,我保留了默认选中状态,但未添加任何其他内容。
[X] Include Subject Alternate Name Extension
Keychain: System
我点击了“创建”,系统提示我输入密码。
回到Keychain Access
应用,我转到System
并右键点击gdb-cert
,然后在下拉菜单Trust
下,我将所有字段更改为{ {1}}。
重新启动计算机。
在终端,我跑了Always Trust
。我在提示时输入了密码。
在终端,我运行了codesign -s gdb-cert /usr/local/bin/gdb
我在gdb控制台中运行echo "set startup-with-shell off" >> ~/.gdbinit
然后gdb myprogram
。在这里,我相信,它提示我输入密码。之后,所有后续运行,都没有提示我输入密码。
答案 10 :(得分:0)
这是一种奇怪的方法,但它对我有用(MacOs HighSierra 10.13.3)。安装CLion。它配备了gdb。一旦使用Terminal运行gdb。将gdb程序复制到usr / local / bin /。没有登录,sudo等问题。
答案 11 :(得分:0)
按照这里的说明Codesign gdb on macOS似乎解决了这个问题,对我来说,在macOS High Sierra(10.13.3)上。