Commit ae5ea67f authored by Vincent Laviron's avatar Vincent Laviron
Browse files

Update README.md

parent 4ad58212
# GDB scripts for OCaml
Simple scripts to help debugging native ocaml programs with gdb
\ No newline at end of file
Simple scripts to help debugging native ocaml programs with gdb
## How to setup
The easiest way is to launch a gdb session, then use the `source` gdb command
with the file to load, e.g.:
```
(gdb) source /path/to/ocaml-gdb-scripts/ocaml-gdb.py
```
TODO: Find how to configure gdb to load the fiel automatically at startup
## Features
There are currently only two features exported:
- the `camlprint` command, which takes as argument a gdb value, and prints
a message explaining what kind of OCaml value it is. If it is not a valid
OCaml value, all kind of fun can happen.
Examples:
```
(gdb) p/x $rax
$23 = 0x555556388440
(gdb) camlprint $rax
Extension constructor Not_found, with id -7
(gdb) camlprint $23
Extension constructor Not_found, with id -7
(gdb) info symbol 0x555556388440
caml_exn_Not_found in section .data of ./ocamlopt.opt
(gdb) camlprint &caml_exn_Not_found
Extension constructor Not_found, with id -7
```
Symbols in gdb expressions are resolved to the underlying block, so to turn
them into proper OCaml values you need to take their address.
- the `camlfield` convenience function, which can be used in expressions
to perform field lookup. Its first argument should be a valid OCaml value,
while its second argument, if present, is the 0-based index of the field.
If the second argument is absent, it defaults to 0.
Examples:
```
(gdb) camlprint $rax
Extension constructor Not_found, with id -7
(gdb) p $camlfield($rax, 0)
$24 = 93825007125592
(gdb) camlprint $24
String "Not_found"
(gdb) p $camlfield($rax, 1)
$25 = -13
(gdb) camlprint $25
Integer -7
(gdb) p $camlfield($rax)
$26 = 93825007125592
```
For some reason, using `$camlfield` in the argument to `camlprint` doesn't
work, so you should use regular `print` commands to bind the results to
convenience variables, then call `camlprint` on it.
## Problems
All of this is very lightly tested, so don't be surprised if some things do
not work as expected. You can try to contact the author to report bugs.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment