mac上eclipse用gdb调试(转)

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

  1. Install Xcode and MacPorts, if not already installed.
  2. Now install the Apple GCC and GDB from MacPorts:

    $ sudo port install gdb-apple
    $ sudo port install apple-gcc42

  3. For the remainder of the tutorial, use /opt/local/bin/gdb-apple as the GDB executable
  4. 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

  1. Install Xcode and Homebrew, if not already installed.
  2. Now install GDB from Homebrew:

    $ brew tap homebrew/dupes
    $ brew install gdb

  3. 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.

$ ps -e | grep taskgated
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).

$ sudo kill -9 56822

Now you can finally code sign GDB.

# MacPorts version
$ 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...):


    1. 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.
    2. The procedure is derived from this StackOverflow post and this GDB Wiki page.
    3. 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.
时间: 2024-10-08 10:20:45

mac上eclipse用gdb调试(转)的相关文章

Eclipse+CDT+GDB调试android NDK程序(转)

Eclipse+CDT+gdb调试android ndk程序 先介绍一下开发环境,在这个环境下,up主保证是没有问题的. ubuntu 11.10 eclipse 3.7(indego) for java jdk 6 android sdk 2.2 andrid ndk r7 当然,在windows环境下通过cygwin等工具也是可以实现gdb调试的,我也确实实现过.但是性能实在太低,卡的根本没法用.Linux下直接用gdb调试本地方法是很流畅的. 再确定安装并配置好开发环境之后,就可以开始了.

mac上eclipse上运行word count

1.打开eclipse之后,建立wordcount项目 package wordcount; import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.had

mysql在mac上的编译和调试

今天正式开始漫漫长路,打算这几年用业余时间刷刷mysql5.5源代码,由于手边的书籍基本都是基于mysql5.5的,所以就不用5.7版本的代码了,更何况我更关注基本内核.因此,没有特殊指明,那么,一般都指mysql5.5版本.工作原因没有深入去了解mysql,既然想玩技术,工作上的技术挑战没有研究mysql内核这么直接,因此,决定用业余时间搞搞些技术活,一方面可以让自己的技术深入储备,另一方面也让自己在工作之余从技术中获得点点成就感. 选择mac平台因为简单,windows平台我也编译成功了,但

windows下eclipse中gdb调试输出stl容器的内容(终极解决方案)

摸索了一天终于把这个问题搞定了 首先下载MinGw 地址:http://sourceforge.net/projects/mingw/?source=directory 下载完之后安装G++,在安装程序中步骤如下 之后利用CMD安装gdb-python MinGw-get.exe install gdb-python 同时安装GDB 同时按照以下步骤安装并配置Python 1)从http://python.org/download/下载python 2.7.x 2)设置python环境变量 PY

Mac上eclipse+tomcat+mysql的配置

来源:http://stephen830.iteye.com/blog/2001939 安装 mysql MySQL Community Server (GPL)  5.6.15 安装 tomcat7.0 http://tomcat.apache.org/download-70.cgi 下载的是tar版 安装 jdk1.7 安装 eclipse 在启动eclipse的时候说找不到jdk,就自动下载了一个1.6的jdk. eclipse启动后发现里面有2个jre. 还是选择先前安装的1.7的jdk

Mac OSX上eclipse adb 无法识别(调试)真机的解决方案

最近在Mac上开发安卓,遇到个问题.用vivo x3t作为开发机,连上电脑后发现eclipse中ddms里没有我的真机,经过一番google和百度,终于找到了解决方案,在这里分享给大家. 如果遇到adb命令提示找不到的情况,可以看我另外一篇文章,MAC中设置android adb环境变量 1.首先,确保已经安装了android sdk或者集成开发环境ADT.将手机连接到电脑上之后,在终端中输入 [plain] view plaincopy adb devices 如果回车后看到有设备则说明已经配

mac安装gdb调试(转载)

转载自:http://blog.plotcup.com/a/129 最近一直用go写一个项目,本想在mac上用gdb调试一下,但xcode4.6带的gdb版 本还是太低了,不支持go,只好自己安装一个.本以为直接brew install gdb就 完事了,后来发现不是那么回事,还要给gdb制作证书签名.下面是操作步骤: 安装gdb brew install gdb 程序编译完成后在/usr/local/bin/下面建立一个gdb的软链,并且将/usr/bin/ 下面的gdb改名. 制作证书 打开

Mac上使用Visual Studio Code开发/调试.NET Core代码

Mac上使用Visual Studio Code开发/调试.NET Core代码 .Net Core 1.0终于发布了,Core的一大卖点就是跨平台.这个跨平台不只是跨平台运行,而且可以跨平台开发.今天抽空研究了下在Mac下如何使用VS Code来开发.NET Core程序,并且调试代码. 1.安装.NET Core 在mac上打开终端: ~$ brew update ~$ brew install openssl ~$ brew link --force openssl 如果不能使用brew命

在Mac上使用Visual Studio Code开发/调试.NET Core代码

.Net Core 1.0终于发布了,Core的一大卖点就是跨平台.这个跨平台不只是跨平台运行,而且可以跨平台开发.今天抽空研究了下在Mac下如何使用VS Code来开发.NET Core程序,并且调试代码. 1.安装.NET Core 在mac上打开终端: ~$ brew update ~$ brew install openssl ~$ brew link --force openssl 如果不能使用brew命令,先安装homebrew,玩转Mac必备. 下载.NET Core SDK:ht