Print debugging statement: Difference between revisions

Content added Content deleted
(J)
m (syntax highlighting fixup automation)
Line 14: Line 14:
=={{header|Applesoft BASIC}}==
=={{header|Applesoft BASIC}}==
Debugging commands TRACE and NOTRACE turn on and off showing line numbers as the program runs. The LIST command can be embedded in the program to display lines of the program. The RUN command can used to start the program at a specific line number. The STOP command stops the program and displays an error message. The CLEAR and RUN commands clear all variables.
Debugging commands TRACE and NOTRACE turn on and off showing line numbers as the program runs. The LIST command can be embedded in the program to display lines of the program. The RUN command can used to start the program at a specific line number. The STOP command stops the program and displays an error message. The CLEAR and RUN commands clear all variables.
<lang gwbasic> 0 PRINT "START"
<syntaxhighlight lang="gwbasic"> 0 PRINT "START"
1 IF DEBUG THEN LIST 1: PRINT "TEST"
1 IF DEBUG THEN LIST 1: PRINT "TEST"
2 IF DEBUG THEN LIST 2: TRACE
2 IF DEBUG THEN LIST 2: TRACE
Line 20: Line 20:
4 IF DEBUG THEN LIST 4, 6: PRINT "ALPHA" : RUN 4
4 IF DEBUG THEN LIST 4, 6: PRINT "ALPHA" : RUN 4
5 NOTRACE
5 NOTRACE
6 LIST 6: PRINT "END"</lang>
6 LIST 6: PRINT "END"</syntaxhighlight>
<lang gwbasic>RUN</lang>
<syntaxhighlight lang="gwbasic">RUN</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 33: Line 33:
END
END
</pre>
</pre>
<lang gwbasic>CLEAR:DEBUG=1:GOTO</lang>
<syntaxhighlight lang="gwbasic">CLEAR:DEBUG=1:GOTO</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 61: Line 61:
C doesn't have a built-in print debugging statement. However, it can be defined by users as a macro.
C doesn't have a built-in print debugging statement. However, it can be defined by users as a macro.


<lang C>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


#define DEBUG_INT(x) printf( #x " at line %d\nresult: %d\n\n", __LINE__, x)
#define DEBUG_INT(x) printf( #x " at line %d\nresult: %d\n\n", __LINE__, x)
Line 77: Line 77:
add(2, 7);
add(2, 7);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 95: Line 95:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


// requires support for variadic macros in this form
// requires support for variadic macros in this form
Line 107: Line 107:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Line 114: Line 114:
Explicit debug usually just uses DISPLAY, and usually directed at SYSERR. Compiler Directing Facility debug is supported with <code>>>D</code> directive statements. GnuCOBOL also supports full on line step tracing, controlled by both compile time switch, <code>-ftraceall</code>, and a truthy setting in a `COB_SET_TRACE` environment variable (so program step logging can be switched on and off without a recompile (for tracking down pesky production run mysteries)).
Explicit debug usually just uses DISPLAY, and usually directed at SYSERR. Compiler Directing Facility debug is supported with <code>>>D</code> directive statements. GnuCOBOL also supports full on line step tracing, controlled by both compile time switch, <code>-ftraceall</code>, and a truthy setting in a `COB_SET_TRACE` environment variable (so program step logging can be switched on and off without a recompile (for tracking down pesky production run mysteries)).


<lang cobol>gcobol*>
<syntaxhighlight lang="cobol">gcobol*>
*> steptrace.cob
*> steptrace.cob
*> Tectonics: cobc -xj -fdebugging-line -ftraceall steptrace.cob
*> Tectonics: cobc -xj -fdebugging-line -ftraceall steptrace.cob
Line 134: Line 134:
display "from " FUNCTION MODULE-ID " in " FUNCTION MODULE-SOURCE
display "from " FUNCTION MODULE-ID " in " FUNCTION MODULE-SOURCE
goback.
goback.
end program steptrace.</lang>
end program steptrace.</syntaxhighlight>


