File : a-elchha-vx6-raven-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) 2003-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 run-time lib
  33 
  34 --  Logs error with health monitor, and dumps exception identity and partial
  35 --  argument string for vxaddr2line for generation of a symbolic stack
  36 --  backtrace.
  37 
  38 --  This version cannot reference "adainit" to form the vxaddr2line arguments,
  39 --  as it can be installed in a shared library, possibly with the cert run
  40 --  time. "adainit" is only available in a partition containing an Ada main.
  41 
  42 with GNAT.IO;                  use GNAT.IO;
  43 with GNAT.Debug_Utilities;     use GNAT.Debug_Utilities;
  44 with System.Standard_Library;  use System.Standard_Library;
  45 with System;
  46 
  47 procedure Ada.Exceptions.Last_Chance_Handler (Except : Exception_Occurrence) is
  48 
  49    Max_Error_Message_Size : constant := 128;
  50 
  51    subtype Error_Message_Size_Type is Integer range
  52       1 .. Max_Error_Message_Size;
  53 
  54    ----------------------
  55    -- VxWorks Imports --
  56    ----------------------
  57 
  58    procedure Stop (ID : Integer := 0);
  59    pragma Import (C, Stop, "taskSuspend");
  60    pragma No_Return (Stop);
  61    --  Although taskSuspend returns a result, we ignore it,
  62    --  since in this case (ID = 0 = taskIdSelf) it does not return
  63 
  64    Message : String (1 .. Max_Error_Message_Size);
  65 
  66    Message_Length : Error_Message_Size_Type;
  67 
  68 begin
  69    if Except.Id.Name_Length + 25 > Max_Error_Message_Size then
  70       Message_Length := Max_Error_Message_Size;
  71    else
  72       Message_Length := Except.Id.Name_Length + 25;
  73    end if;
  74 
  75    Message (1 .. 25) := "Unhandled Ada Exception: ";
  76    Message (26 .. Message_Length) :=
  77      To_Ptr (Except.Id.Full_Name) (1 .. Message_Length - 25);
  78 
  79    New_Line;
  80    Put_Line ("In last chance handler");
  81    Put_Line (Message (1 .. Message_Length));
  82    New_Line;
  83 
  84    Put_Line ("traceback addresses for vxaddr2line:");
  85 
  86    --  Dump backtrace PC values
  87 
  88    for J in 1 .. Except.Num_Tracebacks loop
  89       Put (Image_C (Except.Tracebacks (J)));
  90       Put (" ");
  91    end loop;
  92 
  93    New_Line;
  94 
  95    Stop;
  96 end Ada.Exceptions.Last_Chance_Handler;