Visual Studio debugger related attributes cheat sheet
There are some debugger-oriented attributes in .Net, however 70% of developers not even know that they exist and 95% of them has no idea what they doing and how to use it. Today we’ll try to lid light on what those attributes doing and how to achieve the best of using it.
First of all let’s define what we want to get from debugger in VS
| Term | What it actually does |
| Step Into | Steps into immediate child (that is what F11 does for standard VS layout) |
| Step Over | Skips to any depth (that is what F10 does) |
| Step Deeper | Steps into bypassing code, using certain attribute |
| Run Through | Steps into, but only one level. All lower lavels will be Stepped Over |
Now, when we have our set of terms, we can learn what JMC means. It is not famous whisky brand or another car company. It Just My Code option, checked in or out in “Option” dialog inside Visual Studio
Next turn is for attributes, there are four (I know about) attributes, related to debugger and used by me for efficient programming: DebuggerHidden, DebuggerNonUserCode, DebuggerStepThrough and DebuggerStepperBoundary. We will use only three first. DebuggerStepperBoundary is the most secret attribute, which is related to debugging only in multithreaded environment. It used to avoid delusive effect, might appears when a context switch is made on a thread within DebuggerNonUserCode applied. Other words, when you need to Step Through in Thread A and keep running at the same time in Thread B.
So let’s see the effects occurred when using those debugger attributes in case, you are trying to Step Into place, this attribute applied or set a Breakpoint there. When Just My Code (JMC) is checked all those attributes behaviors the same – they Step Deeper. However, when JMC is turned off (as in my picture) they begin to behavior differently.
| Attribute | Step Into | Breakpoint |
| DebuggerHidden | Step Deeper | Step Deeper |
| DebuggerNonUserCode | Step Into | Step Into |
| DebuggerStepThrough | Step Deeper | Step Into |
As you can see, in this case
- DebuggerNonUserCode respects both for F11 (Step Into) and Breakpoints
- DebuggerStepThrough respects only for Breakpoints
- DebuggerHidden does not respects at all – just like when JMC is checked.
Bottom line: if you want people to manage whether to enter or not into your hidden methods – use DebuggerNonUserCode attribute. If you prefer them not to even know that those methods exists, use DebuggerHidden. If you want them to be able to put Breakpoints and stop on them, but keep running without explicit action – use DebuggerStepThrough
Have a nice day and be good people. Happy other developers friendly debugging.
Small bonus: To visualize your struct, class, delegate, enum, field, property or even assembly for user debugger, you can use DebuggerDisplay attribute (you need to put executable code into {} for example (“Value = {X}:{Y}”)]
Thanks to Boris for deep investigation
April 7th, 2009 · Comments (6)
6 Responses to “Visual Studio debugger related attributes cheat sheet”
Leave a Reply
Discover other tags
My tools
- .NET Framework Detector
- Duplicate images finder
- Exchange Security Policy for Windows Mobile Devices Fix
- Gas Price Windows Vista SideBar gadget
- Israel Traffic Information Windows Vista SideBar gadget
- Localization fix for SAP ES Explorer for Visual Studio
- LocTester
- RTL and LTR in Windows Live Writer
- Silverlight controls library
- Snipping tool integration plugin for WLW
- USB FM receiver library
- Vista Battery Saver
- WebCam control for WPF
- Windows Live SkyDrive attachment for Windows Live Writer
- Wireless Migrator
- WPF Virtual Keyboard





May 21st, 2009 at 10:57 am
Пора переименовать блог, присвоив название связанное с доменами
может хватит про них?
May 23rd, 2009 at 11:46 am
Действительно удивили и порадовали
Никогда не поверил бы, что даже такое бывает
May 24th, 2009 at 9:21 am
Офигеть просто! Все, блин, всё знают, кроме меня
May 25th, 2009 at 10:44 pm
Интересно, я даже и недумала об этом…
May 28th, 2009 at 5:23 am
Отличная статья, спасибо!
May 30th, 2009 at 1:37 pm
Кругом война, смерть, глупость, а вы тут… сами знаете, чем занимаетесь.