Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated printline-debugging support #1308

Merged
merged 6 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add dedicated printline-debugging support
When debugging OCaml, it is sometimes useful to print out
intermediate values, etc., to learn more about what is going on.
This adds a dedicated flag [-debug-ocaml] and a support function
Debug.print to make this easier to do.
  • Loading branch information
goldfirere committed Apr 12, 2023
commit 66b499cc3b10cf96366fd1b9c4f5e27bf87889ed
1 change: 1 addition & 0 deletions ocaml/compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ UTILS = \
utils/local_store.cmo \
utils/load_path.cmo \
utils/clflags.cmo \
utils/debug.cmo \
utils/language_extension.cmo \
utils/profile.cmo \
utils/terminfo.cmo \
Expand Down
9 changes: 9 additions & 0 deletions ocaml/driver/main_args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,10 @@ let mk_dstartup f =
"-dstartup", Arg.Unit f, " (undocumented)"
;;

let mk_debug_ocaml f =
"-debug-ocaml", Arg.Unit f, " Debugging output for the compiler\n\
(internal use only)"

let mk_opaque f =
"-opaque", Arg.Unit f,
" Does not generate cross-module optimization information\n\
Expand Down Expand Up @@ -1184,6 +1188,7 @@ module type Optcommon_options = sig
val _dlinear : unit -> unit
val _dinterval : unit -> unit
val _dstartup : unit -> unit
val _debug_ocaml : unit -> unit
end;;

module type Optcomp_options = sig
Expand Down Expand Up @@ -1578,6 +1583,7 @@ struct
mk_dump_into_file F._dump_into_file;
mk_dump_dir F._dump_dir;
mk_dump_pass F._dump_pass;
mk_debug_ocaml F._debug_ocaml;

mk_args F._args;
mk_args0 F._args0;
Expand Down Expand Up @@ -1686,6 +1692,8 @@ module Make_opttop_options (F : Opttop_options) = struct
mk_dinterval F._dinterval;
mk_dstartup F._dstartup;
mk_dump_pass F._dump_pass;
mk_debug_ocaml F._debug_ocaml;

mk_eval F._eval;
]
end;;
Expand Down Expand Up @@ -1882,6 +1890,7 @@ module Default = struct
let _dspill = set dump_spill
let _dsplit = set dump_split
let _dstartup = set keep_startup_file
let _debug_ocaml = set debug_ocaml
let _dump_pass pass = set_dumped_pass pass true
let _inline spec =
Float_arg_helper.parse spec "Syntax: -inline <n> | <round>=<n>[,...]"
Expand Down
1 change: 1 addition & 0 deletions ocaml/driver/main_args.mli
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ module type Optcommon_options = sig
val _dlinear : unit -> unit
val _dinterval : unit -> unit
val _dstartup : unit -> unit
val _debug_ocaml : unit -> unit
end;;

module type Optcomp_options = sig
Expand Down
2 changes: 1 addition & 1 deletion ocaml/dune
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
(modules
;; UTILS
config build_path_prefix_map misc identifiable numbers arg_helper clflags
profile terminfo ccomp warnings consistbl strongly_connected_components
debug profile terminfo ccomp warnings consistbl strongly_connected_components
targetint load_path int_replace_polymorphic_compare domainstate binutils
local_store target_system compilation_unit import_info linkage_name symbol
lazy_backtrack diffing diffing_with_keys language_extension
Expand Down
1 change: 1 addition & 0 deletions ocaml/otherlibs/dynlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ COMPILERLIBS_SOURCES=\
utils/local_store.ml \
utils/load_path.ml \
utils/clflags.ml \
utils/debug.ml \
utils/language_extension.ml \
utils/profile.ml \
utils/consistbl.ml \
Expand Down
5 changes: 5 additions & 0 deletions ocaml/otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
numbers
arg_helper
clflags
debug
language_extension
profile
consistbl
Expand Down Expand Up @@ -109,6 +110,7 @@
(copy_files ../../utils/numbers.ml)
(copy_files ../../utils/arg_helper.ml)
(copy_files ../../utils/clflags.ml)
(copy_files ../../utils/debug.ml)
(copy_files ../../utils/language_extension.ml)
(copy_files ../../utils/profile.ml)
(copy_files ../../utils/consistbl.ml)
Expand Down Expand Up @@ -165,6 +167,7 @@
(copy_files ../../utils/numbers.mli)
(copy_files ../../utils/arg_helper.mli)
(copy_files ../../utils/clflags.mli)
(copy_files ../../utils/debug.mli)
(copy_files ../../utils/language_extension.mli)
(copy_files ../../utils/profile.mli)
(copy_files ../../utils/consistbl.mli)
Expand Down Expand Up @@ -263,6 +266,7 @@
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Numbers.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Profile.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Clflags.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Debug.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Language_extension.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Terminfo.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Location.cmo
Expand Down Expand Up @@ -334,6 +338,7 @@
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Numbers.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Profile.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Clflags.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Debug.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Language_extension.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Terminfo.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Location.cmx
Expand Down
2 changes: 1 addition & 1 deletion ocaml/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ocamldep.opt$(EXE): $(call byte2native, $(OCAMLDEP))
# The profiler

OCAMLPROF=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \
numbers.cmo arg_helper.cmo clflags.cmo terminfo.cmo \
numbers.cmo arg_helper.cmo clflags.cmo debug.cmo terminfo.cmo \
warnings.cmo location.cmo longident.cmo docstrings.cmo \
syntaxerr.cmo ast_helper.cmo \
language_extension.cmo extensions_parsing.cmo extensions.cmo \
Expand Down
1 change: 1 addition & 0 deletions ocaml/utils/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ let dump_linear = ref false (* -dlinear *)
let dump_interval = ref false (* -dinterval *)
let keep_startup_file = ref false (* -dstartup *)
let dump_combine = ref false (* -dcombine *)
let debug_ocaml = ref false (* -debug-ocaml *)
let default_timings_precision = 3
let timings_precision = ref default_timings_precision (* -dtimings-precision *)
let profile_columns : Profile.column list ref = ref [] (* -dprofile/-dtimings *)
Expand Down
1 change: 1 addition & 0 deletions ocaml/utils/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ val dump_reload : bool ref
val dump_scheduling : bool ref
val dump_linear : bool ref
val dump_interval : bool ref
val debug_ocaml : bool ref
val keep_startup_file : bool ref
val dump_combine : bool ref
val native_code : bool ref
Expand Down
20 changes: 20 additions & 0 deletions ocaml/utils/debug.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Richard Eisenberg, Jane Street, New York *)
(* *)
(* Copyright 2023 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

open Format

let print fmt =
if !Clflags.debug_ocaml
then printf (fmt ^^ "@\n@?")
else ifprintf std_formatter fmt
24 changes: 24 additions & 0 deletions ocaml/utils/debug.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Richard Eisenberg, Jane Street, New York *)
(* *)
(* Copyright 2023 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)

open Format

(** Print some output to stdout, if [-debug-ocaml] is given on this
invocation of ocaml. Example:

{|
Debug.print "The type is %a" Printtyp.raw_type_expr ty
|}
*)
val print : ('a, formatter, unit) format -> 'a