un-catched segfault exception

Christopher Wright dhasenan at gmail.com
Wed Jan 9 18:28:36 PST 2008


Hxal wrote:
> Christopher Wright Wrote:
>> What you can do, though, is convert a signal to an exception. It's going 
>> to be a lot slower than just checking a pointer to see if it's null, but 
>> if you have traced exceptions, the debugging benefit is enormous. 
>> Someone else probably has a cleaner version, but here's something that I 
>> cooked up a couple weeks back. Tested on Linux, dmd1.023-ish; not 
>> guaranteed to work for you. It might destroy your computer, kill your 
>> firstborn, raise Cthulhu from the depths, overwrite your doctoral thesis 
>> with dancing hamsters, et cetera.
> 
> I have played with throwing exceptions out of signal handlers and
> it's not going to work in a reliable way at all, on Linux at least.
> The compiler doesn't generate exception handling frames for blocks
> of code it doesn't expect to throw an exception, and it doesn't
> expect single instructions to do so. AFAIK this is true for both
> dmd and gdc. When you throw an exception and the stack unwinding
> procedure doesn't find an EH frame, it will abort your application.
> gcc has two switches to remedy this: -fnon-call-exceptions that
> expects exceptions to be thrown from dereferences and arithmetics;
> and -fasynchronous-unwind-tables that generates EH frames
> encompassing all instructions. Alas gdc doesn't support these.
> 
> I've played with this a bit in my own stacktracing module
> (which you can find at http://zygfryd.net/jive/).
> The same disclaimer applies.
> 
> PS. Throwing exceptions across C code aborts too, you can however
> add one of the previously mentioned flags when compiling C code.
> 

I haven't had much need for this stuff yet -- I do mostly 
metaprogramming stuff -- but thanks for the link. Whenever I do 
applications work, I'll use your stuff.



More information about the Digitalmars-d mailing list