Skip to content

Ruby OO Debugging

Monday, 3 January 2005  |  richard dale

I've been working on the QtRuby and Korundum bindings full time for nearly a year and a half now, and I'm really pleased how well it's turned out. It's been my ambition to create a development environment for about 20 years or so, and it's a great feeling to have to think 'how an earth could I ever top this?'. Lots things have turned out better than I ever could have expected; such as total completeness the Smoke library in its coverage of the Qt and KDE apis. Or the fact that the whole of Smoke is autogenerated directly from the headers - something I would have never thought possible three years ago.





The KDevelop ruby debugger is the latest thing to end up unexpectedly impressive. I had planned to make the ruby debugger look much like the John Birch's gdb front end, with some C++ only features like disassembly viewers or attaching to core dumps removed. That's how the project started off, and after about a month at the end of November I had the basic debugger front end working and visually stepping through the code.



You can customise how a ruby instance appears in a debugger by implementing 'inspect()' and 'pretty_print()' methods. The default behaviour is to show something like:

#<KDE::Application:0x300b9ec8>

However, the problem was that it doesn't show any details, and so I got the idea of retrieving all the QObject properties and showing them in the inspect and pretty_print output.

For example:

#<KDE::Application:0x300b9ec8 name="trymain">

Where 'name' is a property of every QObject.

Then I thought why not show stuff like the QObject's children and parent, or its metaObject too?

#<KDE::Application:0x300b9ec8
  children=Array (5 element(s)),
  metaObject=#<Qt::MetaObject:0x0 className=KDE::Application, superClass=#<Qt::MetaObject:0x0>>,
  name="trymain">

The final good idea was to think of a way to show the QConnectionList of receivers for each connected signal:

#<KDE::Application:0x300b9ec8
  children=Array (5 element(s)),
  metaObject=#<Qt::MetaObject:0x0 className=KDE::Application, superClass=#<Qt::MetaObject:0x0>>,
 receivers=Hash (1 element(s)),
  name="trymain">

Here's a screenshot of how this all appears in the debugger. You can see that KDE::Application 'aboutToQuit()' signal is connected to the 'shutdown()' signal. Or that the KDE::Application has five children including a SessionManager and EventLoop.

The Qt Object Inspector is similar although I hadn't personally tried it, but it is a separate tool rather than being integrated into the debugger. I've learned a lot about the insides of a KDE::Application be just fishing around looking at the slots/signals connections, or which signals a class emits via the metaObject property. I hope the screenshot is enough to whet people's appetite to try it out..