File tree Expand file tree Collapse file tree 5 files changed +38
-5
lines changed Expand file tree Collapse file tree 5 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,14 @@ where the test file or test dir are specified with respect to the
56
56
57
57
## Debugging
58
58
59
- OCaml 4.14 makes `type_expr` abstract, and thus normal debug printing
60
- of types no longer works. However, there is now an installable printer
61
- for types, which we can use to see the types. Here are the instructions:
59
+ We make several custom printers available so that we can print more values in
60
+ `ocamldebug`. Notable examples:
61
+
62
+ * OCaml 4.14 makes `type_expr` abstract, and thus normal debug printing
63
+ of types no longer works without a custom printer.
64
+ * The debug printer for `Ctypes.global_state` lets you see the global mutable state maintained within the `Ctypes` module.
65
+
66
+ Here's how to install the custom printers for a run of `ocamldebug`:
62
67
63
68
1. Use the old `Makefile`, not the new `Makefile.jst`. This is an infelicity
64
69
we hope to fix.
@@ -69,4 +74,4 @@ we hope to fix.
69
74
the debugger to load the compiler code, required for the next
70
75
step.
71
76
72
- 4. Execute `source tools/debug_printers` to install the printers.
77
+ 4. From your debugging session, run `source tools/debug_printers` to install the printers.
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ install_printer Debug_printers.type_expr
3
3
install_printer Debug_printers.row_field
4
4
install_printer Debug_printers.ident
5
5
install_printer Debug_printers.path
6
+ install_printer Debug_printers.ctype_global_state
Original file line number Diff line number Diff line change @@ -3,4 +3,4 @@ let type_expr = Printtyp.raw_type_expr
3
3
let row_field = Printtyp. raw_field
4
4
let ident = Ident. print_with_scope
5
5
let path = Path. print
6
-
6
+ let ctype_global_state = Ctype. print_global_state
Original file line number Diff line number Diff line change @@ -5697,3 +5697,25 @@ let immediacy env typ =
5697
5697
else
5698
5698
Type_immediacy. Always
5699
5699
| _ -> Type_immediacy. Unknown
5700
+
5701
+ (* For use with ocamldebug *)
5702
+ type global_state =
5703
+ { current_level : int ref ;
5704
+ nongen_level : int ref ;
5705
+ global_level : int ref ;
5706
+ }
5707
+
5708
+ let global_state : global_state =
5709
+ { current_level;
5710
+ nongen_level;
5711
+ global_level;
5712
+ }
5713
+
5714
+ let print_global_state fmt global_state =
5715
+ let print_field fmt s r = Format. fprintf fmt " %s = %d;@;" s ! r in
5716
+ let print_fields fmt { current_level; nongen_level; global_level; } =
5717
+ print_field fmt " current_level" current_level;
5718
+ print_field fmt " nongen_level" nongen_level;
5719
+ print_field fmt " global_level" global_level;
5720
+ in
5721
+ Format. fprintf fmt " @[<1>{@;%a}@]" print_fields global_state
Original file line number Diff line number Diff line change @@ -450,3 +450,8 @@ val package_subtype :
450
450
451
451
(* Raises [Incompatible] *)
452
452
val mcomp : Env .t -> type_expr -> type_expr -> unit
453
+
454
+ (* For use with ocamldebug *)
455
+ type global_state
456
+ val global_state : global_state
457
+ val print_global_state : Format .formatter -> global_state -> unit
You can’t perform that action at this time.
0 commit comments