That is fixed form COBOL, columns 1 through 6 ignored by the preprocessor (historical format, from the days of punch card input) with column 7 being a special indicator column, star for comments, dash for continuations, and D is supported by GnuCOBOL for Debug lines. The <code>>>D</code> form is a newer addition to the Compiler Directing Facility, and can float anywhere on a free format compile line.
That is fixed form COBOL, columns 1 through 6 ignored by the preprocessor (historical format, from the days of punch card input) with column 7 being a special indicator column, star for comments, dash for continuations, and D is supported by GnuCOBOL for Debug lines. The <code>>>D</code> form is a newer addition to the Compiler Directing Facility, and can float anywhere on a free format compile line.
Line 166: Line 166:
Using templates and default arguments provides options for specifying a debug function.
Using templates and default arguments provides options for specifying a debug function.
The file and line could be included as either template arguments or function arguments.
The file and line could be included as either template arguments or function arguments.
<lang d>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


void debugln(string file = __FILE__, size_t line = __LINE__, S...)(S args) {
void debugln(string file = __FILE__, size_t line = __LINE__, S...)(S args) {
Line 185: Line 185:
debugWrite("Goodbye", ' ', "world", '!');
debugWrite("Goodbye", ' ', "world", '!');
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>[debug.d@12]
<pre>[debug.d@12]
Line 197: Line 197:
{{libheader| System.sysutils}}
{{libheader| System.sysutils}}
Delphi has a "OutputDebugString" for debug, but not give lines and filename of source.
Delphi has a "OutputDebugString" for debug, but not give lines and filename of source.
<syntaxhighlight lang="delphi">
<lang Delphi>
program DebugApp;
program DebugApp;


Line 215: Line 215:
writeln(Add(2, 7));
writeln(Add(2, 7));
readln;
readln;
end.</lang>
end.</syntaxhighlight>


In next we have a workaround using a idea from '''user3989283'''[[https://stackoverflow.com/questions/7214213/how-to-get-line-number-at-runtime]]. This code override the default assert function to gain access to line and file name.
In next we have a workaround using a idea from '''user3989283'''[[https://stackoverflow.com/questions/7214213/how-to-get-line-number-at-runtime]]. This code override the default assert function to gain access to line and file name.
Obs.: In this example default action of assert is disabled, but you can enable calling in HookAssert (at end).
Obs.: In this example default action of assert is disabled, but you can enable calling in HookAssert (at end).


<syntaxhighlight lang="delphi">
<lang Delphi>
program DebugApp;
program DebugApp;


Line 278: Line 278:


ReleaseDebug;
ReleaseDebug;
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
Example log:
Example log:
Line 291: Line 291:


Note that a label for the expression (whether it's a simple variable or not) must be passed to the 'debug' function as there is no way to deduce it otherwise.
Note that a label for the expression (whether it's a simple variable or not) must be passed to the 'debug' function as there is no way to deduce it otherwise.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 326: Line 326:
q := &p
q := &p
debug("q", q)
debug("q", q)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 356: Line 356:


=={{header|J}}==
=={{header|J}}==
J does not provide any specialized debugging statements. So we might typically use <code>echo</code>. But, we could define <code>dump=:{{y[echo(,:x,':&nbsp;'),&.|:1&nbsp;1}._1&nbsp;_1}.":<y }}</code> which would let us include informative labels in the debugging output. Thus, for example, we could use function composition to see what's going on inside a J expression like this:<lang J> $i.3 3
J does not provide any specialized debugging statements. So we might typically use <code>echo</code>. But, we could define <code>dump=:{{y[echo(,:x,':&nbsp;'),&.|:1&nbsp;1}._1&nbsp;_1}.":<y }}</code> which would let us include informative labels in the debugging output. Thus, for example, we could use function composition to see what's going on inside a J expression like this:<syntaxhighlight lang="j"> $i.3 3
3 3
3 3
$'a' dump i.3 3
$'a' dump i.3 3
Line 362: Line 362:
3 4 5
3 4 5
6 7 8
6 7 8
3 3</lang> Or, like this:<lang J> +/\2 3 5 7
3 3</syntaxhighlight> Or, like this:<syntaxhighlight lang="j"> +/\2 3 5 7
2 5 10 17
2 5 10 17
' sum'&dump@+/@('list'&dump)\2 3 5 7
' sum'&dump@+/@('list'&dump)\2 3 5 7
Line 375: Line 375:
sum: 15
sum: 15
sum: 17
sum: 17
2 5 10 17</lang>Caution: this approach disables J's internal optimizations for frequently used expressions (in the above example, J uses associativity to increase the performance of +/\ from O(n^2) to O(n), but the <tt>dump</tt> version gains no such benefit).<br /><br />
2 5 10 17</syntaxhighlight>Caution: this approach disables J's internal optimizations for frequently used expressions (in the above example, J uses associativity to increase the performance of +/\ from O(n^2) to O(n), but the <tt>dump</tt> version gains no such benefit).<br /><br />
That said, we could also rely on J's debugging information if we did not want to provide explicit labels for everything (this would not usefully distinguish between different points on the same line). For example: <lang j>dump=: {{
That said, we could also rely on J's debugging information if we did not want to provide explicit labels for everything (this would not usefully distinguish between different points on the same line). For example: <syntaxhighlight lang="j">dump=: {{
if.#d=.13!:13'' do.
if.#d=.13!:13'' do.
echo (,:': ',~;:inv":&.>0 2{1{d) ,&.|:1 1}._1 _1}.":<y
echo (,:': ',~;:inv":&.>0 2{1{d) ,&.|:1 1}._1 _1}.":<y
end.
end.
y
y
}}</lang>
}}</syntaxhighlight>


Here, we get debugging output only if debugging is enabled. And we're annotating each value with the name of the routine, and the line within that routine. Thus:
Here, we get debugging output only if debugging is enabled. And we're annotating each value with the name of the routine, and the line within that routine. Thus:
<lang J>example=: {{
<syntaxhighlight lang="j">example=: {{
j=. 1
j=. 1
dump r=. 2
dump r=. 2
Line 395: Line 395:
example''
example''
example 1: 2
example 1: 2
3</lang>
3</syntaxhighlight>




Line 401: Line 401:


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.util.Objects;
<syntaxhighlight lang="java">import java.util.Objects;


public class PrintDebugStatement {
public class PrintDebugStatement {
Line 436: Line 436:
oops.run();
oops.run();
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>[DEBUG][PrintDebugStatement.java PrintDebugStatement.main#30] Hello world.
<pre>[DEBUG][PrintDebugStatement.java PrintDebugStatement.main#30] Hello world.
Line 451: Line 451:


The '''debug''' built-in is a 0-arity filter which behaves somewhat like `tee /dev/stderr` in *ix -- that is, it prints its input as a message to '''stderr''' and also passes it along to the next filter, as illustrated by this transcript:
The '''debug''' built-in is a 0-arity filter which behaves somewhat like `tee /dev/stderr` in *ix -- that is, it prints its input as a message to '''stderr''' and also passes it along to the next filter, as illustrated by this transcript:
<syntaxhighlight lang="sh">
<lang sh>
jq -n '"abc" | debug | length'
jq -n '"abc" | debug | length'
["DEBUG:","abc"]
["DEBUG:","abc"]
3
3
</syntaxhighlight>
</lang>


'''$__loc__'''
'''$__loc__'''
Line 471: Line 471:
=={{header|Julia}}==
=={{header|Julia}}==
Julia has native print logging type functions, including a core Logging module. In addition, there are several additional downloadable modules, such as Memento, with extended logging functionality. Julia's builtin logging has defined macros for logging levels: @error, @warn, @info, and @debug. By default, debug level statements in code are not printed unless the logging level is set to allow debug statements to print, which can be enabled by setting the JULIA_DEBUG environment variable.
Julia has native print logging type functions, including a core Logging module. In addition, there are several additional downloadable modules, such as Memento, with extended logging functionality. Julia's builtin logging has defined macros for logging levels: @error, @warn, @info, and @debug. By default, debug level statements in code are not printed unless the logging level is set to allow debug statements to print, which can be enabled by setting the JULIA_DEBUG environment variable.
<lang julia>function test()
<syntaxhighlight lang="julia">function test()
@info "starting test()"
@info "starting test()"
a = [1, 2]
a = [1, 2]
Line 490: Line 490:


test()
test()
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
[ Info: starting test()
[ Info: starting test()
Line 504: Line 504:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>fun printDebug(message: String) {
<syntaxhighlight lang="scala">fun printDebug(message: String) {
val exception = RuntimeException()
val exception = RuntimeException()
val stackTrace = exception.stackTrace
val stackTrace = exception.stackTrace
Line 531: Line 531:
}
}
nested()
nested()
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>[DEBUG][PrintDebuggingStatement.kt PrintDebuggingStatementKt.main#18] Hello world.
<pre>[DEBUG][PrintDebuggingStatement.kt PrintDebuggingStatementKt.main#18] Hello world.
Line 539: Line 539:


=={{header|Ksh}}==
=={{header|Ksh}}==
<lang ksh>
<syntaxhighlight lang="ksh">
#!/bin/ksh
#!/bin/ksh


Line 577: Line 577:
(( result = x + y ))
(( result = x + y ))
exit
exit
</syntaxhighlight>
</lang>
{{out}}<pre>
{{out}}<pre>
Line 33: Command: 'typeset -li x y result'
Line 33: Command: 'typeset -li x y result'
Line 600: Line 600:
Together with data functors like <code>$module</code>, <code>$pred</code>, <code>$line</code>, trace goals can be used for debugging print statements as in the following example. Together with the [https://mercurylang.org/information/doc-latest/mercury_library/require.html require] module's utilities, trace goals can be used for assert() statements or pre/post assertions.
Together with data functors like <code>$module</code>, <code>$pred</code>, <code>$line</code>, trace goals can be used for debugging print statements as in the following example. Together with the [https://mercurylang.org/information/doc-latest/mercury_library/require.html require] module's utilities, trace goals can be used for assert() statements or pre/post assertions.


<lang Mercury>:- module add.
<syntaxhighlight lang="mercury">:- module add.
:- interface.
:- interface.
:- import_module io.
:- import_module io.
Line 617: Line 617:
main(!IO) :-
main(!IO) :-
2 `add` 7 = N,
2 `add` 7 = N,
io.print_line(N, !IO).</lang>
io.print_line(N, !IO).</syntaxhighlight>


{{out}} (with a non-debug grade)
{{out}} (with a non-debug grade)
Line 636: Line 636:


The conditional activation is done using a “when” statement. Here is an example:
The conditional activation is done using a “when” statement. Here is an example:
<lang Nim>when defined(debug):
<syntaxhighlight lang="nim">when defined(debug):
echo "Debugging info: $1 $2 $3".format(x, y, z)</lang>
echo "Debugging info: $1 $2 $3".format(x, y, z)</syntaxhighlight>
When compiling, if nothing is specified, no code is generated to display the debugging information. If we want to generate the debug statements, we have to specify <code>-d:debug</code> when compiling, for instance if the file is named “example.nim”: <code>nim c -d:debug example.nim</code>. Note that the name “debug” has been chosen as an example but maybe any valid Nim identifier not already used. This allows to use different flags according to what we want to debug.
When compiling, if nothing is specified, no code is generated to display the debugging information. If we want to generate the debug statements, we have to specify <code>-d:debug</code> when compiling, for instance if the file is named “example.nim”: <code>nim c -d:debug example.nim</code>. Note that the name “debug” has been chosen as an example but maybe any valid Nim identifier not already used. This allows to use different flags according to what we want to debug.


If is also possible to use existing flags instead of defining new ones:
If is also possible to use existing flags instead of defining new ones:
<lang Nim>when not defined(release):
<syntaxhighlight lang="nim">when not defined(release):
echo "Debugging info: ", x, " ", y, " ", z</lang>
echo "Debugging info: ", x, " ", y, " ", z</syntaxhighlight>
In this case, by default (debug build), the code for the statement is generated. But if we produce a release build (<code>-d:release</code> option), the debugging code will not be generated.
In this case, by default (debug build), the code for the statement is generated. But if we produce a release build (<code>-d:release</code> option), the debugging code will not be generated.


Line 651: Line 651:
Last, but not least, Nim provides a simple and efficient log module. Using logger objects, this module allows to write log data to the console or into a file. As expected of a logging module, it provides several levels for debugging:
Last, but not least, Nim provides a simple and efficient log module. Using logger objects, this module allows to write log data to the console or into a file. As expected of a logging module, it provides several levels for debugging:


<lang Nim>Level = enum
<syntaxhighlight lang="nim">Level = enum
lvlAll, ## All levels active
lvlAll, ## All levels active
lvlDebug, ## Debug level and above are active
lvlDebug, ## Debug level and above are active
Line 659: Line 659:
lvlError, ## Error level and above are active
lvlError, ## Error level and above are active
lvlFatal, ## Fatal level and above are active
lvlFatal, ## Fatal level and above are active
lvlNone ## No levels active; nothing is logged</lang>
lvlNone ## No levels active; nothing is logged</syntaxhighlight>


These levels are mapped to the following names: "DEBUG", "DEBUG", "INFO", "NOTICE", "WARN","ERROR", "FATAL", "NONE".
These levels are mapped to the following names: "DEBUG", "DEBUG", "INFO", "NOTICE", "WARN","ERROR", "FATAL", "NONE".
Line 666: Line 666:


Logging debugging data is then a simple as writing:
Logging debugging data is then a simple as writing:
<lang Nim>debug "Debugging info: $1 $2 $3".format(x, y, z)</lang>
<syntaxhighlight lang="nim">debug "Debugging info: $1 $2 $3".format(x, y, z)</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
<code>Carp</code> is a core module, always available.
<code>Carp</code> is a core module, always available.
<lang perl>use Carp;
<syntaxhighlight lang="perl">use Carp;


$str = 'Resistance'; carp "'$str' is futile."; print "\n";
$str = 'Resistance'; carp "'$str' is futile."; print "\n";
Line 682: Line 682:
sub fiddle { faddle(2*shift) }
sub fiddle { faddle(2*shift) }
sub faddle { fuddle(3*shift) }
sub faddle { fuddle(3*shift) }
sub fuddle { ( carp("'$_[0]', interesting number.") ); }</lang>
sub fuddle { ( carp("'$_[0]', interesting number.") ); }</syntaxhighlight>
{{out}}
{{out}}
<pre>'Resistance' is futile. at printf_debug.pl line 11.
<pre>'Resistance' is futile. at printf_debug.pl line 11.
Line 700: Line 700:
to the language, albeit as yet undocumented.
to the language, albeit as yet undocumented.


<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">_debug_info</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">_debug_info</span><span style="color: #0000FF;">()</span>
<span style="color: #000080;font-style:italic;">-- use throw to convert a return address and routine number
<span style="color: #000080;font-style:italic;">-- use throw to convert a return address and routine number
Line 755: Line 755:
<span style="color: #008080;">return</span> <span style="color: #000000;">_debug_info</span><span style="color: #0000FF;">()[</span><span style="color: #000000;">E_PATH</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">_debug_info</span><span style="color: #0000FF;">()[</span><span style="color: #000000;">E_PATH</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


This can be used as follows (0.8.1+)
This can be used as follows (0.8.1+)


<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">reflections</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">reflections</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 771: Line 771:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


{{out}}
{{out}}
Line 790: Line 790:
{{libheader|logging}}
{{libheader|logging}}
Python's builtin [https://docs.python.org/3.8/library/logging.html logging module] allows extensive customization of output format and destination.
Python's builtin [https://docs.python.org/3.8/library/logging.html logging module] allows extensive customization of output format and destination.
<lang python>import logging, logging.handlers
<syntaxhighlight lang="python">import logging, logging.handlers


LOG_FILENAME = "logdemo.log"
LOG_FILENAME = "logdemo.log"
Line 827: Line 827:
print_cubes(10)
print_cubes(10)


logger.info("All done")</lang>
logger.info("All done")</syntaxhighlight>
{{out}}<b>Contents of logdemo.log</b>
{{out}}<b>Contents of logdemo.log</b>
<pre>
<pre>
Line 859: Line 859:
Pyret has the [https://www.pyret.org/docs/latest/s_spies.html <code>spy</code> expression]. The expression can print the value of an identifier, using the identifier itself as a label if it's not already given. It could also print the value of an arbitrary expression, but it needs an explicit label in this case.
Pyret has the [https://www.pyret.org/docs/latest/s_spies.html <code>spy</code> expression]. The expression can print the value of an identifier, using the identifier itself as a label if it's not already given. It could also print the value of an arbitrary expression, but it needs an explicit label in this case.


<lang pyret>fun add(x, y):
<syntaxhighlight lang="pyret">fun add(x, y):
result = x + y
result = x + y
spy "in add":
spy "in add":
Line 870: Line 870:
end
end


add(2, 7)</lang>
add(2, 7)</syntaxhighlight>


{{out}}
{{out}}
Line 887: Line 887:
Racket doesn't have a built-in print debugging statement. However, it can be defined by users as a macro.
Racket doesn't have a built-in print debugging statement. However, it can be defined by users as a macro.


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(require syntax/parse/define)
(require syntax/parse/define)
Line 912: Line 912:
(debug result))
(debug result))


(add 2 7)</lang>
(add 2 7)</syntaxhighlight>


{{out}}
{{out}}
Line 943: Line 943:
Comments with the files line numbers are added here to make it easier to match up the debug output with the file. Typically you would be editing the file in an editor that provides line numbering so that wouldn't be necessary/helpful.
Comments with the files line numbers are added here to make it easier to match up the debug output with the file. Typically you would be editing the file in an editor that provides line numbering so that wouldn't be necessary/helpful.


<lang perl6>my &pdb = &die;
<syntaxhighlight lang="raku" line>my &pdb = &die;


CATCH {
CATCH {
Line 978: Line 978:
alpha($a); #line 34
alpha($a); #line 34
delta("Δ"); #line 35
delta("Δ"); #line 35
.&beta for ^3; #line 36</lang>
.&beta for ^3; #line 36</syntaxhighlight>


{{out}}
{{out}}
Line 1,041: Line 1,041:


The following output is from the Regina REXX interpreter.
The following output is from the Regina REXX interpreter.
<lang rexx>/*REXX program to demonstrate debugging (TRACE) information while executing a program*/
<syntaxhighlight lang="rexx">/*REXX program to demonstrate debugging (TRACE) information while executing a program*/
/*────────────────────────────────────────────── (below) the I is for information. */
/*────────────────────────────────────────────── (below) the I is for information. */
trace i
trace i
Line 1,053: Line 1,053:
end /*j*/
end /*j*/


say 'total=' total /*stick a fork in it, we're all done. */</lang>
say 'total=' total /*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 9 </tt>}}
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 9 </tt>}}
<pre>
<pre>
Line 1,107: Line 1,107:


What is generally done in practice is to hard-code some location indicator (such as the line number itself) at which a variable's value is being obtained. The Go example code then looks like this when translated to Wren.
What is generally done in practice is to hard-code some location indicator (such as the line number itself) at which a variable's value is being obtained. The Go example code then looks like this when translated to Wren.
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt


class Point {
class Point {
Line 1,140: Line 1,140:
debug.call("p", p, 32)
debug.call("p", p, 32)
var l = [1, "two", 3]
var l = [1, "two", 3]
debug.call("l", l, 34)</lang>
debug.call("l", l, 34)</syntaxhighlight>


{{out}}
{{out}}
Line 1,172: Line 1,172:
Print debugging is similar to C. The _debug_ keyword conditionally compiles
Print debugging is similar to C. The _debug_ keyword conditionally compiles
code (ie the debug code isn't compiled unless debugging is turned on).
code (ie the debug code isn't compiled unless debugging is turned on).
<lang zkl>fcn ds(line=__LINE__){
<syntaxhighlight lang="zkl">fcn ds(line=__LINE__){
println("This is line %d of file %s compiled on %s"
println("This is line %d of file %s compiled on %s"
.fmt(line,__FILE__,__DATE__));
.fmt(line,__FILE__,__DATE__));
Line 1,179: Line 1,179:
ds(__LINE__); println("Debug level is ",__DEBUG__);
ds(__LINE__); println("Debug level is ",__DEBUG__);
vm.stackTrace().println();
vm.stackTrace().println();
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>