Configuring Just-In-Time debugging with Toad allows a 3rd party external application to sync with Toad during the debug process.
Here is a Just-In-Time Debugging example that was copied from our ToadSoft website: http://www.toadsoft.com/get2know85/#Step. For a more detailed example of Just-In-Time Debugging, refer to the attached "Just in Time Debugging Example.doc".
When performing normal debugging, Toad does two things, in the first Oracle session it starts an execution of the procedure it is about to debug, and in the second session it traps the first session into a debugger. Just in Time Debugging allows the user to debug PL/SQL code that is written and run from any client-server application including Visual Basic, Delphi, PowerBuilder, Developer/2000, etc. The external application does not need to exist on the same computer.
This feature is extremely useful when the client-server application calls a stored program with complex parameters, such as cursors, that are not easily simulated from Toad. Rather than trying to simulate the complex environment within Toad, you can simply connect to the external application and then debug the code in its native environment.
-- run this in a SQL*Plus session -- first block gets the debug session ready DECLARE id VARCHAR2(255); BEGIN id := DBMS_DEBUG.INITIALIZE('TOAD_EXAMPLE'); DBMS_DEBUG.DEBUG_ON; END; /
--this fires off your stored pl/sql object so it can be debugged. DECLARE l_cursor case3_pkg.t_rc; BEGIN OPEN l_cursor FOR SELECT * FROM scott.emp WHERE empno = 7369; case3_pkg.receive_cursor(l_cursor); case3_pkg.create_cursor(l_cursor); case3_pkg.receive_cursor(l_cursor); DBMS_DEBUG.DEBUG_OFF; END; /
CREATE OR REPLACE PACKAGE case3_pkg AS TYPE t_rc IS REF CURSOR; PROCEDURE create_cursor( p_cursor IN OUT t_rc ); PROCEDURE receive_cursor( p_cursor IN t_rc ); END; /
--make sure you have a SCOTT.EMP env setup CREATE OR REPLACE PACKAGE BODY case3_pkg AS PROCEDURE create_cursor( p_cursor IN OUT t_rc ) IS BEGIN -- make sure to set a BREAKPOINT here OPEN p_cursor FOR SELECT * FROM scott.emp WHERE empno = 7499; END;
PROCEDURE receive_cursor( p_cursor IN t_rc ) IS l_rec scott.emp%ROWTYPE; BEGIN FETCH p_cursor INTO l_rec; DBMS_OUTPUT.PUT_LINE( 'row = ' || l_rec.empno ); CLOSE p_cursor; END; END; /
To initialize Debug mode, the external application must execute three commands:
* ALTER SESSION SET PLSQL_DEBUG=TRUE * id := dbms_debug.initialize('TOAD') * dbms_debug.debug_on;
where any ID string can replace 'TOAD.' This ID string also must be entered into Toad from the Attach External Session dialog.
Attach External Session is found under Toad's Debug Menu
To debug your Package Body code that gets executed from a calling program, first compile the Package with DEBUG info. Then set a breakpoint within the Code. Execute the Anonymous block from a separate program/session, then Attach the External Session from the Procedure Editor.
In our debug session we can now Step Over the code just like any normal debug session.