In our ever more abstracted and open systems, it's becoming increasingly important to be able to inspect code more effectively. A very useful technique for this, is to trigger your debugger from code. I.E. rather than setting arbitrarily complex breakpoints in your debugger, one can use the following simple triggers in various languages.
|Python||import pdb; pdb.set_trace()|
These will pass control to your debugger where you can inspect or modify the current context and continue.
- To catch the "C" trigger, your program must be running in a debugger, which I usually do like gdb --tui --args .... If not running under a debugger your program will generally dump core and exit. Note that this asm() is x86 specific, and if you want a more portable equivalent, see the debugbreak.h wrapper.
- The "Python" trigger will start an interactive console. To support debugging a service not connected to a console, one can easily export the debug session over the network with a helper like rdb. Note one can also trigger pdb after an uncaught exception
© Feb 24 2011