Using breakpoints and watchpoints

Breakpoints

A breakpoint indicates a line of code, a program, or a method at which you want the execution of an application to pause. When the application is paused, you can view and change the values of data items at that particular step.

Breakpoints in Eclipse are set in source files, not in programs (as they are in other Micro Focus products). This means that a single breakpoint may actually be encountered many times if the source file is used in multiple programs or used multiple times in the same program.

For example, consider the following program, Main.cbl:

Procedure division.
       Copy "Code.cpy".
       …
       Copy "Code.cpy".

The copybook, Code.cpy, has the following code:

       Add 1 to count		// set breakpoint here

When a breakpoint is set before debugging is started, or no program that uses the copybook is active, the breakpoint is pending. This means that it has not been resolved to a real code position. When debugging is started or a new program is called, the debugger attempts to resolve all pending breakpoints and bind them to actual code positions.

In the above example, when the main executable is loaded by the debugger it binds the single (pending) breakpoint to two actual (bound) breakpoints. The breakpoints are then shown with a plus sign added to the breakpoint icon bound breakpoint marker, both in the margin of the editor and in the Breakpoints view.

Watchpoints

Restriction: Watchpoints are not supported for JVM COBOL applications.

A watchpoint is a type of breakpoint that 'watches' an area of memory associated with a data item; the application breaks when that memory is updated. You set this type of breakpoint on a data item, as opposed to a particular line of code.

Breakpoint and watchpoint setting

You can set breakpoints and watchpoints in one of the following ways:

  • Double-click on the marker bar to the left of the requisite line of executable source code for a breakpoint, or to the left of the requisite Working Storage item for a watchpoint.
  • Right-click on the marker bar and choosing either Toggle Breakpoint or Toggle Watchpoint from the context menu.
  • Right-click on a paragraph name, section name, or data item name in the Outline view and choosing Toggle Breakpoint or Toggle Watchpoint from the context menu.

    Perform any of the above methods on the Procedure Division heading creates a program breakpoint; similarly, performing them on a method-id header (COBOL JVM only) creates a method breakpoint. When these types of breakpoints are hit, execution stops on the first valid line after the header.

    If the editor is not open, you can still create some types of breakpoint. You can create a program breakpoint for any program in the workspace by clicking Run > Add Program Breakpoint, or clicking the Add Program Breakpoint icon icon in the Breakpoints view, and entering the name of the file.

The Breakpoint marker icon appears in the marker bar when a breakpoint is set, and the watchpoint marker icon when a watchpoint is set. A tick mark is added to these icons when the breakpoint or watchpoint is bound to the program currently attached to the debugger. A program breakpoint is indicated by the Program Breakpoint icon icon.

Warning: If you have identically-named programs within your workspace, setting a breakpoint in one could cause the other programs to break when they are debugged (if the corresponding lines are debuggable). To guard against this behavior, select Ignore breakpoints in resources within unrelated projects (available from Window > Preferences > Micro Focus > Debug), and any breakpoints set for identically-named programs outside of the current project (and its dependencies) are ignored.

Accessing properties for a breakpoint or watchpoint

The Breakpoints view shows a list of all breakpoints and watchpoints, active and dormant, in the workspace. To view the properties of each, right-click the entry and select Breakpoint Properties. This displays a Properties... dialog box shows details for the breakpoint or watchpoint, and enables you to configure its behavior.

Setting Conditions

You can add conditions to both types of breakpoints. A condition can be a hit count - for example, for a conditional breakpoint on line 15 of a program, where hit count > 2 is set, execution will only break when an attempt is made to execute that line for the third time. If you are reverse debugging, the hit count still increments when you step backwards.

In native COBOL code, a condition can also be a coded expression - for example, for a conditional watchpoint set on my-variable, with an expression of my-variable > your-variable, would only break execution when the memory for my-variable was updated and the value of my-variable was greater than your-variable. You can also combine both types of condition, where both conditions must be true before execution will break.

See Setting conditional breakpoints and watchpoints.