7

There is huge amount of code in my project which already debugged 50% of it.
Every time I try to debug it I have to manually set breakpoints after unwanted piece of code to skip it.
Is there a way to tell debugger not to debug that part of code ? Any extension for this ?

Let's face debugger is on line 1500.

Method1(){
   Line 1500 CODE
   Line 1501 CODE
   ...
   Line 1726 CODE
   Line 1727 CODE
   ...
   Line 2200 CODE
}

I won't need to debug lines between 1727 and 2200.

NOTE : It's not just one piece. Otherwise I would be fine with manual breakpoints

Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
  • If it would really skip those lines and your code is not executed, won't that break the rest of your code? – MrFox Feb 22 '13 at 12:16
  • @MrFox It must get executed but not debugged. – Mohsen Sarkar Feb 22 '13 at 12:17
  • @MrFox - OP means he doesn't want to manually debug through these (or set breakpoints after), just have the debugger jump over them automatically. – Oded Feb 22 '13 at 12:18
  • 1
    I think this would be a great feature. While I agree with @Oded that in some scenarios (this one) a refactored method would work, there are other scenarios, like ones that involve events that are constantly hit (*cough* OnPaint) that you may want to, on-the-fly, tell the debugger to not run during your debug session (semi-permanent, but not permanent). Like a breakpoint... or a "skippoint" (tm)... Perhaps a VS extension should come our way ... ;-) – Adam Plocher Aug 15 '17 at 13:10
  • Another scenario this would be handy: a place where your stupid coworker thought it was a good idea to put a System.Diagnostics.Debugger.Break() that gets hit 100% of the time. ARGH! – Adam Plocher Aug 15 '17 at 13:15
  • Related posts - [Visual Studio Debugger skips over breakpoints](https://stackoverflow.com/q/2026510/465053) & [Skip current line in debugger](https://stackoverflow.com/q/31474563/465053) – RBT Feb 13 '21 at 14:11

3 Answers3

25

Don't know why it's not in the answer but you can set next statement by CTRL+SHIFT+F10 or dragging the yellow arrow to wanted line and code before next statement will not be executed.

Found it here

Pawcio
  • 399
  • 5
  • 15
20

If the code in question is encapsulated in a method, you can skip the method by applying the DebuggerStepThroughAttribute on it.

Other than that, setting breakpoints is how to do it.

So, extract this code into a method and apply the attribute to it ;)

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @Mahdi - What do you mean? – Oded Feb 22 '13 at 12:17
  • The CODE you see in my question is inside one method which might call or not call another methods. – Mohsen Sarkar Feb 22 '13 at 12:18
  • @Mahdi - I still don't follow. If you take the lines between 1727 and 2200 and extract them into a method and then put the attribute on that method, the debugger will not go through that method. – Oded Feb 22 '13 at 12:21
  • The ignored code is related to other parts of code so I can't do that – Mohsen Sarkar Feb 22 '13 at 12:24
  • @Mahdi - You probably could, using the `Extract Method` refactoring. – Oded Feb 22 '13 at 12:30
  • 1
    @Mahdi: You should be able to extract parts of your method into another method without problems. Actually, it usually is a bad sign to even have a class with over 500 lines. Let alone a single method... – Daniel Hilgarth Feb 22 '13 at 12:31
0

You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor). It will jump directly to that line.

live-love
  • 48,840
  • 22
  • 240
  • 204