Chapter 5. Debugging

Set breakpoints

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, double-click the marker bar directly to the left of the line where you want to add the breakpoint or open the marker bar pop-up menu and select Add Breakpoint:

    Add Breakpoint

    A new breakpoint marker appears on the marker bar, directly to the left of the line where you added the breakpoint.

    A new breakpoint marker

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

    Breakpoints

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.

Debug

Enabling and disabling breakpoints

Do one of the following sets of tasks:

  1. In the editor area, open the file where you want to enable or disable a breakpoint.

  2. Directly to the left of the line where you want to add the breakpoint, open the marker bar pop-up menu and select Enable Breakpoint or Disable Breakpoint depending on the current state of the breakpoint.

    Disable Breakpoint

OR

  1. In the Breakpoints view select the breakpoint(s) to be enabled or disabled.

  2. In the context menu of the view, select Enable or Disable.

If the breakpoint is enabled, its image will be a blue circle and if it is disabled the image will be a white circle:

Disabled Breakpoint

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.

Editing breakpoint properties

You can edit the following properties of line, address, watch, load, and entry breakpoints:

  • Which threads the breakpoint applies to.

  • How often the debugger should skip the breakpoint (the frequency).

  • Whether to stop on the breakpoint only when a given expression is true (where any non-zero value is true). Expressions can only be applied to the following breakpoints:

    • entry breakpoints

    • address breakpoints

    • line breakpoints

  • You can edit required breakpoint information, as follows:

    • You can edit the address of an address breakpoint.

    • You can edit the function or entry point of an entry breakpoint.

    • You can edit the library name of a load breakpoint.

    • You can edit the address or expression and the number of bytes to watch for a watch breakpoint.

To change a breakpoint's properties:

  1. In the Breakpoints view, right-click on the breakpoint you want to modify.

  2. Select Properties... from the pop-up menu. The Breakpoint Properties dialog corresponding to the breakpoint type appears displaying the current settings for the breakpoint.

    Properties

  3. When you have made all desired changes, click Ok.

Applying hit counts

A hit count can be applied to line breakpoints, exception breakpoints, watchpoints and method breakpoints. When a hit count is applied to a breakpoint, the breakpoint suspends execution of a thread the n-th time it is hit, but never again, until it is re-enabled or the hit count is changed or disabled.

  1. Select the breakpoint to which a hit count is to be added.

  2. From the breakpoint's pop-up menu, select Hit Count:

    Hit Count

  3. In the Set Breakpoint Hit Count field, type the number of times you want to hit the breakpoint before suspending execution.

    Set Breakpoint Hit Count

NOTE: When the breakpoint is hit for the n-th time, the thread that hit the breakpoint suspends. The breakpoint is disabled until either it is re-enabled or its hit count is changed.

Managing conditional breakpoints

To set a condition on a breakpoint:

  1. Do one of the following sets of tasks:

    • From the editor area:

      1. In the editor area, open the file where you want to set a condition for a breakpoint.

      2. From the breakpoint's pop-up menu, select Breakpoint Properties....

    • From the Breakpoints view:

      1. In the Breakpoints view select the breakpoint to set the condition for

      2. In the context menu of the view, select Properties....

  2. The Breakpoint Properties dialog will open.

  3. In the properties dialog, check the Enable Condition checkbox. To disable the condition, uncheck this checkbox.

  4. In the Condition field enter the boolean expression for the breakpoint condition.

    Condition

  5. Click Ok to close the dialog and commit the changes.

While the breakpoint is enabled, thread execution suspends before that line of code is executed if the breakpoint condition evaluates to true. 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.

Thread execution suspends

A conditional breakpoint has a question mark overlay on the breakpoint icon.

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