Skip to content

Commit

Permalink
Pack ocamldebug modules to minimize clashes (#9621)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonologico committed Sep 9, 2021
1 parent 9410b9c commit 8177967
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Working version
until the program creates a thread for the first time, then fail cleanly.
(Xavier Leroy, report by @anentropic, review by Gabriel Scherer)

- #9621: Pack the ocamldebug modules to minimize clashes
(Raphael Sousa Santos, review by Vincent Laviron and Gabriel Scherer)

### Manual and documentation:

- #7812, #10475: reworded the description of the behaviors of
Expand Down
4 changes: 4 additions & 0 deletions debugger/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ main.cmx : \
../file_formats/cmi_format.cmx \
../utils/clflags.cmx \
checkpoints.cmx
ocamldebug_entry.cmo : \
$(UNIXDIR)/unix.cmi
ocamldebug_entry.cmx : \
$(UNIXDIR)/unix.cmx
parameters.cmo : \
../utils/load_path.cmi \
../typing/envaux.cmi \
Expand Down
17 changes: 12 additions & 5 deletions debugger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ debugger_modules := \
show_source time_travel program_management frames eval \
show_information loadprinter debugger_parser command_line main

all_modules := $(compiler_modules) $(debugger_modules)
compiler_objects := $(addsuffix .cmo,$(compiler_modules))

all_objects := $(addsuffix .cmo,$(all_modules))
debugger_objects := $(addsuffix .cmo,$(debugger_modules))

libraries = $(ROOTDIR)/compilerlibs/ocamlcommon.cma \
$(UNIXDIR)/unix.cma $(DYNLINKDIR)/dynlink.cma

all: ocamldebug$(EXE)

ocamldebug$(EXE): $(libraries) $(all_objects)
ocamldebug.cmo: $(debugger_objects)
$(CAMLC) -pack $(COMPFLAGS) -o $@ $^

ocamldebug$(EXE): $(libraries) $(compiler_objects) ocamldebug.cmo \
ocamldebug_entry.cmo
$(CAMLC) $(LINKFLAGS) -o $@ -linkall $^

install:
Expand All @@ -62,11 +66,14 @@ clean::
rm -f ocamldebug ocamldebug.exe
rm -f *.cmo *.cmi

%.cmo: %.ml
ocamldebug_entry.cmo: ocamldebug_entry.ml ocamldebug.cmo
$(CAMLC) -c $(COMPFLAGS) $<

%.cmo: %.ml
$(CAMLC) -c $(COMPFLAGS) -for-pack ocamldebug $<

%.cmi: %.mli
$(CAMLC) -c $(COMPFLAGS) $<
$(CAMLC) -c $(COMPFLAGS) -for-pack ocamldebug $<

depend: beforedepend
$(CAMLDEP) $(DEPFLAGS) $(DEPINCLUDES) *.mli *.ml \
Expand Down
3 changes: 0 additions & 3 deletions debugger/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,3 @@ let main () =
| Cmi_format.Error e ->
report Cmi_format.report_error e;
exit 2

let _ =
Unix.handle_unix_error main ()
2 changes: 2 additions & 0 deletions debugger/ocamldebug_entry.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let _ =
Unix.handle_unix_error Ocamldebug.Main.main ()
7 changes: 7 additions & 0 deletions testsuite/tests/tool-debugger/module_named_main/input_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load_printer main.cmo
install_printer Main.Submodule.pp
goto 0
break @ Main 26
run
print value
quit
30 changes: 30 additions & 0 deletions testsuite/tests/tool-debugger/module_named_main/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(* TEST
flags += " -g "
ocamldebug_script = "${test_source_directory}/input_script"
* debugger
** shared-libraries
*** setup-ocamlc.byte-build-env
**** ocamlc.byte
***** check-ocamlc.byte-output
****** ocamldebug
******* check-program-output
*)

module Submodule = struct

type t = unit

let value = ()

let pp (fmt : Format.formatter) (_ : t) : unit =
Format.fprintf fmt "DEBUG: Aux.Submodule.pp"

end

let debug () =
let value = Submodule.value in
ignore value

;;

debug ();
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
File main.cmo loaded
Loading program... done.
Beginning of program.
Breakpoint: 1
26 <|b|>ignore value
value: unit = DEBUG: Aux.Submodule.pp
2 changes: 1 addition & 1 deletion testsuite/tests/tool-debugger/printer/printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let p : Format.formatter -> int -> unit = fun fmt n ->
(* We use `max_printer_depth` to tweak the output so that
this test shows that the printer not only compiles
against the debugger's code, but also uses its state. *)
for _i = 1 to min n !Printval.max_printer_depth do
for _i = 1 to min n !Ocamldebug.Printval.max_printer_depth do
Format.pp_print_string fmt "S ";
done;
Format.pp_print_string fmt "O"

0 comments on commit 8177967

Please sign in to comment.