proposal(+working code): catch block callback before stack unwinds to allow attaching debugger

Iain Buclaw ibuclaw at ubuntu.com
Mon Oct 28 00:08:39 PDT 2013


On 27 October 2013 23:43, Timothee Cour <thelastmammoth at gmail.com> wrote:
> ideal syntax would be something along those lines:
>
> try{...}
> catch(SomeThrowableType e, &callback_before_unwinding){...}
> with callback_before_unwinding of type 'void function(Throwable t)'
>
> The semantics of which is:
> if 'e' is about to be caught in this particular catch block, call
> callback_before_unwinding(e) _before_ unwinding stack and entering catch
> block.
>
> Advantages are:
> * it allows one to, for example, attach a debugger before stack unwinds and
> entering this catch block
> * the debugger is only attached at that point, hence not making the regular
> program slower
> * it doesn't affect other catch blocks nor does it affect how
> exceptions/errors are thrown
> * it could even allow one to make speed up exception handling, by computing
> backtrace _only_ inside this callback_before_unwinding, so that usual
> exceptions (std.conv conversions etc) can be caught without any backtrace
> inside the main program while unusual unintended exceptions would be caught
> at the root and show proper stack trace.
>
> This saves a lot of time when debugging issues, at _zero_ cost in
> performance.
>
> Does libunwind allow that? Otherwise could it be adapted to do that?
>

GDB has 'catch throw' and 'catch catch' as convenient C++ breakpoint
placeholders in the debugger.  Can certainly implement them for D too.

http://www.delorie.com/gnu/docs/gdb/gdb_31.html


-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list