mac上eclipse用gdb调试(转)
With its new OS release, Apple has discontinued the use of GDB in OS X. Since 2005 Apple has steadily been moving away from the GNU toolchain in favor of LLVM. This means that Xcode now uses LLDB instead.
LLDB looks to be a very nice replacement for GDB, and I hope to use it in the future, but currently Xcode is the only graphical front-end that supports its use; pretty much every other debugging GUI uses GDB under the hood, including Eclipse. So, if you want to debug C/C++ code in Eclipse CDT on the Mac, you must install GDB.1
Here is the procedure that worked for me.2 Others have reported issues with this, so please do let me know in the comments if it doesn't work for you.
Known Issues
GDB will not be able to breakpoint inside any template function, though it should be able to step into it. This problem may be resolved if you use the MacPorts installation procedure (below) but it may only work if you also compile with Apple's GCC.
It was also reported in the comments that it cannot breakpoint into a shared library function. I have not confirmed this issue myself.
Installing GDB
You can install via MacPorts or Homebrew. MacPorts has Apple's official GDB distribution, which is modified for OS X. This is probably the best option (thanks to CC's comment for this tip). However, on my machine this only seems to work if the program is compiled using Apple's GCC, which is no longer supported by Apple. All things being equal, I vastly prefer to avoid MacPorts altogether. So I installed with Homebrew, despite recommending MacPorts. If you have no preference either way, go with MacPorts.
Install with MacPorts
- Install Xcode and MacPorts, if not already installed.
- Now install the Apple GCC and GDB from MacPorts:
$ sudo port install gdb-apple
$ sudo port install apple-gcc42 - For the remainder of the tutorial, use /opt/local/bin/gdb-apple as the GDB executable
- Remember if you want breakpoints in template functions to work, you'll need to change your compiler to g++-apple-4.2 instead of g++! This can be done in your Makefiles or in your IDE settings.
Install with Homebrew
- Install Xcode and Homebrew, if not already installed.
- Now install GDB from Homebrew:
$ brew tap homebrew/dupes
$ brew install gdb - For the remainder of the tutorial, use /usr/local/bin/gdb as the GDB executable
If that worked, then lucky you! Getting it compiled is where many people seem to have trouble. Now you just need to sign it to give it permission to control OS X processes.
Certifying GDB
Open up the Keychain Access application (/Applications/Utilities/Keychain Access.app). Navigate via the menu to Keychain Access > Certificate Assistant > Create Certificate...
Enter a name for the certificate. For this how-to, I'll call it "gdb-cert". Set the fields exactly as shown below.
The maximum validity period is 999 days. I don't really want to deal with this again, so I'm going to max it out.
Keep clicking the "Continue" button until you are asked for a location. Set it to "System".3
Success!
Now make sure the cert is always trusted. Right-click the new certificate and select Get Info. Under the Trust section, set Code Signing to Always Trust.
Now that we have a certificate, we need to use it to sign GDB. First, we'll restart the taskgatedprocess to make sure it picks up the new certificate. Quit Keychain Access (you must quit Keychain Access!) and return to the Terminal for these final commands.
Find the taskgated process.
56822 ?? 0:03.11 /usr/libexec/taskgated -s
60944 ttys002 0:00.00 grep --color=auto taskgated
The first number in the above output is the PID. Use this to kill the process (it will immediately restart itself).
Now you can finally code sign GDB.
$ codesign -s gdb-cert $(which gdb-apple)
# Homebrew version
$ codesign -s gdb-cert $(which gdb)
Now you should be all set! The OS X Keychain may ask for your password the first time you attempt to debug a program, but it should work!
Getting it to Work with Eclipse
There's one more step for Eclipse users. You need to specify where Eclipse can find the new GDB. Specify the path to GDB in Preferences > C/C++ > Debug > GDB:
If you already have some debug configurations, you may need to edit them individually to point to the correct place (under Run > Debug Configurations...):
- The CDT developers are planning to support LLDB, but they will have to write a whole new interface, and I think most of them only work on Eclipse in their spare time, so it will likely be at least some months before LLDB support is there.
- The procedure is derived from this StackOverflow post and this GDB Wiki page.
- If you are unable to save it to the System keychain, then save it to the login keychain. You can later export the cert, and then import it into the System keychain. I didn't have to do this, so comment if you have any problem.
mac上eclipse用gdb调试(转)的更多相关文章
- Eclipse+CDT+GDB调试android NDK程序(转)
Eclipse+CDT+gdb调试android ndk程序 先介绍一下开发环境,在这个环境下,up主保证是没有问题的. ubuntu 11.10 eclipse 3.7(indego) for ja ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- 在mac上如何用safari调试ios手机的移动端页面
第一步:打开iphone手机的开发者模式,流程是:[设置]->[Safari]->[高级]->开启[Web检查器] ,如图1.图2 图1 图2第二步:打开Mac上Safari的开发者 ...
- 对“线上问题 不能gdb调试怎么处理??“”的思考
Q1:线上问题的process 都为release版本!不带调试信息怎么查?(目前有时需要查线上问题, 不得不解决这个问题) 之前查问题都是编译环境编译一个带有debug信息的版本进行替换来调试,但是 ...
- 使用 VSCode 在 Mac 上配置 C/C++ 调试环境
Background VSCode是微软开发的一款开源代码编辑器,具有可拓展性强,多语言支持,跨平台等优点,在不同的个性化配置下几乎可以用作所有的轻量级开发.我在初学C的时候也使用的是类似于Xcode ...
- mac上eclipse上运行word count
1.打开eclipse之后,建立wordcount项目 package wordcount; import java.io.IOException; import java.util.StringTo ...
- Mac下Eclipse/adb无法调试MX5手机
前提是环境已经配置好,其他手机可以连接但MX系列不可以 解决方法:打开终端 echo 0x2a45 >> ~/.android/adb_usb.ini adb kill-server ad ...
- Mac配置Eclipse CDT的Debug出现的问题(转)
问题1:出现 Could not determine GDB version using command: gdb --version 原因: mac上没有安装gdb或者gdb位置配置有问题 解决 ...
- mac OSX上eclipse adb无法识别(调试)小米的解决方案
最近在Mac上开发安卓,用小米2a作为开发机,连上电脑后发现idea和eclipse真机调试的时候都提示USB device not found.经过一番google和百度,终于找到了解决方案,在这里 ...
随机推荐
- ubuntu下的时间设定(硬件时间,系统时间,本地时间)
问题的来由是在这里: 在cron里设定任务是在凌晨6点执行,检查日志时发现时间总是不对,是在22点左右的时间执行的.研究发现,任务是在本地时间的6点执行了,但不知为什么syslog中的时间都是为utc ...
- vm网络设置
设置NET模式 cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="stati ...
- web前端开发和后端开发有什么区别?
web前端分为网页设计师.网页美工.web前端开发工程师 首先网页设计师是对网页的架构.色彩以及网站的整体页面代码负责 网页美工只针对UI这块儿的东西,比如网站是否做的漂亮 web前端开发工程师是负责 ...
- h5 与app交互
http://www.jianshu.com/p/7151987f012d JSContext *context = [self.webView valueForKeyPath:@"docu ...
- mysql 几个命令
show databases; 显示所有数据库 create database 数据库名; 创建数据库 drop database 数据库名; 删除数据库
- Python 的安装与配置(Windows)
Python2.7安装配置 python的官网地址:https://www.python.org/ 我这里下载的是python2.7.12版本的 下载后点击安装文件,直接点击下一步知道finally完 ...
- vi编辑器的使用
在命令模式下进入编辑模式,输入字母"a","A","i","I","o","O" ...
- RGB颜色表
RGB(255,23,140)是光的三原色,也即红绿蓝Red.Green.Blue,它们的最大值是255,相当于100%. 白色:rgb(255,255,255) 黑色:rgb(0,0,0) 红色:r ...
- 使用geoserver发布arcgis切片
arcgis map 版本:10.1,10.2,10.3均可 jre:7或者8 geoserver:2.8.2以上 切片:松散型,256*256 ,png 1:安装geoserver并独立部署geo ...
- mbed学习之Digital IO (一)
mbed的IO操作非常灵活,常见的关于Digital IO操作整理如下表 ,其中蓝色字体是构造函数,绿色字体的是操作符重载,使用时只要创建对象,就可以调用对应的方法来操作,并且每种都提供了操作符重载, ...