{"id":117,"date":"2011-06-22T16:39:52","date_gmt":"2011-06-22T20:39:52","guid":{"rendered":"http:\/\/www.joshmatthews.net\/blog\/?p=117"},"modified":"2011-06-24T15:02:23","modified_gmt":"2011-06-24T19:02:23","slug":"nscomptr-has-never-been-so-pretty","status":"publish","type":"post","link":"https:\/\/www.joshmatthews.net\/blog\/2011\/06\/nscomptr-has-never-been-so-pretty\/","title":{"rendered":"nsCOMPtr has never been so pretty"},"content":{"rendered":"<p>Jim Blandy announced his <a href=\"http:\/\/itcouldbesomuchbetter.wordpress.com\/2010\/12\/20\/debugging-spidermonkey-with-archer-2\/\">archer-mozilla<\/a> pretty-printers for Spidermonkey late last year. I&#8217;ve used them a few times while working on some JS proxy bugs, and I&#8217;ve found them to be invaluable. So invaluable, in fact, that I&#8217;ve written a bunch of pretty-printers for some pain points outside of js\/.  If this prospect excites you so much that you can&#8217;t be bothered to read the remaining examples, you can acquire the code from <a href=\"http:\/\/hg.mozilla.org\/users\/josh_joshmatthews.net\/archer-mozilla\/\">its hg repo<\/a>. Please note, you&#8217;ll need to be using gdb >7.2 (meaning probably <a href=\"http:\/\/www.gnu.org\/software\/gdb\/current\/\">trunk<\/a> at the time of writing) due to dependencies on the dynamic_type feature which was recently added.<\/p>\n<h2>What&#8217;s supported right now:<\/h2>\n<h3>nsCOMPtr&lt;nsIFoo&gt;<\/h3>\n<p>If you print an nsCOMPtr, you&#8217;ll see one of two things:<br \/>\n<code>[(nsIFoo*) 0x0]<\/code><br \/>\nor<br \/>\n<code>[(nsConcreteFoo*) 0x12345678]<\/code><\/p>\n<p>In addition, pretty-printers chain, so if there&#8217;s a pretty printer for nsConcreteFoo*, you&#8217;ll see that printed instead of just the pointer value.  Furthermore, nsRefPtr and nsAutoPtr are also supported, and maybe nsWeakPtr (untested).<\/p>\n<h3>nsCString\/nsString<\/h3>\n<p>It prints the string inline, up to the limit specified by gdb. This probably only works for ascii strings at the moment; the code is a bit of a mess.<\/p>\n<h3>nsTArray\/InfallibleTArray<\/h3>\n<p>You&#8217;ll get output along the lines of <code>[0x12345678, 0x12345678]<\/code> at the moment. Like the smart pointers, each printed element will be pretty-printed if possible.<\/p>\n<h3>nsStandardURL*<\/h3>\n<p>You&#8217;ll see the spec printed. This works wonderfully when you&#8217;re looking at an object with nsCOMPtr&lt;nsIURI&gt; foo, where foo is actually pointing to an nsStandardURL object.<\/p>\n<h3>Tagged reference counts<\/h3>\n<p>You know in cycle-collected objects when the refcount shows you <code>mTagged = 0x8<\/code>? Yeah, not any more.<\/p>\n<h3>PRPackedBool<\/h3>\n<p>I found the existing display of <code>mBoolVal = 1 '\\001'<\/code> to be silly.<\/p>\n<h2>What&#8217;s coming up?<\/h2>\n<p>I&#8217;ve got a list of things that still need fixing\/improving, and I&#8217;m open to suggestions\/patches.<\/p>\n<ul>\n<li>Auto arrays &#8211; the kinda-sorta work right now, but it looks gross.<\/li>\n<li>COM\/void\/observer arrays &#8211; don&#8217;t work at all<\/li>\n<li>Hashtables &#8211; don&#8217;t work at all right now<\/li>\n<li>Stricter regexes for matching types &#8211; things like pointers to arrays are matched by the nsTArray printer right now<\/li>\n<li>Auto strings &#8211; I don&#8217;t remember if they don&#8217;t work at all or semi-work<\/li>\n<li>PRUnichar* &#8211; doesn&#8217;t work.<\/li>\n<\/ul>\n<p>and so on and so forth. It&#8217;s really not difficult to write more printers, and it improves the output of gdb immensely in my opinion. Give it a shot! The instructions for how to set this up can be found in the README file. You&#8217;ll need a version of gdb > 7.2 (probably trunk, at the time of writing), since my printers rely on gdb.Type.dynamic_type.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jim Blandy announced his archer-mozilla pretty-printers for Spidermonkey late last year. I&#8217;ve used them a few times while working on some JS proxy bugs, and I&#8217;ve found them to be invaluable. So invaluable, in fact, that I&#8217;ve written a bunch &hellip; <a href=\"https:\/\/www.joshmatthews.net\/blog\/2011\/06\/nscomptr-has-never-been-so-pretty\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,15,22],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-code","category-mozilla","category-projects"],"_links":{"self":[{"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":8,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshmatthews.net\/blog\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}