2016年6月15日星期三

Mac 配置 Eclipse gdb

 Mac 下Eclipse C++默认采用gdb调试代码, 但是mac为支持自己的debugger, 不再默认安装gdb.

1) 安装gdb

https://www.gnu.org/software/gdb/

下载解压后:
./configure
make
sudo make install

安装后, which gdb显示/usr/local/bin/gdb

2) 配置gdb for eclipse
菜单 Eclipse --> Preferences --> C/C++ --> Debug --> GDB, 确保GDB debugger中选择的gdb路径正确.

3) 注册gdb
虽然上以设置gdb路径正确, 启动C++的debug模式, 会一直保留在 Launching : Configuring GDB Aborting configuring GDB

需要注册gdb, 注册方法 (http://stackoverflow.com/questions/19877047/eclipse-gdb-macosx-mavericks):

------------------
This means Eclipse can find the GDB now but cannot run it because of the Apple certificates issue.
To sign the GDB application and make it possible that Eclipse runs it follow the guide here:
https://sourceware.org/gdb/wiki/BuildingOnDarwin
which can be summarized in:
  1. Start Keychain Access application (/Applications/Utilities/Keychain Access.app)
  2. Open menu /Keychain Access/Certificate Assistant/Create a Certificate (TOP MENU BAR)
  3. Choose a name (gdb-cert in the example) 3.1 Set "Identity Type" to "Self Signed Root" 3.2 Set "Certificate Type" to "Code Signing" 3.3 Check the flag "Let me override defaults" 3.4 Click several times on "Continue" until you get to the "Specify a Location For The Certificate screen" then set Keychain to "System" 3.5 If you can't store the certificate in the "System" keychain, create it in the "login" keychain, then export it. You can then import it into the "System" keychain. 3.6 Make sure you have the "gdb-cert" in your "System" (left top window)
  4. Select "Get Info" by pressing twice on the fresh made certificate (gdb-cert),
  5. Open the "Trus"t item, and set "Code Signing to Always Trust"
  6. Close Keychain Access application
  7. Restart "taskgated" application from activity monitor
Now you need to sign the Certificated by doing from terminal
$ codesign -s gdb-cert ../path of GDB
Example:
$ codesign -s gdb-cert /usr/local/bin/gdb
------------------

重新启动eclipse, debug成功.