Expand/Shrink

trace

Definition: with trace
trace(integer i)
Description: If i is 1 or 2, turn on full-screen interactive statement tracing/debugging.
If i is 3, turn on tracing of statements to a file called ctrace.out.
If i is 0, turn off tracing.
When i is 1 a color display appears.
When i is 2 a monochrome trace display appears.

See Debugging for a full discussion of tracing / debugging.
pwa/p2js: Ignored, in other words transpilation behaves much like compilation as far as this routine is concerned.
You can of course use the browser development tools to trace/debug the generated JavaScript code.
Comments: Tracing can only occur in a with trace section of your program.

Use trace(2) if the color display is hard to view on your system.

The trace() function is only available during interpretation; it is not and cannot be part of a compiled application, other than in p[w].exe. Any thoughts of "trace a compiled application" suggest that there is a behavioural discrepancy (between compilation and interpretation) which should be directly addressed as a bug in Phix. I know of no such cases, but it is only reasonable to expect one to crop up every now and again, hopefully occuring quite rarely and promptly fixed.

Tracing does not apply to inline assembly (#ilASM{}), only hll code.
Example:
if x < 0 then
    -- ok, here's the case I want to debug...
    trace(1)
    -- etc.
    ...
end if
Implementation: The trace() routine itself is implemented via :%opTrace in builtins\VM\pTrace.e (an autoinclude/part of the compiler) - be warned however this is hard-won ad-hoc code (often written one tiny disjointed step at a time) and it ain’t particularly clear what is really going on, even to me. See also technicalia below.
See Also: profile, debugging and profiling
Expand/Shrink