{"id":28,"date":"2005-09-02T21:16:39","date_gmt":"2005-09-03T04:16:39","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/?p=28"},"modified":"2005-09-02T21:18:18","modified_gmt":"2005-09-03T04:18:18","slug":"bonus-bugs-with-gdb","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/28\/bonus-bugs-with-gdb","title":{"rendered":"Bonus bugs with GDB"},"content":{"rendered":"<p>I guess the last bug report got me in the mood, and since it&#8217;s 11:55 here in Somerville, I have time to write up a quickie that I just noticed again, while investigating the <a href=\"http:\/\/www.red-sweater.com\/blog\/?p=27\">other bug<\/a> I reported tonight!<\/p>\n<p>\nThis 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 &#8220;info sharedlibrary&#8221; extension Apple was kind enough to add several releases ago, which allows the debugger (that&#8217;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&#8217;re digging around through somebody else&#8217;s code, you might find it handy.\n<\/p>\n<p>\nIn 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 &#8220;info shared&#8221; 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.\n<\/p>\n<p>\nIn 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:<\/p>\n<div style=\"margin-left:1cm\">\n<pre>\n(gdb) info shared 0x52240\n  1 Finder                     - 0x1000            exec Y Y \/System\/Library\/\n<\/pre>\n<\/div>\n<p>\nSweet! Love that taking away the pain functionality.  The only problem is, when a nice new feature comes along, you expect it to do <i>everything<\/i> wonderfully and perfectly. In the case of &#8220;info shared&#8221;, 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&#8217;t accept variable arguments! If I&#8217;m stopped in gdb, and I want to know where I&#8217;m at, my feeble little brain <i>still<\/i> expects &#8220;info shared&#8221; to do the right thing, so I inevitably do something like the following:<\/p>\n<div style=\"margin-left:1cm\">\n<pre>\n(gdb) info shared $pc\n[unknown]\n(gdb) ugh!\nUndefined command: \"ugh\".  Try \"help\".\n(gdb) p $pc\n$6 = 336448\n(gdb) info shared 336448\n  1 Finder                     - 0x1000            exec Y Y \/System\/Library\/CoreServices\/Finder.app\/Contents\/MacOS\/Finder (offset 0x0)\n(gdb)\n<\/pre>\n<\/div>\n<p>That&#8217;s no way to live! It&#8217;s time that this wonderful little helper got with the program. Any reasonable expression that evaluates to &#8220;a number&#8221; and can be passed to any other command in gdb should also be accepted by this little gem. Radar #4243991.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I guess the last bug report got me in the mood, and since it&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-applebugfriday","category-debugging"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}