Wednesday, August 05, 2009

The world's simplest log file

Back when I was doing embedded programming we had a debugging feature called 'pokeouts'. The idea was that the program could write a single character to the screen when some important even occurred.

Now writing single characters to the screen might not seem like a good way to do debugging. After all, these days we've got tons of disk space and can spew log files out and our CPUs are not burdened. But in embedded programming you tend to have little space and little time.

This system worked by having code that resembled the following:

pokeout: LD AH, 0Eh
INT 10h
RET

And to make things even easier we actually implemented this by hooking an interrupt so that programs didn't need to know whether the pokeout facility was available. They could safely do INT xxh for debugging output. This meant that the logging facility could be loaded onto a running system.

It's amazing how much information you can convey with single characters scrolling across the screen. It's easy to get critical area entry and exit (we used lots of combinations of ( ) [ ] { } < > followed by single characters to identify the area). You can build on that to output hexadecimal numbers easily. And individual events can be hooked individual characters.

I'd spend my days looking at these scrolling screens of characters waiting for a program to crash. Everything was on the screen.

For some high-speed systems the screen pokeout was too slow. We replaced the routine above with code that wrote the pokeouts into a circular buffer in memory. When the program finally crashed the buffer could be examined using a high-powered debugger like SoftICE to give us a trace of the program's final moments. It was the equivalent of an aircraft's 'black box'.

No comments: