Chapter 6. Debugging and Testing

Manage breakpoints

Breakpoints

Breakpoints are temporary markers you place in your executable program to tell the debugger to stop your program at a given point. For example, if problems are occurring at a particular line in your program, you can set a breakpoint at that line, then run your program. Execution stops at the breakpoint before the instruction at that line is executed.

Important: When the debugger is running a program and encounters a breakpoint, it suspends execution of all threads (that is, the application temporarily stops running).

When a breakpoint is encountered, execution suspends at the breakpoint before the statement is executed, at which point you can see the stack for the thread and check the contents of variables, registers, and storage/memory. You can then step over (execute) the statement and see what effect it has on the argument.

Depending on the debug engine that the debugger user interface is connected to, you can set one or more of the following types of breakpoints when you are debugging a compiled language application:

  • Line breakpoints - are triggered when the line they are set on is about to be executed.

  • Function breakpoints or Entry breakpoints - are triggered when the function or entry points they apply to are entered.

  • Address breakpoints - are triggered before the disassembly instruction at a particular address is executed.

  • Watch breakpoints - are triggered when execution changes data at a specific address.

  • Load breakpoints - are triggered when a DLL or object module is loaded.

  • Statement breakpoints - are triggered when the statement they are set on is reached.

  • Some languages support suspending execution when a date field is accessed.

Statement breakpoints are only supported when debugging zSeries (or OS/390) programs, where they are used instead of line breakpoints. Line numbers (and line breakpoints) deal with the absolute line numbers of a source file (generally, from line 1 to line X). Statement numbers (and statement breakpoints) deal with the executable statements generated by the compiler. In languages like COBOL, these might correspond to labels or blocks in the source rather than an source line number. When you are debugging zSeries programs, the prefix area in the Debugger editor displays statement numbers.

With the debugger, setting breakpoints is easily accomplished with wizards, click actions, or pop-up menus in the source editor - or by pop-up menus in the Debug view. Once set, you might be able to edit entry, address, watch, and load breakpoints, and you can disable them so that they do not suspend execution and then, later, enable them again.

Adding breakpoints

Line breakpoints are set on an executable line of a program.

  1. In the editor area, open the file where you want to add the breakpoint.

  2. Directly to the left of the line where you want to add the breakpoint, open the marker bar (vertical ruler) pop-up menu and select Toggle Breakpoint.

    Toggle Breakpoint

    You can also double-click on the marker bar next to the source code line. A new breakpoint marker appears on the marker bar, directly to the left of the line where you added the breakpoint.

    Marker bar

    Also, the new breakpoint appears in the Breakpoints view list.

    Breakpoints view list

While the breakpoint is enabled, thread execution suspends before that line of code is executed. The debugger selects the thread that has suspended and displays the stack frames on that thread's stack. The line where the breakpoint was set is highlighted in the editor in the Debug perspective.

Removing breakpoints

Breakpoints can be easily removed when you no longer need them.

  1. In the editor area, open the file where you want to remove the breakpoint.

  2. Directly to the left of the line where you want to remove the breakpoint, open the marker bar pop-up menu and select Toggle Breakpoint. The breakpoint is removed from the workbench. You can also double-click directly on the breakpoint icon to remove it.

Breakpoints can also be removed in the Breakpoints view. Select the breakpoint(s) to be removed and from the context menu select Remove.

Remove Breakpoint

All breakpoints can be removed from the workbench using the Remove All action in the context menu of the Breakpoints view.

If you find yourself frequently adding and removing a breakpoint in the same place, consider disabling the breakpoint when you don't need it (using Disable Breakpoint in the breakpoint context menu or the Breakpoints view) and enabling it when needed again.

Enabling and disabling breakpoints

Breakpoints can be enabled and disabled as needed. When a breakpoint is enabled, thread execution suspends before that line of code is executed. When a breakpoint is disabled, thread execution is NOT suspended by the presence of the breakpoint.

To disable a breakpoint in the Breakpoints view:

  1. Open the breakpoint's context menu and select Disable, or deselect the breakpoint's checkbox.

    Disable Breakpoint

  2. The breakpoint image will change to a white circle and its checkbox will be empty:

    The breakpoint image will change to a white circle

To disable a breakpoint in the marker bar of an editor:

  1. Open the breakpoint's context menu and select Disable Breakpoint.

  2. The breakpoint image will change to a white circle.

To enable the breakpoint in the Breakpoints view:

  1. Open the breakpoint's context menu and select Enable, or select the breakpoint's checkbox.

  2. The breakpoint image will change back to a blue circle, and its checkbox will be checked.

To enable a breakpoint in the marker bar of an editor:

  1. Open the breakpoint's context menu and select Enable Breakpoint.

  2. The breakpoint image will change to a white circle.

Professional hosting     Belorussian informational portal         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide