This is the mail archive of the gdb-patches@sourceware.org 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]

[RFC] Add support for stopping in Ada exception handler


Hello,

I'm working on a patch that adds support for stopping on Ada exceptions handling using Ada catchpoint.

This command is:

  - catch handle [exception name]
If the exception name is omitted, then all Ada exception handlers are used.

This command will stop if the program handles an Ada exception which has been raised or on all Ada exception handlers if not exception name has been specified.

Here is a typical GDB session debugging a program that does the
following:

    1. Raise exception Constraint_Error (and catch it)
    2. Raise exception Program_Error (and catch it)
    3. Raise exception Storage_Error (and catch all exceptions)

We'll first stop on Constraint_Error exception handle, and see how it catches it for the first exception:

    (gdb) catch handle Constraint_Error
    Catchpoint 1: `Constraint_Error' Ada exception handler
    (gdb) info break
    Num     Type           Disp Enb Address            What
1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler
    Starting program: /tmp/foo

    Catchpoint 1, exception at 0x0000000000402553 in foo () at foo.adb:24
    24          when Constraint_Error => -- SPOT1

Now we add a Program_Error exception handling:

    (gdb) catch handle Program_Error
    Note: breakpoint 1 also set at pc 0x4030f8.
    Catchpoint 2: `Program_Error' Ada exception handler
    (gdb) info b
    Num     Type           Disp Enb Address            What
1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler
        breakpoint already hit 1 time
2 breakpoint keep y 0x00000000004030f8 `Program_Error' Ada exception handler
    (gdb) c
    Continuing.

    Catchpoint 2, exception at 0x00000000004025a5 in foo () at foo.adb:33
    33          when Program_Error => -- SPOT2

Then we finally add a global exception handling catchpoint for all exceptions type:

    (gdb) catch handle
    Note: breakpoints 1 and 2 also set at pc 0x4030f8.
    Catchpoint 3: all Ada exceptions handler
    (gdb) info b
    Num     Type           Disp Enb Address            What
1 breakpoint keep y 0x00000000004030f8 `Constraint_Error' Ada exception handler
        breakpoint already hit 1 time
2 breakpoint keep y 0x00000000004030f8 `Program_Error' Ada exception handler
        breakpoint already hit 1 time
3 breakpoint keep y 0x00000000004030f8 all Ada exceptions handler
    (gdb) c
    Continuing.

    Catchpoint 3, exception at 0x00000000004025f7 in foo () at foo.adb:42
    42          when others => -- SPOT3
    (gdb)

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).

I already have a small testcase that tests the general functioning
of these handler catchpoints. I will write some documentation, but I want to make sure that no one has any objection, that is, at least the user-interface is agreed on before
I start this work.

Attachment: foo.adb
Description: Text document


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