Monday, September 22, 2008

Debugging the compilation of Boo code

If you have non-trivial code that's supposed to run during the compilation Boo code (read: macros, attributes, and so on), its safe to assume that you might need to debug it when if it doesn't work the way you thought it would. Sure, the code should be covered by unit-tests, but hey, sometimes there's nothing like a good'ol debugging session ;)

One of the first questions I asked when introduced to Boo was exactly that. How can I debug my own code when that code is executed during the compilation of... err... some other of my own code? Last time I checked, there's no "Compile this code in debug mode" button anywhere.

Turns out, as a last resort, you can place a Debugger.Launch() somewhere in the code that's run compile-time. When the Debugger.Launch()is discovered during the compilation, you'll be asked to start a debug session with Visual Studio. Just remember to remove the Debugger.Launch()call afterwords :)

I'll bet the über-boo-hero himself has a much better solution, though.

2 comments:

Unknown said...

Yes, I'd like to know the better way to debug the Boo in compilation.

Lars Andreas Ek said...

hyh961 - I'll be the first to admit it's not pretty, though ;)