How to set conditional breakpoints in Visual Studio?

前端 未结 13 2173
忘了有多久
忘了有多久 2020-11-27 03:35

Is there an easy way to set conditional breakpoints in Visual Studio?

If I want to hit a breakpoint only when the value of a variable becomes something, how can I do

相关标签:
13条回答
  • 2020-11-27 04:16

    Set the breakpoint as you do normally, right click the break point and select condion option and sets your condition.

    0 讨论(0)
  • 2020-11-27 04:17

    Set a breakpoint as usual. Right click it. Click Condition.

    0 讨论(0)
  • 2020-11-27 04:19
    1. Set a breakpoint as usual.
    2. Right-click on the breakpoint marker
    3. Click "Condition..."
    4. Write a condition, you may use variable names
    5. Select either "Is True" or "Has Changed"
    0 讨论(0)
  • 2020-11-27 04:21

    When you are using Express edition you can try this:

    #if DEBUG
        if( fooVariable == true )
            System.Diagnostics.Debugger.Break();
    #endif
    

    if statement makes sure that in release build breakepoint will not be present.

    0 讨论(0)
  • 2020-11-27 04:23

    Create a conditional function breakpoint:

    1. In the Breakpoints window, click New to create a new breakpoint.

    2. On the Function tab, type Reverse for Function. Type 1 for Line, type 1 for Character, and then set Language to Basic.

    3. Click Condition and make sure that the Condition checkbox is selected. Type instr.length > 0 for Condition, make sure that the is true option is selected, and then click OK.

    4. In the New Breakpoint dialog box, click OK.

    5. On the Debug menu, click Start.

    0 讨论(0)
  • 2020-11-27 04:26

    Visual Studio provides lots of options for conditional breakpoints:

    To set any of these you

    1. Set a breakpoint.
    2. Right-Click over the breakpoint, and in the popup menu you select an option that suites you.

    These options are as follows:

    • You can set a condition, based on a code expression that you supply (select Condition from the popup menu). For instance, you can specify that foo == 8 or some other expression.
    • You can make breakpoints trigger after they have been hit a certain number of times. (select Hit Count from the popup menu). This is a fun option to play with as you actually aren't limited to breaking on a certain hit count, but you have options for a few other scenarios as well. I'll leave it to you to explore the possibilities.
    • You can Set filters on the Process ID, thread ID, and machine name (select Filter from the popup menu)
    0 讨论(0)
提交回复
热议问题