40 Debugging

▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Classes and Objects
4 | Contracts
5 | Definitions
6 | Dictionaries
7 | Directories
8 | Exceptions
9 | Filesystem
10 | Functions
11 | Lists
12 | Net
13 | Path
14 | PLane T Packages
15 | Ports
16 | Pretty-Printing
17 | Regular Expressions
18 | Requiring Modules
19 | Sandboxed Evaluation
20 | Scribble Documentation
21 | Sets
22 | S-Expression Diff
23 | Source Locations
24 | Strings
25 | Structs
26 | Syntax
27 | Planet Package Macros
28 | Text Representations
29 | Multiple Values
30 | XML and CSS
31 | Polymorphic Contracts
32 | Finding Mutated Variables
33 | Find
34 | Interface-Oriented Programming for Classes
35 | Sequences
36 | Hash Tables
37 | Match
38 | Generics
39 | Mark Parameters
40 | Debugging
41 | Contracts for macro subexpressions
42 | GUI libraries

On this page:

debug
dprintf
debugf
begin/ debug
define/ debug
define/ private/ debug
define/ public/ debug
define/ override/ debug
define/ augment/ debug
let/ debug
let*/ debug
letrec/ debug
let-values/ debug
let*-values/ debug
letrec-values/ debug
with-syntax/ debug
with-syntax*/ debug
parameterize/ debug

Version: 5.0.1.5
top← prev up next →

### 40`` Debugging

Carl Eastlund <cce@racket-lang.org>

( require unstable/debug)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

This module provides macros and functions for printing out debugging information.

( debug options ... expr)

options |  | = |  | #:name name-expr
|  | | |  | #:source srcloc-expr

Writes debugging information about the evaluation of expr to the current error port. The name and source location of the expression may be overridden by keyword options; their defaults are the syntactic form of the expression and its syntactic source location, respectively.

Examples:
> ( debug 0)

>> eval:2.0: 0
result: 0
<< eval:2.0: 0

0
> ( debug #:name "one, two, three" ( values 1 2 3))

>> eval:3.0: "one, two, three"
results: (values 1 2 3)
<< eval:3.0: "one, two, three"

1
2
3

> ( debug #:source ( make-srcloc 'here 1 2 3 4)
( error 'function "something went wrong"))

>> here:1.2: (error 'function "something went wrong")
raised exception: function: something went wrong
<< here:1.2: (error 'function "something went wrong")

function: something went wrong

( dprintf fmt arg ...) → void?
fmt : string?
arg : any/c

Constructs a message in the same manner as format and writes it to ( current-error-port), with indentation reflecting the number of nested debug forms.

Examples:
> ( dprintf "level: ~a" 0)
level: 0
> ( debug ( dprintf "level: ~a" 1))

>> eval:3.0: (dprintf "level: ~a" 1)
level: 1
result: #<void>
<< eval:3.0: (dprintf "level: ~a" 1)

> ( debug ( debug ( dprintf "level: ~a" 2)))

>> eval:4.0: (debug (dprintf "level: ~a" 2))
>> eval:4.0: (dprintf "level: ~a" 2)
level: 2
result: #<void>
<< eval:4.0: (dprintf "level: ~a" 2)
result: #<void>
<< eval:4.0: (debug (dprintf "level: ~a" 2))

( debugf function-expr argument ...)

argument |  | = |  | argument-expr
|  | | |  | argument-keyword argument-expr

Logs debugging information for (#%app function-expr argument ...), including the evaluation and results of the function and each argument.

Example:
> ( debugf + 1 2 3)

>> eval:2.0: debugf
>> eval:2.0: +
result: #<procedure:+>
<< eval:2.0: +
>> eval:2.0: 1
result: 1
<< eval:2.0: 1
>> eval:2.0: 2
result: 2
<< eval:2.0: 2
>> eval:2.0: 3
result: 3
<< eval:2.0: 3
result: 6
<< eval:2.0: debugf

6

( begin/debug expr ...)

( define/debug id expr)
( define/debug (head args) body ...+)

( define/private/debug id expr)
( define/private/debug (head args) body ...+)

( define/public/debug id expr)
( define/public/debug (head args) body ...+)

( define/override/debug id expr)
( define/override/debug (head args) body ...+)

( define/augment/debug id expr)
( define/augment/debug (head args) body ...+)

( let/debug ([lhs-id rhs-expr] ...) body ...+)
( let/debug loop-id ([lhs-id rhs-expr] ...) body ...+)

( let*/debug ([lhs-id rhs-expr] ...) body ...+)

( letrec/debug ([lhs-id rhs-expr] ...) body ...+)

( let-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

( let*-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

( letrec-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

( with-syntax/debug ([pattern stx-expr] ...) body ...+)

( with-syntax*/debug ([pattern stx-expr] ...) body ...+)

( parameterize/debug ([param-expr value-expr] ...) body ...+)

These macros add logging based on debug to the evaluation of expressions in begin, define, define/private, define/public, define/override, define/augment, let, let*, letrec, let-values, let*-values, letrec-values, with-syntax, with-syntax*, and parameterize.
top← prev up next →