How to Debug Oracle Forms Using the Forms Debugger

Find what goes wrong in Oracle Forms 14.1.2: run a form in the debugger, step through code, inspect variables, and attach to running forms.

When code runs but does the wrong thing, reading it again only goes so far. The debugger of Oracle Forms Builder shows the code running: it stops at chosen lines, executes one statement at a time, and shows the values of variables and items.

This guide covers debugging in Oracle Forms 14.1.2: running a form in the debugger, setting breakpoints, stepping through code, the debug panes, the DEBUG package, attaching the debugger to a form that is already running, and simpler techniques for when the debugger is not at hand.

Sample Form for This Guide

The examples and screenshots use the sample form CH26_ERRORS from the Oracle Forms code repository on GitHub. Download it, open it in Forms Builder, and connect as CAREWELL to follow along.

FormFileWhat it shows
CH26_ERRORSforms/ch26/ch26_errors.fmbDr. Sara Nair's appointments, with database errors turned into clear messages

The forms run against the CareWell Clinic sample schema, which you install first.

Debugger Commands at a Glance

CommandKeyWhat it does
Debug ModuleShift+F9Compiles the form with debug information and runs it.
Step IntoF7Runs one statement, entering the procedures it calls, even those of an attached library.
Step OverF8Runs one statement, including whole procedure calls.
Step OutCtrl+F7Runs to the end of the current procedure.
Run to CursorShift+F4Runs to the line of the cursor.
GoF9Runs to the next breakpoint, or on.
StopNoneEnds the form.

Run a Form in the Debugger

Debug, Debug Module (Shift+F9) compiles the current form with the information the debugger needs, and runs it as Program, Run Form does. A form compiled with frmcmp_batch gets that information with debug=yes, as shown in how to compile Oracle Forms modules. The form runs normally until it reaches a breakpoint.

Set a Breakpoint

Open the code in the PL/SQL Editor and choose its Debug tab, which numbers the lines. Double-clicking a line sets a breakpoint, shown as (BRK). The Breakpoints pane lists the breakpoints set.

Debug, Insert/Remove Breakpoint (F5) is meant to do the same for the line of the cursor, but in testing on Forms Builder for Linux it stayed disabled, and double-clicking the line was the way.

Stop and Step

With a breakpoint on the one line of the sample errors form's ON-ERROR trigger, saving an appointment for patient 99999 stopped the form. Its window no longer answered, and in the editor the line showed (BRK)=>, the next line to run. The Debug menu then enabled its commands.

Oracle Forms Builder Debug menu while the debugger is stopped
The Debug menu while the debugger is stopped.

Step Into on cw_err.on_error opened the body of the CW_ERR package from the attached library, and three Step Overs later the editor showed the next line to run as 00012=>.

Stepping through a library procedure in the Oracle Forms debugger
Stepping through the library's CW_ERR.ON_ERROR.

The code being debugged here is explained in how to handle errors in Oracle Forms using ON-ERROR.

The Debug Windows

Debug, Debug Console opens a window that shows the debugger's panes, chosen with its toolbar or with Debug, Debug Windows:

PaneShows
StackThe chain of calls that led to the current line.
VariablesThe variables of the current procedure, or of another stack frame.
WatchVariables you chose to follow.
Form ValuesThe items of the form's blocks, and its parameters.
BreakpointsThe breakpoints set.
PL/SQL PackagesThe variables of the packages in use.
Global/System VariablesThe global and system variables.

Here is the Variables pane for ON_ERROR at line 12: the database error, and the constraint that CONSTRAINT_OF found. Values that changed at the last step are shown in red.

Variables pane of the Oracle Forms debugger at a breakpoint
The Variables pane at a breakpoint.

The DEBUG Package

The built-in package DEBUG lets code work with the debugger.

Syntax:

debug.suspend                                    -- stops here, like a breakpoint
debug.getc(varname varchar2) return varchar2     -- getd, geti, getn: a date, integer, number
debug.setc(varname varchar2, newvalue varchar2)  -- setd, seti, setn
debug.interpret(input varchar2)                  -- runs a debugger command
debug.attach                                     -- shows how to attach the debugger

DEBUG.SUSPEND is a breakpoint written in the code, useful inside a condition, so it stops only when the case you are looking for happens.

Example:

if v_total < 0 then debug.suspend; end if;

GETC, GETD, GETI, and GETN read, and SETC, SETD, SETI, and SETN change, the variables of the stopped code.

Attach the Debugger to a Running Form

DEBUG.ATTACH supports the other way to start the debugger: attaching it to a form that is already running, for example one started by a user on a test server. Called in the running form, it shows the host and the port to connect to, and says what to do with them. Enter them in the dialog of Debug, Attach Debug in Forms Builder.

Oracle Forms DEBUG.ATTACH showing the host and port for Attach Debug
DEBUG.ATTACH in a running form.

Other Ways to Look

The debugger is not always at hand. Three simpler techniques remain useful:

  • MESSAGE with the values you want to see. Add SYNCHRONIZE after it when the screen must be redrawn before the code goes on, as in a loop; see SYNCHRONIZE in Oracle Forms.
  • A trace file written with TEXT_IO, recording the triggers that fire and the values they see, as in how to trace the firing order of triggers.
  • Help, Display Error (Shift+Ctrl+E), which shows the statement and the database error behind the last FRM- error.

The Forms server can also write a trace of a session, every event, trigger, and statement, for problems that only appear on the server.

Conclusion

Debug Module (Shift+F9) runs an Oracle Forms form in the debugger. Set breakpoints by double-clicking lines in the PL/SQL Editor's Debug tab, step with Step Into, Step Over, and Step Out, and inspect the Stack, Variables, Form Values, and other panes of the Debug Console. Use DEBUG.SUSPEND to stop only in the case you are chasing, DEBUG.ATTACH with Attach Debug to debug a form that is already running, and MESSAGE, a TEXT_IO trace, or Display Error when the debugger is not at hand.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE and software veteran with 25+ years of experience, passionate about AI and IT innovation.

guest

0 Comments
Oldest
Newest Most Voted
00