Skip to content

Commit aa2016e

Browse files
Update 1wf_01_debugging.md (#2897)
* Update 1wf_01_debugging.md In the debugging page, some examples regarding print debugging were added, and a link to the stdlib documentation * Update data/tutorials/guides/1wf_01_debugging.md Co-authored-by: Cuihtlauac Alvarado <[email protected]> * Update data/tutorials/guides/1wf_01_debugging.md Co-authored-by: Cuihtlauac Alvarado <[email protected]> * Update data/tutorials/guides/1wf_01_debugging.md Co-authored-by: Cuihtlauac Alvarado <[email protected]> * Update data/tutorials/guides/1wf_01_debugging.md Co-authored-by: Cuihtlauac Alvarado <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Cuihtlauac Alvarado <[email protected]>
1 parent e405e0c commit aa2016e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

data/tutorials/guides/1wf_01_debugging.md

+21
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ purpose formats are more suited to get the relevant information, than what can
161161
be output automatically by the generic pretty-printer used by the trace
162162
mechanism.
163163

164+
Compiler builtins help display useful debugging messages. They indicate a location in the program's source.
165+
For example,
166+
```ocaml
167+
match Message.unpack response with
168+
| Some y -> y
169+
| None -> (Printf.eprintf "Invalid message at %s" __LOC__; raise Invalid_argument)
170+
```
171+
At compile time, the `__LOC__` builtin is substituted with its location in the program, described as a string `"File %S, line %d, characters %d-%d"`. File name, line number, start character and end character are also available through the `__POS__` builtin:
172+
```ocaml
173+
match Message.unpack response with
174+
| Some y -> y
175+
| None ->
176+
let fname, lnum, _cstart, _cend = __POS__ in
177+
Printf.printf "At line %d in file %s, an incorrect response was passed to Message.unpack"
178+
lnum fname;
179+
flush stdout; raise Invalid_argument
180+
```
181+
182+
Compiler builtins are described in the
183+
[standard library](https://ocaml.org/manual/5.2/api/Stdlib.html#1_Debugging) documentation.
184+
164185
## The OCaml Debugger
165186

166187
We now give a quick tutorial for the OCaml debugger (`ocamldebug`). Before

0 commit comments

Comments
 (0)