Enhancing Ocaml Debugging Experience in Visual Studio Code

Hi all,

Ocaml debugger for Visual Studio Code

I am trying to provide full language support for Ocaml in Visual Studio Code. I have already installed this extension. Now, I want to debug my Ocaml source code within Visual Studio Code. I have also installed the Ocaml Debugger extension. However, it does not even provide an option to create a launch file. Do you have any suggestions for debugging Ocaml code? I really need it as I am new to Ocaml and I am working on another developer's extensive code base. Having a debugger will greatly help me understand it in less time.

Thank you in advance.

The only support for debugging inside VS Code is GitHub - hackwaly/ocamlearlybird: OCaml debug adapter but sadly it is not being actively maintained (judging by the README it only supports 4.11 and 4.12). And in any case since it is an adaptor for ocamldebug it only supports bytecode.

Until better alternatives come along, I suggest you get used to the time-tested debugging technique practiced by OCaml experts and beginners alike with unsurpassed effectiveness: printf debugging.

Cheers,
Nicolas

There are ppx_debug and ppx_interact. The associated VS Code extension.

P.S. ppx_minidebug might be easier to install (although not on opam yet.).

1 Like

I’ve been scratching my head because earlier this week I accidentally had working breakpoints (in .ml source files) for native code in Visual Studio Code. Kinda flabbergasted that I’ve been using OCaml for two years and never knew I could do that.

Just for Linux and macOS, not Windows, although I think I understand the (small) gap on Windows. And no printing of the runtime value type yet.

If there is interest, I can figure out how to post a show and tell video on YouTube. Definitely for intermediate-to-advanced OCaml users only though: my setup involves the -output-complete-obj and I’m using my DkSDK product to tweak a zillion things. But underneath it is just options in the C + ASM compiler, the OCaml compiler and Dune which I can show, and perhaps it may motivate someone to wrap it up in a friendly way for beginners. And perhaps it will motivate someone to wrap up a runtime value printer [1] using natvis.

And perhaps it is already common knowledge! If not, “like” this post so I can get a sense if it is worth spending time on a video.

[1]: Bonus: A real pretty printer if the sibling value in a C stub function was a LexiFi/refl/etc. RTTI value.

9 Likes

Thank you for your response.
My Ocaml version is 4.14. if possible for debugging ?

Hi @lukstafi ,

Thank you for your response. I cloned this project (link: GitHub - dariusf/ppx_debug: Tools for record-and-replay debugging). Inside the demo folder in this repository, there is no readme file. Please let me know the commands for how to run this folder for debugging. I have attached a screenshot to this message.

Thanks in advance.

1 Like

There is a link to a tutorial on the readme of the project, have you tried that first?

The author (@dariusf ) is also on the discuss forum — he might be able to help.