New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow does not have exception backtrace #7206
Comments
Comment author: pcouderc Actually the backtrace is available when compiling in bytecode (mk.ml contains your example): |
Comment author: pcouderc It also works in native code actually: let rec make_n n = if n = 0 then [] else n::(make_n (n-1));; $ ocamlopt -g mk.ml In any case, you need to compile with debug informations ("-g") and record the backtraces ('Printexc.record_backtrace true' at the beginning of your program for example) to get the backtrace, for any exception it is the only way to get the location of where it happened. |
Comment author: william interesting, because with this example (that I first tested with toplevel), I get no error. With a higher number, I get actualy this output : => no backtrace from mk.ml I don't know how it happened, but in a previous atempt I got: Also, in my real program, I got a similar but different message : I guess it is not easy to just specify the line (once and only once) that generates the problem. |
Comment author: william ah ok, with Printexc.record_backtrace true, I get like you : |
Comment author: william ==> ok, so I see to things :
|
Comment author: pcouderc
My bad, I've been a little bit lazy and actually truncated my first backtrace (bytecode version) to remove all the "Called from..." lines, since they were not outputed for the native version, instead of properly copying the result of the program I compiled in native code. It is still the 'Stack_overflow' exception though, but printed differently (for what reason?). You're right, in native version it does not give you the complete backtrace (only the place where the exception was raised). |
Comment author: william ah, typo in my previous message. The correct one is here :
|
Comment author: william ahh, my message is still not correct. Here is my last version : let rec make_n n = if n = 0 then [] else n::(make_n (n-1));; (export OCAMLRUNPARAM='b') ** with no Printexc.record, and with "ocamlopt mk.ml" : ** with no Printexc.record, and with "ocamlopt -g mk.ml": ** with Printexc.record, and with "ocamlopt mk.ml" : ** with Printexc.record and with "ocamlopt -g mk.ml" : |
Comment author: @oandrieu getting a bactktrace in case of Stack overflow is a bit inaccurate because the mechanism relies on some C values to unwind the stack: caml_bottom_of_stack and caml_last_return_address. When a regular exception is raised or when it calls a C function, OCaml updates these values. But in case of a stack overflow, control is brutally yanked away from the OCaml code, so when the exception is raised, the backtrace mechanism uses the previous values of these C variables, that is the last time the program entered the runtime. That's why the backtrace points at Pervasives here: the last 'external' call in the program. Calling Printexc.record_backtrace has two effects:
** with no Printexc.record, and with "ocamlopt mk.ml" : ** with no Printexc.record, and with "ocamlopt -g mk.ml": ** with Printexc.record, and with "ocamlopt mk.ml" : ** with Printexc.record and with "ocamlopt -g mk.ml" : |
Comment author: @xavierleroy This is a known limitation. The way stack overflows are caught in natively-compiled programs is a lot of black magic, and not even guaranteed to always turn the condition into a Stack_overflow exception. Don't expect a solution any time soon. |
when OCaml is configured --with-frame-pointers (so, only on AMD64/Linux), we can use it in the stack overflow handler to determine the last_return_address and bottom_of_stack values, which enables correct backtrace stashing for the Stack overflow exception. addresses partially ocaml#7206
when OCaml is configured --with-frame-pointers (so, only on AMD64/Linux), we can use it in the stack overflow handler to determine the last_return_address and bottom_of_stack values, which enables correct backtrace stashing for the Stack overflow exception. addresses partially ocaml#7206
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Original bug ID: 7206
Reporter: william
Status: acknowledged (set by @xavierleroy on 2016-12-03T19:00:41Z)
Resolution: open
Priority: low
Severity: feature
Category: runtime system and C interface
Monitored by: @oandrieu
Bug description
there is no debug indication on what could generate the exception, which can be very annoying, especially when you are running long computations that generate this kind of errors...
Steps to reproduce
let rec make_n n = if n = 0 then [] else n::(make_n (n-1));;
make_n 262066
The text was updated successfully, but these errors were encountered: