Debug from an Anonymous Block?

I want to be able to run this anonymous block in the SE using the Debugger:

declare
v_var number := 1;
begin
my_package.procedure(v_var);
end;

My_package has been compiled with debug but it would appear that in order to debug this in TOAD I have to create a dummy debug procedure, compile it with debug and then execute that procedure. Is that right?

Any clever way TOAD could just run the anonymous block in debug mode for me?

Cheers

Richard

you dont seem to want to debug from an anonymous block but debug my_package.procedure(v_var)

compile the above and then press the button which looks like this (…) This will allow you to set the parameters ie set how the procecure : my_package.procedure is called.

In here put all the code for you anonymous block ie

declare
v_var number := 1;
begin
my_package.procedure(v_var);
end;

I included a very simple example of an anonymous block I was executing in the SE. The reality is that I declare many variables, make a couple of different package calls etc all in that block of code - the complexity shouldn’t matter. Rather than have to create that as a procedure and then run the debug from the new procedure I was hoping I could just run it from the SE in debug mode. I’m not sure why TOAD forces me to run debugging from a package/procedure execution and why it can’t run from the SE directly?

PLSQL Developer allows me to open a Test Window and run an anonymous block directly in debug mode without any requirement for me to create it as a procedure first. Not sure how they do it there but it works very well. I know, I know, I keep banging on about their Test Window but it is where it beats TOAD hands down - I’ll add it as an enhancement request to the Ideas Pond. :slight_smile:

Richard

Their Test Window isn’t ‘debugging’ the anon block in the
strictest sense of the word. DBMS_DEBUG and the newer debug API Oracle provides
does not support debug sessions.

I imagine they are allowing you to step through an anon block and view the
values of variables and such and view the results of anything returned? Have you
tried the Script Debugger for starters in Toad? That might get you further?

It definitely “steps into” the package that has been compiled with debug from the anonymous block providing me with all the hovering over variables functionality I would expect to find.

Not sure what the Script Debugger does, but it doesn’t appear to “step into” my package call.

I’m confused. Are you trying to debug a package or an anon block?

if you’re trying to debug the package, paste the anon block you are using
into the set params window when you go to execute/debug your package.

I have an anonymous block that makes a call to a package(s) that has been compiled with debug. I want to step through the anonymous block and into the package(s) within it.

Do you want to do anything with the anon block other than step into the package?

Unfortunately Toad’s not able to have the script debugger and pl/sql
debugger active for the same debug scenario…so you can debug the anon
block or the pl/sql program, but not both.

Here is what I am doing:

  1. I am running the anonymous block in the SE and checking the results at the end (not in debug mode)
  2. The results aren’t quite right so I want to execute it again, only this time, with debug on so I can see what happened

I don’t see an easy way of doing step 2 in TOAD. In PLSQL Developer I run it in a Test Window and I can run it in debug mode directly, stepping through the anonymous block and into any packages it calls.

I think you have answered the question - TOAD does not have this capability.

Morning Richard,

I have an anonymous block that makes a call to a package(s)
that has been compiled with debug. I want to step through
the anonymous block and into the package(s) within it.

When you run a procedure or package under the debugger, it wraps the
debug compiled code in an anonymous block anyway, so your one is not
needed. Shift+Ctrl+F9 brings up the dialogue that allows you to (a) see
this anon-block and set any required parameters before it enters the
debugger.

HTH

Cheers,
Norm. [TeamT]

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Good Morning Norm

From where should I press CTRL+SHIFT+F9? I don’t see it in my Key Mapping options - is that from the SB or from the SE?

My simple scenario of calling my package from an anonymous block has perhaps oversimplified what I was trying to explain - can we assume that the piece of code is more than 1 line and calls more than one package for now. All I want to do is, in the SE, instead of F9 I want to execute the same piece of code in Debug mode. I don’t want to have to run a package or create a package, I just want another option for running my piece of code directly from the SE.

Unless I’m missing something, executing a piece of code using the debugger in TOAD is anything but straight forward.

Richard

So you have something like this?

DECLARE

A NUMBER;

B NUMBER;

C NUMBER;

BEGIN

A:=function1();

B:=function2(A);

C:=function3(B);

END;

And, you want to step through this block, and debug function1, then debug
function2, then debug function3 all in one execution/session?

You can’t do that. The best you could do is debug one of those functions
with the debugger.

The debugger is pretty straightforward assuming you mean to debug a single
pl/sql object. You can debug multiple objects by tracing into the execution of
a 2nd object directly from inside the main object being debugged. But,
there’s no way to debug through this chain in the calling ANON block.

