【GO】【gdb】

1 安装homebrew
参考 https://www.cnblogs.com/suren2017/p/9249803.html (【Ruby】【环境搭建】macOS Sierra 10.12.6 + Xcode 8 + gpg 2.2.8 + rvm 1.29.3 + Ruby 2.4.0 + RubyMine 2018.1.4)

2 安装gdb
brew update

brew search gdb 有的话就执行下面的 一般情况是有的

brew install gdb

Install gdb 8.0.1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb 为避免遇到During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.问题

3 钥匙串

打开钥匙串访问 -> 创建证书 名字自定义 “身份类型”:自签名根证书 “证书类型”:代码签名

注意一定钥匙代码签名,英文名是codesign,上面的名称随意,这个跟你后面的命令行键入的名称有关,接下来,一直往下

"指定该证书的位置" 把这个钥匙串改成system

双击,将信任改成始终信任:

中间要输入密码之类的,输入就是了。

退出Keychain Access以刷新存储证书

OK,只差最后一步
重启电脑。
然后在命令行上输入:

codesign -fs gdb-cert-hekewen /usr/local/bin/gdb

4 echo "set startup-with-shell off" >> ~/.gdbinit

【gdb遇到的问题】

1 During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

解决方式,回退gdb版本至8.0.1

Unlink current gdb: brew unlink gdb

Install gdb 8.0.1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb

2 During startup program terminated with signal SIG113, Real-time event 113
这个错误好像只有在高版本的OSX系统上才出现,解决办法就是在gdb启动的时候,键入命令

set startup-with-shell off

就解决了
当然,如果这样,你每次在调试的时候都要键入,这时候你就可以添加到.gdbinit,每次运行gdb的时候都执行一次。
关于.gdbinit,就是在你每次用gdb调整程序的时候,如果程序文件中有.gdbinit,就会自动读取里面的命令,全部执行一遍。
于是乎,我们只要用vim在程序文件里面创建一个.gdbinit,并在里面写上set startyup-with-shell off
就解决了。

3 钥匙串问题
https://www.cnblogs.com/suren2017/p/10469284.html (【Mac】【创建钥匙串】)

4 Starting program: /x/y/foo Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))

方法一: 这个原因是mac不允许没有给予许可的进程来调试其它进程,那解决办法自然就想到了root,来个根权限。但是,这个会影响到万一gdb调试了重要内核程序后果不是我们想要的,没有安全证书,我们就自己添加一个安全证书:
首先打开钥匙串访问 -> 创建证书 名字自定义 “身份类型”:自签名根证书 “证书类型”:代码签名

注意一定钥匙代码签名,英文名是codesign,上面的名称随意,这个跟你后面的命令行键入的名称有关,接下来,一直往下

"指定该证书的位置" 把这个钥匙串改成system

双击,将信任改成始终信任:

中间要输入密码之类的,输入就是了。

退出Keychain Access以刷新存储证书

OK,只差最后一步
重启电脑。
然后在命令行上输入:

codesign -fs gdb-cert-hekewen /usr/local/bin/gdb
这个gdb-cert-hekewen,要改成你的证书名,后面就是gdb位置。
没有报错就是成功了。

方法二:
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/BuildingOnDarwin

On 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 -fs gdb-cert $(which gdb)
macOS 10.12 (Sierra) 或以上版本的操作系统
需要使用 gdb 7.12.1 之上的版本
此外,为防止gdb利用shell来启动程序开始debug,执行下面的语句
echo "set startup-with-shell off" >> ~/.gdbinit
重启系统

posted @ 2019-03-04 10:31  素人渔芙2017  阅读(364)  评论(0编辑  收藏  举报