hackwaly / ocamlearlybird

OCaml debug adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Fatal error: exception Not_found` at typing/env.ml

Bannerets opened this issue · comments

Callstack:

Fatal error: exception Not_found
Raised at file "typing/env.ml", line 762, characters 12-27
Called from file "typing/env.ml" (inlined), line 805, characters 2-28
Called from file "typing/env.ml", line 858, characters 13-47
Called from file "typing/env.ml", line 2044, characters 23-52
Called from file "typing/envaux.ml", line 66, characters 22-110
Called from file "typing/envaux.ml", line 41, characters 24-50
Called from file "ocaml_debug_adapter/inspect.ml", line 543, characters 14-65
Called from file "ocaml_debug_adapter/inspect.ml", line 570, characters 12-30
Called from file "ocaml_debug_adapter/inspect.ml", line 183, characters 22-40
Called from file "ocaml_debug_adapter/inspect.ml", line 182, characters 6-140
Called from file "ocaml_debug_adapter/inspect.ml", line 55, characters 15-33
Called from file "src/core/lwt.ml", line 1929, characters 23-26
Re-raised at file "ocaml_debug_adapter/inspect.ml", line 52, characters 6-720
Re-raised at file "ocaml_debug_adapter/inspect.ml", line 50, characters 4-875
Re-raised at file "ocaml_debug_adapter/inspect.ml", line 180, characters 4-281
Re-raised at file "ocaml_debug_adapter/inspect.ml", line 563, characters 4-511
Re-raised at file "ocaml_debug_adapter/inspect.ml", line 581, characters 4-179
Re-raised at file "debug_adapter_protocol/rpc.ml", line 93, characters 4-420
Re-raised at file "debug_adapter_protocol/rpc.ml", line 126, characters 4-84
Re-raised at file "debug_adapter_protocol/rpc.ml", line 144, characters 4-96
Re-raised at file "ocaml_debug_adapter/main.ml", line 11, characters 2-23

Files:

  • dune:
(executable
  (name main)
  (libraries cstruct)
)
  • main.ml:
open Cstruct
let a =
  let b = 2 in
  b + 3
  • .vscode/launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debugger (Server Mode)",
      "type": "ocaml-debugger",
      "request": "launch",
      "program": "${workspaceRoot}/_build/default/main.bc",
      "console": "internalConsole",
      "env": {
        "OCAMLRUNPARAM": "b"
      },
      "debugServer": 4711
    }
  ]
}

Steps to reproduce:

  1. Install dependencies: opam install cstruct
  2. Build: dune build main.bc --profile debug.
  3. Launch server: ocamlearlybird --server --port=4711.
  4. Place breakpoint on line 4 in main.ml file (b + 3).
  5. Run debugger.
  6. See fatal error.

It works correctly without open Cstruct.

Does ocamldebug works on these code?

Yes.

It also works with this extension https://github.com/hackwaly/vscode-ocaml.

ocamldebug doesn't work well too. It will crash when you try to eval the variables at the breakpoint.

➜  debug-ocaml ocamldebug ./_build/default/main.bc
        OCaml Debugger version 4.06.1

(ocd) break @Main 1
Loading program... done.
Breakpoint 1 at 194920: file main.ml, line 4, characters 3-8
(ocd) run
Time: 61 - pc: 194920 - module Main
Breakpoint: 1
4   <|b|>b + 3
(ocd) print b
Removed breakpoint 1 at 194920: file main.ml, line 4, characters 3-8
Uncaught exception: Not_found

The bytecode doesn't have cstruct module as dependency. It might be optimized out. Thus, the search path of cmi file of cstruct module is not loaded from bytecode. This caused envaux raise exception.

I'm planning to use .merlin file to recover (source or compiled) search path to fix this issue.

An option "dotMerlins" was added to debug launch configuration. See https://github.com/hackwaly/ocamlearlybird#example-launch-configuration

If you passed "dotMerlins", then the build path specified by B directive in .merlin files will be added to search path. This solve your issue.

Track progress: ocaml/opam-repository#13153

Thanks for your work.

(btw in new version ocamlearlybird --version just prints %%VERSION%%)

Do you know how to get %% VERSION%% interpolated? I use dune-release for publishing.

It seems, your source contains ~version:"%<U+200C>%VERSION%%" instead of ~version:"%%VERSION%%". I sent you pull request with patch.

Merged, will be published with next release.