I guess the last bug report got me in the mood, and since it’s 11:55 here in Somerville, I have time to write up a quickie that I just noticed again, while investigating the other bug I reported tonight!
This is an obscure bug, but part of my reason for sharing it in a post is that some of you may not be familiar with the particular feature of gdb where this bug rears its head. The feature I speak of is the “info sharedlibrary” extension Apple was kind enough to add several releases ago, which allows the debugger (that’s you!) to easily match up an address in code memory with the shared library from which it was loaded. I thought some of you might not know about it, and the next time you’re digging around through somebody else’s code, you might find it handy.
In the old days (haha! old, meaning like, 2001), if we ran across a mystery chunk of code in gdb, we had to do a plain “info shared” and then scan through the list of libraries, forcing our brains into hex overdrive as we tried to match the address with the ranges of addresses attributed to the bazillion libraries that had inevitably been loaded into the process.
In the new days (haha! new, meaning like, 2003), Apple added the obvious argument to this utility, which allows you to specify the particular address your interested in, and have gdb handle the hard searching for you:
(gdb) info shared 0x52240 1 Finder - 0x1000 exec Y Y /System/Library/
Sweet! Love that taking away the pain functionality. The only problem is, when a nice new feature comes along, you expect it to do everything wonderfully and perfectly. In the case of “info shared”, a major drawback has plagued it since its inception. Sure, it lets you find the associated shared library for an address, but it fails to extend this concept in the most freaking obvious way imaginable. It doesn’t accept variable arguments! If I’m stopped in gdb, and I want to know where I’m at, my feeble little brain still expects “info shared” to do the right thing, so I inevitably do something like the following:
(gdb) info shared $pc [unknown] (gdb) ugh! Undefined command: "ugh". Try "help". (gdb) p $pc $6 = 336448 (gdb) info shared 336448 1 Finder - 0x1000 exec Y Y /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder (offset 0x0) (gdb)
That’s no way to live! It’s time that this wonderful little helper got with the program. Any reasonable expression that evaluates to “a number” and can be passed to any other command in gdb should also be accepted by this little gem. Radar #4243991.