From time to time it’s nice to have a backtrace that matches exactly the literal code flow of a program.
Then, one want to disable inlining, but that’s not easy. Even -Oclassic -inline 0
does not, according to documentation, prevent all inlining. Resorting to the flambda options appears not that trivial either.
Here is a simple example:
% cat test.ml
let[@inline never] foo x = if x = 2 then raise Not_found else x + 1
let[@inline never] bar x = foo (x + 1)
let[@inline never] baz x = bar (x + 1)
let () =
let x = baz 0 in
exit x
% ocamlfind ocamlopt -version
4.07.1
% ocamlfind ocamlopt -inline-max-depth 0 -inline-max-unroll 0 -inline-toplevel 0 -g -linkpkg test.ml -o test
% ./test
Fatal error: exception Not_found
Raised at file "test.ml", line 1, characters 41-56
Called from file "test.ml", line 5, characters 10-15
% ocamlfind ocamlc -g -linkpkg test.ml -o test.byte
% ./test.byte
Fatal error: exception Not_found
Raised at file "test.ml", line 1, characters 47-56
Called from file "test.ml", line 5, characters 10-15
How could one obtain a stack frame that mention foo
, bar
and baz
?