-
Notifications
You must be signed in to change notification settings - Fork 13k
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
panic mode where it aborts upon panic iff there are no catch_unwind calls to catch it #49032
Comments
This feels like a large enough feature to require an RFC, to me. @rust-lang/lang? |
Agreed, but I can see the utility of it. |
@comex curious for your thoughts as another ios dev |
this is basically copying objc exception behavior |
I think this would just require skipping the catch_unwind before main and in thread startup, right? |
It seems like ideally this would just be the default behavior on all platforms. In addition to working better with non-debugger crash reporting tools, this could improve the debugger experience by obviating the need to manually break on The problem, of course, is that we still want to run destructors before aborting, as it provides the user more control. It's just that at the moment the program kicks the bucket, we'd like to show external tools the original stack. I wonder, is it possible to change libunwind to call destructors on top of the full original stack frame from the panic? i.e. currently, if
where the return address for
Actually, this would not be good default behavior when a debugger is attached, since the user may want to inspect objects from outer stack frames and in this case they'd be already destructed. So in that case, the best approach would be the original proposal, i.e. just abort immediately if we would otherwise abort after unwinding. On the other hand, this seems ideal for dealing with most crash reporting tools that just give you a stack trace. It also sounds difficult to implement, but it would be cool :) |
@comex I think this is really not going to work with libunwind. Consider pseudo-IR like this:
Now let's say
Now, you certainly could implement stack maps (note that you will need a custom LSDA too; right now rustc uses C++-compatible LSDA), but they bloat the code considerably, and I think that was an argument in the GC discussion. It's also an enormous amount of work and will place a large burden on lesser-used architectures.
|
In theory libunwind could restore most registers but treat the stack pointer specially (and the landing pad would have to be aware of this). But I guess I'm derailing things a bit, given that this is all orders of magnitude more complicated than the original proposal... |
Note that C++ does not run destructors for uncaught exceptions but instead invokes It certainly makes sense considering that by far the most common and natural use for RAII is the encapsulation of kernel resources like memory allocations or file descriptors which are more efficiently cleaned up by simply letting the process die. This may yield surprising behavior in the edge case where your destructors have some externally observable behavior (IO) but I feel like that's a reasonable price to pay. |
I really want destructors to run in terminal apps to restore terminal back from raw mode. |
Hello. Is this still blocked on someone writing an RFC? If so, I'd volunteer to try writing one. |
I am also interested in this feature, for the exact same reasons as @michaeleiselsc mentioned in the introduction post. |
So, #52652 is sort of the ticket that seems to be tracking this now; i believe this should be closed in favor of that, given that that one is up-to-date |
Is it? That one is about panics across FFI boundary. This one is about panicking „out of stack“ completely. |
The two options for panic handling, abort and unwind, seem insufficient to cover my use case. When I release my app to users, I use a crash reporter (catches crash signals with a signal handler, records the stack trace, and uploads it). If I use abort for panics, then I'll see the stack trace of the panic in my crash reporter, but I won't be able to catch panics. If I use unwind, then I'll be able to catch panics, but uncaught panics will unwind all the way to the FFI boundary (this is an app built in another language and calls into Rust). This means that I won't be able to see the full stack trace. I see a few existing solutions:
Any ideas what a good way to deal with this is?
The text was updated successfully, but these errors were encountered: