macos gdb 因“无法找到进程 ID 的 Mach 任务端口”错误而失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11504377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gdb fails with "Unable to find Mach task port for process-id" error
提问by S B
My app runs fine but gdb fails to debug it with the following error
我的应用程序运行良好,但 gdb 无法调试它并出现以下错误
(gdb) run
Starting program: /path/to/app
Unable to find Mach task port for process-id 83767: (os/kern) failure (0x5).
I am on OS X Lion. GDB version is
我在 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".
采纳答案by Tyilo
In Snow Leopard and later Mac OS versions, it isn't enough to codesign the gdb
executable.
在 Snow Leopard 和更高版本的 Mac OS 版本中,仅对gdb
可执行文件进行协同设计是不够的。
You have to follow this guide to make it work: http://www.opensource.apple.com/source/lldb/lldb-69/docs/code-signing.txt
您必须遵循本指南才能使其工作:http: //www.opensource.apple.com/source/lldb/lldb-69/docs/code-signing.txt
The guide explains how to do it for lldb
, but the process is exactly the same for gdb
.
该指南解释了如何为 执行此操作lldb
,但过程与gdb
.
回答by Mengyuan
It works when I change to sudo gdb executableFileName
! :)
当我更改为时它有效sudo gdb executableFileName
!:)
回答by qed
You need to create a certificate and sign gdb:
您需要创建一个证书并签署 gdb:
- Open application “Keychain Access” (/Applications/Utilities/Keychain Access.app)
- Open menu /Keychain Access/Certificate Assistant/Create a Certificate...
- Choose a name (gdb-cert in the example), set “Identity Type” to “Self Signed Root”, set “Certificate Type” to “Code Signing” and select the “Let me override defaults”. Click “Continue”. You might want to extend the predefined 365 days period to 3650 days.
- Click several times on “Continue” until you get to the “Specify a Location For The Certificate” screen, then set “Keychain to System”.
- If you can't store the certificate in the “System” keychain, create it in the “login” keychain, then export it. You can then import it into the “System” keychain.
- In keychains select “System”, and you should find your new certificate. Use the context menu for the certificate, select “Get Info”, open the “Trust” item, and set “Code Signing” to “Always Trust”.
- You must quit “Keychain Access” application in order to use the certificate and restart “taskgated” service by killing the current running “taskgated” process. Alternatively you can restart your computer.
Finally you can sign gdb:
sudo codesign -s gdb-cert /usr/local/bin/ggdb
sudo ggdb ./myprog
- 打开应用程序“钥匙串访问”(/Applications/Utilities/Keychain Access.app)
- 打开菜单/钥匙串访问/证书助手/创建证书...
- 选择一个名称(示例中的 gdb-cert),将“身份类型”设置为“自签名根”,将“证书类型”设置为“代码签名”并选择“让我覆盖默认值”。单击“继续”。您可能希望将预定义的 365 天期限延长至 3650 天。
- 单击几次“继续”,直到进入“为证书指定位置”屏幕,然后将“钥匙串设置为系统”。
- 如果您无法将证书存储在“系统”钥匙串中,请在“登录”钥匙串中创建它,然后将其导出。然后,您可以将其导入到“系统”钥匙串中。
- 在钥匙串中选择“系统”,您应该会找到您的新证书。使用证书的上下文菜单,选择“获取信息”,打开“信任”项,将“代码签名”设置为“始终信任”。
- 您必须退出“Keychain Access”应用程序才能使用证书并通过终止当前运行的“taskgated”进程来重新启动“taskgated”服务。或者,您可以重新启动计算机。
最后你可以签署gdb:
sudo codesign -s gdb-cert /usr/local/bin/ggdb
sudo ggdb ./myprog
回答by Sam Ruberti
The problem is that you are not logged in as a root user (which you don't want). You need to create a certificate for gdb to be allowed access. Follow this tutorial and you should be good to go...
问题是您没有以 root 用户身份登录(您不想要)。您需要为 gdb 创建一个证书才能被允许访问。按照本教程,你应该很高兴......
http://sourceware.org/gdb/wiki/BuildingOnDarwin
http://sourceware.org/gdb/wiki/BuildingOnDarwin
If all else fails, just use: sudo gdb executableFileName
如果一切都失败了,只需使用: sudo gdb executableFileName
回答by Hans Roggeman
This linkhad the clearest and most detailed step-by-step to make this error disappear for me.
这个链接有最清晰、最详细的一步一步地让这个错误消失。
In my case I had to have the key as a "System" key otherwise it did not work (which not every url mentions).
在我的情况下,我必须将密钥作为“系统”密钥,否则它不起作用(不是每个 url 都提到)。
Also killing taskgated
is a viable (and quicker) alternative to having to restart.
此外,杀死taskgated
是必须重新启动的可行(且更快)的替代方法。
I also uninstalled MacPortsbefore I started this process and uninstalled the current gdb using brew uninstall gdb
.
在开始此过程之前,我还卸载了 MacPorts,并使用brew uninstall gdb
.
回答by Aris
I needed this command to make it work on El Capitan:
我需要这个命令才能让它在 El Capitan 上工作:
sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/gdb-cert.cer
回答by Bhupesh Pant
On MacOSX lldb needs to be code signed. The Debug and Release builds are set to code sign using a code signing certificate named lldb_codesign.
在 MacOSX 上 lldb 需要代码签名。调试和发布版本设置为使用名为 lldb_codesign 的代码签名证书进行代码签名。
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.
[Note: - lldb is used in mac as gdb.]
[注意: - lldb 在 mac 中用作 gdb。]
回答by Yihe
Here is a really useful guidewhich solved my problem(OSX 10.13.6).
这是一个非常有用的指南,它解决了我的问题(OSX 10.13.6)。
- Open Keychain Access
- In the menu, open Keychain Access > Certificate Assistant > Create a certificate
- Give it a name (e.g. gdbc)
- Identity type: Self Signed Root
- Certificate type: Code Signing
- Check: let me override defaults
- Continue until it prompts you for: "specify a location for..."
- Set Keychain location to System
- Create a certificate and close assistant.
- Find the certificate in System keychains, right click it > get info (or just double click it)
- Expand Trust, set Code signing to always trust
- Restart taskgated in terminal: killall taskgated
- Run
codesign -fs gdbc /usr/local/bin/gdb
in terminal: this asks for the root password
- 打开钥匙串访问
- 在菜单中,打开钥匙串访问 > 证书助手 > 创建证书
- 给它一个名字(例如gdbc)
- 身份类型:自签名根
- 证书类型:代码签名
- 检查:让我覆盖默认值
- 继续直到它提示您:“为...指定一个位置”
- 将钥匙串位置设置为系统
- 创建证书并关闭助手。
- 在系统钥匙串中找到证书,右键单击它> 获取信息(或双击它)
- 展开信任,将代码签名设置为始终信任
- 在终端重启 taskgated:killall taskgated
codesign -fs gdbc /usr/local/bin/gdb
在终端中运行:这要求输入 root 密码
回答by irritable_phd_syndrom
These instructions work for OSX High Sierra and avoid running gdb as root (yuck!). I recently updated from OSX 10.13.2 to 10.3.3. I think this is when gdb 8.0.1 (installed w/ homebrew) started failing for me.
这些说明适用于 OSX High Sierra,并避免以 root 身份运行 gdb(糟糕!)。我最近从 OSX 10.13.2 更新到 10.3.3。我认为这是 gdb 8.0.1(安装有自制软件)开始对我失败的时候。
I had difficulty with other people's instructions. After different instructions, everything was a mess. So I started a fresh. I more or less followed these instructions.
我很难听懂别人的指示。经过不同的指示,一切都变得一团糟。所以我开始了新鲜事。我或多或少地遵循了这些说明。
Clean the mess :
清理烂摊子:
brew uninstall --force gdb # This deletes _all_ versions of gdb on the machine
- In
Applications
->Utilities
->Keychain Access
, I deleted all previous gdb certificates and keys (be sure you know what you're doing here!). It's unclear if this is necessary, but since I'd buggered up trying to create those certificates and keys using other instructions I eliminated them anyways. I had keys and certificates in both login and system.
brew uninstall --force gdb # This deletes _all_ versions of gdb on the machine
- 在
Applications
->Utilities
-> 中Keychain Access
,我删除了所有以前的 gdb 证书和密钥(确保您知道自己在做什么!)。目前还不清楚这是否有必要,但由于我尝试使用其他指令创建这些证书和密钥时遇到了麻烦,所以我还是将它们删除了。我在登录和系统中都有密钥和证书。
Now reinstall gdb.
现在重新安装gdb。
brew install gdb
- Within
Keychain Access
, go to menuKeychain Access
->Certificate Assistant
->Create a Certificate
- Check "Let me override defaults" and set
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
Name : gdb-cert Identity Type: Self Signed Root Certificate Type : Code Signing [X] Let me override defaults
- On 1st Certificate Information page:
- 在第一个证书信息页面上:
Serial Number : 1 Validity Period (days): 3650
Serial Number : 1 Validity Period (days): 3650
On 2nd Certificate Information page, I left all fields blank except those already filled in.
On Key Pair Information page, I left the defaults
在第二个证书信息页面上,除了已经填写的字段外,我将所有字段留空。
在 Key Pair Information 页面上,我保留了默认值
Key Size : 2048 Algorithm : RSA
Key Size : 2048 Algorithm : RSA
- On Key Usage Extension page, I left the defaults checked.
- 在 Key Usage Extension 页面上,我保留了默认设置。
[X] Include Key Usage Extension [X] This extension is critical Capabilities: [X] Signature
[X] Include Key Usage Extension [X] This extension is critical Capabilities: [X] Signature
- On Extended Key Usage Extension page, I left the defaults checked.
- 在扩展密钥用法扩展页面上,我保留了默认设置。
[X] Include Extended Key Usage Extension [X] This extension is critical Capabilities: [X] Code Signing
[X] Include Extended Key Usage Extension [X] This extension is critical Capabilities: [X] Code Signing
On Basic Constraints Extension Page, nothing was checked (default).
On Subject Alternate Name Extension page, I left the default checked and didn't add anything else.
在基本约束扩展页面上,没有选中任何内容(默认)。
在主题备用名称扩展页面上,我保留了默认选中状态并且没有添加任何其他内容。
[X] Include Subject Alternate Name Extension
[X] Include Subject Alternate Name Extension
- On Specify a Location for the certificate page, I set
- 在指定证书页面的位置上,我设置
Keychain: System
Keychain: System
I clicked Create and was prompted for my password.
Back in the
Keychain Access
app, I went toSystem
and right clicked ongdb-cert
and under dropdown menuTrust
, I changed all the fields toAlways Trust
.Rebooted computer.
At the Terminal, I ran
codesign -s gdb-cert /usr/local/bin/gdb
. I entered my password when prompted.At the Terminal, I ran
echo "set startup-with-shell off" >> ~/.gdbinit
I ran
gdb myprogram
and thenstart
within the gdb console. Here, I believe, it prompted for me for my password. After that, all subsequent runs, it did not prompt for my password.
我单击“创建”,系统提示我输入密码。
回到
Keychain Access
应用程序,我去System
右键单击gdb-cert
下拉菜单下Trust
,我将所有字段更改为Always Trust
.重新启动计算机。
在终端,我跑了
codesign -s gdb-cert /usr/local/bin/gdb
。我在提示时输入了密码。在终点站,我跑了
echo "set startup-with-shell off" >> ~/.gdbinit
我跑了
gdb myprogram
然后start
在 gdb 控制台中。我相信,在这里,它提示我输入密码。之后,所有后续运行,它都没有提示我输入密码。