OSDN Git Service

* gcc.dg/attr-weakref-1.c: Add exit (0) to avoid spurious
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-elchha.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-2005 Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- GNAT was originally developed  by the GNAT team at  New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37
38 --  Default version for most targets
39
40 with System.Standard_Library; use System.Standard_Library;
41
42 procedure Ada.Exceptions.Last_Chance_Handler
43   (Except : Exception_Occurrence)
44 is
45    procedure Unhandled_Terminate;
46    pragma No_Return (Unhandled_Terminate);
47    pragma Import (C, Unhandled_Terminate, "__gnat_unhandled_terminate");
48    --  Perform system dependent shutdown code
49
50    function Exception_Message_Length
51      (X : Exception_Occurrence) return Natural;
52    pragma Import (Ada, Exception_Message_Length, "__gnat_exception_msg_len");
53
54    procedure Append_Info_Exception_Message
55      (X : Exception_Occurrence; Info : in out String; Ptr : in out Natural);
56    pragma Import
57      (Ada, Append_Info_Exception_Message, "__gnat_append_info_e_msg");
58
59    procedure Append_Info_Exception_Information
60      (X : Exception_Occurrence; Info : in out String; Ptr : in out Natural);
61    pragma Import
62      (Ada, Append_Info_Exception_Information, "__gnat_append_info_e_info");
63
64    procedure To_Stderr (S : String);
65    pragma Import (Ada, To_Stderr, "__gnat_to_stderr");
66    --  Little routine to output string to stderr
67
68    Ptr   : Natural := 0;
69    Nobuf : String (1 .. 0);
70
71    Nline : constant String := String'(1 => ASCII.LF);
72    --  Convenient shortcut
73
74 begin
75    --  Let's shutdown the runtime now. The rest of the procedure needs to be
76    --  careful not to use anything that would require runtime support. In
77    --  particular, functions returning strings are banned since the sec stack
78    --  is no longer functional. This is particularly important to note for the
79    --  Exception_Information output. We used to allow the tailored version to
80    --  show up here, which turned out to be a bad idea as it might involve a
81    --  traceback decorator the length of which we don't control. Potentially
82    --  heavy primary/secondary stack use or dynamic allocations right before
83    --  this point are not welcome, moving the output before the finalization
84    --  raises order of outputs concerns, and decorators are intended to only
85    --  be used with exception traces, which should have been issued already.
86
87    System.Standard_Library.Adafinal;
88
89    --  Check for special case of raising _ABORT_SIGNAL, which is not
90    --  really an exception at all. We recognize this by the fact that
91    --  it is the only exception whose name starts with underscore.
92
93    if To_Ptr (Except.Id.Full_Name) (1) = '_' then
94       To_Stderr (Nline);
95       To_Stderr ("Execution terminated by abort of environment task");
96       To_Stderr (Nline);
97
98    --  If no tracebacks, we print the unhandled exception in the old style
99    --  (i.e. the style used before ZCX was implemented). We do this to
100    --  retain compatibility.
101
102    elsif Except.Num_Tracebacks = 0 then
103       To_Stderr (Nline);
104       To_Stderr ("raised ");
105       To_Stderr
106         (To_Ptr (Except.Id.Full_Name) (1 .. Except.Id.Name_Length - 1));
107
108       if Exception_Message_Length (Except) /= 0 then
109          To_Stderr (" : ");
110          Append_Info_Exception_Message (Except, Nobuf, Ptr);
111       end if;
112
113       To_Stderr (Nline);
114
115    --  Traceback exists
116
117    else
118       To_Stderr (Nline);
119       To_Stderr ("Execution terminated by unhandled exception");
120       To_Stderr (Nline);
121
122       Append_Info_Exception_Information (Except, Nobuf, Ptr);
123    end if;
124
125    Unhandled_Terminate;
126 end Ada.Exceptions.Last_Chance_Handler;