annotate gcc/ada/libgnat/a-elchha.adb @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
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 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2003-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Default version for most targets
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 pragma Compiler_Unit_Warning;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 with System.Standard_Library; use System.Standard_Library;
kono
parents:
diff changeset
37 with System.Soft_Links;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 procedure Ada.Exceptions.Last_Chance_Handler
kono
parents:
diff changeset
40 (Except : Exception_Occurrence)
kono
parents:
diff changeset
41 is
kono
parents:
diff changeset
42 procedure Unhandled_Terminate;
kono
parents:
diff changeset
43 pragma No_Return (Unhandled_Terminate);
kono
parents:
diff changeset
44 pragma Import (C, Unhandled_Terminate, "__gnat_unhandled_terminate");
kono
parents:
diff changeset
45 -- Perform system dependent shutdown code
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 function Exception_Message_Length
kono
parents:
diff changeset
48 (X : Exception_Occurrence) return Natural;
kono
parents:
diff changeset
49 pragma Import (Ada, Exception_Message_Length, "__gnat_exception_msg_len");
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 procedure Append_Info_Exception_Message
kono
parents:
diff changeset
52 (X : Exception_Occurrence;
kono
parents:
diff changeset
53 Info : in out String;
kono
parents:
diff changeset
54 Ptr : in out Natural);
kono
parents:
diff changeset
55 pragma Import
kono
parents:
diff changeset
56 (Ada, Append_Info_Exception_Message, "__gnat_append_info_e_msg");
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 procedure Append_Info_Untailored_Exception_Information
kono
parents:
diff changeset
59 (X : Exception_Occurrence;
kono
parents:
diff changeset
60 Info : in out String;
kono
parents:
diff changeset
61 Ptr : in out Natural);
kono
parents:
diff changeset
62 pragma Import
kono
parents:
diff changeset
63 (Ada, Append_Info_Untailored_Exception_Information,
kono
parents:
diff changeset
64 "__gnat_append_info_u_e_info");
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 procedure To_Stderr (S : String);
kono
parents:
diff changeset
67 pragma Import (Ada, To_Stderr, "__gnat_to_stderr");
kono
parents:
diff changeset
68 -- Little routine to output string to stderr
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 Ptr : Natural := 0;
kono
parents:
diff changeset
71 Nobuf : String (1 .. 0);
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 Nline : constant String := String'(1 => ASCII.LF);
kono
parents:
diff changeset
74 -- Convenient shortcut
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 begin
kono
parents:
diff changeset
77 -- Do not execute any task termination code when shutting down the system.
kono
parents:
diff changeset
78 -- The Adafinal procedure would execute the task termination routine for
kono
parents:
diff changeset
79 -- normal termination, but we have already executed the task termination
kono
parents:
diff changeset
80 -- procedure because of an unhandled exception.
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 System.Soft_Links.Task_Termination_Handler :=
kono
parents:
diff changeset
83 System.Soft_Links.Task_Termination_NT'Access;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- We shutdown the runtime now. The rest of the procedure needs to be
kono
parents:
diff changeset
86 -- careful not to use anything that would require runtime support. In
kono
parents:
diff changeset
87 -- particular, functions returning strings are banned since the sec stack
kono
parents:
diff changeset
88 -- is no longer functional. This is particularly important to note for the
kono
parents:
diff changeset
89 -- Exception_Information output. We used to allow the tailored version to
kono
parents:
diff changeset
90 -- show up here, which turned out to be a bad idea as it might involve a
kono
parents:
diff changeset
91 -- traceback decorator the length of which we don't control. Potentially
kono
parents:
diff changeset
92 -- heavy primary/secondary stack use or dynamic allocations right before
kono
parents:
diff changeset
93 -- this point are not welcome, moving the output before the finalization
kono
parents:
diff changeset
94 -- raises order of outputs concerns, and decorators are intended to only
kono
parents:
diff changeset
95 -- be used with exception traces, which should have been issued already.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 System.Standard_Library.Adafinal;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -- Print a message only when exception traces are not active
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 if Exception_Trace /= RM_Convention then
kono
parents:
diff changeset
102 null;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 -- Check for special case of raising _ABORT_SIGNAL, which is not
kono
parents:
diff changeset
105 -- really an exception at all. We recognize this by the fact that
kono
parents:
diff changeset
106 -- it is the only exception whose name starts with underscore.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 elsif To_Ptr (Except.Id.Full_Name) (1) = '_' then
kono
parents:
diff changeset
109 To_Stderr (Nline);
kono
parents:
diff changeset
110 To_Stderr ("Execution terminated by abort of environment task");
kono
parents:
diff changeset
111 To_Stderr (Nline);
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- If no tracebacks, we print the unhandled exception in the old style
kono
parents:
diff changeset
114 -- (i.e. the style used before ZCX was implemented). We do this to
kono
parents:
diff changeset
115 -- retain compatibility.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 elsif Except.Num_Tracebacks = 0 then
kono
parents:
diff changeset
118 To_Stderr (Nline);
kono
parents:
diff changeset
119 To_Stderr ("raised ");
kono
parents:
diff changeset
120 To_Stderr
kono
parents:
diff changeset
121 (To_Ptr (Except.Id.Full_Name) (1 .. Except.Id.Name_Length - 1));
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 if Exception_Message_Length (Except) /= 0 then
kono
parents:
diff changeset
124 To_Stderr (" : ");
kono
parents:
diff changeset
125 Append_Info_Exception_Message (Except, Nobuf, Ptr);
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 To_Stderr (Nline);
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 -- Traceback exists
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 else
kono
parents:
diff changeset
133 To_Stderr (Nline);
kono
parents:
diff changeset
134 To_Stderr ("Execution terminated by unhandled exception");
kono
parents:
diff changeset
135 To_Stderr (Nline);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 Append_Info_Untailored_Exception_Information (Except, Nobuf, Ptr);
kono
parents:
diff changeset
138 end if;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 Unhandled_Terminate;
kono
parents:
diff changeset
141 end Ada.Exceptions.Last_Chance_Handler;