Some hints on reference count debugging

Tracing references with GDB

(From Bonobo documentation).

You can make GDB break on changing the number of references of an object just adding a watch to the object instance reference counter.

First you can break on some point where you get the object pointer. For example, adding a breakpoint in its construction:

(gdb) break my_object_instance_init

Once you have a valid reference, you get the memory address of the reference count, and add a watch to that address:

Breakpoint 1, my_object_instance_init (instance=0x2244ffe, g_class=0x2222334) at my-object.c:100

(gdb) print &(((GObject *)instance)->ref_count)
$1 = (volatile guint *) 0x2245010

(gdb) watch *0x2245010

After this, GDB will stop on any change on the watchpoint.

The watch can fail sometimes (for example, on simultaneous accesses to the same thread, but the watch should anyway help a bit on finding where we add and remove references to the object, and if these refs are correctly paired.

Valgrind still reachable

You can also get some information using valgrind with --show-reachable=yes parameter, as it will show the memory allocations not freed on finishing execution. Be careful with the detail, as this is really very detailed.

Tips from projects

Attic/ReferenceCountDebugging (last edited 2013-11-23 00:49:43 by WilliamJonMcCann)