If I mistake what you propose, my apologies. Please provide us an example so
we can better understand your needs.

Jeff

Hi Jeff

Yes, that’s exactly the scenario I’m talking about.

Perhaps a possible enhancement to the SE to allow this - I’m not sure how the Test Window in PLSQL Developer does it but I could paste your example into the Test Window and hit the Start Debugger button and I’d start debugging into function1, function2, etc.

Richard

Morning Richard,

From where should I press CTRL+SHIFT+F9? I don't see it in
my Key Mapping options - is that from the SB or from the SE?
Stick the cursor on the procedure you want to debug - anywhere within
it's code - in the Editor, and press those keys, or, click on one of the
debug buttons (I step into myself) or click debug->set Parameters.

Toad will popup a dialogue allowing you to set any parameters for the
procedure your cursor is inside
. When you click OK, you can then F11 to
execute that anon-block under the debugger.

The shortcut keys, CTRL SHIFT F9, is shown on the debug->set parameters
menu option.

The alternative is to click inside the procedure, and click the step
into button, the dialogue will appear for you to set up parameters etc.
Now clicking on the execute button will step you into the code. (There's
nothing stopping you from editing the code in the dialogue that appears
by the way!

I did try stepping into three procs this morning, I had all three open
in the same editor tab. When I set the parameters for the first one, I
manually added the code to run the other two and I was able to step
into each one.

The code originally looked like :

declare
-- variables for "test_1" defined here.
begin
test_1(params);
COMMIT;
end;

The params dialogue only let me enter the params for test_1. I changed
the anon-block to the following:

declare
-- variables for "test_1" defined here.
-- Added variable for "test_2" & "test_3".
begin
test_1(params);
test_2(params);
test_3(params);
end;

The debugger was happy to step into all three procs.

However, these were simple procs and things may not be as happy in real
world code.

HTH

Cheers,
Norm. [TeamT]

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Morning Richard,

From where should I press CTRL+SHIFT+F9? I don't see it in
my Key Mapping options - is that from the SB or from the SE?
Stick the cursor on the procedure you want to debug - anywhere within
it's code - in the Editor, and press those keys, or, click on one of the
debug buttons (I step into myself) or click debug->set Parameters.

Toad will popup a dialogue allowing you to set any parameters for the
procedure your cursor is inside
. When you click OK, you can then F11 to
execute that anon-block under the debugger.

The shortcut keys, CTRL SHIFT F9, is shown on the debug->set parameters
menu option.

The alternative is to click inside the procedure, and click the step
into button, the dialogue will appear for you to set up parameters etc.
Now clicking on the execute button will step you into the code. (There's
nothing stopping you from editing the code in the dialogue that appears
by the way!

I did try stepping into three procs this morning, I had all three open
in the same editor tab. When I set the parameters for the first one, I
manually added the code to run the other two and I was able to step
into each one.

The code originally looked like :

declare
-- variables for "test_1" defined here.
begin
test_1(params);
COMMIT;
end;

The params dialogue only let me enter the params for test_1. I changed
the anon-block to the following:

declare
-- variables for "test_1" defined here.
-- Added variable for "test_2" & "test_3".
begin
test_1(params);
test_2(params);
test_3(params);
end;

The debugger was happy to step into all three procs.

However, these were simple procs and things may not be as happy in real
world code.

HTH

Cheers,
Norm. [TeamT]

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

You could wrap your anan block in create procedure junk ….

Debug junk, and then when done drop procedure

That’s interesting Norm, I suppose I should have tested that scenario
before just declaring it wasn’t supported J

I think that would give Richard everything he needs!

Hi Jeff,

That's interesting Norm, I suppose I should have tested that
scenario before just declaring it wasn't supported J
Happy for you to test it out using better code than my simple test
procs.

I've tried it with no parameters and then with one. So far so good.

I think that would give Richard everything he needs!
Probably. But the usual caveats apply :

  • Don't think, find out (my motto!); and
  • Trust no-one, no matter who, test and test again to be sure!

:slight_smile:

Cheers,
Norm. [TeamT]

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.

If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk

“There’s nothing stopping you from editing the code in the dialogue that appears
by the way!”

I think that’s the way to go. Could CTRL+SHIFT+F9 in the SQL Editor copy whatever block is current (or highlighted) into the Debugger Dialogue window and let you start your debugging from there?

I’m not sure if am asking the same thing, but here is my situation.

I have an anoymous block. And I simply want to step through the code line by line, and hover over variables in the process to see what their current values are.

Is there a way to do this?

Thanks,
Dennis