Archive for July, 2009

Thoughts on debugging

Thursday, July 16th, 2009

Recently I’ve been doing a lot of debugging on several of the projects I’m working on alongside a few other developers. During this period I have come up with a few “thoughts” on good debugging procedures.

Micro analysis vs Macro analysis

Most bug reports you get are macro analysis… like “I don’t make the highscore eventhough I get the most points”. From that you cannot conclude wether the score is reported wrongly, not reported at all, not saved to database or simply just not shown in the highscore or something completely else.

In my opinion micro analysis is required. The process I follow is to figure out an in and an out point and put breakpoints from the in to the out point. Then run the application and step through the breakpoints looking at the relevant variables and verifying every action.

The process is no doubt slower than digging in directly at the point where the macro analysis states the problem occurs. But on the other hand it tend to be a lot faster in cases where the bug report is not correct.

Defining in and out points

The hardest part of the process is defining the in and out points. You want them to be as close to the problem as possible but also far enough away to be sure that you find the bug if it turns out it resides another places than where the bug says it is.

In 9 out of 10 cases some kind of user interaction starts the chain that ends in the bug. The place where the interaction occurs is a good place to start with the first breakpoint (in). In our example there most be a place where the game ends and the score is saved. This would be a good place to start.

The last breakpoint (out) should be set where the bug report specifies there is a problem. In our example I would set the last breakpoint where the view that shows the highscores is build.

The in point is more important than the out point. I usually just step through the code from the in point until I’ve found some irregularity that suggests the bug.

This is the process I run through whenever I debug code. I hope that someone might found it useful.