mac安裝gdb調試(轉載)

 轉載自:http://blog.plotcup.com/a/129git

 

最近一直用go寫一個項目,本想在mac上用gdb調試一下,但xcode4.6帶的gdb版 本仍是過低了,不支持go,只好本身安裝一個。本覺得直接brew install gdb就 完事了,後來發現不是那麼回事,還要給gdb製做證書籤名。下面是操做步驟:shell

安裝gdb

brew install gdb

程序編譯完成後在/usr/local/bin/下面創建一個gdb的軟鏈,而且將/usr/bin/ 下面的gdb更名。xcode

製做證書

  1. 打開鑰匙串訪問
  2. 建立證書
/upload/zj4sqh/2.png
  1. 輸入名稱,並選擇類型
/upload/gKoRCL/3.png
  1. 輸入有效期,通常默認365就好,也就是一年
/upload/fox8Z1/4.png
  1. 而後一直直接繼續,直到建立畫面,選擇系統,並建立
/upload/1---Vv/5.png
  1. 選擇剛剛生成的gdb-cert證書,並雙擊
/upload/VG9vCy/6.png
  1. 在證書簡介中打開信任,並將使用此證書時選擇爲老是信任
/upload/I9zY5R/7.png

對gdb簽名

有了剛剛製做的證書後,打開shell,而後執行以下代碼:app

codesign -s gdb-cert /usr/local/bin/gdb

Tipide

執行這個以前可能要重啓計算機ui

完成以上工做後gdb就能夠調試go了,可是每次使用的時候都會提示輸入管理員 密碼。this

使普通用戶也可以使用gdb

因爲以前製做的證書是在系統下面的,因此每次執行gdb都會提示管理員密碼,解 決方法也很簡單,打開鑰匙串訪問將系統下面的gdb-cert複製一份放到登陸下面 就行。spa

參考資料

Building GDB for Darwin

Creating the binary for Darwin isn't very difficult. Download a release snapshot or get the current source via git/CVS/FTP, then configure and make as usual.debug

Building the 7.0 release unfortunately results in many "warning: format not a string literal and no format arguments" warnings. This problem has been fixed in CVS. To avoid such warnings building 7.0, configure with --disable-intl.調試

 

Giving gdb permission to control other processes

If you try to use your freshly built gdb, you will get an error message such as:

 

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))

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. This is an easy process once you have a certificate (see the section below). If the certificate is known as gdb-cert, just use:

 

$ codesign -s gdb-cert gdb

Old notes: In Tiger, the kernel would accept processes whose primary effective group is procmod or procview. That means that making gdb setgid procmod should work. Later versions of Darwin should accept this convention provided that taskgated (the daemon that control the access) is invoked with option '-p'. This daemon is configured by/System/Library/LaunchDaemons/com.apple.taskgated.plist. I was able to use this rule provided that I am also a member of the procmod group.

 

Creating a certificate

Start Keychain Access application (/Applications/Utilities/Keychain Access.app)

Open menu /Keychain Access/Certificate Assistant/Create a Certificate...

Choose a name (gdb-cert in the example), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults. Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.

If you can't store the certificate in the System keychain, create it in the login keychain, then exported it. You can then imported it into the System keychain.

Finally, using the contextual menu for the certificate, select Get Info, open the Trust item, and set Code Signing to Always Trust.

You must quit Keychain Access application in order to use the certificate and restart taskgated service by killing the current running taskgated process (so before using gdb).

 

相關文章
相關標籤/搜索