Debug the Haxe Compiler with OCamlDebug

1. Apply the following patch to the Makefile:

diff --git a/Makefile b/Makefile
index e912e15..1f6c71f 100644
--- a/Makefile
+++ b/Makefile
@@ -80,7 +80,7 @@ libs:
        make -C libs/objsize OCAMLOPT=$(OCAMLOPT) OCAMLC=$(OCAMLC) $(TARGET_FLAG)
 
 haxe: $(MODULES:=.$(MODULE_EXT))
-       $(COMPILER) -o $(OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(LIBS:=.$(LIB_EXT)) $(MODULES:=.$(MODULE_EXT))
+       $(COMPILER) -g -o $(OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(LIBS:=.$(LIB_EXT)) $(MODULES:=.$(MODULE_EXT))
 
 haxelib:
        (cd $(CURDIR)/extra/haxelib_src && $(CURDIR)/$(OUTPUT) haxelib.hxml && nekotools boot bin/haxelib.n)

2. Build the compiler with the following command:

make BYTECODE=1

3. Execute ocamldebug:

ocamldebug ./haxe [arguments]
% ocamldebug ./haxe
	OCaml Debugger version 4.02.1

(ocd) break @ Main 979
Loading program... done.
Breakpoint 1 at 3223236: file main.ml, line 980, characters 2-29726
(ocd) run
Time: 69442 - pc: 3223236 - module Main
Breakpoint: 1
980 	<|b|>let usage = Printf.sprintf
(ocd) n 20
Time: 69757 - pc: 3223608 - module Main
1000 	Common.define_value com Define.HaxeVer (float_repres (float_of_int version /. 1000.))<|a|>;
(ocd) p version
version: int = 3300
(ocd) rev
Time: 69442 - pc: 3223236 - module Main
Breakpoint: 1
980 	<|b|>let usage = Printf.sprintf
(ocd) prev
Time: 69441 - pc: 3198700 - module Main
637 			<|b|>init ctx;
(ocd)

You can even trace back to the past!

Check the debugger commands at The debugger (ocamldebug).

Happy hacking!