mac Certifying GDB

来源:互联网 发布:淘宝发货地与实际不符 编辑:程序博客网 时间:2024/04/29 08:17

背景

mac gdb调试程序时报错:
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))

问题原因:
This is because the Darwin kernel will refuse to allow gdb to debug another process if you don’t have special rights, since debugging a process means having full control over that process, and that isn’t allowed by default since it would be exploitable by malware. (The kernel won’t refuse if you are root, but of course you don’t want to be root to debug.)

The most up to date method to allow gdb to control another process is to sign it with any system-trusted code signing authority.

一、打开钥匙串访问程序

Open up the Keychain Access application (/Applications/Utilities/Keychain Access.app). Navigate via the menu to Keychain Access > Certificate Assistant > Create Certificate…
这里写图片描述

二、输入证书名并选择证书类型

这里写图片描述
除第一个红框name可以自定义外,其它两个红框内容的选择必须和这里一致,否则会Certifying GDB失败。

三、设置认证时长

The maximum validity period is 999 days. I don’t really want to deal with this again, so I’m going to max it out.
这里写图片描述

四、选择证书存储位置

Keep clicking the “Continue” button until you are asked for a location. Set it to “System”.
这里写图片描述
这里一定要选择“system”。

五、生成成功

这里写图片描述

六、使证书被信任

Now make sure the cert is always trusted. Right-click the new certificate and select Get Info. Under the Trust section, set Code Signing to Always Trust.
这里写图片描述
这里写图片描述

七、重启mac加载证书

Now that we have a certificate, we need to use it to sign GDB. Quit Keychain Access (you must quit Keychain Access!) 。重启mac,使刚才创建的证书被系统加载(网上介绍的杀掉进程taskgated后,让其自动重启加载证书的方法并不总是有效)。

八、code sign GDB

在终端下运行如下命令:
codesign -s gdb-cert $(which gdb-apple)
其中:

  1. 参数-s后面跟的为刚才创建的证书名。
  2. 参数$(which gdb-apple)为gdb的路径名(可通过运行命令which gdb获得)。

这里我运行的命令为:
codesign -s gdb-cert /usr/local/bin/gdb

到此为止,mac Certifying GDB完成,可以gdb调试程序了。

九、参考链接

http://ntraft.com/installing-gdb-on-os-x-mavericks/
http://opensource.apple.com//source/lldb/lldb-69/docs/code-signing.txt
http://stackoverflow.com/questions/11504377/gdb-fails-with-unable-to-find-mach-task-port-for-process-id-error
http://www.cnblogs.com/yishuiliunian/archive/2013/01/13/2858836.html

0 0
原创粉丝点击