How to break a loop at a certain point during debugging?

Env: Visual Studio 2008 - C #

I have a for that runs 1000+ times on a string array.

I want my application to crash when one of the lines matches a specific term, so I can go through that point in my code.

Now I know that I can add a piece of code that is looking for this, and a breakpoint when it hits, but is there no way to do this in the debugger?

+4
source share
4 answers

Go to your code

  • create breakpoint
  • right-click on the red dot on the left.
  • select condition
  • Put something like me == 1000

or

mid cycle

to write

 if (i == 1000){ int a = 1; } 

and break int a = 1;

The second method is more like garbage, but it’s easier and faster for me to do

+12
source

Yes you can in the debugger. It was called a "conditional breakpoint." Basically, right-click the red breakpoint and go to the condition option.

A quick google turned this and this up:

PS The latter is VS 2005, but it is the same in 2008.

+6
source

I would like to add a general debugger to this conversation ... (not directly targeting you, coding monkey)

Debugging is NOT a sport for viewers. Every developer should know what their debugging tools do, and how to get the most out of them.

With a modern language like C # and a powerful IDE such as Visual Studio and even SharpDevelop, there really is no excuse for (advanced) debugging sessions that consist entirely of console.writeline () statements.

Watch windows, conditional breakpoints (and data breakpoints in native code), thread windows, call stack, command window, direct window, etc. All this gives you everything you need to solve your problems in the prescribed scientific and not just wallow with registration applications.

I urge all developers to spend 15 minutes every day to learn a new debugging technique using the tools at your disposal.

+4
source

In visual studio, you can set a conditional breakpoint - set a breakpoint at the point where you want to break normally, and then right-click on the brown circle in the left margin and select "conditional breakpoint ..." or something else. Then you enter an expression that evaluates to true when you want to split (for example, I == 1000, or MyString = "hello world")

+1
source

Source: https://habr.com/ru/post/1286441/


All Articles