Bug Hunting

If you ever come to hacking on an interpreter, remember the following advice: 1. Develop stuff in very small increments, 2. Test thouroughly after each increment, 3. keep track of this (e.g. using CVS).

I was hunting down a bug in Jamaica’s interpreter the last couple of days. That one was really haunting me. Here’s how I caught it:

  1. Compared the current changes to the version in CVS. Unfortunately I was not following advice #1 above. This one was a rather large patch and digging through it revealed no obvious mistake.
  2. Debugging in GDB. Well, usually this should help but here it was quite pointless. The backtrace was useless as it’s in the interpret() function because the interpreter is just one big loop inside this function. Stepping through it is also pointless because the failure didn’t pop up right at the start, but instead after the zillionth opcode. So where should I have set the breakpoint?
  3. Searching backwards through CVS. It turned out the the breakage was not caused by the current patch, but by one of the patches that I already checked in. At least, that was what I found after going back 2 revisions in CVS. Unfortunately, this patch was also quite big, so I incrementally went from revision-2 to revision-1, only to find out that this one was a different bug from the one that I was looking for (and one that already was solved magically in the current code). ARRRG!
  4. OK. There must be a problem between rev-1 and rev then (not counting the current local patch). Repeat step#3 with this. This enabled me to narrow the problem to the buggy function and I could finally find and fix this bug. It turned out to be a small typo in the end. Why I couldn’t find it in step#1? Well, the variable names d1 and dl are almost distinguishable… Sigh. So I add adivce #4 here: Make up good variable names. Two-letter names like dl definitely are no good.

Ok, back to work now. Gotta finish that WindML VolatileImage and work some more on the interpreter. Ah, and I really should start learning a little for the 3 exams on thursday and friday. Y’know, three of those exams where I never attended the actual courses and do the exams anyway. This time it is ‘Internet Programming’, ‘XML’ and ‘Software Engineering’. Should provide some relaxation from VM and graphics hacking 😉 The best thing is, these are going to be the last (really really last) three exams, except the diploma thing itself. Hurray!


One Response to Bug Hunting

  1. Dmitri Trembovetski says:

    Good luck with those exams! =)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: