hackwaly / ocamlearlybird

OCaml debug adapter
MIT License
208 stars 23 forks source link

ocamlearlybird debug session fails, crashes when debuggee bin fails #36

Closed cdaringe closed 2 years ago

cdaringe commented 2 years ago

problem

when starting a debug session against a faulty debugee program,

(incomplete) reproduction

to debug, i edited the extension as follows:

+ return new vscode.DebugAdapterServer(4711, "localhost");
- return new vscode.DebugAdapterExecutable(ocamlearlybirdPath, [
-   "debug",
- ]);

I then ran serve locally and started a debug session:

❯ ocamlearlybird serve --port 4711 -v
ocamlearlybird: [INFO] Debug adapter server listening at port 4711
ocamlearlybird: [INFO] Client 127.0.0.1:51340 connected

The command that connected to the server from VSCode was:

cd /Users/myuser/src/js_of_ocaml ; /usr/bin/env CAML_DEBUG_SOCKET=127.0.0.1:51341 /Users/myuser/src/js_of_ocaml/_build/default/compiler/bin-js_of_ocaml/js_of_ocaml.bc compile /tmp/dummy.bc 
Segmentation fault: 11  # 👀 ☠️

That segfault certainly does not look to be an ocamlearlybird issue, clearly :). It very well be result of me using a new compiler and not waiting for this dependent work completing? Nonetheless, back in the ocamlearlybird shell, the proc just crashes, and echo $? emits:

ocamlearlybird on  feat/extension-logging [!?] via 🐫 v4.12.0+domains (4.12.0+domains) took 6s
❯ echo $?
141

It seems like the earlybird side likely hit an unexpected condition and crashed. Perhaps additional Lwt.catch error handling is warranted? I'm not certain, but I suspect that https://microsoft.github.io/debug-adapter-protocol/specification would send a "Terminated Event", which earlybird should perhaps be receiving to exit gracefully.

I was testing using v4.12.0+domains, which may not be formally supported. i will be trying w/ the vanilla 4.12 compiler to see if it reproduces. nonetheless, ocamlearlybird does compile and run under 4.12+domains,