-
-
Notifications
You must be signed in to change notification settings - Fork 415
Make catching of exceptions from Fibers optional #1288
Conversation
src/core/thread.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this the last parameter to avoid breaking code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative I could also add two new c'tors with the same arguments as this one right now
Update:
|
This commit allows exceptions from Fibers to be completely uncaught thus causing a termination of the program and, depending on the configuration, creation of a core dump. An attached debugger can then be used to properly investigate the status of the program at the time of the failure.
The failed test seems to be unrelated to my PR:
|
@MartinNowak I've been told I could hilight you to get more attention for this PR :) |
This'll remove the final catch handler for the Fiber stacks. That's a bad idea, you're program will get halted b/c unwinding will likely fail, but it might also cause a memory corruption instead. |
I wasn't aware of the issue. My goal here is that an uncaught exception/error results in a core dump/program termination that leaves me with a backtrace within GDB (or the core dump) which allows me to investigate the state of the program, e.g. printing the variables the assert was checking etc. Without this, it would just print a mostly unhelpful stack trace (because of missing line numbers) to the terminal and kill the fiber but keep running. When an assert fails I want to have my core dump from the assert that failed and not some location where we re-threw the exception/error. I guess an alternative could be to do a call to (I am Marenz) |
I'm not sure if what you want to do is actually possible. You do not get a core dump from uncaught errors. If you get one with these patches then it's because you crash the unwinder as you read out of the stack bounds, as @MartinNowak already said. However, I don't see how such a core dump would be helpful. A backtrace in the core dump wouldn't point at your assert or wherever you originally threw the error, it'd point at the crash in the unwinder AFAICS.
If you want to get the correct trace in GDB you'll have to abort at the throw location. But you can't know at the throw location if the error is "uncaught". You can only do one thing: You can make all asserts abort ( But if you just want to debug a concrete problem there might be simpler solutions. First of all even if the dmd stacktraces don't provide function names they should provide addresses. Then you can simply use addr2line to find the function. Or you simply set a breakpoint at |
That is not my experience though. I did get useful stack traces that did point at the place where the assert fails.
As far as I understand,
I am more trying to find a generic useful behaviour in typical debug situations. I actually find it hard to believe that something like this hasn't been implemented so far. It feels like such a intuitive and normal thing. Get assert -> abort. Normal c++ behaviour. Normal c behaviour. And the most useful thing you can do. |
Sorry, you're right. It looks like our unwinders are smart enough to recognize the end of the Fiber stack. So as you say the exception handling doesn't crash in the unwind process, it explicitly aborts as it can't find a top level exception handler (It doesn't find higher level druntime handlers as the corresponding functions are not on the fiber callstack). I think this would still require some further thinking whether this is 100% safe and guaranteed by the language. AFAICS we don't use that 'abort' feature anywhere right now. Another problem is that we print stack traces for asserts in normal programs. Doing something different in Fibers might be strange. We probably need an option to make uncaught exceptions core-dump in non-fiber programs as well.
You're probably starting a holy language-feature war here ;-) It does indeed make sense to stop programs at asserts. But some people prefer builtin unwinding instead of crashing (=>calling a debugger) as it provides a backtrace without a debugger (ask Walter what he thinks of GDB ;-). OTOH the fact that So I'll leave this pull request up to the druntime maintainers. I think it would make most sense to:
|
That would indeed be something I want, too. I just thought of this as the first step.
Sounds good to me. |
,
|
This commit allows exceptions from Fibers to be completely uncaught thus
causing a termination of the program and, depending on the configuration,
creation of a core dump.
An attached debugger can then be used to properly investigate the status of the
program at the time of the failure.