This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC/RFA] Add support for catch Ada exceptions

This is quite elegant really.

On Sat, Dec 30, 2006 at 07:21:11AM +0400, Joel Brobecker wrote:
> Hello,
> Here is a patch that adds support for "catch"-ing Ada exceptions.
> There are 3 different kinds of commands I am introducing:
>   - catch exception [exception name]
>     If the exception name is omitted, then all Ada exception are caught.
>   - catch exception unhandled
>     This catchpoint will stop if the program raises an exception
>     that is not handled (and eventually causes the task or program death)
>   - catch exception assert
>     This catchpoint stops the program when assertions in the program
>     fail. With GNAT, they are inserted like this:
>         [code]
>         pragma Assert (boolean_EXPRESSION);
>         [code]
>     They are activated only if the unit was compiled with assertions
>     enabled.

This sounds an awful lot like "catch throw" and "catch catch" for C++.
I realize you'll want different terms, but should we make them share
a common mechanism?

Also, is this more like "catch catch" or "catch throw"?  I think it's
more like "catch throw" from your example, i.e. stops you at the
raise site.  If so, the other alternative may be useful too (if there's
any way to implement that in Ada).  If not, that's not a big deal.
Depends on your exceptions implementation.

If possible, I'd like to have the same command work for both C++ and
Ada in a mixed binary.  I don't think it's possible to throw exceptions
between them yet, but I'm sure it's been talked about.

On the other hand, if this makes things too complex, we can postpone

> In terms of implementation, these catchpoints are implemented using
> breakpoints inside known functions of the GNAT runtime. However,
> when we stop at these breakpoints, it would be confusing to the user
> to leave them there. This is why, after the catchpoint hit, we go up
> the stack automatically, and find the first "printable" frame, that
> is a frame that is not part of the GNAT runtime and that has debugging
> info (see ada_find_printable_frame).

Nice.  I meant to do this for the C++ equivalent, too, but never got
around to it.

As for the breakpoints, could you please check if you really need
new bp_* constants?  It's hard to spot in the history of breakpoint.c,
but when I implemented something similar for C++, I added a "virtual
table" that let us mark the breakpoint as a normal bp_breakpoint,
and that simplified the change a bit.  Search for
handle_gnu_v3_exceptions.  You're already using the virtual table,
I see.  I couldn't tell from the breakpoint.c changes quite why
you needed new bp constants.  I guess avoiding printing
the condition might be one reason?

The existing cases for "bp_catch_catch" and "bp_catch_throw" date
back to HP/UX, which used a rather different OS mechanism to intercept
exceptions, I believe.  Treating them as normal breakpoints scales
better and I think it will simplify the patch.

Suppressing the "breakpoint also set at" for things with a custom
set of breakpoint ops might be good for the C++ version too, just like
your FIXME.

Daniel Jacobowitz

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]