<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/html" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Ross Burton</title><link>http://www.burtonini.com/blog</link><description>A potted account of Ross' life</description><language>en</language><ttl>60</ttl><dc:creator>Ross Burton</dc:creator><admin:generatorAgent rdf:resource="http://pyblosxom.sourceforge.net/"/><admin:errorReportsTo rdf:resource="mailto:ross@burtonini.com"/><item><title>Secret GObject Fu</title><guid isPermaLink="false">computers/secret-gobject-2005-06-29-11-02</guid><link>http://www.burtonini.com/blog/computers/secret-gobject-2005-06-29-11-02</link><description>Whilst trying to find a nasty reference counting problem in my code, Alex told me about the g_trap_object_ref variable in ...</description><content:encoded><![CDATA[    <p>
      Whilst trying to find a nasty reference counting problem in my code, Alex
      told me about the <tt>g_trap_object_ref</tt> variable in debug builds of
      GObject.  Basically, when a debug version of GObject refs or unrefs an
      object, it is compared to the pointer in <tt>g_trap_object_ref</tt>, and
      if it matches it causes a breakpoint.
    </p>
    <p>
      Very useful, I can do this:
    </p>
    <pre>
$ libtool gdb ./EDataBookFactory...
[line 191 is known to be after my object has been created]
(gdb) break e-data-book-factory.c:191
(gdb) run
Breakpoint 1, impl_BookFactory_getBook (...) at e-data-book-factory.c:191
[book is the pointer to the new object]
(gdb) set g_trap_object_ref=book
(gdb) cont
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0xb7e74869 in IA__g_object_ref (_object=0x806fd88) at gobject.c:1672
1672        G_BREAKPOINT ();
(gdb) bt
#0  0xb7e74869 in IA__g_object_ref (...) at gobject.c:1672
#1  0xb7e751a1 in IA__g_value_set_object (...) at gobject.c:1907
#2  0xb7e52f74 in invoke_object_method (...) at dbus-gobject.c:848
...</pre>
    <p>
      Here ew can see that <tt>invoke_object_method</tt> in
      <tt>dbus-gobject.c</tt> is incrementing the reference count on my object
      via a <tt>GValue</tt>.  A quick peek at the code reveals that this
      reference is not being released in some situations, which I fixed and now
      my objects are being disposed as expected.
    </p>
    <p>
      I hope this is a documented feature, and if not I'll add a comment about
      it when CVS is back.  To make my life complete, if anyone knows a way to
      make gdb print the stack and continue when it breaks, please tell me!
    </p>
    <p>
      Update: the most excellent Daniel Stone pointed out the <tt>commands</tt>
      command, which lets you run arbitary commands when a breakpoint is
      reached.  Now all I need to know is how to tie <tt>commands</tt> to a
      <tt>SIGTRAP</tt>...
    </p>
    <p>
      <small>NP: <cite>Sounds From The Verve Hi-Fi</cite>, Thievery Corporation</small>
    </p>
]]></content:encoded><dc:date>2005-06-29T10:02:00Z</dc:date></item></channel></rss>