Search code examples
c#visual-studio-2010stacktimemachine

Call stack time machine in Visual Studio 2010


I know the title is a bit ambitious, but I am wondering if there is a way, after displaying a previous state in the call stack window (Visual Studio 2010) when debugging a C# program, to restart (like when hitting "Continue"/F5) from there.

This would be particularly useful to debug a lambda expression that generates an exception, as there is no way to move outside.

For a real OO code time machine, the historical state of all objects would need to be stored in memory, so I doubt it is feasible at this stage. Now if the state of all objects has not changed much, then we could keep the current state and jump back in time (as a shortcut to doing the same thing with "edit and continue").


Solution

  • Some times, you can right click on a stack frame and choose "Unwind to here" (or very similar wording). It's not always possible, and I'm not sure what the necessary conditions are, but I'm going to make a guess as to what might prevent it:

    • A native code frame on the call stack in the middle
    • Being halted at a StackOverflowException (obviously, death to a process in any case)
    • Maybe lambda expressions or other things that prevent Edit-and-Continue from working (?)

    Basically, anything "unusual".

    Other than that, if it works, then there you go!