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

Timothee Cour thelastmammoth at gmail.com
Mon Oct 28 01:32:36 PDT 2013


On Mon, Oct 28, 2013 at 12:08 AM, Iain Buclaw <ibuclaw at ubuntu.com> wrote:

> 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
>
>
I'm worried about that from performance standpoint:
* that implies running the normal program execution while attached to a
debugger, which would be slower
* catch throw will stop at every thrown exception as opposed to the ones
that are caught at a certain 'root' point.

In what I suggested (and implemented for dmd), it has 0 performance penalty
and only triggers when a thrown exception is caught in a particular
location; debugger isn't attached during normal program execution.








> --
> Iain Buclaw
>
> *(p < e ? p++ : p) = (c & 0x0f) + '0';
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131028/ac67c137/attachment-0001.html>


More information about the Digitalmars-d mailing list