Skip to content

Commit a3ec83f

Browse files
authored
Add dedicated printline-debugging support (#1308)
1 parent 7bcca63 commit a3ec83f

File tree

12 files changed

+75
-3
lines changed

12 files changed

+75
-3
lines changed

ocaml/.depend

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ utils/consistbl.cmx : \
7575
utils/consistbl.cmi
7676
utils/consistbl.cmi : \
7777
utils/misc.cmi
78+
utils/debug.cmo : \
79+
utils/clflags.cmi \
80+
utils/debug.cmi
81+
utils/debug.cmx : \
82+
utils/clflags.cmx \
83+
utils/debug.cmi
84+
utils/debug.cmi :
7885
utils/diffing.cmo : \
7986
utils/misc.cmi \
8087
utils/diffing.cmi

ocaml/compilerlibs/Makefile.compilerlibs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ UTILS = \
3434
utils/local_store.cmo \
3535
utils/load_path.cmo \
3636
utils/clflags.cmo \
37+
utils/debug.cmo \
3738
utils/language_extension.cmo \
3839
utils/profile.cmo \
3940
utils/terminfo.cmo \

ocaml/driver/main_args.ml

+12
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,10 @@ let mk_dstartup f =
921921
"-dstartup", Arg.Unit f, " (undocumented)"
922922
;;
923923

924+
let mk_debug_ocaml f =
925+
"-debug-ocaml", Arg.Unit f, " Debugging output for the compiler\n\
926+
(internal use only)"
927+
924928
let mk_opaque f =
925929
"-opaque", Arg.Unit f,
926930
" Does not generate cross-module optimization information\n\
@@ -1005,6 +1009,7 @@ module type Common_options = sig
10051009
val _version : unit -> unit
10061010
val _vnum : unit -> unit
10071011
val _w : string -> unit
1012+
val _debug_ocaml : unit -> unit
10081013

10091014
val anonymous : string -> unit
10101015
end
@@ -1341,6 +1346,7 @@ struct
13411346
mk_dprofile F._dprofile;
13421347
mk_dump_into_file F._dump_into_file;
13431348
mk_dump_dir F._dump_dir;
1349+
mk_debug_ocaml F._debug_ocaml;
13441350

13451351
mk_args F._args;
13461352
mk_args0 F._args0;
@@ -1409,6 +1415,7 @@ struct
14091415
mk_drawlambda F._drawlambda;
14101416
mk_dlambda F._dlambda;
14111417
mk_dinstr F._dinstr;
1418+
mk_debug_ocaml F._debug_ocaml;
14121419

14131420
mk_args F._args;
14141421
mk_args0 F._args0;
@@ -1578,6 +1585,7 @@ struct
15781585
mk_dump_into_file F._dump_into_file;
15791586
mk_dump_dir F._dump_dir;
15801587
mk_dump_pass F._dump_pass;
1588+
mk_debug_ocaml F._debug_ocaml;
15811589

15821590
mk_args F._args;
15831591
mk_args0 F._args0;
@@ -1686,6 +1694,8 @@ module Make_opttop_options (F : Opttop_options) = struct
16861694
mk_dinterval F._dinterval;
16871695
mk_dstartup F._dstartup;
16881696
mk_dump_pass F._dump_pass;
1697+
mk_debug_ocaml F._debug_ocaml;
1698+
16891699
mk_eval F._eval;
16901700
]
16911701
end;;
@@ -1738,6 +1748,7 @@ struct
17381748
mk_vnum F._vnum;
17391749
mk_w F._w;
17401750
mk__ F.anonymous;
1751+
mk_debug_ocaml F._debug_ocaml;
17411752
]
17421753
end;;
17431754

@@ -1823,6 +1834,7 @@ module Default = struct
18231834
let _unsafe_string = set unsafe_string
18241835
let _w s =
18251836
Warnings.parse_options false s |> Option.iter Location.(prerr_alert none)
1837+
let _debug_ocaml = set debug_ocaml
18261838

18271839
let anonymous = Compenv.anonymous
18281840

ocaml/driver/main_args.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module type Common_options = sig
5050
val _version : unit -> unit
5151
val _vnum : unit -> unit
5252
val _w : string -> unit
53-
53+
val _debug_ocaml : unit -> unit
5454

5555
val anonymous : string -> unit
5656
end

