annotate gcc/ada/libgnat/a-exextr.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
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 COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- ADA.EXCEPTIONS.EXCEPTION_TRACES --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
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 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 pragma Warnings (Off);
kono
parents:
diff changeset
35 with Ada.Exceptions.Last_Chance_Handler;
kono
parents:
diff changeset
36 pragma Warnings (On);
kono
parents:
diff changeset
37 -- Bring last chance handler into closure
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 separate (Ada.Exceptions)
kono
parents:
diff changeset
40 package body Exception_Traces is
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 Nline : constant String := String'(1 => ASCII.LF);
kono
parents:
diff changeset
43 -- Convenient shortcut
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 type Exception_Action is access procedure (E : Exception_Occurrence);
kono
parents:
diff changeset
46 Global_Action : Exception_Action := null;
kono
parents:
diff changeset
47 pragma Export
kono
parents:
diff changeset
48 (Ada, Global_Action, "__gnat_exception_actions_global_action");
kono
parents:
diff changeset
49 -- Global action, executed whenever an exception is raised. Changing the
kono
parents:
diff changeset
50 -- export name must be coordinated with code in g-excact.adb.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Raise_Hook_Initialized : Boolean := False;
kono
parents:
diff changeset
53 pragma Export
kono
parents:
diff changeset
54 (Ada, Raise_Hook_Initialized, "__gnat_exception_actions_initialized");
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 procedure Last_Chance_Handler (Except : Exception_Occurrence);
kono
parents:
diff changeset
57 pragma Import (C, Last_Chance_Handler, "__gnat_last_chance_handler");
kono
parents:
diff changeset
58 pragma No_Return (Last_Chance_Handler);
kono
parents:
diff changeset
59 -- Users can replace the default version of this routine,
kono
parents:
diff changeset
60 -- Ada.Exceptions.Last_Chance_Handler.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 function To_Action is new Ada.Unchecked_Conversion
kono
parents:
diff changeset
63 (Raise_Action, Exception_Action);
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -----------------------
kono
parents:
diff changeset
66 -- Local Subprograms --
kono
parents:
diff changeset
67 -----------------------
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 procedure Notify_Exception (Excep : EOA; Is_Unhandled : Boolean);
kono
parents:
diff changeset
70 -- Factorizes the common processing for Notify_Handled_Exception and
kono
parents:
diff changeset
71 -- Notify_Unhandled_Exception. Is_Unhandled is set to True only in the
kono
parents:
diff changeset
72 -- latter case because Notify_Handled_Exception may be called for an
kono
parents:
diff changeset
73 -- actually unhandled occurrence in the Front-End-SJLJ case.
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 ----------------------
kono
parents:
diff changeset
76 -- Notify_Exception --
kono
parents:
diff changeset
77 ----------------------
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 procedure Notify_Exception (Excep : EOA; Is_Unhandled : Boolean) is
kono
parents:
diff changeset
80 begin
kono
parents:
diff changeset
81 -- Output the exception information required by the Exception_Trace
kono
parents:
diff changeset
82 -- configuration. Take care not to output information about internal
kono
parents:
diff changeset
83 -- exceptions.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 if not Excep.Id.Not_Handled_By_Others
kono
parents:
diff changeset
86 and then
kono
parents:
diff changeset
87 (Exception_Trace = Every_Raise
kono
parents:
diff changeset
88 or else
kono
parents:
diff changeset
89 (Is_Unhandled
kono
parents:
diff changeset
90 and then
kono
parents:
diff changeset
91 (Exception_Trace = Unhandled_Raise
kono
parents:
diff changeset
92 or else Exception_Trace = Unhandled_Raise_In_Main)))
kono
parents:
diff changeset
93 then
kono
parents:
diff changeset
94 -- Exception trace messages need to be protected when several tasks
kono
parents:
diff changeset
95 -- can issue them at the same time.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Lock_Task.all;
kono
parents:
diff changeset
98 To_Stderr (Nline);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 if Exception_Trace /= Unhandled_Raise_In_Main then
kono
parents:
diff changeset
101 if Is_Unhandled then
kono
parents:
diff changeset
102 To_Stderr ("Unhandled ");
kono
parents:
diff changeset
103 end if;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 To_Stderr ("Exception raised");
kono
parents:
diff changeset
106 To_Stderr (Nline);
kono
parents:
diff changeset
107 end if;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 To_Stderr (Exception_Information (Excep.all));
kono
parents:
diff changeset
110 Unlock_Task.all;
kono
parents:
diff changeset
111 end if;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- Call the user-specific actions
kono
parents:
diff changeset
114 -- ??? We should presumably look at the reraise status here.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 if Raise_Hook_Initialized
kono
parents:
diff changeset
117 and then Exception_Data_Ptr (Excep.Id).Raise_Hook /= null
kono
parents:
diff changeset
118 then
kono
parents:
diff changeset
119 To_Action (Exception_Data_Ptr (Excep.Id).Raise_Hook) (Excep.all);
kono
parents:
diff changeset
120 end if;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 if Global_Action /= null then
kono
parents:
diff changeset
123 Global_Action (Excep.all);
kono
parents:
diff changeset
124 end if;
kono
parents:
diff changeset
125 end Notify_Exception;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 ------------------------------
kono
parents:
diff changeset
128 -- Notify_Handled_Exception --
kono
parents:
diff changeset
129 ------------------------------
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Notify_Handled_Exception (Excep : EOA) is
kono
parents:
diff changeset
132 begin
kono
parents:
diff changeset
133 Notify_Exception (Excep, Is_Unhandled => False);
kono
parents:
diff changeset
134 end Notify_Handled_Exception;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 --------------------------------
kono
parents:
diff changeset
137 -- Notify_Unhandled_Exception --
kono
parents:
diff changeset
138 --------------------------------
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 procedure Notify_Unhandled_Exception (Excep : EOA) is
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 -- Check whether there is any termination handler to be executed for
kono
parents:
diff changeset
143 -- the environment task, and execute it if needed. Here we handle both
kono
parents:
diff changeset
144 -- the Abnormal and Unhandled_Exception task termination. Normal
kono
parents:
diff changeset
145 -- task termination routine is executed elsewhere (either in the
kono
parents:
diff changeset
146 -- Task_Wrapper or in the Adafinal routine for the environment task).
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 Task_Termination_Handler.all (Excep.all);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 Notify_Exception (Excep, Is_Unhandled => True);
kono
parents:
diff changeset
151 Debug_Unhandled_Exception (SSL.Exception_Data_Ptr (Excep.Id));
kono
parents:
diff changeset
152 end Notify_Unhandled_Exception;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 -----------------------------------
kono
parents:
diff changeset
155 -- Unhandled_Exception_Terminate --
kono
parents:
diff changeset
156 -----------------------------------
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 procedure Unhandled_Exception_Terminate (Excep : EOA) is
kono
parents:
diff changeset
159 Occ : Exception_Occurrence;
kono
parents:
diff changeset
160 -- This occurrence will be used to display a message after finalization.
kono
parents:
diff changeset
161 -- It is necessary to save a copy here, or else the designated value
kono
parents:
diff changeset
162 -- could be overwritten if an exception is raised during finalization
kono
parents:
diff changeset
163 -- (even if that exception is caught). The occurrence is saved on the
kono
parents:
diff changeset
164 -- stack to avoid dynamic allocation (if this exception is due to lack
kono
parents:
diff changeset
165 -- of space in the heap, we therefore avoid a second failure). We assume
kono
parents:
diff changeset
166 -- that there is enough room on the stack however.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 begin
kono
parents:
diff changeset
169 Save_Occurrence (Occ, Excep.all);
kono
parents:
diff changeset
170 Last_Chance_Handler (Occ);
kono
parents:
diff changeset
171 end Unhandled_Exception_Terminate;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 ------------------------------------
kono
parents:
diff changeset
174 -- Handling GNAT.Exception_Traces --
kono
parents:
diff changeset
175 ------------------------------------
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -- The bulk of exception traces output is centralized in Notify_Exception,
kono
parents:
diff changeset
178 -- for both the Handled and Unhandled cases. Extra task specific output is
kono
parents:
diff changeset
179 -- triggered in the task wrapper for unhandled occurrences in tasks. It is
kono
parents:
diff changeset
180 -- not performed in this unit to avoid dependencies on the tasking units
kono
parents:
diff changeset
181 -- here.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 -- We used to rely on the output performed by Unhanded_Exception_Terminate
kono
parents:
diff changeset
184 -- for the case of an unhandled occurrence in the environment thread, and
kono
parents:
diff changeset
185 -- the task wrapper was responsible for the whole output in the tasking
kono
parents:
diff changeset
186 -- case.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 -- This initial scheme had a drawback: the output from Terminate only
kono
parents:
diff changeset
189 -- occurs after finalization is done, which means possibly never if some
kono
parents:
diff changeset
190 -- tasks keep hanging around.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 -- The first "presumably obvious" fix consists in moving the Terminate
kono
parents:
diff changeset
193 -- output before the finalization. It has not been retained because it
kono
parents:
diff changeset
194 -- introduces annoying changes in output orders when the finalization
kono
parents:
diff changeset
195 -- itself issues outputs, this also in "regular" cases not resorting to
kono
parents:
diff changeset
196 -- Exception_Traces.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 -- Today's solution has the advantage of simplicity and better isolates
kono
parents:
diff changeset
199 -- the Exception_Traces machinery.
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 end Exception_Traces;