简体   繁体   中英

Visual studio breakpoint conditional on the stack state

Visual Studio可以在断点命中时打印调用堆栈,并且可以在条件满足时停止,是否有任何方法可以组合它并在从另一个选定的函数调用函数时停止,并忽略所有其他调用?

I believe the only way to do this is with a macro. Right click your breakpoint, choose "When Hit..", select "Run a macro", and point it to a macro that goes something like:

 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

The above is half psuedo code; I didn't actually test it, but should work with some minor edits.

Note that this will be slow as hell if the breakpoint is hit a lot of times, because running macros from breakpoints is inherently very slow.

BTW, If you were asking about .NET / C# it would've been a lot simpler, you could've just made a conditional breakpoint on

new System.Diagnostics.StackTrace().ToString().Contains("SomeOtherMethodsName")

...and be done with it.

Not sure but you might be able to with either Filtering or Conditions, though it might be easier to just put the breakpoint on the calling process instead

This is a good resource: Mastering Debugging in Visual Studio 2010 - A Beginner's Guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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