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.
| Language | Trigger |
| C | asm("int $0x3\n"); |
| Python | import pdb; pdb.set_trace() |
| Javascript | debugger |
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 under a debugger, which I usually do like gdb --tui --args ...
- The "Javascript" trigger is ignored unless something like firebug is enabled. To support debugging a page on a mobile device for example, one can use webkit remote debugging
- 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