博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mac上eclipse用gdb调试
阅读量:6525 次
发布时间:2019-06-24

本文共 4766 字,大约阅读时间需要 15 分钟。

With its new OS release, Apple has discontinued the use of  in OS X. Since 2005 Apple has steadily been moving away from the GNU toolchain in favor of . This means that Xcode now uses  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  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 , 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 , 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 , 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  and .
    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.

转载地址:http://objbo.baihongyu.com/

你可能感兴趣的文章
iphone IOS5.0都有哪些新功能
查看>>
单例模式(Singleton)
查看>>
函数指针和指针函数
查看>>
认识配置设置文件(INI与XML)
查看>>
影响谷歌排名算法的因素(2) – 页面的外链数量和质量
查看>>
POJ-1753 Flip Game 枚举 状态压缩
查看>>
DZ!NT论坛 3.6.711删除用户各种错解决方案
查看>>
Python的函数参数传递:传值?引用?
查看>>
HDU 1426 Sudoku Killer(搜索)
查看>>
[转]分享2011年8个最新的jQuery Mobile在线教程
查看>>
云平台 测试
查看>>
64位Win8企业版终于使用Hyper-V功能了!
查看>>
android call require api level
查看>>
redis简介
查看>>
Mac下android环境搭建
查看>>
Visual Studio及TFS进行单元测试、负载测试、代码覆盖率、每日构建配置
查看>>
创建Visual Studio项目模版向导的几篇参考文章
查看>>
深入浅出SQL Server Replication第一篇:走近Replication(上)
查看>>
Windows 8,VS 2012,SQL Server 2012,Office 2013使用体验
查看>>
c++中dll的种类用法分析
查看>>