先說問題:1、gdb不能使用,重新用homebrew install 了gdb
2、brew裝的gdb可以用了,但是等start調試的時候報這些錯誤:
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
gdb Reason: image not found
或者:
Unable to find Mach task port for process-id 15634: (os/kern) failure (0x5).
During startup program terminated with signal ?, Unknown signal.
經google研究,說沒有code-sign的原因,然后一通stackoverflow亂搜,遂,卒。
總之是怎么整都不行,然后brew info gdb查看發現當初安裝好gdb homebrew有這么幾句提示:
==> Caveats
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
遂按照上面的提示最后一行 echo "set startup-with-shell off" >> ~/.gdbinit結果發現,也不行。
確定了是沒有codesign引起的原因,又google,查到一遍文章apple專門關於codesign的:https://opensource.apple.com/source/lldb/lldb-69/docs/code-signing.txt
大概看了下意思,發現要手動Create a Certificate...,覺得好麻煩啊,肯定沒這么麻煩,還不死心,繼續google。。。結果你懂的
無奈,只能返回去看brew info gdb,發現上面這句鏈接:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
發現還是需要手動Create a Certificate,罷了,這個寫的排版和Troubleshooting都不錯,耐着心看下去吧,
跟着嘗試了一遍,證書也創好了,taskgated也kill掉了,結果還是不行。。。
再Troubleshooting,
發現沒有“Ensure that the certificate is marked as Always Trust”
把證書打開,顯示簡介,發現里面有調整的選項,換成Always Trust
重新kill了taskgated
新開一個terminal
gdb
start
彈出了一框:輸入用戶名和密碼,老老實實照辦,最終:
[New Thread 0x1403 of process 17715]
warning: unhandled dyld version (15)
Thread 2 hit Temporary breakpoint 1, main () at int.c:4
4 int a = 0;
(gdb)
真是不容易啊!
這件事說明:碰到問題不要動不動就google亂找一氣,應該沉下心來仔細觀察應有的報錯和已知提示,從中找到解決問題的辦法,往往是最有效的!
