Visual Studio可以在断点命中时打印调用堆栈,并且可以在满足条件时停止,有没有办法将它结合起来并在从另一个选定的函数调用函数时停止,并忽略所有其他调用?
问问题
2178 次
2 回答
4
我相信做到这一点的唯一方法是使用宏。右键单击断点,选择“当命中时..”,选择“运行宏”,然后将其指向类似于以下内容的宏:
Sub ContinueUnlessCalledFromRightContext()
For Each frame As EnvDTE.StackFrame In DTE.Debugger.CurrentThread.StackFrames
If (frame.FunctionName.Contains("SomeOtherMethodsName") Then Exit Function
Next
DTE.Debugger.Go() ` we weren't called from the right context so continue execution.
End Sub
以上是半伪代码;我实际上并没有对其进行测试,但应该进行一些小的编辑。
请注意,如果断点被多次命中,这将非常慢,因为从断点运行宏本质上非常慢。
顺便说一句,如果您问的是 .NET / C#,它会简单得多,您可以在
new System.Diagnostics.StackTrace().ToString().Contains("SomeOtherMethodsName")
...并完成它。
于 2012-01-25T19:12:13.370 回答
3
不确定,但您可能可以使用过滤或条件,尽管将断点放在调用进程上可能更容易
这是一个很好的资源:Mastering Debugging in Visual Studio 2010 - A Beginner's Guide
于 2012-01-25T16:37:19.213 回答