How to disable inlining in ocamlc

I’m fairly far along in my first Objective CAML application, at the moment ca. 1300 lines. Given a certain file for input, it raises an exception right away, and I was finally motivated to search out the secret OCAMLRUNPARAM incantation (“b”) to get a traceback. And compiled with “-g”.

Sadly, however, that’s no use at all, because each of the reported 9 locations is Unknown, having been inlined by the ocamlc bytecode compiler. I see that in an older version I might have been able to turn that off, with an -inline=0 flag. Is something like that supported in version 4.07?

If memory serves, backtraces should work even in the presence of inlining. Are you sure you are compiling every module with “-g” ? By the way, you can activate exception backtraces by calling “Printexc.record_backtrace true” instead of setting the “OCAMLRUNPARAM” environment variable.

Yes, I witnessed the modules all being compiled with “-g”.

[ … just to double check that, I installed ocaml 4.08 (first ocaml install on this host, MacOS X 10.13), brought over an entirely different program, compiled everything with ocamlc -g. Same thing: two locations in the traceback, neither identified. One of them, identified as “primitive operation at unknown location (inlined)”, was apparently int_of_string. The other, “Called from unknown location (inlined)”. ]

You may try this:

let () =
  Printexc.record_backtrace true;
  main ()

Not sure if there is a way to trigger it from OCAMLRUNPARAM

In case this is unclear, I am indeed getting a traceback, or backtrace if you prefer. OCAMLRUNPARAM=“b” yields the same result as Printexc.record_backtrace true - successfully producing a traceback.

The problem is that it looks like this:
Fatal error: exception Invalid_argument(“unknown cv type {”."; “unit”; “U”; “?”; “”}")
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)
Called from unknown location (inlined)

This is why I wonder if there is a way to turn off inlining. Is there a way to turn that off?

Sorry for the noise, if this is the case. What does ocamlopt -inline 0 do ?

`unknown option -inline’

Well, ocamlc does not seem to have to have that option. Only ocamlopt has them

You may try to switch to -fp variants where fp stands for frame-pointer. There’s a chance that you’ll have more chance with that.

I could be crazily mistaken, but I don’t believe that “ocamlc” does inlining. [does it?] I thought only the optimizing compiler did so?

Indeed, ocamlc does not do inlining (it looks like a bug of the printer to report the calls as inlined).
Given the look of the backtrace, I suspect something like stack corruption or incorrect use of FFIs.

Can you give a bit more context about your code? What does the code that raised the initial exception look like?

Ah, I have to confess that I am an idiot. I use UNIX make to compile all this stuff, configured to use ocaml -c -g for .ml -> .cmo. But the main module is a different ocamlc -o main b.cmo a.cmo main.ml … where I neglected to add -g.

Once I use -g for the main module as well, I get more informative tracebacks. Sorry about this!

1 Like