mac Certifying GDB

背景

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值