PL debugger v10
You can use the debugger to debug PL/pgSQL functions in PostgreSQL, EDB-SPL functions, stored procedures, and packages in EDB Postgres Advanced Server. The debugger is available as an extension for your PostgreSQL installation and is distributed as part of EDB Postgres Advanced Server. You need superuser privileges to use the debugger.
Before using the debugger, modify the postgresql.conf
file,
adding the server-side debugger components to the value of the
shared_preload_libraries
parameter:
shared_preload_libraries =\'\$libdir/`other_libraries`/plugin_debugger\'
After modifying the shared_preload_libraries
parameter, restart the
server to apply the changes.
You can use the debugger for in-context debugging or direct debugging of a target function or procedure. When you use the debugger for in-context debugging, you set a breakpoint at the first line of a program. When a session invokes the target, control is transferred to the debugger. When using direct debugging, the debugger prompts you for any parameters required by the target and then allows you to step through the code.
In-context debugging
To set a breakpoint at the first line of a program, right-click the name of the object you want to debug, and select Debugging > Set breakpoint. The debugger window opens and waits for another session to invoke the program.
When another session invokes the target, the debugger displays the code, allowing you to add breakpoints or step through line by line. The other session is suspended until the debugging completes. Then control is returned to the session.
Direct debugging
To use the debugger for direct debugging, in the browser tree control, right-click the name of the object that you want to debug and select Debugging > Debug.
Use the fields on the Debugger dialog box to provide a value for each parameter:
- The Name field displays the formal parameter name.
- The Type field contains the parameter data type.
- Select the Null? check box if the parameter is a NULL value.
- If the Value box contains an expression, select the Expression? check box.
- In the Value box, enter the parameter value to
pass to the program. When entering parameter values, you can either:
- Type the value into the appropriate cell on the grid.
- Leave the cell empty to represent NULL.
- Enter two single quotes (\'\') to represent an empty string.
- Enter a literal string consisting of just two single quotes (\'\').
- PostgreSQL 8.4 and later supports variadic function parameters. You can enter these as a comma-delimited list of values, quoted or cast as required.
- Select the Use default? check box if you want the program to use the value in the Default Value box.
- The Default Value box displays the default value of the parameter.
After you enter the values the program requires, select Debug to start stepping through the program.
The values you selected are saved and appear the next time you open the dialog box. To clear the values, select Clear All.
Using the debugger
The main debugger window consists of two panels and a context-sensitive toolbar. Use toolbar icons to manage breakpoints and step into or through code.
Icon | Action |
---|---|
Step into | Execute the currently highlighted line of code. |
Step over | Execute a line of code, stepping over any subfunctions invoked by the code. The subfunction executes but isn't debugged unless it contains a breakpoint. |
Continue/Start | Execute the highlighted code and continue until the program encounters a breakpoint or completes. |
Toggle breakpoint | Enable or disable a breakpoint without removing the breakpoint. |
Clear all breakpoints | Remove all breakpoints from the program. |
Stop | Stop the program from executing. |
The top panel of the debugger window displays the program body. Click the gray margin next to a line number to add a breakpoint. The highlighted line in the top panel is the line that's about to execute.
The lower panel of the debugger window provides a set of tabs that allow you to review information about the program:
- The Parameters tab displays the value of each parameter.
- The Local variables tab displays the current value of the program variables.
- The Messages tab displays any messages returned by the server.
- The Results tab displays the server message when the program completes.
- The Stack tab displays the list of functions that were invoked but that haven't yet completed.
As you step through a program, the Local variables tab displays the current value of each variable.
When you step into a subroutine, the Stack tab displays the call stack, including the name of each caller, the parameter values for each caller (if any), and the line number within each caller.
Select a caller to change focus to that stack frame and display the state of the caller in the upper panel.
When the program completes, the Results tab displays the message returned by the server. If the program encounters an error, the Messages tab displays details.
Note
If the ENABLE_DEBUGGER
configuration option is set to false, then the debugger is disabled.