Setting breakpoints

A breakpoint is a point in your application code where you want to interrupt the normal execution of the application while you are debugging. If you suspect a problem is occurring in a particular script or function call, set a breakpoint at the beginning of the script or at the line where the function is called.

When you close the debugger, any breakpoints you set are written to a file called targetname.usr.opt in the same directory as the target, where targetname is the name of the target. The breakpoints are available when you reopen the debugger. When you clear breakpoints, they are permanently removed from the usr.opt file (if it is not marked readonly).

NoteSharing targets If multiple developers use the same target without using source control (a practice that is not recommended) individual developers can save the breakpoints they set in a separate file by adding the following entry to the [pb] section of their pb.ini file:

UserOptionFileExt=abc

where abc might be the developer’s name or initials. Breakpoints set by the developer would be saved in a file called appname_abc.usr.opt.

Setting a simple breakpoint

This procedure describes setting a breakpoint in the Source view in the debugger. You can also set a breakpoint by selecting Add Breakpoint from the pop-up menu in the Script view when you are not running the debugger.

StepsTo set a breakpoint on a line in a script:

  1. Display the script in a Source view and place the cursor where you want to set the breakpoint.

    For how to change the script shown in the Source view, see “Using the Source view”.

  2. Double-click the line or select Add Breakpoint from the pop-up menu.

    PowerBuilder sets a breakpoint and a red circle displays at the beginning of the line. If you select a line that does not contain executable code, PowerBuilder sets the breakpoint at the beginning of the next executable statement.

Setting special breakpoints

Breakpoints can be triggered when a statement has been executed a specified number of times (an occasional breakpoint), when a specified expression is true (a conditional breakpoint), or when the value of a variable changes.

You use the Edit Breakpoints dialog box to set and edit occasional and conditional breakpoints. You can also use it to set a breakpoint when the value of a variable changes. The Edit Breakpoints dialog box opens when you:

Setting occasional and conditional breakpoints

If you want to check the progress of a loop without interrupting execution in every iteration, you can set an occasional breakpoint that is triggered only after a specified number of iterations. To specify that execution stops only when conditions you specify are met, set a conditional breakpoint. You can also set both occasional and conditional breakpoints at the same location.

StepsTo set an occasional or conditional breakpoint:

  1. On the Location tab in the Edit Breakpoints dialog box, specify the script and line number where you want the breakpoint.

    You can select an existing location or select New to enter a new location.

  2. Specify an integer occurrence, a condition, or both.

    The condition must be a valid boolean PowerScript expression (if it is not, the breakpoint is always triggered). PowerBuilder displays the breakpoint expression in the Edit Breakpoints dialog box and in the Breakpoints view. When PowerBuilder reaches the location where the breakpoint is set, it evaluates the breakpoint expression and triggers the breakpoint only when the expression is true.

Setting a breakpoint when a variable changes

You can interrupt execution every time the value of a variable changes. The variable must be in scope when you set the breakpoint.

StepsTo set a breakpoint when a variable changes:

  1. Do one of the following:

    • Select the variable in the Variables view or Watch view and select Break on Change from the pop-up menu.

    • Drag the variable from the Variables view or Watch view to the Breakpoints view.

    • Select New on the Variable tab in the Edit Breakpoints dialog box and specify the name of a variable in the Variable box.

    The new breakpoint displays in the Breakpoints view and in the Edit Breakpoints dialog box if it is open. PowerBuilder watches the variable at runtime and interrupts execution when the value of the variable changes.

Disabling and clearing breakpoints

If you want to bypass a breakpoint for a specific debugging session, you can disable it and then enable it again later. If you no longer need a breakpoint, you can clear it.

StepsTo disable a breakpoint:

  1. Do one of the following:

    • Click the red circle next to the breakpoint in the Breakpoints view or Edit Breakpoints dialog box

    • Select Disable Breakpoint from the pop-up menu in the Source view

    • Select Disable from the pop-up menu in the Breakpoints view

    The red circle next to the breakpoint is replaced with a white circle.

    You can enable a disabled breakpoint from the pop-up menus or by clicking the white circle.

NoteDisabling all breakpoints To disable all breakpoints, select Disable All from the pop-up menu in the Breakpoints view.

StepsTo clear a breakpoint:

  1. Do one of the following:

    • Double-click the line containing the breakpoint in the Source view

    • Select Clear Breakpoint from the pop-up menu in the Source view

    • Select Clear from the pop-up menu in the Breakpoints view

    • Select the breakpoint in the Edit Breakpoints dialog box and select Clear

    The red circle next to the breakpoint disappears.

NoteClearing all breakpoints To clear all breakpoints, select Clear All in the Edit Breakpoints dialog box or from the pop-up menu in the Breakpoints view.