(lispkit debug)
Last updated
Last updated
Library (lispkit debug)
provides utilities for debugging code. Available are procedures for measuring execution latencies, for tracing procedure calls, for expanding macros, for disassembling code, as well as for inspecting the execution environment.
(time expr)
time
compiles expr and executes it. The form displays the time it took to execute expr as a side-effect. It returns the result of executing expr.
(time-values expr)
time-values
executes expr. If expr evaluates to n values x1, ..., xn
, time-values
returns n + 1 values t, x1, ..., xn
where t
is the time it takes to evaluate expr.
(trace-calls) (trace-calls level)
This function is used to enable/disable call tracing. When call tracing is enabled, all function calls that are executed by the virtual machine are being printed to the console. Call tracing operates at three levels:
0
: Call tracing is switched off
1
: Call tracing is enabled only for procedures for which it is enabled (via function set-procedure-trace!
)
2
: Call tracing is switched on for all procedures (independent of procedure-level tracing being enabled or disabled)
(trace-calls n)
will set call tracing to level n
. If the level is ommitted, trace-calls
will return the current call tracing level.
For instance, if call tracing is enabled via (trace-calls 2)
, executing (fib 3)
will print the following call trace.
Function invocations are prefixed with ⟶
, or ↪
if it's a tail call. The value returned by a function call is prefixed with ⟵
.
Returns #f
if procedure-level call tracing is disabled for proc, #t
otherwise.
Enables procedure-level call tracing for procedure proc if trace? is set to #t
. It disables call tracing for proc if trace? is #f
.
quote-expanded
is syntax for macro-expanding expression expr in the current syntactical environment. Macro-expansion is applied consecutively as long as the top-level can be expanded further.
quote-expanded-1
is syntax for macro-expanding expression expr in the current syntactical environment. Macro-expansion is applied at most once, even if the top-level can be expanded further.
Procedure macroexpand
applies macro-expansion to the expression expr in the environment env as long as the expression on its top-level can be expanded further. If env is not provided, the current interaction environment is used.
Procedure macroexpand-1
applies macro-expansion to the expression expr in the environment env at most once. The resulting expression might therefore only be partially expanded at the top-level. If env is not provided, the current interaction environment is used.
Compiles expression expr in environment env and displays the disassembled code. If env is not given, the current interaction environment is used. This is what is being printed when executing (compile '(do ((i 0 (fx1+ i)))((fx> i 10))(display i)(newline)))
:
Disassembles procedure proc and prints out the code. This is what is being printed when executing (disassemble caddr)
:
Force garbage collection to be performed.
Returns a list of all symbols that have been used so far.
Returns a list of all libraries that have been loaded so far.
Returns a list of all sources that have been loaded.
Prints out debug information about the current execution environment (mostly relevant for developing LispKit).
Returns the number of elements that are currently on the stack.
Returns a list of procedures that are currently in process of being executed in the current thread.
Returns a list of procedure calls that are currently in process of being executed in the current thread. The result is a list of lists, where each element corresponds to an active procedure call (with the given parameters, where this can be reconstructed).
When exceptions and errors are created, a call stack trace is attached to them. Since these can be quite large, call stack traces are capped at the top-most n entries. n can be at most 1000, default is 20.
Returns a list of strings, each representing a native function that is currently being executed internally.
(procedure-trace? proc)
(set-procedure-trace! proc trace?)
(quote-expanded expr)
(quote-expanded-1 expr)
(macroexpand expr) (macroexpand expr env)
(macroexpand-1 expr) (macroexpand-1 expr env)
(compile expr) (compile expr env)
(disassemble proc)
(gc)
(available-symbols)
(loaded-libraries)
(loaded-sources)
(environment-info)
(stack-size)
(call-stack-procedures)
(call-stack-trace)
(set-max-call-stack! n)
(internal-call-stack)