How to use ocamldebug to debug the rescript-vscode analysis step by step?

I spent a full day to read our analysis code, i have to add a lot of ugly print_endline statement in the OCaml code to understand the logic. As a newbee in OCaml, i am stuck at configuring the project to use ocamldebug.
Here is my modified dune file:

(executable
 (public_name rescript-editor-analysis)
 ; (modes byte exe)
 (modes byte)
 ; The main module that will become the binary.
 (name Cli)
 (flags
  (-w "+6+26+27+32+33+39"))
 (ocamlc_flags
  (:standard "-g"))
 ; Depends on:
 (libraries unix str ext ml jsonlib syntax reanalyze))

After building the project, i ran this command:

ocamldebug ./rescript-editor-analysis.exe completion /home/ming/projects/rescript-playground/src/Play.res 26 3 /home/ming/projects/rescript-playground/src/Play.res true

And got the error below:

Another curioused thing, are you guys just only using printing something to debug the OCaml code?

1 Like

Yeah, both me and @cristianoc, who do the bulk of the work with the extension, just use print statements + the tests to work out things. That said, if you get ocamldebug running then that’d be cool to look into too.

1 Like

After some hard trying, i did debug the OCaml code successfully. :slight_smile:


This is the dune file

(executable
 (public_name rescript-editor-analysis)
 ; (modes byte exe)
 (modes byte)
 ; The main module that will become the binary.
 (name Cli)
 (flags
  (:standard -g)
  (-w "+6+26+27+32+33+39-9-30-34-27"))
 ; (ocamlc_flags
 ;  (:standard "-g"))
 ; Depends on:
 (libraries unix str ext ml jsonlib syntax reanalyze))

After running make command, use the command below to debug, pointting the library path by set LB_LIBRARY_PATH env variable.

LD_LIBRARY_PATH=/home/ming/projects/rescript-vscode/analysis/_build/default/vendor/ext ocamldebug  ./_build/default/src/Cli.bc completion /home/ming/projects/rescript-playground/src/Play.res 45 4 /home/ming/projects/rescript-playground/src/Play.res true

Adding breakpoints with using break command, but the entry module name is changed from Cli to Dune__exe__Cli, so if you want to add a breakpoint in the main function, you should use break Dune__exe__Cli.main, this information can be get by running the command ocamlobjinfo /_build/default/src/Cli.bc

3 Likes