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

Hi @Mng12345, I’m trying to run this as well after the code was moved from rescript-vscode to rescript.

I keep running into:

Loading program... Fatal error: cannot load shared library dllext_stubs
Reason: dlopen(dllext_stubs.so, 0x000A): tried: 'dllext_stubs.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSdllext_stubs.so' (no such file), '/usr/lib/dllext_stubs.so' (no such file, not in dyld cache), 'dllext_stubs.so' (no such file)

I do find that so file though in

 ls _build/default/compiler/ext/*so
_build/default/compiler/ext/dllext_stubs.so

LD_LIBRARY_PATH=/Users/nojaf/Projects/rescript/_build/default/compiler/ext does not seem to work for me on Mac.

Longshot but any thoughts?

Update:

Setting CAML_LD_LIBRARY_PATH solved my problem.

earlybird config:

        {
            "name": "Debug analysis",
            "type": "ocaml.earlybird",
            "request": "launch",
            "program": "${workspaceFolder}/_build/default/analysis/bin/main.bc",
            "stopOnEntry": true,
            "cwd": "/Users/nojaf/Projects/a-squirtle-tale",
            "env": {
                "CAML_LD_LIBRARY_PATH": "${workspaceFolder}/_build/default/compiler/ext"
            },
            "arguments": [
                "test",
                "src/Main.res"
            ]
        }
1 Like