3.7 Debugging PL/SQL Objects

You can debug PL/SQL functions and procedures using the PL/SQL Debugger in SQL Developer for VS Code..

This section covers the following topics:

3.7.1 Required Debugging Database Privileges

To debug a PL/SQL object, you must have the following privilege:

DEBUG CONNECT SESSION

You also need DEBUG and EXECUTE privileges on SYS.DBMS_DEBUG_JDWP, which is the package used to start or stop the debug session.

If the PL/SQL object to debug belongs to you, no further privileges are required.

If the PL/SQL object does not belong to you, then you must be granted DEBUG and EXECUTE privileges on the PL/SQL object.

3.7.2 Understanding Database Debug Sessions

For a database session, the network connection is initiated by the client (SQL Developer for VS Code) and addressed by the server (Oracle Database). For a database debug session, SQL Developer for VS Code acts as the debug server and listens for connections from the debug client (Oracle Database).

The database must initiate the connection to SQL Developer for VS Code. For this to happen:

  • The database must be configured to allow network access from the database to SQL Developer for VS Code. This done by creating an entry in the network access control list (ACL).
  • The network ACL must specify the IP address (or host name) and port that SQL Developer for VS Code is using to listen for debug connections.
  • There must be a network route from the database to SQL Developer for VS Code. For example, the firewall on the machine where SQL Developer for VS Code is running may need to be configured to allow the incoming connection from Oracle Database. Or if the Oracle Database is running within a Docker container, the container's network configuration may need to be adjusted to create a route between the Docker container and the machine where SQL Developer for VS Code is running.

SQL Developer for VS Code can help you add an entry to the ACL required for the database to connect to SQL Developer for VS Code.

  1. From the Connections panel, open the PL/SQL object to debug and click the Debug icon in the toolbar at the top of the worksheet editor panel.

  2. In the editor pane that appears, click View ACL.

    Configure network ACL
  3. You are prompted to provide the IP address that the database should use to connect to SQL Developer for VS Code. Choose one of the suggestions or enter your own.

    The PL/SQL code block that is required to add an entry in ACL is shown.

    Note:

    The PL/SQL block must be executed by a user with DBA privileges.
    PL/SQL code block

3.7.3 Debugging a PL/SQL Object

This section covers the steps to debug a PL/SQL object.
  1. Before debugging a PL/SQL object, it must be compiled with debug symbols that have been generated. Open the PL/SQL object in the PL/SQL editor and click the Compile for Debug icon in the PL/SQL Editor toolbar.
  2. After a PL/SQL object has been compiled for debugging, you can set breakpoints on any executable line in the PL/SQL object. To configure a breakpoint, in the gutter to the left of the line number, hover till you see a red dot and then click to set the breakpoint.
    Configure break points
  3. To debug the PL/SQL object, expand the Execute icon and then click Debug. In the editor pane that appears, provide values for the arguments required (if any) to invoke the PL/SQL object.
    Enter input value
  4. Click Debug.

    If prompted, confirm the IP address that the database should use to connect to SQL Developer for VS Code.

    The execution of the PL/SQL object pauses on the first breakpoint encountered.

    Breakpoint paused
    Using the icons in the Debug toolbar, you can:
    • Step Over: To move to the next statement.
    • Step Into: To open and debug the current statement.
    • Continue: To resume execution.
    • Stop: To stop debugging,

    You can navigate up and down the call stack using the call stack panel on the left. You can inspect the variables in the Variables panel.