Unfortunately, the only way to get the return line inside the code is when an exception occurs, you can use Printexc.get_backtrace (). This will not give you, although the function names, just a place in the code of what is on the stack, and only if OCaml was able to restore them ...
Fabrice le fessant
source share