This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Very Dirty But Very Useful Debugging Trick
  Submitted by



Just a short tip, that I found very useful about bug hunting. Many times when an assert fails or a memory exception happen is just too late to try to know what was wrong.

And when is a very strange situation is very hard to breakpoint before it happens and try to understand why does it failed.

So, you have the debug window, in break mode, just over the line where the exceptions happen, or where the assert failed.

If you change to the Disassembly window, you can see the memory address for each line of assembly code, and their correspondence with c source.

The tip consist in changing the EIP register to the address of a previous line of code of the same function, using the watch window.

That way you can go a bit back in execution and debug, step by step a few lines before the exception or the assert, so you can get more useful info about what was wrong.

You can go back in code outside the current function, but you have to be very careful about the ESP and EBP registers and always take in account the unpredictable results in execution of unsuitable use of that tip. If you are curious about the correct values of ESP and EBP, you can look at the begin and end of the assembly code of the current function and do some reverse engineering of your compiler's calls protocol.

Alberto Garcia-Baquero Vega
Nebula Entertainment


The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.