diff --git a/.gitignore b/.gitignore index e5620675e8b..063315e6107 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ _coverage/ # Debugger support ocamlc +ocamlopt +.ocamldebug diff --git a/.ocamldebug b/.ocamldebug deleted file mode 100644 index 3bb4ee68742..00000000000 --- a/.ocamldebug +++ /dev/null @@ -1 +0,0 @@ -source ocaml/tools/debug_printers diff --git a/HACKING.md b/HACKING.md index 0966180a0e3..b5275c287ea 100644 --- a/HACKING.md +++ b/HACKING.md @@ -206,21 +206,23 @@ something like: ## Using the OCaml debugger to debug the compiler -First, run `make debug`. This completes three steps: +First, run `make debug`. This completes four steps: 1. `make install` 2. Sets up the `ocaml/tools/debug_printers` script so that you can `source ocaml/tools/debug_printers` during a debugging session to see - otherwise-abstract variable values. This script is automatically loaded by - the debugger due to the `.ocamldebug` file at the root of the compiler repo. + otherwise-abstract variable values. 3. Symlinks `./ocamlc` and `./ocamlopt` to point to the bytecode versions of those compilers. This is convenient for emacs integration, because emacs looks for sources starting in the directory containing the executable. +4. Creates a `.ocamldebug` file to automatically load the right search path + and the `debug_printers` set up above. Then it's time to run the debugger itself. The recommended workflow is to add the elisp below to your emacs init file, and then use the command `ocamldebug-ocamlc` to debug `ocamlc` or the command `ocamldebug-ocamlopt` to -debug `ocamlopt`. +debug `ocamlopt`. Running your built `ocamldebug` file on `ocamlc` or `ocamlopt` +should also work, if you wish to work outside emacs. ``` ;; directly inspired by the ocamldebug implementation in ocamldebug.el @@ -243,6 +245,9 @@ debug `ocamlopt`. (setq ocamldebug-debuggee-args (read-from-minibuffer (format "Args for ocamlc: ") ocamldebug-debuggee-args)) + ;; In addition to the directories in .ocamldebug, use 'find' to + ;; see also list directories with -I; this finds any new cmo directories + ;; since the last 'make debug' (let* ((cmo-top-dir (file-name-concat ocaml-dir "_build/main")) (find-cmo-cmd (concat "find " cmo-top-dir diff --git a/Makefile b/Makefile index 3f8c4432fc9..9b1aab02ca0 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,7 @@ coverage: boot-runtest .PHONY: debug .NOTPARALLEL: debug -debug: install ocaml/tools/debug_printers ocamlc ocamlopt +debug: install debug-printers ocamlc ocamlopt .ocamldebug ocamlc: ln -s $(prefix)/bin/ocamlc.byte ocamlc @@ -171,9 +171,6 @@ ocamlc: ocamlopt: ln -s $(prefix)/bin/ocamlopt.byte ocamlopt -ocaml/tools/debug_printers: ocaml/tools/debug_printers.ml ocaml/tools/debug_printers.cmo - echo 'load_printer "ocaml/tools/debug_printers.cmo"' > $@ - awk '{ print "install_printer Debug_printers." $$2 }' < $< >> $@ - -ocaml/tools/debug_printers.cmo: ocaml/tools/debug_printers.ml _build/install/main/bin/ocamlc.byte - _build/install/main/bin/ocamlc.byte -c -I _build/main/ocaml/.ocamlcommon.objs/byte ocaml/tools/debug_printers.ml +.ocamldebug: install + find _build/main -name '*.cmo' -type f -printf 'directory %h\n' | sort -u > .ocamldebug + echo "source ocaml/tools/debug_printers" >> .ocamldebug diff --git a/ocaml/tools/dune b/ocaml/tools/dune index 737ed27a95e..90c5f965daf 100644 --- a/ocaml/tools/dune +++ b/ocaml/tools/dune @@ -91,4 +91,16 @@ (libraries ocamlcommon) (modules debug_printers)) +(rule + (target debug_printers) + (deps debug_printers.ml %{cmo:debug_printers}) + (action + (with-stdout-to %{target} + (progn + ; Resorting to Bash instead of the built-in [echo] action because I + ; couldn't find a better way to get an absolute path out of Dune + (bash "echo load_printer \\\"$(realpath %{cmo:debug_printers})\\\"") + (with-stdin-from debug_printers.ml + (run awk "{ print \"install_printer Debug_printers.\" $2 }")))))) + ; ocamlcp, ocamloptp and ocamlprof are not currently supported.