[RFC] Add support for stopping in Ada exception handler

Xavier Roirand roirand@adacore.com
Tue Nov 21 11:32:00 GMT 2017


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.
-------------- next part --------------
--  Copyright 2017 Free Software Foundation, Inc.
--
--  This program is free software; you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation; either version 3 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.

procedure Foo is
begin

   begin
      raise Constraint_Error;
   exception
      when Constraint_Error => -- SPOT1
         null;
      when others =>
         null;
   end;

   begin
      raise Program_Error;
   exception
      when Program_Error => -- SPOT2
         null;
      when others =>
         null;
   end;

   begin
      raise Storage_Error;
   exception
      when others => -- SPOT3
         null;
   end;

end Foo;


More information about the Gdb-patches mailing list