views:

79

answers:

7

What can be done to skip through the parts of code when stepping through code? I find this particularly annoying when the debugger jumps to property gets and sets. Is there way to avoid this?

+5  A: 

there's an option Step over properties and operators (Managed only)

or use F10 instead of F11 (with default keyboard binding)

Andreas Niedermair
That option is not available in VS2005.
Craig Johnston
A: 

You could use "run to cursor" for one time breakpoints.

DiggyF
+1  A: 

Yes, there's a step over (F10) function, as well as a step into (F11).

pm_2
And also Step Out (ctrl-F11) (continue until you have returned to the immediate calling function).
Richard
A: 

When you used F10 the code simply steps over each statement unless you've set a break point in a deeper level. I've never found the debugger miss behave the way you've suggested , mind you I'm only using VS2008.

Am
+7  A: 

If you want to skip an entire method you can mark it with the DebuggerStepThrough attribute:

[DebuggerStepThrough]
public void SomeMethod()
{
    // lots of code...
}

public int SomeProperty
{
    [DebuggerStepThrough] 
    get { return ComplexLogicConvertedToMethod(); } 
    [DebuggerStepThrough]      
    set { this.quantity = value ; }
}

Note that the attribute prevents the debugger from stepping into the method or property, but you can always place a breakpoint in that method and stop there1.

The attribute comes in handy especially when you have code like this:

DoSomething(obj.SomeProperty);

If you want to step into DoSomething and press F11 you will - without the attribute - first step into SomeProperty and then into DoSomething. With the attribute however, you end up immediately in the DoSomething method.

1If you want to completely prevent users from placing a breakpoint into a method you can use the DebuggerHiddenAttribute.

0xA3
Not awarded because did not mention F10.
Craig Johnston
A: 

You can set the attribute DebuggerStepThroughAttribute on any methods/properties you don't want to step into.

And you can also use the "Step Over" rather than "Step Into" command.

ho1
A: 

Add DebuggerStepThrough attribute to your property:

[DebuggerStepThrough]
private static void DO() {
  Console.WriteLine("test");
}
Alex Veremeenko