Join GitHub today
caml_print_exception_backtrace do not print backtrace when main program is C #4880
Original bug ID: 4880
This is a regression with 3.10.0.
Comment author: daweil
After deeper analysis, it appears that :
Is it the good hack?
Comment author: @xavierleroy
In OCaml 3.11, you can either
In native code, this will produce backtraces even if your Caml code is embedded in C.
Seeting "caml_backtrace_active = 1;" is a little bit less safe than calling "caml_record_backtrace". The stakes are low (a re-raise of an exception can be confused for an initial raise), but better go through the function.
In bytecode, this is not supported: the C object file produced by ocamlc -output-obj does not contain the debugging information associated to the corresponding bytecode.
Finally, your example shows that the exception raising in an "assert" construct lacks debugging information when compiled with the native-code compiler, which results in a less precise backtrace than for a regular "raise". In other terms, your example works better if "assert false" is replaced by "raise (Failure "foo")". I'll investigate this further.