Debuggers Are Wonderful Things
tenglin: Or, instead of crafting all that custom code and modifying tons of source files and so on, you could just learn how to use a debugger properly and get all that for free without needing to modify or hack anything. ;-)
Here's a link to the on-line version of the GDB Manual.