06 September 2005

Bigloo Tracing

I just saw that I'm being syndicated at planet scheme. Looks like it hasn't quite made it to planet lisp-like number of contributors (or probably readers). But, in honor of the nevertheless auspicious occasion I plan to say something scheme-y after the past few days of political posts (which, by the way, have probably alienated my one reader---sorry dude, but I call it the way I see it :) ).

I just noticed a very useful thing for debugging Bigloo: tracing macros! The way this works is you put (with-tracing n 'foo ...) declarations around your code and if the debug level (set by -g[2..4]) when compiling is greater than n you get a trace which outputs the symbol 'foo indented according to how many previous traces are active. You can also issue (trace-item . items) commands which display the items given at the appropriate level (though this only seems to work when the debug level is greater than 2). Want the debugging info to go away? Just lower the debug level (or---even easier---increase n) when you compile that module. It doesn't sound like much, but the indentation and (trace-item ...) are leaps and bounds better than the (print ...) statements I was constantly un-commenting and commenting out. I now have (with-tracing ...) scattered through my code---it's great.

Two warts if you use Bee in Emacs and dynamically load your compiled modules:

  1. If an error occurs within the dynamic extent of the (with-tracing ...) form, the indentation doesn't always reset, so sometimes after several errors your traces are walking off the edge of the screen. (I don't know why a simple dynamic-wind doesn't cut it here:
       (lambda () (increase-trace-indentation!))
       (lambda () 'do something)
       (lambda () (decrease-trace-indentation!)))
    but it sometimes doesn't work.)
  2. Sometimes the prefix of the trace data contains shell formatting characters that kind of mess up the output:
      |  |  |  |  |  |  |--+make-advancer-lambda
      |  |  |  |  |  |  |  |--+ calculate-new-dt
    Sometimes calling (trace-margin-set! "") clears this stuff, but sometimes it doesn't.

Anyways, even with the warts it's a pretty useful feature. Enjoy.

Update: In fact, you can get rid of all the cruft at the beginning of these lines by setting the parameter bigloo-trace-color to #f: (bigloo-trace-color-set! #f). Then everything works great within emacs.

No comments: