trace on and off inside functions

What would you like to see in CSPro?
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 594
Joined: July 22nd, 2016, 3:55 pm

trace on and off inside functions

Post by AriSilva »

Hi folks,
Just for you to know, I use TRACE a lot, and I mean it. It is very helpful when you want to see where the flow is going, and the contents of some particular variables.
And I use functions a lot also.
The problem is thatsome functions are already debugged, and I do not want to see them in the trace output. Just to know that entering function xxx and exiting it is enough.
Is there a way to set trace on (or off) as a local set inside the function?
For example:
function xx

set trace(local, on|off);

Best
Ari
Best
Ari
justinlakier
Posts: 143
Joined: November 21st, 2022, 4:41 pm

Re: trace on and off inside functions

Post by justinlakier »

Hi Ari,

You should be able to set trace on or off whenever you need to, such as turning trace off at the start of an uninteresting function and back on at the end of the function, or using an if statement to switch tracing on or off depending on a variable. The example on the Help page for Trace shows how to close and reopen a trace file or window in different circumstances.
For example:
trace(on);
function xx
trace(off);
//contents of the function which you don't want to debug
trace(on);
//contents of the function or beyond which you do want to debug

Hope that answers your question,
Justin
AriSilva
Posts: 594
Joined: July 22nd, 2016, 3:55 pm

Re: trace on and off inside functions

Post by AriSilva »

Thanks for your answer, but the problem with that solution is that the set on and off has to be done entering the function and leaving it, and sometimes the functions can have intermediate exits in the code, than, every time I set the trace off for a certain function I do not want to "see", I have to set trace on in several places.
Best
Ari
Best
Ari
Gregory Martin
Posts: 1783
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: trace on and off inside functions

Post by Gregory Martin »

Based on the trace helps: https://www.csprousers.org/help/CSPro/t ... ction.html
// logic statements after this point will be outputted
set trace(on);

// logic statements after this point will not be outputted
set trace(off);
For a function you're not interested in tracing (other than knowing that you entered/exited the function), can't you do:
set trace(off);

function doNotCareToTrace()

end;

set trace(on);
AriSilva
Posts: 594
Joined: July 22nd, 2016, 3:55 pm

Re: trace on and off inside functions

Post by AriSilva »

Thank you for the reply.
I did not realize that you could put a set trace on and off command outside the function code, as in your example. My understanding of the trace behaviour was that the tace command was executed at execution time when the logic flow was directed to the function, and then, entering the function, you would set the trace on or off.
By having the set trace on or off outside the function it means that I can put a bunch of functions inside a set trace(off) block?
That is
set trace(off);
function func1() ... end;
function func2()... end;
...
function funcn() ... end;
set trace(on);
I´m not sure this will behave.
Thanks anyway
Best
Ari
Best
Ari
Gregory Martin
Posts: 1783
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: trace on and off inside functions

Post by Gregory Martin »

The way we implemented trace was perhaps a bit confusing.

Statements that begin with "set trace" control whether or not the logic code is stored as part of the application so that it can be output in a trace window/file. That is, if you create a .pen file, where the logic is compiled into bytecode, those lines of logic will be stored as part of that bytecode (because the .apc file isn't available when running the .pen file).

Statements that begin with "trace" (without "set") control whether or not a trace window is displayed or file is logged.

So you use "set trace" to indicate which parts of the logic you want to make available for tracing and you use "trace" to control whether or not the trace window/file should be used.
AriSilva
Posts: 594
Joined: July 22nd, 2016, 3:55 pm

Re: trace on and off inside functions

Post by AriSilva »

Thanks, Greg, for clarifying this issue of set trace and trace.
Best
Ari
Post Reply