Native debugging for macOS (written by Claude, mostly)

With DWARF v5 support, the compiler now includes proper debug info — line mappings, symbols, and variable names — so LLDB can actually follow your code.

A small LLDB Python plug-in reads OCaml values at runtime and prints them in a readable form: lists, tuples, closures, strings, etc. It follows DWARF location lists to track where each variable lives and uses the runtime headers to decode them. The p and ocaml_vars commands work like normal LLDB commands but understand OCaml values.

It’s not complete yet (records and variants still show as tuples), but it makes debugging native OCaml code straightforward. You can finally set breakpoints by source, inspect locals, and understand what’s in memory without switching to disassembly.

1 Like

I didn’t write a single line of code for this PR but I did carefully shepherd it to completion.

The important part is that it does all kinds of complicated work like propagating types and tracking variable allocation to registers… and it works!!!

I wouldn’t have known how to implement this before but I’m able to follow, understand and reason about implementation. Any issues should be addressed to me.

This seems to be largely a copy of the work done in OxCaml, including the missing features like DWARF information for OO, changes to the shapes constructors, and the python based printers rather than built-in LLDB/GDB language plugin.

It’s cool to see a POC port of this onto OCaml, I’ve got a similar branch as well :slight_smile: It’s so nice having a working debugger in OCaml.

I would re-iterate what I said here https://github.com/ocaml/ocaml/pull/14353#issuecomment-3530060798 this is being actively worked on the work is detailed and the source diff will be large. So upstreaming it will take some time.

2 Likes

There was a comment on the PR so I’d like to address it…

It’s not where I obtained this PR but how.

Claude Sonnet 4.5 (Claude Code) wrote most of it with ChatGPT 5 (Codex) reviewing and Claude addressing issues in each review. Codex wrote the last 10% or so when Claude kept getting stuck.

I did not write a single line of code but carefully shepherded AI over the course of several days and kept it on the straight and narrow.

  • AI: I need to keep track of variables moving across registers. This is too hard, let’s go shopping…
  • Me: Hey, don’t any no shortcuts!

My work was just directing, shaping, cajoling and reviewing.

1 Like

The PR does include a Python LLDB plugin for OCaml.

Could be a C++ one but I didn’t bother.

I had AI do a code attribution analysis and it claims that there are substantial differences.

I’d love to foster a wider discussion of AI-assistem development and bits of the PR discussion may be of interest here…

we have in fact known this for years and the difficulty is to find a way to do it that maintainers agree comes at a reasonable maintenance burden).

I’m not a compiler developer by trade, although I’ve done all sorts of development over the years. I’m approaching this strictly as a user, perhaps a power user. I used to look at my needs and wants, and sulk because they were not addressed.

Damn, I can’t debug OCaml on my Mac because there’s no DWARF info.

Oh, wow, Jane St released OxCaml! Yay, native debugging on the Mac! Darn, all kinds of package hell is breaking loose. Let me offer my help… Tarides takes care of maintenance of these bits? I’ll talk to them, maybe they can hire me to fix it.

Alas, I’m still here and my needs are not addressed. But, hey, there’s AI and it seems to one-shot fairly complex stuff in different languages, from just a Github issue. Maybe I can try it…

Wow, oh wow! My needs are finally taken care of!

The code seems clean and well-written. I can understand what AI it’s doing and why. All tests pass, documentation and comments are in order. I can definitely use this!

I think that it is a case of different-to-the-point-of-being-incompatible software development processes (rather than a given process being fundamentally right or wrong), and I think that the uncertainty here is in part caused by our lack, on the upstream side, of a clear policy for what we expect regarding AI-assisted code contributions.

That is something I’ve been pondering myself. I tried approaching several projects this way, trying to take care of things that bother me. The reaction is similar across the board. Folks want a nuanced and thorough discussion, as well as buy-in, before an implementation is submitted.

This is incompatible with what I found to be the most efficient way of using AI, though. It doesn’t need that much input. I can kick off a project just by telling it to add DWARF debugging information to OCaml, such that breakpoints and source code listings, as well as variable printing, works in lldb and gdb. I tell it to follow the practices of the OCaml code base, and to make sure new tests are compatible with existing test infrastructure. Then I add that I want all new code to be thoroughly tested.

AI goes away and does the work, asking me for input. I review what it’s doing and make sure it doesn’t take shortcuts. This is more art than science at this point. Different models produce different work so you need to know which model to use. For example, some models are great at code review and some are better at coding. You also need to carefully steer the AI and make sure it stays on track.

I don’t know of a single project that’s ready for this kind of development process. It often gets emotions high (is artisanal coding dead? will AI take my job?) and creates a lot of friction.

This is why I decided to have AI write me a new Lisp compiler, targeting small binaries and bare metal targets. I’ve been cooking it for the last few days and the results are beyond awesome! Next, I will have AI write me a graph database and a Lisp version of Slint. I’m 100% sure it will work and work well, and I will have it in the next few weeks. The best part is that I won’t have to bother anyone with my forced contributions and can just showcase the end results.

To summarize, I love the new AI sausage and, having visited the sausage factory and done a thorough investigation, I’m not concerned with how the sausage is made. I won’t be forcing my sausage-making processes on anyone and will go make my own sausage!

1 Like

Added pretty-printing examples.