Freigeben über


.NET debugging made easier

Not sure about you but I was not aware of the existence of the DebuggerStepThroughAttribute. Debugging code can be difficult at times and any tool or mechanism that can ease this pain is always welcome.

As far as the CLR is concerned, there is no semantic attached to this attribute. However Visual Studio does not step through methods or classes that are decorated with this attribute. Although you could still use breakpoints in those methods or classes, they are never hit.

And here is how breakpoints would look in Visual Studio 2008:

 

This attribute can be applied to methods, property accessors, classes and structs. I found it to be extremely useful when I wanted to step through a method without first stepping through all property accessors used as parameters or the source instance of the method. In the example below, a.Value and b.Value are not stepped through when pressing F11 in Visual Studio. It is only the Add method that is fully debugged:

var a = new SomeValue(10);

var b = new SomeValue(150);

...

Add(a.Value, a.Value);

class SomeValue

{

  ...

  public int Value

  {

    [DebuggerStepThrough]

    get { return value; }

  }

}

Enjoy!

Comments

  • Anonymous
    July 19, 2008
    PingBack from http://wordnew.acne-reveiw.info/?p=11003

  • Anonymous
    July 31, 2008
    I am a big fan of this attribute.  If you want to stop at a breakpoint set in a method decorated with this attribute there is an option.  In visual studio 2008 (I believe it is in the same place in 2005) under Tools | Options | Debugger | General uncheck "Enable Just My Code (Managed Only)" and your breakpoint will still trip.  If you attempt to step into the same method without the breakpoint you will still glide over.

  • Anonymous
    August 01, 2008
    Thanks very much, this will speed up debugging considerably

  • Anonymous
    August 01, 2008
    I read about this moons ago.  Then when I got fed up with the debugger stepping over all the properties I I thought I should give it a try.  Alas, I could not remember it.  I asked about but did not really get the answer I was looking for.  Thanks for bringing it up.

  • Anonymous
    August 01, 2008
    I don't really like the fact that you have to flag each property that you want to skip.  There should be some other directive to just skip all property accessors.

  • Anonymous
    August 01, 2008
    The comment has been removed

  • Anonymous
    August 04, 2008
    I have also removed these attributes to aid debugging. (The designers add these by default) Schneider

  • Anonymous
    August 05, 2008
    The comment has been removed

  • Anonymous
    August 12, 2008
    Should it not be called DebuggerStepOver though? It is technically not stepping through that code.

  • Anonymous
    August 14, 2008
    thanks for sharing. That is so useful

  • Anonymous
    August 21, 2008
    The comment has been removed

  • Anonymous
    August 31, 2008
    The comment has been removed

  • Anonymous
    February 06, 2009
    Art is the process or product of deliberately arranging elements in a way that appeals to the sense or

  • Anonymous
    February 07, 2009
    Art is the process or product of deliberately arranging elements in a way that appeals to the sense or

  • Anonymous
    February 13, 2009
    More like DebuggerStepOverAttribute than step through.

  • Anonymous
    April 19, 2009
    Hey this is really good stuff. Actually been waiting for such thing. Keep sharing these and help people in the community. Thanks! :D