Saturday, June 9, 2012

The power of built-in debugging and introspection

I've recently started reading the excellent "Code Complete" by Steve McConnell and - as is often the case when you encounter a good book - got inspired by some of its ideas. I was particularly enlightened by the idea of implementing advanced built-in debugging/introspection capabilities, only available if application was compiled with DEBUG flag.
I found this idea very interesting for QComicBook - it would be very cool to be able to check internal state of some more sophisticated widgets when debugging issues. QComicBook has fairly detailed tracing (if you compile it with -DCMAKE_BUILD_TYPE=Debug flag), but it's not very useful in debugging subtle issues (such as with drawing) as it simply produces too much text output to analyse.
So, I started hacking it today. For starters I picked the most troublesome widget in QComicBook - ContinuousPageView, responsible for continuous view mode. This widget still has some minor issues that show up under specific circumstances, and they are very hard to debug. I implemented a simple Debug window, available via Debug > Continuous View menu option; it displays frames for all pages, showing their sizes, position on the QGraphicsScene and internal state. And it didn't take long as I spotted first potential problem: when rotation is applied, some sizes manifested by QGraphicsItem interface (blue boxes) don't match numbers used internally to handle continuous view logic; this seems to affect pages that use estimated sizes only (i.e. not loaded yet).
I'm not sure yet if this can cause real problems, but certainly it looks suspicious. It also definitely shows the potential of built-in debugging tools and I'm going to add some more to QComicBook in the future. Frame View mode, job subsystem, memory usage are just a few top candidates for live introspection. Having them at hand, it will hopefully be much easier to prepare a rock solid QComicBook 1.0.0 :)

No comments: