Re:Some things I've learnt about programming
by StavrosK on Thursday July 12, 2012 @07:50AM
(#4234087)
Aren't there debuggers that step backwards? That sounds useful in many cases, and not impossible to create, at least for special cases.
Yes, they're usually called "Omniscient Debuggers". Intellitrace on Visual Studio provides this kind of funcionality.
Re:Some things I've learnt about programming
by zaptheimpaler on Thursday July 12, 2012 @11:08AM
(#4234859)
Also GDB has supported reverse-execution on some environments (i386-linux and amd64-linux included) since version 7.
Re:Some things I've learnt about programming
by brianpan on Thursday July 12, 2012 @10:06AM
(#4234536)
Some debuggers let you "drop frames". This brings you back up the call stack and you can step back down into the beginning of the method call.
http://stackoverflow.com/questions/2367816/when-using-the-ja...
One example. Sometimes what you want is a time machine: figuring out how a particular variable reached its value. So you swap out the Windows memory allocator (which randomizes initial heap addresses) for one with predictable addresses, run the program until you find the dodgy value, take its address, then restart the program with a hardware breakpoint setup to monitor and log the stack whenever modifications are made to that memory address.
This kind of "backward tracking" takes no more than 5 minutes on a project that's set up for it (i.e. with the appropriate allocator available and switchable). Solving the problem by guessing locations, dropping printfs in the code, etc. is rather less productive.
Other uses: debugging code you don't have the source for, OS code, binary compatibility issues etc.
(Crash bugs are usually not a big deal; usually, when the code crashes, the crash location is relevant. Bugs that corrupt state are much worse (heap corruption, races / concurrent modification, etc.). The original bug resulting in the final bad behaviour may be completely different from where it appears.)