File : a-elchha-lynxos178-cert.adb


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT RUN-TIME COMPONENTS                         --
   4 --                                                                          --
   5 --    A D A . E X C E P T I O N S . L A S T _ C H A N C E _ H A N D L E R   --
   6 --                                                                          --
   7 --                                 B o d y                                  --
   8 --                                                                          --
   9 --          Copyright (C) 2012-2015, 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 --  Default last chance handler for use with the ravenscar-cert and cert
  33 --  run-time libs on LynxOS-178
  34 
  35 --  Dumps exception identity and partial argument string to addr2line for
  36 --  generation of a symbolic stack backtrace (when gnatbind -E is used)
  37 
  38 with GNAT.IO;                  use GNAT.IO;
  39 with GNAT.Debug_Utilities;     use GNAT.Debug_Utilities;
  40 with System.Standard_Library;  use System.Standard_Library;
  41 with System;
  42 
  43 procedure Ada.Exceptions.Last_Chance_Handler (Except : Exception_Occurrence) is
  44 
  45    Max_Error_Message_Size : constant := 128;
  46 
  47    --  The length of the exception name.  We have to subtract one
  48    --  because it is NUL-terminated.
  49    Exception_Name_Length : constant Integer := Except.Id.Name_Length - 1;
  50 
  51    subtype Error_Message_Size_Type is Integer range
  52       1 .. Max_Error_Message_Size;
  53 
  54    ------------------------
  55    -- LynxOS-178 Imports --
  56    ------------------------
  57 
  58    procedure Stop (ID : Integer := 0);
  59    pragma Import (C, Stop, "exit");
  60    pragma No_Return (Stop);
  61 
  62    Message : String (1 .. Max_Error_Message_Size);
  63 
  64    Message_Length : Error_Message_Size_Type;
  65 
  66 begin
  67    if Exception_Name_Length + 25 > Max_Error_Message_Size then
  68       Message_Length := Max_Error_Message_Size;
  69    else
  70       Message_Length := Exception_Name_Length + 25;
  71    end if;
  72 
  73    Message (1 .. 25) := "Unhandled Ada Exception: ";
  74    Message (26 .. Message_Length) :=
  75      To_Ptr (Except.Id.Full_Name) (1 .. Message_Length - 25);
  76 
  77    New_Line;
  78    Put_Line ("In last chance handler");
  79    Put_Line (Message (1 .. Message_Length));
  80    New_Line;
  81 
  82    Put_Line ("Traceback addresses for addr2line:");
  83 
  84    for J in 1 .. Except.Num_Tracebacks loop
  85       Put (Image_C (Except.Tracebacks (J)));
  86       Put (" ");
  87    end loop;
  88 
  89    New_Line;
  90 
  91    Stop;
  92 end Ada.Exceptions.Last_Chance_Handler;