Toad for Oracle
PL/SQL Debugger
The Toad for Oracle Professional, Toad for Oracle Xpert, and Toad for Oracle
Suite editions include debugging functionality (PL/SQL Debugger, Script
Debugger).
The PL/SQL Debugger, which is run in the Procedure Editor window, lets you step through the code as it executes, line-by-line, statement-by-statement. The
Debug menu is only enabled in a Procedure Edit window. You can run a debug session with or without argument values. With the click of the toolbar button, debugging begins and stops on breakpoints, as appropriate, or it runs to the end.
If you have the Debugger installed, the Debug toolbar displays to the right of the
Procedure Edit toolbar in the Procedure Edit window. You can also access the
Debug menu using the keyboard by pressing <ALT>U.
Unless you specify parameter values in the Set Parameters dialog, they will default to NULL values. So, for functions that depend on the argument values, you can still check the branching, logic, etc. You can also set argument values in the Set Parameters dialog, and it will use those values.
You can add, edit, and delete breakpoints. You can also set conditional breakpoints and apply pass counts.
After the procedure has executed, you can view the DBMS_OUTPUT from the server.
For all databases, you must have the Oracle Probe API installed in order to debug
PL/SQL using Toad.
Objects you can Debug
• Top-level Functions
• Top-level Procedures
• Package Functions
• Package Procedures
• Triggers
Objects you cannot debug
• Java classes
• Anonymous PL/SQL blocks
Right-click over the editor, select Debug from the menu, and several Debug functions will appear on the submenu.
152
Procedure Editor
To start the Debugger
1.
Open the Procedure Edit window from either the
Database | Procedure Editor menu item
– OR –
Click the Open a New Procedure Edit window button on the main toolbar.
2.
Load a PL/SQL procedure into the editor or write a new procedure.
You can
Load a procedure from a file on disk
– OR –
Load a procedure from an existing object in the database
– OR –
Type a procedure from scratch
– OR –
Click the New Procedure button.
3.
Compile the procedure by
Pressing F9
– OR –
Clicking the Compile button on the Procedure Editor toolbar.
4.
Press F7 (Trace Into) to start stepping through the code. Toad generates the symbol table required to obtain debug information for this procedure.
If you want to step into other procedures and view debug information, you'll need to click the Compile Dependencies with Debug toolbar button before beginning the debug process.
153
Toad for Oracle
When you begin debugging, you can set Toad to
• Always compile dependent procedures
• Never compile dependent procedures
• Prompt you whether or not to compile dependent procedures
To set any of these options go to View | Options | Debugging tab.
Otherwise, watched variable values in the dependent procedures will have "no debug information" displayed in the watches window.
The View | Options | Debugging | Show executable line indicators in
gutter option (available for Oracle 8.1.7 and later) will display a small blue dot in the editor gutter for an executable line of code. This indicates where breakpoints may be set in the code.
When debugging a procedure, if no breakpoints have been set and no errors occur, the procedure will execute to completion, and it appears to have "done nothing." This is a common cause of confusion when people first start using the
Debugger. To avoid this confusion, if you haven't set any breakpoints you might want to use the Step function <F8> instead of the Execute function <F11>.
Tooltip Feature for Variables
The Debugger has a handy tooltip feature. When you are running the Debugger if you move the pointer over a variable, a tooltip pops up that tells you what the value of that variable is at that point in the code.
The Status Panel Indicators
When debugging PL/SQL code, the word "Running" displays in a segment of the
Procedure Edit window status panel at the bottom of the window. If you are not debugging a procedure, "Valid" or "Invalid" displays.
154
Procedure Editor
The Dockable Windows
There are four stay-on-top windows in the Debug menu: Breakpoints, Call Stack,
Watches, and DBMS Output. Any of these windows can be docked together into one window (or combinations of multiple docked windows) by dragging the window title bar of one window and dropping it on another window. This creates a tabbed interface to the separate panels. A right-click menu item lets you Dock
to Procedure Editor which groups and docks all four windows.
You can display all the windows at once. To return the windows to their docked as one position, drag them by their tabs and place them on top of each other.
You can double-click on a floating debug window's title bar to dock it.
DBMS Output
DBMS Output is also discussed in the Procedure Editor chapter.
To view the DBMS_OUTPUT
1.
Select Debug | DBMS Output.
2.
The DBMS Output dockable window displays with the variable value listed, after execution of the procedure has completed.
Preparing PL/SQL Code for Production
Once you have finished debugging your PL/SQL code, compile your procedure and any called procedures one last time with the debugger toggled off. This recompiles it without the debug symbol tables. This will make your code smaller; so it will run faster.
For more information about the PL/SQL Debugger and the other debug features
refer to Toad Help.
155
Toad for Oracle
156
8
Schema Browser
Toad
158