ocaml/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
(modules
6161
;; UTILS
6262
config build_path_prefix_map misc identifiable numbers arg_helper clflags
63-
profile terminfo ccomp warnings consistbl strongly_connected_components
63+
debug profile terminfo ccomp warnings consistbl strongly_connected_components
6464
targetint load_path int_replace_polymorphic_compare domainstate binutils
6565
local_store target_system compilation_unit import_info linkage_name symbol
6666
lazy_backtrack diffing diffing_with_keys language_extension

ocaml/otherlibs/dynlink/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ COMPILERLIBS_SOURCES=\
8080
utils/local_store.ml \
8181
utils/load_path.ml \
8282
utils/clflags.ml \
83+
utils/debug.ml \
8384
utils/language_extension.ml \
8485
utils/profile.ml \
8586
utils/consistbl.ml \

ocaml/otherlibs/dynlink/dune

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
numbers
3232
arg_helper
3333
clflags
34+
debug
3435
language_extension
3536
profile
3637
consistbl
@@ -109,6 +110,7 @@
109110
(copy_files ../../utils/numbers.ml)
110111
(copy_files ../../utils/arg_helper.ml)
111112
(copy_files ../../utils/clflags.ml)
113+
(copy_files ../../utils/debug.ml)
112114
(copy_files ../../utils/language_extension.ml)
113115
(copy_files ../../utils/profile.ml)
114116
(copy_files ../../utils/consistbl.ml)
@@ -165,6 +167,7 @@
165167
(copy_files ../../utils/numbers.mli)
166168
(copy_files ../../utils/arg_helper.mli)
167169
(copy_files ../../utils/clflags.mli)
170+
(copy_files ../../utils/debug.mli)
168171
(copy_files ../../utils/language_extension.mli)
169172
(copy_files ../../utils/profile.mli)
170173
(copy_files ../../utils/consistbl.mli)
@@ -263,6 +266,7 @@
263266
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Numbers.cmo
264267
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Profile.cmo
265268
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Clflags.cmo
269+
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Debug.cmo
266270
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Language_extension.cmo
267271
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Terminfo.cmo
268272
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Location.cmo
@@ -334,6 +338,7 @@
334338
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Numbers.cmx
335339
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Profile.cmx
336340
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Clflags.cmx
341+
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Debug.cmx
337342
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Language_extension.cmx
338343
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Terminfo.cmx
339344
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Location.cmx

ocaml/tools/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ocamldep.opt$(EXE): $(call byte2native, $(OCAMLDEP))
8383
# The profiler
8484

8585
OCAMLPROF=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \
86-
numbers.cmo arg_helper.cmo clflags.cmo terminfo.cmo \
86+
numbers.cmo arg_helper.cmo clflags.cmo debug.cmo terminfo.cmo \
8787
warnings.cmo location.cmo longident.cmo docstrings.cmo \
8888
syntaxerr.cmo ast_helper.cmo \
8989
language_extension.cmo extensions_parsing.cmo extensions.cmo \

ocaml/utils/clflags.ml

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ let dump_linear = ref false (* -dlinear *)
132132
let dump_interval = ref false (* -dinterval *)
133133
let keep_startup_file = ref false (* -dstartup *)
134134
let dump_combine = ref false (* -dcombine *)
135+
let debug_ocaml = ref false (* -debug-ocaml *)
135136
let default_timings_precision = 3
136137
let timings_precision = ref default_timings_precision (* -dtimings-precision *)
137138
let profile_columns : Profile.column list ref = ref [] (* -dprofile/-dtimings *)

ocaml/utils/clflags.mli

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ val dump_reload : bool ref
138138
val dump_scheduling : bool ref
139139
val dump_linear : bool ref
140140
val dump_interval : bool ref
141+
val debug_ocaml : bool ref
141142
val keep_startup_file : bool ref
142143
val dump_combine : bool ref
143144
val native_code : bool ref

ocaml/utils/debug.ml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Richard Eisenberg, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2023 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
open Format
16+
17+
let print fmt =
18+
if !Clflags.debug_ocaml
19+
then printf (fmt ^^ "@.")
20+
else ifprintf std_formatter fmt

ocaml/utils/debug.mli

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Richard Eisenberg, Jane Street, New York *)
6+
(* *)
7+
(* Copyright 2023 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
open Format
16+
17+
(** Print some output to stdout, if [-debug-ocaml] is given on this
18+
invocation of ocaml. Example:
19+
20+
{[
21+
Debug.print "The type is %a" Printtyp.raw_type_expr ty
22+
]}
23+
*)
24+
val print : ('a, formatter, unit) format -> 'a

0 commit comments

Comments
 (0)