
Set Breakpoints #36
Chapter 5, Debugging
|
143
HACK
HACK
#36
Set Breakpoints Hack #36
Visual Studio’s breakpoints appear pretty trivial at first, but you can create
some that have quite a bit of intelligence.
Visual Studio offers a powerful debugger to aid with testing and trouble-
shooting your applications. One of the most common uses of a debugger is
to set breakpoints, which are positions in the code that, when reached, cause
the program execution to pause, allowing the developer to inspect the code
and state of the program. When a breakpoint is reached and the application
suspended, the application is in break mode. In break mode, you, the devel-
oper, can examine and change the values of the program variables. With
Visual Studio 2005, you can even change the program’s code during this
time.
In its simplest form, a breakpoint interrupts program execution whenever it
is reached. However, Visual Studio allows for more intelligent breakpoints,
ones that suspend the program only if a certain condition has been met or if
the breakpoint has already been passed over a certain number of times.
Enter Break Mode Whenever a Particular Line
of Code Is Reached
Developers often want to suspend their program’s execution and enter break
mode when a specific line of code is reached, such as the first line of code for
a particular method or a line of code inside a conditional statement. The
simplest way to add a breakpoint ...