

How to compile GDB in Mountain Lion (updated)
source link: https://reverse.put.as/2013/03/20/how-to-compile-gdb-in-mountain-lion-updated/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to compile GDB in Mountain Lion (updated)
This is an up-to-date version of the old original post about recompiling GDB and other open source packages available at opensource.apple.com. I’m doing it mostly because code signing is now mandatory for GDB and there’s a stupid old bug that Apple still didn’t fixed since Snow Leopard. I forgot about it on my latest reinstall and lost an afternoon. This way you and me will not make the same mistake.
You should have Xcode installed. Follow these steps:
-
Download darwinbuild from their SVN repository.
-
Since Snow Leopard there is a svn client by default so no need to download.
-
Follow the instructions on how to download,compile and install darwinbuild here. Use the guide for Snow Leopard/Lion version, it’s compatible with Mountain Lion.
-
Compile and install darwinbuild:
$ make ; sudo make install
- Create the DMG file and initialize darwinbuild environment (you should use at least 2 gigabytes):
The plists and build numbers are available at http://svn.macosforge.org/repository/darwinbuild/trunk/plists/. Use build number 12A269 (it’s for 10.8.0 but works ok for all others).
$ hdiutil create -size 2G -type UDIF -fs HFSX -volname Builds -uid 0 -gid 0 -attach Builds.dmg
$ sudo sh
# vsdbutil -a /Volumes/Builds
# cd /Volumes/Builds
# mkdir Build12A269
# cd Build12A269
# darwinbuild -init 12A269 (you need Internet connection)
# darwinxref edit
In darwinxref edit you need to add the GDB package to the configuration. Go to the projects section and add the following:
gdb = {
version = 1822;
};
Default editor is vi. Save and quit. If you have a problem with an invalid property list, use the same tab alignment as the other entries. That should fix it.
- Clone the gdb-ng repo from github if you want my patches included (you probably do!). Else skip to next (darwinbuild will download the package from Apple opensource repo).
# cd /Volumes/Builds/Build12A269/Sources
# git clone git://github.com/gdbinit/gdb-ng.git
# cd gdb-ng
# bash pack.sh
# mv gdb-1822.tar.gz .. (check version in case it changes)
# cd /Volumes/Builds/Build12A269
- Compile GDB.
# darwinbuild -nochroot gdb
The -nosource option has been added to recent darwinbuild versions. This option will allow you to patch directly into BuildRoot/SourceCache/. The first time you shouldn’t use this option so darwinbuild will download the GDB package. After that you can use it if you want to patch directly GDB source files (that’s what I do with my GDB patches). It’s much easier and faster than having to patch and compress the whole GDB source. After you patch, you just issue darwinbuild -nochroot -nosource gdb and this will not unpack the original source but instead use whatever is at SourceCache.
Wait for the compilation to finish…
Go to Roots/gdb/gdb-1822.root*/usr/libexec/gdb. You should have a gdb-i386-apple-darwin binary. Backup the original and copy this one over.
# cp /usr/libexec/gdb/gdb-i386-apple-darwin /usr/libexec/gdb/gdb-i386-apple-darwin.orig
# cp gdb-i386-apple-darwin /usr/libexec/gdb/
The latest step is to codesign the binary. This is because taskgated default configuration has changed and it’s not anymore sufficient to have the binary suid to procmod group. It must have entitlements and be codesigned. The process is not just creating a self-signed certificate and codesign the binary with it. There is an old bug since Snow Leopard that complicates it a little bit. Follow this guide from LLDB code signing document. You can either code sign the binary you copied above to /usr/libexec/gdb or sign it at the Roots folder and copy the signed version.
Launch GDB and see if it works. It should ask you for your password the first time (after each reboot). If everything is ok you should be able to attach to or run the target process.
Now you can enjoy your next afternoon in case you want/have to compile GDB. You might also want to download and install gdbinit to improve GDB output and available commands.
Recommend
-
15
Mountain Lion misery with AirPlay Last summer, I wrote about the lack of coverage for Airplay on Apple's actual computer line. In short, you could throw basically any...
-
11
Alternative explanations for mountain lion safety signs Writing Software, technology, sysadmin war stories, and more. Saturday, March 10, 2012 Alternati...
-
6
Home Chevron iconIt indicates an expandable section or menu, or sometimes previous / next navigation options.Travel ...
-
9
VMware 9 安装 Mac OS X 10.8 Mountain Lion 图文全程 2012-10-20 — Yanbin 本教程是在 VMware 9 下安装当前最新版的 Mac OS X Mountain Lion 苹果系统。曾在 VirtualBox/VMware 下安装过 Mac OS Lion 系统,但安装后是无法升级到 Mountain L...
-
12
Apple finally makes OS X Lion and Mountain Lion free to downloadNews
-
7
How to compile GDB for iOS! One obstacle that I faced long time ago and came again into spotlight is how to recompile GDB for iOS. It is not useful to fix the ARM disassembler and then not be able to compile. As far as I know...
-
10
How GDB disables ASLR in Mac OS X Lion This isn’t a rocket science post but more like some notes for future reference ?. Lion finally introduces full ASLR and GDB has the possibility to disable that fea...
-
11
Developer ID, Mountain Lion, and the Keychain Posted on August 26, 2012 Recently, I released a Cheddar for Mac
-
7
Unhide hidden ~/Library in OSX Mountain Lion: chflags nohidden ~/Library For some reason in OS X Lion+ Apple hides the Library folder that normally appears in a User’s Home folder. To p...
-
12
Are you annoyed that you need to wait almost 3 seconds for the stupid Apple Mail animation to complete when replying/forwarding a message? Thankfully you can turn off that behavior with a little command line: defaults wri...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK