OS X Mavericks Xcode 5 上找回GDB

来源:互联网 发布:纽约大学 知乎 编辑:程序博客网 时间:2024/05/21 10:33

最近比较忙,忙着找一个新下家,结果很多东西就没来得及写,今天来聊聊GDB。

从Xcode5开始,OS X彻底移除了GDB调试工具,对于很多在Linux上用惯的人难免会感觉难受,一心想找回GDB,那么这篇文章就是来告诉你如何找回GDB的。

要声明的是:以下内容转载于部分网站,已全部链接。


英文原文: GDB on OS X Mavericks and Xcode 5 

http://wiki.lazarus.freepascal.org/GDB_on_OS_X_Mavericks_and_Xcode_5


在这里我们用到了一个类似Ubuntu中的APT包管理工具/机制——Homebrew,其中文网站为

http://brew.sh/index_zh-cn.html

自然,上面也完全介绍了如何使用Homebrew。


下面笔者简要概括下如何使用Homebrew来安装久违的GDB。由于奇特的中国网络关系,有可能导致下载经常性的失败,多试几次甚至隔两天试下就好了,笔者是在夜里12点才成功的Q_Q

打开你的mac终端,键入命令来安装Homebrew

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”

安装过程是全英文的,要键入密码键入就好,当然了最后会提示:

==> Downloading and installing Homebrew…

如果接下来没有文字出现,那么你很可能悲剧,强制关掉按照提示键入

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

后在键入一开始的命令即可。直到如下提示:==> Downloading and installing Homebrew...

remote: Counting objects: 167631, done.

remote: Compressing objects: 100% (47010/47010), done.

remote: Total 167631 (delta 119526), reused 167604 (delta 119505)

Receiving objects: 100% (167631/167631), 31.94 MiB | 103.00 KiB/s, done.

Resolving deltas: 100% (119526/119526), done.

From https://github.com/Homebrew/homebrew

 * [new branch]      master     -> origin/master

HEAD is now at 20dbbe0 ola: add Python support and change homepage.

==> Installation successful!

You should run `brew doctor' *before* you install anything.

Now type: brew help

部分可能不同不过看到successfully的字样就搞定了。

随后就可以安装GDB了。

brew installhttps://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

网址是基于github的相关安装包,大部分情况下不会改变,要是找不到就得自己去查找了。

当你看到如下提示表示你已经成功了一半。

gdb requires special privileges to access Mach ports.

You will need to codesign the binary. For instructions, see:


 http://sourceware.org/gdb/wiki/BuildingOnDarwin

接着另一半步骤就是授权。

1. 打开“钥匙串访问”(/Applications/Utilities/Keychain Access.app)

2. 打开 菜单钥匙串访问-证书助理-创建证书

3. 键入一个名字比如“gdb”,身份类型为“自签名根证书”,证书类型为“代码签名”,选择“让我覆盖这些默认值”

4. 至于授权时间默认是365天,哦,你可以自己设置,不过过期不能用,你看着办吧

5. 然后一直到证书存放位置的选项,一半建议选择系统根钥匙串,要是不行选登陆也行

6. 这时候创建完成,在钥匙串访问中找到你刚刚创建的证书,选择显示简介,在信任栏里选择总是信任

7. 退出钥匙串访问并且重启你的系统,当然你也可以仅仅重新启动“taskgated”服务

这时候大功告成,在终端输入 codesign -s gdb-cert /usr/local/bin/gdb后,直接键入GDB,熟悉的GDB又回来了~

GNU gdb (GDB) 7.7

Copyright (C) 2014 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-apple-darwin13.0.0".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:

<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".

Type "apropos word" to search for commands related to "word".

(gdb) quit

当然了,其实Xcode和lldb的搭配还是不错的,而且熟悉GDB的也会比较喜欢lldb吧。

两者对比可以参考

http://blog.sina.com.cn/s/blog_71715bf801016d38.html

基本GDB命令

http://blog.sina.com.cn/s/blog_71715bf801016d2y.html


The End.


转载请注明出处。

0 0
原创粉丝点击