Artisanal Coding Is Dead, Long Live Artisanal Coding!

I wrote a blog post about adding command history browsing and editing, as well as tab completion, to ocamldebug, without typing a single line of code. I challenge you to review the PR for fun, and to try to find holes in it!

I’m going to add DWARF debugging information to OCaml next. I think it’s almost ready to go but needs double and triple checking. Commits look like this

Date: Thu Nov 13 14:55:24 2025 +0200

Add DWARF tests for basic functionality

Add minimal tests to verify DWARF emission works correctly with -g flag.
Tests compile OCaml programs with debugging enabled and verify correct
execution.

and

Date: Thu Nov 13 14:54:30 2025 +0200

Implement DWARF v4 debugging support for OCaml

Add complete DWARF version 4 debugging information generation for OCaml
native code. The implementation generates debug info for functions, types,
and line numbers, enabling debugger support for OCaml programs.

Key components:

  • Low-level DWARF primitives (tags, attributes, forms, encodings)
  • Debug Information Entries (DIE) construction
  • Line number program generation
  • String table management with offset tracking
  • Code address tracking and relocation
  • Integration with OCaml compilation pipeline
  • Configuration flags to enable/disable DWARF emission

The implementation follows the DWARF 4 specification and generates
valid debug sections (.debug_info, .debug_line, .debug_str, .debug_abbrev)
that can be consumed by standard debuggers like gdb and lldb.

3 Likes

I’m pretty sanguine about our new AI overlords and don’t care who wrote the code as long as it looks good and works good. It’s my code and my responsibility!

Do you care who wrote your favorite Dune or Opam features as long as you got them fast and they worked fine? I’m already unleashing my new superpowers on Dune!

2 Likes
  • Is there a reason you went with DWARF 4 rather than 5?
  • While I get your excitement, and I also think AI could help OCaml achieve parity with other languages and ecosystems as far as engineering is concerned, this kind of change has to be extremely intrusive to many layers of the compiler. It’d probably be a good idea to present your work to get some sense of its validity from people in the know, before putting in any more time.
1 Like

Somewhat tongue-in-cheek, but perhaps that’s down to the training data, given that https://github.com/ocaml/ocaml/pull/574 (2016) is DWARF4…

2 Likes

I’m doing this as a scientific experiment of sorts, just to see how far I can push AI.

The change set is massive but it will be fun to review and poke holes in!

Also, I mentioned the future PR to the maintainers and my sense was that they are already against it. Apparently, a similar PR has been rejected back in 2016.

Something about the macOS linker crashing and DWARF 5 not being as widespread.

I’ll do an upgrade to DWARF 5 if this change set works.

There’s a lot of existing work in flight on OxCaml GitHub - oxcaml/oxcaml: OCaml - Oxidized!), LLDB (Pull requests · ocaml-flambda/llvm-project · GitHub), and GDB (Implementing OxCaml support in GDB by tmcgilchrist · Pull Request #1 · tmcgilchrist/binutils-gdb · GitHub) to support DWARF 5. All of which we plan to upstream and will hopefully see upstream OCaml next year. I’d suggest helping out with that rather than starting a new effort, happy to discuss here or on a call. :slight_smile:

7 Likes