Conditional Breakpoints on Call Stack

为君一笑 提交于 2019-12-03 05:06:55

问题


Is it possible to specify a breakpoint in Visual Studio 2010 that hits only if the calling methods up the call stack meet some specific condition? For example, and most likely, method name.

I am ideally looking for a solution in Visual Studio itself such as the conditional breakpoint, but I'll settle for testing method names up the stack in code and having a coded breakpoint.

What I'm trying to achieve is to cut out calls from a specific caller.


回答1:


Right click the breakpoint, choose "Condition" and use something like this:

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



回答2:


The StackTrace class should give you what you need.

StackTrace stackTrace = new StackTrace();           
StackFrame[] stackFrames = stackTrace.GetFrames(); 


来源:https://stackoverflow.com/questions/5540431/conditional-breakpoints-on-call-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!