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和百度,终于找到了解决方案,在这里 ...
随机推荐
- golang map getkeys
golang 获取map的keys package main import "fmt" import "reflect" func main() { abc : ...
- jsp中的form表单中的 id和name有什么区别了
<form action="./system/WebServer_webServerLogin" method="post" id="login ...
- 第一篇:白话tornado源码之一个脚本引发的血案
本系列博文计划: 1.剖析基于Python的Web框架Tornado的源码 2.为Python开发一个完善的MVC框架 首先将带着大家一起来剖析基于python编写的Web框架 tornado ,本着 ...
- Spring操作指南-IoC基础环境配置(基于XML)
- Ubuntu下安装Numpy, SciPy and Matplotlib
Python开发环境包含科学计算,需要安装NumPy, SciPy, Matplotlib.其中Matplotlib依赖于Python和NumPy.我们先安装NumPY和SciPy. Matplot ...
- java List<Item> its=new ArrayList<Item>(); Map按value中的某字段排序
public List<Item> getAllItem(){ Map<Long, Item> itemDic = new HashMap<Long, Item>( ...
- Android -- 常见控件的小效果
1,EditText控件 ① 修改光标颜色 自定义drawable 创建cursor.xml文件 <?xml version="1.0" encoding="utf ...
- app推送中的通知和消息区别
最近在做mqtt及其他消息推送的功能,推送服务挺多的,小米推,极光推,华为推,个推等,当然还有苹果的apns.感觉都差不多,尝试了apns,小米推和个推,各个厂家都提供的有sdk,demo. 关于通知 ...
- 【转载】jQuery动画连续触发、滞后反复执行解决办法
转载: http://www.cnblogs.com/yuejin/archive/2012/12/18/2822595.html jQuery中slideUp .slideDown.animate等 ...
- 非常强大的table根据表头排序,点击表头名称,对其内容排序
js代码: /** * 通过表头对表列进行排序 * * @param sTableID * 要处理的表ID<table id=''> * @param iCol * 字段列id eg: 0 ...