-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 overflows #271
Comments
Yes, it would be nice. I tried this some time ago: require "signal"
Signal.trap(Signal::SEGV) do
puts 1
end
def foo
foo
end
foo But the signal handler is never invoked. I don't know if this is the correct way to do it. Do you know if in C++ or another non-interpreted language this happens? We can learn from that. |
Is not invoked because the signal handler would have to run in the same stack. To solve this |
I'm not saying that exception should be recoverable, or be an exception at all really, I think it would just be a great feature of crystal to print something more informational to the users and for a stackoverflow a stacktrace can be very helpful. |
Can't it be solved in a "soft" way? ie: by limiting the depth of method calls. Will probably cause performance issues, though.. |
Or I would look into this one: http://llvm.org/docs/doxygen/html/StackProtector_8cpp_source.html EDIT: nope, it is majorly for security protection (to prevent datastructures (such as string or int[]) to overflow, when they are created on stack). |
The other "soft"/"hard" method to do that is:
Handling code is something that is responsible for raising an exception. This will in theory add about 5-6 asm instructions to each function call. EDIT: this will still be susceptible to SEGV, if you allocate something huge on stack, or pass around some huge datastructure by value. But for normal recursion should work. |
My two cents: Ignore the stack overflow. Use @waj's suggestion to trap SIGSEGV, then figure out how to recover the line number info and print it. This is what Nim does. A stack trace would be nice, but it seems impossible to implement portably. |
+1 for printing something more usefull than "Segmentation fault: 11" :). Rubinius prints both C++ and Ruby backtrace on segfault (here is example of this behavior https://gist.github.com/benweint/44b15ff689fd694b83a8). |
+1 here, on mac today all I get is this, no hint I just overflowed the stack:
|
For segfaults, build with --debug then run in gdb or lldb: you'll have a backtrace with file:line numbers! |
Nice, the line numbers do show up in lldb. Would be nice if they showed up from within "spawn"s as well, but that's more generic exceptions and not just stack overflows... |
I'm not sure if that's possible, but I think it would be great if we could turn stack overflows into exceptions. Currently they just cause a segfault.
To be clear what I'm talking about, a simple trigger:
Valgrind hints:
The text was updated successfully, but these errors were encountered: