0

I am trying to use ocamldebug with my project, to understand why a 3rd party lib I'm using is not behaving the way I expected.

https://ocaml.org/manual/debugger.html

The OCaml debugger is invoked by running the program ocamldebug with the name of the bytecode executable file as first argument

I have added (modes byte exe) to my dune file.

When I run dune build I can see the bytecode file output, alongside the exe, as _build/default/bin/cli.bc

When I pass this to ocamldebug I get the following error:

ocamldebug _build/default/bin/cli.bc
    OCaml Debugger version 4.12.0

(ocd) r
Loading program... done.
Fatal error: debugger does not support channel locks
Lost connection with process 33035 (active process)
between time 170000 and time 180000
Restart from time 170000 and try to get closer of the problem ? (y or n)

If I choose y the console seems to hang indefinitely.

I found the source of the error here:
https://github.com/ocaml/ocaml/blob/f68acd1a618ac54790a8347fad466084f15a9a9e/runtime/debugger.c#L144

  /* The code in this file does not bracket channel I/O operations with
     Lock and Unlock, so fail if those are not no-ops. */
  if (caml_channel_mutex_lock != NULL ||
      caml_channel_mutex_unlock != NULL ||
      caml_channel_mutex_unlock_exn != NULL)
    caml_fatal_error("debugger does not support channel locks");

...but I don't know what might be triggering it.

My project is using cmdliner and lwt ...I think at this early point of execution it hasn't hit any lwt code though.

Is ocamldebug incompatible with cmdliner?

If that's the case then I will need to make a new entrypoint just for debugging I guess. (currently the bin/cli is the only executable artefact in my project, the code I need to debug is all under lib/s)

3
  • what operating system are you using? Commented Jul 15, 2021 at 12:59
  • @ivg macOS, ocaml installed via homebrew Commented Jul 15, 2021 at 13:06
  • 1
    This question is about a bug in a tool, which should be properly reported using the issue tracker. github.com/ocaml/ocaml/issues/new/choose Commented Jul 15, 2021 at 18:33

1 Answer 1

0

It looks like that the OCaml debugger is broken for your version of macOS. Please, report the issue to the OCaml issue tracker including the detailed information on your system. I can't reproduce it on my machine, but I am using a pretty old version of macOS (10.11.6) and I have the 4.12 debugger working flawlessly.

As a workaround, try using an older version of OCaml, as this channel lock test was introduced very recently you can install any version prior to 4.12,

opam switch create 4.11.0 
eval $(opam env)

Then, do not forget to rebuild your project (previously installing the required dependencies),

opam install lwt cmdliner
dune build

and then you can use the debugger to your taste.

Sign up to request clarification or add additional context in comments.

3 Comments

I already did these steps to arrive at my current state (i.e. my opam comes from homebrew, but I am running under a switch). can you elaborate more what is wrong on my system?
I have updated the answer, but it is definitely not for SO. Your debugger is broken and doesn't work with your version of macOS. It has nothing to do with the program that you're debugged, those functions are called just when you start the debugger (you can test with the hello_world program if you don't believe me). Anyway, the workaround is to use an older version of compiler, but please report the issue to the OCaml issue tracker.
github.com/ocaml/ocaml/issues/10517 apparently the problem is the debugger is incompatible with lwt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.