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 appname.usr.opt in the same directory as the target, where appname is the name of the application. The breakpoints are available when you reopen the debugger.
Sharing 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.
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.
To set a breakpoint on a line in a script:
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”.
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.
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:
Click the Edit Stop button on the PainterBar
Select Breakpoints from the pop-up menu in the Source, Variables, Watch, or Breakpoints view
Select Edit>Breakpoints from the menu bar
Double-click a line in the Breakpoints view
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.
If you specify an occurrence Each time PowerBuilder passes through the specified location, it increments a counter by one. When the counter reaches the number specified, it triggers the breakpoint and resets the counter to zero.
If you specify a condition Each time PowerBuilder passes through the specified location, it evaluates the expression. When the expression is true, it triggers the breakpoint.
If you specify both an occurrence and a condition Each time PowerBuilder passes through the specified location, it evaluates the expression. When the expression is true, it increments the counter. When the counter reaches the number specified, it triggers the breakpoint and resets the counter to zero.
For example, if you specify an occurrence of 3 and the condition notisNull(val)
,
PowerBuilder checks whether val is NULL each
time the statement is reached. The breakpoint is triggered on the
third occurrence of a non-NULL val, then again
on the sixth occurrence, and so forth.
To set an occasional or conditional breakpoint:
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.
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.
You can interrupt execution every time the value of a variable changes. The variable must be in scope when you set the breakpoint.
To set a breakpoint when a variable changes:
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.
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.
To disable a breakpoint:
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.
Disabling all breakpoints To disable all breakpoints, select Disable All from the pop-up menu in the Breakpoints view.
To clear a breakpoint:
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.