hackwaly / vscode-ocaml-debugger

OCaml debugger for VS Code
14 stars 4 forks source link

Esy/Reason compatibility #9

Open bandersongit opened 4 years ago

bandersongit commented 4 years ago

Hi,

I have really been craving a native debugging experience with my VSCode Reason workflow that I can use and evangelize to others.

I've spent a little bit of time trying to get vscode-ocaml-debugger/earlybird working with Esy and Reason, and have had some limited success so far.

I cloned this repo and updated the package.json to support reason breakpoints. I've played around with changing the child_process.spawn command in debug-adapter.js to use my esy sandboxed version of ocamlearlybird, but have only had success with running earlybird in sandbox mode.

Essentially I have been able to run earlybird in server mode and see the output from my tests in the debug console by running esy x ocamlearlybird --server --port=4711 and using a launch configuration that looks like

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch file",
      "type": "ocaml-debugger",
      "request": "launch",
      "program": "${workspaceRoot}/_esy/default/build/default/testExe/RunDebuggerPlaygroundTests.bc",
      "debugServer": 4711,
      "stopOnEntry": true
    }
  ]
}

However while I can set breakpoints, I can't hit them and hit errors when I try to step through things that look like this.

benderson-mbp:debugger-playground benderson$ esy x ocamlearlybird --server --port=4711
Fatal error: exception Invalid_argument("index out of bounds")
Raised by primitive operation at file "ocaml_debug_adapter/time_travel.ml", line 87, characters 18-58
Called from file "src/core/lwt.ml", line 1930, characters 23-26
Re-raised at file "ocaml_debug_adapter/time_travel.ml", line 83, characters 4-296
Re-raised at file "ocaml_debug_adapter/time_travel.ml", line 113, characters 6-47
benderson-mbp:debugger-playground benderson$ esy x ocamlearlybird --server --port=4711
Fatal error: exception Invalid_argument("index out of bounds")
Raised by primitive operation at file "ocaml_debug_adapter/time_travel.ml", line 87, characters 18-58
Called from file "src/core/lwt.ml", line 1930, characters 23-26

The repository I've been using to test this is here. The README goes through how to reproduce what I've done in great detail.

I would really love to get this working and am happy to help however I can.

hackwaly commented 4 years ago

By add this line to dune file of your playground project. It will fix the "index out of bounds" error. But, ocamlearlybird doesn't support debug with "*.re" sources at this time. So you can't use breakpoints feature on ".re" file.

The "*.ml" dune generated ".ml" file seems binary and not readable. You can manually generate .ml file and set breakpoints on .ml files. Or you can contribute to ocamlearlybird project to add ".re" support.

diff --git a/testExe/dune b/testExe/dune
index 9d2cc35..bbbb00b 100644
--- a/testExe/dune
+++ b/testExe/dune
@@ -1,4 +1,5 @@
 (executable (name RunDebuggerPlaygroundTests)
     (public_name RunDebuggerPlaygroundTests.exe)
     (flags -g)
-    (libraries debugger-playground.test)) 
+    (modes byte)
+    (libraries debugger-playground.test))
bandersongit commented 4 years ago

Thanks for getting back to me so promptly. Using (modes byte) seems to have fixed the "index out of bounds" errors, and I'm actually able to step through reason code now with this change (see the attached gif), however I still can't hit reason breakpoints (I can set them by modifying a local version of this extension).

I've spent a little time playing with ocamlearlybird itself and found that symbols.ml seems to be hardcoding a ".ml" extension in one place. I want to play with this, however while I can get the project building locally I'm not actually sure how to run it.

Running _build/4.06.1/ocaml_debug_adapter/main.bc --server --port=4711 definitely spins something up on port 4711, but I get Failure("No debug symbols.") when I actually run the debugger task.

If you can point me in the right direction in terms of the local development process and verify that this is what I should be changing I would much appreciate it.

Ocamlearlybirdvscodedebugger

hackwaly commented 4 years ago

You can use

opam pin add earlybird ./
dune build @install

To build ocamlearlybird locally

If you want to debug ocamlearlybird self. See https://github.com/hackwaly/ocamlearlybird/issues/8

bandersongit commented 4 years ago

Hey, I'm spending a little bit of time working on this again.

I took a step back to try and isolate what's going on and am currently using master ocamlearlybird with zero modifications and a local checkout of vscode-ocaml-debugger that has been updated to contribute reason breakpoints.

With this simple setup I'm able to get quite a lot of behavior, however calls into Libraries I depend on aren't working for source maps. See the attached gif.

This is a tool that I'd love to share with my team at Facebook and the broader Reason community and I'm happy to keep working on this if I can get some direction.

Reason-debugger-issue