File : a-excach-cert.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --             A D A . E X C E P T I O N S . C A L L _ C H A I N            --
   6 --                                                                          --
   7 --                                 B o d y                                  --
   8 --                                                                          --
   9 --          Copyright (C) 1992-2014, Free Software Foundation, Inc.         --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 -- You should have received a copy of the GNU General Public License and    --
  23 -- a copy of the GCC Runtime Library Exception along with this program;     --
  24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  25 -- <http://www.gnu.org/licenses/>.                                          --
  26 --                                                                          --
  27 -- GNAT was originally developed  by the GNAT team at  New York University. --
  28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  This version is for the AE653 Level A run time and for bare board targets
  33 
  34 pragma Warnings (Off);
  35 --  Allow withing of non-Preelaborated units in Ada 2005 mode where this
  36 --  package will be categorized as Preelaborate. See AI-362 for details.
  37 --  It is safe in the context of the run-time to violate the rules.
  38 
  39 with System.Traceback;
  40 with Ada.Exceptions.Traceback;
  41 
  42 pragma Warnings (On);
  43 
  44 separate (Ada.Exceptions)
  45 
  46 procedure Call_Chain (Excep : EOA) is
  47 
  48    Exception_Tracebacks : Integer;
  49    pragma Import (C, Exception_Tracebacks, "__gl_exception_tracebacks");
  50    --  Boolean indicating whether tracebacks should be stored in exception
  51    --  occurrences.
  52 
  53    Local_Traceback : Traceback.Tracebacks_Array (1 .. Max_Tracebacks);
  54    --  Introduce an intermediate copy of the traceback. The call to Call_Chain
  55    --  requires a parameter of type Ada.Exceptions.Traceback.Tracebacks_Array,
  56    --  and the result must be stored in an exception occurrence that has a
  57    --  component of type Ada.Exceptions.Tracebacks_Array. View conversions
  58    --  between these two types are not allowed by Ada 2005 (see RM 4.6 par.
  59    --  24) because these types have a component of private type (Address).
  60    --  Hence we need to do explicit type conversions.
  61    --  ???This conversion should no longer be necessary.
  62 
  63 begin
  64    if Exception_Tracebacks /= 0 and then Excep.Num_Tracebacks = 0 then
  65 
  66       --  If Exception_Tracebacks = 0 then the program was not compiled for
  67       --  storing tracebacks in exception occurrences (-bargs -E switch) so
  68       --  that we do not generate them. If Num_Tracebacks > 0 then this is
  69       --  a reraise, so we should not regenerate the traceback.
  70 
  71       --  We ask System.Traceback.Call_Chain to skip 5 frames to ensure that
  72       --  itself, ourselves and our caller and its caller are not part of the
  73       --  result. Our caller is always an exception propagation actor that we
  74       --  don't want to see, and it may be part of a separate subunit which
  75       --  pulls it outside the AAA/ZZZ range.
  76 
  77       System.Traceback.Call_Chain
  78         (Traceback   => Local_Traceback,
  79          Max_Len     => Max_Tracebacks,
  80          Len         => Excep.Num_Tracebacks,
  81          Exclude_Min => Code_Address_For_AAA,
  82          Exclude_Max => Code_Address_For_ZZZ,
  83          Skip_Frames => 5);
  84 
  85       --  Copy the resulting traceback to the exception occurrence
  86 
  87       Excep.Tracebacks (1 .. Excep.Num_Tracebacks) :=
  88          Ada.Exceptions.Tracebacks_Array
  89             (Local_Traceback (1 .. Excep.Num_Tracebacks));
  90    end if;
  91 end Call_Chain;