Tuesday, October 13, 2009

Avoiding strange gdb errors in SnowLeopard

If you’re suddenly experiencing the following warnings when loading a binary
unable to read unknown load command 0x80000022
and the following error when running your binary
Error calling thread_get_state for GP registers for thread 0x14855lxerror on line 207 of "/SourceCache/gdb/gdb-768/src/gdb/macosx/i386-macosx-nat-exec.c" in function "fetch_interior_register": (os/kern) invalid argument (0x4)
then it’s very likely you’re running the wrong version of gdb. In my case, I have both Xcode 3.0 and Xcode 3.2 installed, since the former is the “officially supported” toolset (i.e., what the build lab is using to produce our products). Unfortunately, our build environment, in an attempt to keep you from accidentally using the wrong tools / SDK to build the product, will set the path to include the official toolset’s /usr/bin (e.g., /Xcode3.0/usr/bin) before /usr/bin. Thus, I was accidentally getting the older version of gdb, which doesn’t work quite right on SnowLeopard.

Fix: Use the Xcode 3.2 (or later) version of gdb.