views:

73

answers:

3

A historical debugger is able to revert program state (including current instruction) to a former state. How is this possible in managed or unmanaged environments? I can't imagine that the debugger takes a state shot of the whole system on every instruction.

A: 

It probably takes a snapshot of the state every time, but only retains the deltas between the states (of course, it's impossible to say exactly how any given one really works without looking at its code).

Jerry Coffin
+4  A: 

One way to do this is to record the sources of non-determinism in the system (I/O, interrupts) and take state snapshots at various intervals. This way, you can "rewind" by restoring to a previous snapshot and playing forward using the recorded non-determinism until you hit your desired point in the past.

For example, imagine this timeline:

1    2           3     4
|    |           |     |
  1. Program start
  2. State snapshot taken by historical debugger
  3. The point in time to which the user wants to rewind
  4. Now

Suppose the user wants to rewind to point 3. You can do that by restoring the system state (e.g. memory, registers) to point 2 and letting the system execute as usual until it hits point 3. When data is needed from disk, the network, or some other non-deterministic source, the historical debugger can use its recorded information to provide the data. To the user, it appears that the state of the program was simply restored to point 3.

I believe this is a simplified view of how VMWare's Replay Debugger works (see also the tech talk).

Chris Schmich
Interesting idea, sounds reasonable. Do you know if any of the popular historical debuggers actually use this approach? Do you know of other ways that are in use to achieve the same goal?
mafutrct
+2  A: 

Well, most importantly, they don't snapshot at every instruction just at various "points of interest" (for example, when an exception is thrown, when certain methods are called, etc). For example, Microsoft's IntelliTrace (in VS2010) snapshots on access to the file system and registry, interactions with WinForms UI and so on.

Secondly, it doesn't snapshot the entire program state. For example, when you access a file, IntelliTrace records the name of the file, the access permissions you asked for and so on - but you can't just go back to that point and look at the state of every single global variable.

I don't know about other historical debuggers, but that's how IntelliTrace works in VS2010, anyway.

Dean Harding

related questions