One known problem with Apple’s fork of open source software is their slowness in fixing vulnerabilities and bugs. GDB fork isn’t immune to this; it was forked around release 6.6 or something like that and lots of stuff isn’t kept in sync with GNU’s GDB version.

The short story for this bug is that you can’t have a commands command inside a define command. This creates some problems for useful scripting. The funny thing is that I had hit this bug a few weeks ago but didn’t paid any attention to it, just worked around it and never bothered to understand why my script didn’t work.
What I did here was to find where the bug was, compare with GNU GDB to find where it was fixed (version 6.7) and backport the required code. So all coding work was done by someone else (thank you 😃). I just “reversed” the problem!

Hey Apple, I am not your codebase maintainer (but I would be interested in working for you, probably in Strategy or Marketing, since you rock at those areas [well I also love design but I can’t draw anything] and I suck at coding, LOL).

For now I will only post the patch – the version that includes all previous patches, and another just for this bug. Later I will put up patched binaries for Leopard/Snow Leopard and Lion.
I have to format my computer since I had to install some Chinese kernel drivers for Internet access. I do not trust their shit, especially low level stuff such as kernel drivers (TODO list has one more item – verify the code for those modules!). It’s a real sad state of affairs! But a format once in a while is always healthy, despite what is commonly said in Mac space.

To patch & compile your own GDB, please refer to here and here.


SHA256(all_patches_v0.3.patch.gz)= 38a891327b14b94d73b7e6f5ef66b4848df03a59a8bac5e89b93869046078608

SHA256(commands_bug.patch.gz)= b84be03e73a5a5ada59ab8b7fbd595e531fe149446418750d5d747d6598aa6a0


Here is the binary version for Snow Leopard, 32 and 64 bit fat binary. Replace as in /usr/libexec/gdb and don’t forget to fix permissions.

(SHA256(gdb-i386-apple-darwin.1344)= a0be45855569ad76c24f3422597c97aafa7bbb4d78793361f5978567be0f2506)

And the version for Lion, also a fat binary for 32 and 64 bit.

(SHA256(gdb-i386-apple-darwin-1705)= be1c462c8f271fd59581142d8d87a410d2cf1d2fcf27019796bee6424e50a9c6)

End of update

Here’s how the problem looks like:

$ gdb
GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Mon Feb 28 15:50:14 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
gdb$ define test
>b *0x1000
>commands 1
>set $eax=1
gdb$ bpl
No breakpoints or watchpoints.
gdb$ test
Breakpoint 1 at 0x1000
gdb$ bpl
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00001000