ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Purpose
This package API is primarily intended to implement server-side debuggers and provides a way to debug server-side PL/SQL program units. The name of the debugger is PROBE.
AUTHID
DEFINER
Constants
Name
Data Type
Value
Break Flags
break_exception
PLS_INTEGER
2
break_any_call
PLS_INTEGER
12
break_return
PLS_INTEGER
16
break_next_line
PLS_INTEGER
32
break_control_c
PLS_INTEGER
256
break_any_return
PLS_INTEGER
512
break_handler
PLS_INTEGER
2048
break_RPC
PLS_INTEGER
4096
abort_exception
PLS_INTEGER
8192
Breakpoints
breakpoint_status_unused
PLS_INTEGER
0
breakpoint_status_active
PLS_INTEGER
1
breakpoint_status_active2
PLS_INTEGER
2
breakpoint_status_disabled
PLS_INTEGER
4
breakpoint_status_remote
PLS_INTEGER
8
Client Side Error Codes
error_pbrun_mismatch
PLS_INTEGER
9
error_no_rph
PLS_INTEGER
10
error_probe_invalid
PLS_INTEGER
20
error_upierr
PLS_INTEGER
21
error_noasync
PLS_INTEGER
22
error_nologon
PLS_INTEGER
23
error_reinit
PLS_INTEGER
24
error_unrecognized
PLS_INTEGER
25
error_synch
PLS_INTEGER
26
error_incompatible
PLS_INTEGER
30
Cursor Flags
cflags_open
PLS_INTEGER
1
cflags_found
PLS_INTEGER
2
cflags_notfound
PLS_INTEGER
4
cflags_uninitialized
PLS_INTEGER
32
cflags_recursive
PLS_INTEGER
128
cflags_refcur_bind
PLS_INTEGER
1024
cflags_dynamic_sql
PLS_INTEGER
2048
cflags_first_iter
PLS_INTEGER
4096
cflags_dynamic_open
PLS_INTEGER
16384
Error Codes
success
PLS_INTEGER
0
error_bogus_frame
PLS_INTEGER
1
error_no_debug_info
PLS_INTEGER
2
error_no_such_object
PLS_INTEGER
3
error_unknown_type
PLS_INTEGER
4
error_unimplemented
PLS_INTEGER
17
error_indexed_table
PLS_INTEGER
18
error_illegal_index
PLS_INTEGER
19
error_deferred
PLS_INTEGER
27
error_exception
PLS_INTEGER
28
error_communication
PLS_INTEGER
29
error_timeout
PLS_INTEGER
31
error_nullvalue
PLS_INTEGER
32
error_nullcollection
PLS_INTEGER
40
Libunit Types
LibunitType_cursor
PLS_INTEGER
0
LibunitType_procedure
PLS_INTEGER
7
LibunitType_function
PLS_INTEGER
8
LibunitType_package
PLS_INTEGER
9
LibunitType_package_body
PLS_INTEGER
11
LibunitType_trigger
PLS_INTEGER
12
LibunitType_Unknown
PLS_INTEGER
-1
Statuses returned by set_value
error_illegal_value
PLS_INTEGER
5
error_illegal_null
PLS_INTEGER
6
error_value_malformed
PLS_INTEGER
7
error_other
PLS_INTEGER
8
error_name_incomplete
PLS_INTEGER
11
Statuses returned by the breakpoint functions
error_illegal_line
PLS_INTEGER
12
error_no_such_breakpt
PLS_INTEGER
13
error_idle_breakpt
PLS_INTEGER
14
error_stale_breakpt
PLS_INTEGER
15
error_bad_handle
PLS_INTEGER
16
Information Flags
info_getStackDepth
PLS_INTEGER
2
info_getBreakpoint
PLS_INTEGER
4
info_getLineinfo
PLS_INTEGER
8
info_getOerInfo (Probe 2.4)
PLS_INTEGER
32
Reasons Flags
reason_none
PLS_INTEGER
0
reason_interpreter_starting
PLS_INTEGER
2
reason_breakpoint
PLS_INTEGER
3
reason_enter
PLS_INTEGER
6
reason_return
PLS_INTEGER
7
reason_finish
PLS_INTEGER
8
reason_line
PLS_INTEGER
9
reason_interrupt
PLS_INTEGER
10
reason_exception
PLS_INTEGER
11
reason_ICD_call
PLS_INTEGER
12
reason_ICD_return
PLS_INTEGER
13
reason_exit
PLS_INTEGER
15
reason_handler
PLS_INTEGER
16
reason_timeout
PLS_INTEGER
17
reason_instantiate
PLS_INTEGER
20
reason_abort
PLS_INTEGER
21
reason_knl_exit
PLS_INTEGER
25
Namespaces
namespace_cursor
PLS_INTEGER
0
namespace_pkgspec_or_toplevel
PLS_INTEGER
1
namespace_pkg_body
PLS_INTEGER
2
namespace_trigger
PLS_INTEGER
3
namespace_none
PLS_INTEGER
255
Other
full_diagnostics
PLS_INTEGER
1
Timeout Options
retry_on_timeout
PLS_INTEGER
0
continue_on_timeout
PLS_INTEGER
1
nodebug_on_timeout
PLS_INTEGER
2
abort_on_timeout
PLS_INTEGER
3
Not Yet Supported
reason_sql
PLS_INTEGER
4
reason_rpc
PLS_INTEGER
14
reason_rpc
PLS_INTEGER
18
reason_unhandled
PLS_INTEGER
19
Public Variables
default_timeout (60 minutes)
PLS_INTEGER
3600
diagnostic_level
PLS_INTEGER
0
Data Types
-- the following fields are used when setting a breakpoint
TYPE program_info IS RECORD (
Namespace BINARY_INTEGER, -- See 'NAMESPACES' section below.
Name VARCHAR2(30), -- name of the program unit
Owner VARCHAR2(30), -- owner of the program unit
Dblink VARCHAR2(30), -- database link, if remote
Line# BINARY_INTEGER,
-- read-only fields (set by Probe when doing a stack backtrace)
LibunitType BINARY_INTEGER, -- ie. kglobtyp
EntrypointName VARCHAR2(512));
/
TYPE runtime_info IS RECORD (
Line# BINARY_INTEGER, -- (duplicate of program.line#)
Terminated BINARY_INTEGER, -- has the program terminated?
Breakpoint BINARY_INTEGER, -- breakpoint number
StackDepth BINARY_INTEGER, -- number of frames on the stack
InterpreterDepth BINARY_INTEGER, -- <reserved field>
Reason BINARY_INTEGER, -- reason for suspension
Program program_info, -- source location
oer PLS_INTEGER); -- OER (exception), if any for Probe 2.4
/
-- these fields are duplicates of 'program_info'
TYPE breakpoint_info IS RECORD (
Name VARCHAR2(30),
Owner VARCHAR2(30),
DbLink VARCHAR2(30),
Line# BINARY_INTEGER,
LibunitType BINARY_INTEGER,
Status BINARY_INTEGER); -- see breakpoint_status below
/
TYPE index_table IS TABLE OF BINARY_INTEGER INDEX BY BINARY_INTEGER;
TYPE backtrace_table IS TABLE OF program_info INDEX BY BINARY_INTEGER;
TYPE breakpoint_table IS TABLE OF breakpoint_info INDEX BY BINARY_INTEGER;
TYPE vc2_table IS TABLE OF VARCHAR2(90) index by BINARY_INTEGER;
TYPE oer_table IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
Execute some SQL or PL/SQL code in target session. Program is assumed to be suspended in the target session awaiting commands.
dbms_debug.execute(
what IN VARCHAR2,
frame# IN BINARY_INTEGER,
bind_results IN BINARY_INTEGER,
results IN OUT NOCOPY dbms_debug_vc2coll,
errm IN OUT NOCOPY VARCHAR2);
dbms_debug.get_encoded_pkgvars_for_client(
handle IN program_info,
flags IN BINARY_INTEGER,
pbrun_version IN BINARY_INTEGER,
status IN OUT BINARY_INTEGER,
tidl_version OUT BINARY_INTEGER,
tidl_buf IN OUT RAW);
TBD
Overload 2
dbms_debug.get_encoded_pkgvars_for_client(
handle IN program_info,
flags IN BINARY_INTEGER,
pbrun_version IN BINARY_INTEGER,
status IN OUT BINARY_INTEGER,
tidl_buf IN OUT VARCHAR2,
tidl_version OUT BINARY_INTEGER);
Return an encoded form of one or more stack frames. Only useful if the caller is client-side PL/SQL
Overload 1
dbms_debug.get_encoded_stack_for_client(
start_frame IN BINARY_INTEGER,
frame_count IN BINARY_INTEGER,
flags IN BINARY_INTEGER,
max_string_length IN BINARY_INTEGER,
max_index_values IN BINARY_INTEGER,
pbrun_version IN BINARY_INTEGER,
tidl_version OUT BINARY_INTEGER,
tidl_buf IN OUT RAW;
TBD
Overload 2
dbms_debug.get_encoded_stack_for_client(
start_frame IN BINARY_INTEGER,
frame_count IN BINARY_INTEGER,
flags IN BINARY_INTEGER,
max_string_length IN BINARY_INTEGER,
max_index_values IN BINARY_INTEGER,
pbrun_version IN BINARY_INTEGER,
tidl_buf IN OUT VARCHAR2,
tidl_version OUT BINARY_INTEGER);
Finds program unit and returns highest source line number, number of entry points, and a line map that allows to determine which lines are executable (or, to be precise, whether user can install a break-point or step on that line)
dbms_debug.get_line_map(
program IN program_info,
maxline OUT BINARY_INTEGER,
number_of_entry_points OUT BINARY_INTEGER,
linemap OUT RAW)
RETURN BINARY_INTEGER;
Returns information about the current program. It is only needed if the 'info_requested' parameter to synchronize or continue was set to 0
dbms_debug.get_runtime_info(
info_requested IN BINARY_INTEGER,
run_info OUT runtime_info) -- success, error_timeout, or error_communication
RETURN BINARY_INTEGER;
Returns a value from the currently-executing program
Overload 1
dbms_debug.get_value(
variable_name IN VARCHAR2,
frame# IN BINARY_INTEGER,
scalar_value OUT VARCHAR2,
format IN VARCHAR2 := NULL)
RETURN BINARY_INTEGER;
TBD
Overload 2
dbms_debug.get_value(
variable_name IN VARCHAR2,
handle IN program_info,
scalar_value OUT VARCHAR2,
format IN VARCHAR2 := NULL)
RETURN BINARY_INTEGER;
Sets a breakpoint in a program unit, which persists for the current session. Execution will pause if the target program reaches the breakpoint.
dbms_debug.set_breakpoint(
program IN program_info,
line# IN BINARY_INTEGER,
breakpoint# OUT BINARY_INTEGER,
fuzzy IN BINARY_INTEGER := 0,
iterations IN BINARY_INTEGER := 0)
RETURN BINARY_INTEGER;
The only time where this is used is when backtrace shows an anonymous unit is executing at a given frame position and source is required for viewing and possibly setting a breakpoint.
dbms_debug.show_frame_source(
first_line IN BINARY_INTEGER,
last_line IN BINARY_INTEGER,
source IN OUT NOCOPY vc2_table,
frame_num IN BINARY_INTEGER);
dbms_debug.show_source(first_line IN BINARY_INTEGER,
last_line IN BINARY_INTEGER,
source IN OUT NOCOPY vc2_table);
TBD
Overload 2
dbms_debug.show_source(
first_line IN BINARY_INTEGER,
last_line IN BINARY_INTEGER,
window IN BINARY_INTEGER,
print_arrow IN BINARY_INTEGER,
buffer IN OUT VARCHAR2,
buflen IN BINARY_INTEGER,
pieces OUT BINARY_INTEGER);
-- create an intersession alert DECLARE
msg VARCHAR2(30);
x PLS_INTEGER;
BEGIN
dbms_alert.register('debug_alert');
dbms_alert.waitone('debug_alert', msg, x);
dbms_output.put_line(msg);
dbms_debug.attach_session(msg);
END;
/
-- create a procedure in debug mode CREATE OR REPLACE PROCEDURE testproc
AUTHID CURRENT_USER IS
sid servers.srvr_id%TYPE;
lat servers.latitude%TYPE;
CURSOR dbcur IS
SELECT srvr_id, latitude
FROM servers
WHERE rownum < 4;
BEGIN
FOR dbrec IN dbcur LOOP
sid := dbrec.srvr_id;
lat := dbrec.latitude;
END LOOP;
END testproc;
/
desc dba_plsql_object_settings
col plsql_debug format a15
SELECT DISTINCT name, plsql_debug
FROM user_plsql_object_settings
ORDER BY 1;
ALTER PROCEDURE testproc COMPILE DEBUG;
or
ALTER SESSION SET PLSQL_DEBUG = TRUE;
ALTER PROCEDURE testproc COMPILE;
-- expect an error message
ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL = 1;
-- expect an error message
SELECT DISTINCT name, plsql_debug
FROM user_plsql_object_settings
ORDER BY 1;
set serveroutput on
DECLARE
sess_id VARCHAR2(30);
PROCEDURE display_id(sid IN VARCHAR2)IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
dbms_output.put_line(sess_id);
END;
BEGIN
sess_id := dbms_debug.initialize;
display_id(sess_id);