简体   繁体   English

Visual Studio 2010中的调用堆栈时间机器

[英]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. 我知道标题有点野心,但我想知道是否有办法在调试C#程序时在调用堆栈窗口(Visual Studio 2010)中显示以前的状态之后重新启动(例如,单击“继续” / F5)从那里。

This would be particularly useful to debug a lambda expression that generates an exception, as there is no way to move outside. 这对于调试生成异常的lambda表达式特别有用,因为无法移出外部。

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. 对于真正的OO代码时间机器,所有对象的历史状态都需要存储在内存中,因此我怀疑在此阶段是否可行。 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"). 现在,如果所有对象的状态变化不大,那么我们可以保留当前状态并及时返回(这是使用“编辑并继续”进行相同操作的捷径)。

Some times, you can right click on a stack frame and choose "Unwind to here" (or very similar wording). 有时,您可以右键单击堆栈框架并选择“ Unwind to here”(或非常相似的措词)。 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) 在StackOverflowException处暂停(显然,无论如何,进程都会死亡)
  • Maybe lambda expressions or other things that prevent Edit-and-Continue from working (?) 可能是lambda表达式或其他阻止编辑并继续工作的东西(?)

Basically, anything "unusual". 基本上,任何“异常”。

Other than that, if it works, then there you go! 除此之外,如果可行,那么您就可以了!

This is a bit kludgy but: 这有点麻烦,但是:

While viewing the previous state in the call stack window, open the disassembly window (Debug | Windows | Disassembly or CTRL+ALT+D). 在调用堆栈窗口中查看先前状态时,打开反汇编窗口(“调试” |“ Windows” |“反汇编”或CTRL + ALT + D)。 Now you should be able to create a breakpoint which will stop execution when you get back to that location. 现在您应该能够创建一个断点,当您回到该位置时它将停止执行。

If you don't care what else executes, press F5 and allow the code to run back to your new breakpoint. 如果您不关心其他什么,请按F5键,然后让代码重新运行到新的断点。

Now right click on the statement you want to restart from and select Set Next Statement. 现在,右键单击要重新启动的语句,然后选择“设置下一条语句”。 Press F5 to restart from there. 按F5从那里重新启动。

If you do care about what else executes on your way back to the new breakpoint you could use Set Next Statement to set the program counter to the end of the function you are in and use Shift+F11 to step out of that function (thus not executing any of the remaining logic in that function). 如果您确实担心返回新断点的过程中还会执行其他操作,则可以使用Set Next语句将程序计数器设置为所在函数的末尾,然后使用Shift + F11退出该函数(因此执行该功能中其余的任何逻辑)。 Repeat as needed until you get back to your new breakpoint. 根据需要重复,直到返回到新的断点。

Note the various dire warnings about using Set Next Statement 注意有关使用Set Next语句各种可怕警告

Edit 6/18 When I tested the above I was running Visual Studio 2010 Ultimate. 编辑6/18当我测试以上内容时,我正在运行Visual Studio 2010 Ultimate。 I just checked Visual Studio Express C# and it does not support the Disassembly Debug Window. 我刚刚检查了Visual Studio Express C#,它不支持反汇编调试窗口。 When I can I'll check Visual Studio 2010 Professional and update this answer again. 如果可以,我将检查Visual Studio 2010 Professional并再次更新此答案。 If you have Visual Studio Ultimate then the Intellitrace suggestion by @Hans is maybe a better bet. 如果您拥有Visual Studio Ultimate,那么@Hans的Intellitrace建议可能是更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM