Ocaml 4.11.1 debugging support through ocamlearlybird

Hello, dear friends!

Just recently, hackwaly has added ocaml debugging support through ocamlearlybird for ocaml version 4.11.1 and it is available in Visual Studio Code.

If one follows his example (“ Debug utop ” here: GitHub - hackwaly/ocamlearlybird: OCaml debug adapter), it can be seen that this new approach is different from the old one, described here:

https://marketplace.visualstudio.com/items?itemName=hackwaly.ocaml-debugger

Before, we would compile main.ml ocamlc -g src/main.ml,

then set breakpoints in main.ml and run “OCaml Debug” from the VS Code Debug panel.

Now, we compile main.ml using dune toolchain and then select context menu “Start an OCaml Debug Session” on bytecode file (main.bc) in vscode explorer to quickly start a debug session.

And now it is all done in utop enviroment unlike the old way where we just executed ./main in a terminal.

Could somebody explain what is the idea behind the new approach and how is it different from the old one.

Thanks in advance!

Total noob here… it seems to me

  • this debugger might be able to run any .bc file
  • the example just happens to be a “custom toplevel

I’d like to try this debugger out, however hacwaly/ocamlearlybird extension is ostensibly missing from https://open-vsx.org/, it’s only present on M$ marketplace. Does it mean I need to get the extension from git and do some manipulations from my machine to install in VSCodium? Anybody can help me with the steps?..

P.S. I have actually pleaded with Hackwaly to take on the trouble of uploading to one more extension repository, let’s see if he’s got time for this

1 Like

If I correctly understand your question,
use “opam install earybird” in terminal. Do not use Market Place extension.

I am afraid that didn’t quite work. I’ve done exactly that and there is no Start an OCaml Debug Session item in my menu when I right-click a .bc file:

Actually the hacwaly/ocamlearlybird readme does suggest to first opam install earlybird and then to install the extension.

This is also how I got OCaml Platform to work: first opam install ocaml-lsp-server then install OCaml Platform extension.

And that is also how I got Haskell support to work in VSCodium: first install made sure that haskell-language-server-wrapper is on my $PATH and then installed Haskell extension to VSCodium. This seems like a pattern.

Even though for Haskell the VSCod(e/ium) extension is said to be smart enough to download pre-built -haskell-language-server.

it works perfectly on debian 9.x
Try to follow this example Imgur: The magic of the Internet

Does it work for you? If it does could you please copy-paste the output of the following command

code --list-extensions

For me it’s

$ codium --list-extensions
ocamllabs.ocaml-platform

Thank you.

P.S. now after some looking around I suspect that I will either need to a) install from M$ marketplace, or b) wait for author to publish to https://open-vsx.org/ or c) install nodejs, git clone earlybird repository perform package in ~/.opam/myswitch/.opam-switch/sources/earlybird.1.0.0/integrations/vscode to produce this vsx file and then have VSCodium digest it… No automatic updates for me under option c), c’est la vie… (b) would have been best I guess

I despair :frowning:

I’ve done

opam install earlybird
# that installs LOTS AND LOTS OF STUFF... 
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm install -g vsce

git clone https://github.com/hackwaly/ocamlearlybird.git
cd ocamlearlybird/integrations/vscode/
vsce package

This resulted in ocamlearlybird-1.0.1.vsix which I installed into VSCodium
Now when I right-click proj1.bc I do get this Start an OCaml Debug Session menu item.
I’ve even made my launch.js look like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "try debug",
            "type": "ocamlearlybird",
            "request": "launch",
            "program": "${workspaceRoot}/_build/default/proj1.bc",
            "stopOnEntry": true,
            "yieldSteps": 4096,
            "onlyDebugGlob": "<${workspaceRoot}/_build/default/**/*>",
            "cwd": "${workspaceRoot}"
        }
    ]
}

However when I click that Start an OCaml Debug Session menu item nothing much happens!
A blue progress line runs for 5-10 seconds and it’s all!
Yes it does look like it’s trying to run my try debug launch config…
But really nothing happens!
I don’t stop on my breakpoint, my one-line program print_endline "Hello, world 42 42!" isn’t executing, there’s no output anywhere… not in OUTPUT not in TERMINAL… All the same when I run _build/default/proj1.bc it works - it prints that line… Nothing helps…

This /usr/bin/env CAML_DEBUG_SOCKET=127.0.0.1:... ... that is seen in the video just never gets printed to the terminal… I even did an opam install . in a fresh git checkout to use absolutely latest ocamlearlybird code but it didn’t help either

Update: since I already went this far I have decided to trouble the author with a new issue

i would greatly appreciate if you could start a new thread and move all your questions there because they really have nothing to do with the question i have asked at the beginning of this tread.
Now the thread is cluttered with unrelated stuff and nobody seems to be willing to answer it.
Thanks in advance

I have suggested my guess in post #2 on this thread and @gopiandcode expressed his agreement by adding his ‘like’. I guess that’s as far as we’re going to get with the question as posed…

It does seem like utop being part of the picture is red herring and the debugger is supposed to be able to operate on any OCaml program compiled to bytecode.

My feeling is that this is a fair use of the topic. I am treating it as a generic topic on ocamlearlybird and in my view it would have created clutter to create a new one.

Further it seems that me and you are the only people willing to engage in a discussion at this level of proficiency in OCaml universe :slight_smile:

So here goes my question to you: does it really work for you? Can you please help me get it to work if it does work for you?

I also feel pretty confident that you have a version of extension installed in VSCode. My experience is that without this extension you just don’t get the menu item we’re talking about.

I have engaged in a conversation with the author, but he hasn’t been able to spend that much time so far on the problem I’m seeing. I asked him to produce a special version of the extension with more logging, however unfortunately his answer was

So it really comes down to us to help each other. Or else abandon this debugger and debug in different ways.

btw as @hackwaly announced on the neighbouring thread the issue on Linux has been fixed - the debugger is working with VSCodium on Ubuntu.

To do that pulled latest code from github, did opam install . for main codebase and vsce package to obtain a new .vsix in integrations/vscode folder, then installed the resulting extension.