3

I have been reading the tutorials for the Ocaml language and for Jbuilder. The official tutorial indicates that one must compile Ocaml code using the '-g' flag with ocamlc in order to then run ocamldebug.

I cannot find any mention of debug builds on the Jbuilder documentation. The only section that seems close is https://jbuilder.readthedocs.io/en/latest/jbuild.html#ocaml-flags. However, even if I add '-g' as a compilation flag..

(executable
 ((name [REDACTED])
  (public_name [REDACTED])
  (libraries ([REDACTED]))
  (flags (:standard -w -9+27-30-32-40@8
                    -safe-string
                    -linkall
                    -g))
  (modules ([REDACTED]))))

..I still don't seem to get a debug binary:

$ ocamldebug [REDACTED] 
    OCaml Debugger version 4.04.2

(ocd) r
Loading program... [REDACTED] is not a bytecode file.

Am I doing something wrong? If not, what is the recommended way to produce debug builds from jbuilder?

glennsl
  • 28,186
  • 12
  • 57
  • 75
Vishakh
  • 1,168
  • 1
  • 11
  • 20

1 Answers1

4

ocamldebug only works with bytecode builds. You're producing native code. To create a bytecode build, you can invoke jbuilder using prog.bc instead of prog.exe.

Note that this might not be what you're after: you can also debug native programs using plain old gdb, but you'll need to be a bit familiar with the runtime.

Étienne Millon
  • 3,018
  • 11
  • 27
  • After reading the documentation, I added this to the jbuild file: (modes (byte)) After this, .bc files were produced and ocamldebug seemed to work. Is this the right method to produce bytecode or is there a better way? – Vishakh Dec 07 '17 at 04:04
  • 1
    I think that `(modes (bytes))` only affects what is built by default, but that you can always run `jbuild build prog.bc`. – Étienne Millon Dec 07 '17 at 07:35