# 问题描述:Mac OS Sierra 无法使用gdb调试
- Unable to find Mach task port for process-id 47072: (os/kern) failure (0x5).
- (please check gdb is codesigned - see taskgated(8))
- During startup program terminated with signal SIG113, Real-time event 113.
# 如果是用Homebrew安装的gdb,brew install gdb,安装完有提示
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:
https://sourceware.org/gdb/wiki/BuildingOnDarwinOn 10.12 (Sierra) or later with SIP, you need to run this:
echo “set startup-with-shell off” >> ~/.gdbinit在macOS上,gdb使用Mach ports需要特殊权限
你需要对二进制文件进行签名。指导步骤,查看:
https://sourceware.org/gdb/wiki/BuildingOnDarwin在10.12 (Sierra) 或之后带SIP的操作系统版本,你还需要运行这个命令:
echo “set startup-with-shell off” >> ~/.gdbinit
# 解决方法
# 具体操作,按照https://sourceware.org/gdb/wiki/BuildingOnDarwin步骤2开始
# 2. Giving gdb permission to control other processes
- 启动 /Applications/Utilities/Keychain Access.app
- 顶部菜单选择 /Keychain Access/Certificate Assistant/Create a Certificate…
- Create Your Certificate
- Name: gdb-cert
- Identity Type: Self Signed Root
- Certificate Type: Code Signing
- 勾选 Let me override defaults
- 一直按continue,直到Specify a Location For The Certificate
- Keychain: System
- tips: 如果无法将Certificate保存到System keychain,就先保存到login keychain,然后导出,再导入到System keychain。
- Create
- 如附图,右键选择gdb-cert的Get Info,打开Trust项,将Code Signing改成Always Trust
- 最后退出Keychain Access以刷新存储证书
- codesign gdb,执行
codesign -s gdb-cert $(which gdb)
- macOS 10.12 (Sierra) 或以上版本的操作系统
- 需要使用 gdb 7.12.1 之上的版本
- 此外,为防止gdb利用shell来启动程序开始debug,执行下面的语句
echo "set startup-with-shell off" >> ~/.gdbinit
- 重启系统