【问题标题】:Visual Studio. Using stacktrace's sequence as hit breakpoint condition视觉工作室。使用 stacktrace 的序列作为命中断点条件
【发布时间】:2014-07-04 11:42:30
【问题描述】:

我使用了命中断点条件

(new System.Diagnostics.StackTrace(true).GetFrame(2) != null 
&& new System.Diagnostics.StackTrace(true).GetFrame(2).GetMethod().Name 
== "UpdateFromLocationInfo")

当我“逐步”点击这个断点时,我通过快速观察检查了这个条件,这是真的。但条件不适用于 f5 模式

【问题讨论】:

  • 作为一种解决方法,您可以将其放入 if 语句中,然后在 if 语句中放置一个非条件断点。显然,您希望在完成调试后恢复它
  • 我不需要使用额外的代码。我只想用Visual Studio Instrument:right click onto breakpoint, then choose "Condition..." in popup window
  • 我明白了。如果您无法按照您尝试的方式工作,我会告诉您一种解决方法
  • @BenAaronson 谢谢!但这不适合我的情况

标签: c# .net visual-studio visual-studio-2013


【解决方案1】:

如果您尝试使用条件表达式在当前方法中放置条件断点,则当前方法应为“UpdateFromLocationInfo”。 StackTrace 上的 new 始终适用于您的新对象所在的当前方法。

        // Create a StackTrace that captures filename, line number, and column 
        // information for the current thread.
            StackTrace st = new StackTrace(true);
            StackFrame[] stFrames = st.GetFrames();

            foreach (StackFrame sf in stFrames)
            {
                Console.WriteLine(sf.GetMethod());
            }
          //The StackFrame at array index 0 represents the most recent function call 
          // in the stack trace and the last 
          //frame pushed onto the call stack.
            if ((new StackTrace(true).GetFrame(0) != null && 
            new  StackTrace(true).GetFrame(0).GetMethod().Name == "UpdateFromLocationInfo"))
            {
            }
            else
            {
            }

您可以通过上述过程清楚地看到您的输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    相关资源
    最近更新 更多