[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
16.5 Tracing
Bigloo provides a trace facility whose is intended for simple
debugging tasks. It is a replacement for user display
s that
clutters the source code. Here is a typical example using it:
(define (foo x) (with-trace 1 'foo (let loop ((n x)) (with-trace 2 'loop (trace-item "n=" n) (when (> n 0) (let liip ((m n)) (with-trace 2 'liip (trace-item "m=" m)) (when (> m 0) (liip (- m 1)))) (loop (- n 1))))))) (foo 3)
which produces the following output:
+ foo |--+ loop | |- n=3 | |--+ liip | | |- m=3 | |--+ liip | | |- m=2 | |--+ liip | | |- m=1 | |--+ liip | | |- m=0 | |--+ loop | | |- n=2 | | |--+ liip | | | |- m=2 | | |--+ liip | | | |- m=1 | | |--+ liip | | | |- m=0 | | |--+ loop | | | |- n=1 | | | |--+ liip | | | | |- m=1 | | | |--+ liip | | | | |- m=0 | | | |--+ loop | | | | |- n=0
Traces generation is controlled by a set of functions and parameters (see Parameters). The functions are described in this chapter.
- bigloo syntax: with-trace level label . body
-
The variable level is the level of a trace. It is a positive integer. It enables simple filtering for traces. A trace is displayed if and only if the debugging level used to compile or to execute the program is greater than the trace level. The variable label is a label, .e.i., an identifier denoting the trace. This identifier will be displayed in debug mode. The variable body is the body of the form, that is, the expression to be evaluated.
Unless a trace is activated
(with-trace lv la body)
(when its level lv is greater than the current debug level) is equivalent to(begin body)
. When traces are activated, before executing body.The debugging level is controlled by two parameters:
bigloo-debug
andbigloo-compiler-debug
(see Parameters).
- bigloo function: trace-item . args
This function displays all its arguments. It has to be used nested in a with-trace form.
- bigloo function: trace-bold s
- bigloo function: trace-string s
These two functions are provided for convenience. They returns strings made of their parameters.
- bigloo function: trace-color color . args
The color argument is a positive integer. This function returns a string which is the representation of args and that appears on the terminal in color color.
Colors can be enable or disabled using the
bigloo-trace-color
parameter (see Parameters).
- bigloo function: trace-margin
- bigloo function: trace-margin-set!
The trace-margin parameter is used to control the characters that are displayed in the margin of a trace. Usual applications should not use this. However, it may be convenient to set the margin by hands in some context. For instance, it can be used to distinguished threads in a multi-threaded application such as:
(make-thread (lambda () (trace-margin-set! (trace-color 1 "=")) ...)) (make-thread (lambda () (trace-margin-set! (trace-color 2 "=")) ...))
- bigloo function: trace-port
- bigloo function: trace-port-set!
These functions return and set the output port used by traces.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on October 23, 2011 using texi2html 5.0.