Lisphacker.com

Single-stepping in SBCL/x86

The SBCL debugger, at present, can only single-step code which has been compiled with some phenominally high DEBUG setting which makes the compiler slow and the resulting code slow.

This works based on having the compiler insert extra code to handle stepping for each form.

Now, the x86 has a control flag which causes an exception after executing each instruction. It exists specifically to support single-stepping in debuggers.

The basic idea behind this hack is that we can set this flag in the context record supplied to a signal handler (in this case, SIGINT) and return, causing execution to resume where it left off, run one instruction, and then SIGTRAP.

This is a proof-of-concept, which means that it demonstrates the technique, but is missing all the bells and whistles, and may not be suitable for production use. Usage instructions (and this warning again) can be found at the top of the file.

So, without further ado, here's a single-step hack for SBCL/x86/Linux.