|
1 | 1 | # Debugging
|
2 | 2 |
|
3 |
| -## Printing |
4 |
| -Goblint extensively uses [CIL's `Pretty`](https://people.eecs.berkeley.edu/~necula/cil/api/Pretty.html) module for printing due to many non-primitive values. |
| 3 | +## Logging |
| 4 | +Instead of debug printing directly to `stdout`, all logging should be done using the `Logs` module. |
| 5 | +This allows for consistent pretty terminal output, as well as avoiding interference with server mode. |
| 6 | +There are five logging levels: result, error, warning, info and debug. |
| 7 | +Log output is controlled by the `dbg.level` option, which defaults to "info". |
5 | 8 |
|
6 |
| -* Printing CIL values (e.g. an expression `exp`) using the corresponding pretty-printer `d_exp` from `Cil` module: |
| 9 | +Logs are written to `stderr`, except for result level, which go to `stdout` by default. |
| 10 | + |
| 11 | +Goblint extensively uses [CIL's `Pretty`](https://people.eecs.berkeley.edu/~necula/cil/api/Pretty.html) module for output due to many non-primitive values. |
| 12 | + |
| 13 | +* Logging CIL values (e.g. an expression `exp`) using the corresponding pretty-printer `d_exp` from `Cil` module: |
7 | 14 |
|
8 | 15 | ```ocaml
|
9 |
| -ignore (Pretty.printf "A CIL exp: %a\n" d_exp exp); |
| 16 | +Logs.debug "A CIL exp: %a\n" d_exp exp; |
10 | 17 | ```
|
11 | 18 |
|
12 |
| -* Printing Goblint's `Printable` values (e.g. a domain `D` element `d`) using the corresponding pretty-printer `D.pretty`: |
| 19 | +* Logging Goblint's `Printable` values (e.g. a domain `D` element `d`) using the corresponding pretty-printer `D.pretty`: |
13 | 20 |
|
14 | 21 | ```ocaml
|
15 |
| -ignore (Pretty.printf "A domain element: %a\n" D.pretty d); |
| 22 | +Logs.debug "A domain element: %a\n" D.pretty d; |
16 | 23 | ```
|
17 | 24 |
|
18 |
| -* Printing primitives (e.g. OCaml ints, strings, etc) using the standard [OCaml `Printf`](https://ocaml.org/api/Printf.html) specifiers: |
| 25 | +* Logging primitives (e.g. OCaml ints, strings, etc) using the standard [OCaml `Printf`](https://ocaml.org/api/Printf.html) specifiers: |
19 | 26 |
|
20 | 27 | ```ocaml
|
21 |
| -ignore (Pretty.printf "An int and a string: %d %s\n" 42 "magic"); |
| 28 | +Logs.debug "An int and a string: %d %s\n" 42 "magic"; |
22 | 29 | ```
|
23 | 30 |
|
24 |
| -* Printing lists of pretty-printables (e.g. expressions list `exps`) using `d_list`: |
| 31 | +* Logging lists of pretty-printables (e.g. expressions list `exps`) using `d_list`: |
25 | 32 |
|
26 | 33 | ```ocaml
|
27 |
| -ignore (Pretty.printf "Some expressions: %a\n" (d_list ", " d_exp) exps); |
| 34 | +Logs.debug "Some expressions: %a\n" (d_list ", " d_exp) exps; |
28 | 35 | ```
|
29 | 36 |
|
30 | 37 |
|
31 | 38 | ## Tracing
|
32 |
| -Tracing is a nicer alternative to debug printing, because it can be disabled for best performance and it can be used to only see relevant tracing output. |
| 39 | +Tracing is a nicer alternative to some logging, because it can be disabled for best performance and it can be used to only see relevant tracing output. |
33 | 40 |
|
34 | 41 | Recompile with tracing enabled: `./scripts/trace_on.sh`.
|
35 | 42 |
|
36 |
| -Instead of debug printing use a tracing function from the `Messages` module, which is often aliased to just `M` (and pick a relevant name instead of `mything`): |
| 43 | +Instead of logging use a tracing function from the `Messages` module, which is often aliased to just `M` (and pick a relevant name instead of `mything`): |
37 | 44 | ```ocaml
|
38 | 45 | if M.tracing then M.trace "mything" "A domain element: %a\n" D.pretty d;
|
39 | 46 | ```
|
|
0 commit comments