Using lldb on MacOS

Hey,
I’m currently trying to debug a very simple OCaml program via lldb on MacOS.

The program

let printSum sum =
    Printf.printf "Sum: %d\n" sum

let () =
    let x = 1 in
    let y = 2 in
    printSum (x + y)

I was following Getting Started with LLDB on OCaml · Perpetually Curious Blog and building the program via

$ ocamlopt -g -o main main.ml

and invoke it via

$ lldb ./main

There are two things that don’t work:

  1. Creating breakpoints via filename and line number does not work (or I’m doing it wrong). I.e. -f main.ml -l 1 does not resolve to a valid breakpoint.

I can set breakpoints via -n camlMain__printSum_xxx (where xxx is some number) or via regex -r camlMain\.printSum* on newer versions of OCaml (due to the name mangling bug).

  1. When a breakpoint is hit, no source code is available, only assembler (list also does not work). I assume that is connected to the first issue as well.

Am I doing something wrong? Is there an option I’m missing for ocamlopt?

1 Like

No you are not doing anything wrong, that is the state of debugging with LLDB on MacOS.

So #13050 will restore setting breakpoints using the current name mangling scheme in 5.2 and will work nicely with tab complete in LLDB. It’s marked for 5.3 release so fingers crossed it makes it.

Setting breakpoints using filename and line number requires the compiler to output a small amount of DWARF information to associate symbols with source files, and OCaml structures like functions and modules with symbols. Without this you won’t see source code when you hit a breakpoint and list won’t work either. I’m actively working on a fix for this issue.

The problem on macOS with Mach-O binaries is the tooling expects a minimum amount of DWARF information to associate an object file with the pieces of source code used to build that binary. For OCaml purposes that is source file names, mapping from symbols to location ranges and some minimal Debugging Information Entry (abbreviated DIE) to tie everything together.

1 Like

Awesome, thanks for the explanation! I was trying for hours with multiple local switches and different setups :person_facepalming: back to ocamldebug it is then (at least for the time being).

Try out GitHub - hackwaly/ocamlearlybird: OCaml debug adapter if you want easy integration with VSCode GUI debugger.

I fear that this feature was not ready in time for the 5.3 feature freeze in August. It will not be part of the 5.3 release.

@lambda_foo do you have an idea when your work on Mach-O binaries will be ready/merged?

Over the next few months I expect to have an implementation for writing minimal DWARF such that setting breakpoints based on filename and line number works on macOS. Either that or #13050 will give a decent experience setting breakpoints.

Aiming for both to be available in 5.4.

3 Likes

What about source code not being available? Is this the same issue?

Also, how can I contribute to fixing it?