111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT RUN-TIME COMPONENTS --
|
|
4 -- --
|
|
5 -- A D A . E X C E P T I O N S --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
145
|
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
|
111
|
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 3, 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. --
|
|
21 -- --
|
|
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
23 -- additional permissions described in the GCC Runtime Library Exception, --
|
|
24 -- version 3.1, as published by the Free Software Foundation. --
|
|
25 -- --
|
|
26 -- You should have received a copy of the GNU General Public License and --
|
|
27 -- a copy of the GCC Runtime Library Exception along with this program; --
|
|
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
29 -- <http://www.gnu.org/licenses/>. --
|
|
30 -- --
|
|
31 -- GNAT was originally developed by the GNAT team at New York University. --
|
|
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
33 -- --
|
|
34 ------------------------------------------------------------------------------
|
|
35
|
145
|
36 -- This is the default version of this package. We also have cert and zfp
|
|
37 -- versions.
|
111
|
38
|
|
39 pragma Polling (Off);
|
|
40 -- We must turn polling off for this unit, because otherwise we get
|
|
41 -- elaboration circularities with ourself.
|
|
42
|
|
43 with System;
|
|
44 with System.Parameters;
|
|
45 with System.Standard_Library;
|
|
46 with System.Traceback_Entries;
|
|
47
|
|
48 package Ada.Exceptions is
|
|
49 pragma Preelaborate;
|
|
50 -- In accordance with Ada 2005 AI-362.
|
|
51
|
|
52 type Exception_Id is private;
|
|
53 pragma Preelaborable_Initialization (Exception_Id);
|
|
54
|
|
55 Null_Id : constant Exception_Id;
|
|
56
|
|
57 type Exception_Occurrence is limited private;
|
|
58 pragma Preelaborable_Initialization (Exception_Occurrence);
|
|
59
|
|
60 type Exception_Occurrence_Access is access all Exception_Occurrence;
|
|
61
|
|
62 Null_Occurrence : constant Exception_Occurrence;
|
|
63
|
|
64 function Exception_Name (Id : Exception_Id) return String;
|
|
65
|
|
66 function Exception_Name (X : Exception_Occurrence) return String;
|
|
67
|
|
68 function Wide_Exception_Name
|
|
69 (Id : Exception_Id) return Wide_String;
|
|
70 pragma Ada_05 (Wide_Exception_Name);
|
|
71
|
|
72 function Wide_Exception_Name
|
|
73 (X : Exception_Occurrence) return Wide_String;
|
|
74 pragma Ada_05 (Wide_Exception_Name);
|
|
75
|
|
76 function Wide_Wide_Exception_Name
|
|
77 (Id : Exception_Id) return Wide_Wide_String;
|
|
78 pragma Ada_05 (Wide_Wide_Exception_Name);
|
|
79
|
|
80 function Wide_Wide_Exception_Name
|
|
81 (X : Exception_Occurrence) return Wide_Wide_String;
|
|
82 pragma Ada_05 (Wide_Wide_Exception_Name);
|
|
83
|
|
84 procedure Raise_Exception (E : Exception_Id; Message : String := "");
|
|
85 pragma No_Return (Raise_Exception);
|
|
86 -- Note: In accordance with AI-466, CE is raised if E = Null_Id
|
|
87
|
|
88 function Exception_Message (X : Exception_Occurrence) return String;
|
|
89
|
|
90 procedure Reraise_Occurrence (X : Exception_Occurrence);
|
|
91 -- Note: it would be really nice to give a pragma No_Return for this
|
|
92 -- procedure, but it would be wrong, since Reraise_Occurrence does return
|
|
93 -- if the argument is the null exception occurrence. See also procedure
|
|
94 -- Reraise_Occurrence_Always in the private part of this package.
|
|
95
|
|
96 function Exception_Identity (X : Exception_Occurrence) return Exception_Id;
|
|
97
|
|
98 function Exception_Information (X : Exception_Occurrence) return String;
|
|
99 -- The format of the exception information is as follows:
|
|
100 --
|
|
101 -- exception name (as in Exception_Name)
|
|
102 -- message (or a null line if no message)
|
|
103 -- PID=nnnn
|
|
104 -- 0xyyyyyyyy 0xyyyyyyyy ...
|
|
105 --
|
|
106 -- The lines are separated by a ASCII.LF character
|
|
107 --
|
|
108 -- The nnnn is the partition Id given as decimal digits
|
|
109 --
|
|
110 -- The 0x... line represents traceback program counter locations,
|
|
111 -- in order with the first one being the exception location.
|
|
112
|
|
113 -- Note on ordering: the compiler uses the Save_Occurrence procedure, but
|
|
114 -- not the function from Rtsfind, so it is important that the procedure
|
|
115 -- come first, since Rtsfind finds the first matching entity.
|
|
116
|
|
117 procedure Save_Occurrence
|
|
118 (Target : out Exception_Occurrence;
|
|
119 Source : Exception_Occurrence);
|
|
120
|
|
121 function Save_Occurrence
|
|
122 (Source : Exception_Occurrence)
|
|
123 return Exception_Occurrence_Access;
|
|
124
|
|
125 -- Ada 2005 (AI-438): The language revision introduces the following
|
|
126 -- subprograms and attribute definitions. We do not provide them
|
|
127 -- explicitly. instead, the corresponding stream attributes are made
|
|
128 -- available through a pragma Stream_Convert in the private part.
|
|
129
|
|
130 -- procedure Read_Exception_Occurrence
|
|
131 -- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
|
|
132 -- Item : out Exception_Occurrence);
|
|
133
|
|
134 -- procedure Write_Exception_Occurrence
|
|
135 -- (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
|
|
136 -- Item : Exception_Occurrence);
|
|
137
|
|
138 -- for Exception_Occurrence'Read use Read_Exception_Occurrence;
|
|
139 -- for Exception_Occurrence'Write use Write_Exception_Occurrence;
|
|
140
|
|
141 private
|
|
142 package SSL renames System.Standard_Library;
|
|
143 package SP renames System.Parameters;
|
|
144
|
|
145 subtype EOA is Exception_Occurrence_Access;
|
|
146
|
|
147 Exception_Msg_Max_Length : constant := SP.Default_Exception_Msg_Max_Length;
|
|
148
|
|
149 ------------------
|
|
150 -- Exception_Id --
|
|
151 ------------------
|
|
152
|
|
153 subtype Code_Loc is System.Address;
|
|
154 -- Code location used in building exception tables and for call addresses
|
|
155 -- when propagating an exception. Values of this type are created by using
|
|
156 -- Label'Address or extracted from machine states using Get_Code_Loc.
|
|
157
|
|
158 Null_Loc : constant Code_Loc := System.Null_Address;
|
|
159 -- Null code location, used to flag outer level frame
|
|
160
|
|
161 type Exception_Id is new SSL.Exception_Data_Ptr;
|
|
162
|
|
163 function EId_To_String (X : Exception_Id) return String;
|
|
164 function String_To_EId (S : String) return Exception_Id;
|
|
165 pragma Stream_Convert (Exception_Id, String_To_EId, EId_To_String);
|
|
166 -- Functions for implementing Exception_Id stream attributes
|
|
167
|
|
168 Null_Id : constant Exception_Id := null;
|
|
169
|
|
170 -------------------------
|
|
171 -- Private Subprograms --
|
|
172 -------------------------
|
|
173
|
|
174 function Exception_Name_Simple (X : Exception_Occurrence) return String;
|
|
175 -- Like Exception_Name, but returns the simple non-qualified name of the
|
|
176 -- exception. This is used to implement the Exception_Name function in
|
|
177 -- Current_Exceptions (the DEC compatible unit). It is called from the
|
|
178 -- compiler generated code (using Rtsfind, which does not respect the
|
|
179 -- private barrier, so we can place this function in the private part
|
|
180 -- where the compiler can find it, but the spec is unchanged.)
|
|
181
|
|
182 procedure Raise_Exception_Always (E : Exception_Id; Message : String := "");
|
|
183 pragma No_Return (Raise_Exception_Always);
|
|
184 pragma Export (Ada, Raise_Exception_Always, "__gnat_raise_exception");
|
|
185 -- This differs from Raise_Exception only in that the caller has determined
|
|
186 -- that for sure the parameter E is not null, and that therefore no check
|
|
187 -- for Null_Id is required. The expander converts Raise_Exception calls to
|
|
188 -- Raise_Exception_Always if it can determine this is the case. The Export
|
|
189 -- allows this routine to be accessed from Pure units.
|
|
190
|
|
191 procedure Raise_From_Signal_Handler
|
|
192 (E : Exception_Id;
|
|
193 M : System.Address);
|
|
194 pragma Export
|
|
195 (Ada, Raise_From_Signal_Handler,
|
|
196 "ada__exceptions__raise_from_signal_handler");
|
|
197 pragma No_Return (Raise_From_Signal_Handler);
|
|
198 -- This routine is used to raise an exception from a signal handler. The
|
|
199 -- signal handler has already stored the machine state (i.e. the state that
|
|
200 -- corresponds to the location at which the signal was raised). E is the
|
|
201 -- Exception_Id specifying what exception is being raised, and M is a
|
|
202 -- pointer to a null-terminated string which is the message to be raised.
|
|
203 -- Note that this routine never returns, so it is permissible to simply
|
|
204 -- jump to this routine, rather than call it. This may be appropriate for
|
|
205 -- systems where the right way to get out of signal handler is to alter the
|
|
206 -- PC value in the machine state or in some other way ask the operating
|
|
207 -- system to return here rather than to the original location.
|
|
208
|
|
209 procedure Raise_From_Controlled_Operation
|
|
210 (X : Ada.Exceptions.Exception_Occurrence);
|
|
211 pragma No_Return (Raise_From_Controlled_Operation);
|
|
212 pragma Export
|
|
213 (Ada, Raise_From_Controlled_Operation,
|
|
214 "__gnat_raise_from_controlled_operation");
|
|
215 -- Raise Program_Error, providing information about X (an exception raised
|
|
216 -- during a controlled operation) in the exception message.
|
|
217
|
|
218 procedure Reraise_Library_Exception_If_Any;
|
|
219 pragma Export
|
|
220 (Ada, Reraise_Library_Exception_If_Any,
|
|
221 "__gnat_reraise_library_exception_if_any");
|
|
222 -- If there was an exception raised during library-level finalization,
|
|
223 -- reraise the exception.
|
|
224
|
|
225 procedure Reraise_Occurrence_Always (X : Exception_Occurrence);
|
|
226 pragma No_Return (Reraise_Occurrence_Always);
|
|
227 -- This differs from Raise_Occurrence only in that the caller guarantees
|
|
228 -- that for sure the parameter X is not the null occurrence, and that
|
|
229 -- therefore this procedure cannot return. The expander uses this routine
|
|
230 -- in the translation of a raise statement with no parameter (reraise).
|
|
231
|
|
232 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence);
|
|
233 pragma No_Return (Reraise_Occurrence_No_Defer);
|
|
234 -- Exactly like Reraise_Occurrence, except that abort is not deferred
|
|
235 -- before the call and the parameter X is known not to be the null
|
|
236 -- occurrence. This is used in generated code when it is known that abort
|
|
237 -- is already deferred.
|
|
238
|
|
239 function Triggered_By_Abort return Boolean;
|
|
240 -- Determine whether the current exception (if it exists) is an instance of
|
|
241 -- Standard'Abort_Signal.
|
|
242
|
|
243 -----------------------
|
|
244 -- Polling Interface --
|
|
245 -----------------------
|
|
246
|
|
247 -- The GNAT compiler has an option to generate polling calls to the Poll
|
|
248 -- routine in this package. Specifying the -gnatP option for a compilation
|
|
249 -- causes a call to Ada.Exceptions.Poll to be generated on every subprogram
|
|
250 -- entry and on every iteration of a loop, thus avoiding the possibility of
|
|
251 -- a case of unbounded time between calls.
|
|
252
|
|
253 -- This polling interface may be used for instrumentation or debugging
|
|
254 -- purposes (e.g. implementing watchpoints in software or in the debugger).
|
|
255
|
|
256 -- In the GNAT technology itself, this interface is used to implement
|
|
257 -- immediate asynchronous transfer of control and immediate abort on
|
|
258 -- targets which do not provide for one thread interrupting another.
|
|
259
|
|
260 -- Note: this used to be in a separate unit called System.Poll, but that
|
|
261 -- caused horrible circular elaboration problems between System.Poll and
|
|
262 -- Ada.Exceptions.
|
|
263
|
|
264 procedure Poll;
|
|
265 -- Check for asynchronous abort. Note that we do not inline the body.
|
|
266 -- This makes the interface more useful for debugging purposes.
|
|
267
|
|
268 --------------------------
|
|
269 -- Exception_Occurrence --
|
|
270 --------------------------
|
|
271
|
|
272 package TBE renames System.Traceback_Entries;
|
|
273
|
|
274 Max_Tracebacks : constant := 50;
|
|
275 -- Maximum number of trace backs stored in exception occurrence
|
|
276
|
|
277 subtype Tracebacks_Array is TBE.Tracebacks_Array (1 .. Max_Tracebacks);
|
|
278 -- Traceback array stored in exception occurrence
|
|
279
|
|
280 type Exception_Occurrence is record
|
145
|
281 Id : Exception_Id := Null_Id;
|
111
|
282 -- Exception_Identity for this exception occurrence
|
|
283
|
|
284 Machine_Occurrence : System.Address;
|
|
285 -- The underlying machine occurrence. For GCC, this corresponds to the
|
|
286 -- _Unwind_Exception structure address.
|
|
287
|
|
288 Msg_Length : Natural := 0;
|
|
289 -- Length of message (zero = no message)
|
|
290
|
|
291 Msg : String (1 .. Exception_Msg_Max_Length);
|
|
292 -- Characters of message
|
|
293
|
|
294 Exception_Raised : Boolean := False;
|
|
295 -- Set to true to indicate that this exception occurrence has actually
|
|
296 -- been raised. When an exception occurrence is first created, this is
|
|
297 -- set to False, then when it is processed by Raise_Current_Exception,
|
|
298 -- it is set to True. If Raise_Current_Exception is used to raise an
|
|
299 -- exception for which this flag is already True, then it knows that
|
|
300 -- it is dealing with the reraise case (which is useful to distinguish
|
|
301 -- for exception tracing purposes).
|
|
302
|
|
303 Pid : Natural := 0;
|
|
304 -- Partition_Id for partition raising exception
|
|
305
|
|
306 Num_Tracebacks : Natural range 0 .. Max_Tracebacks := 0;
|
|
307 -- Number of traceback entries stored
|
|
308
|
|
309 Tracebacks : Tracebacks_Array;
|
|
310 -- Stored tracebacks (in Tracebacks (1 .. Num_Tracebacks))
|
|
311 end record;
|
|
312
|
|
313 function "=" (Left, Right : Exception_Occurrence) return Boolean
|
|
314 is abstract;
|
|
315 -- Don't allow comparison on exception occurrences, we should not need
|
|
316 -- this, and it would not work right, because of the Msg and Tracebacks
|
|
317 -- fields which have unused entries not copied by Save_Occurrence.
|
|
318
|
|
319 function Get_Exception_Machine_Occurrence
|
|
320 (X : Exception_Occurrence) return System.Address;
|
|
321 pragma Export (Ada, Get_Exception_Machine_Occurrence,
|
|
322 "__gnat_get_exception_machine_occurrence");
|
|
323 -- Get the machine occurrence corresponding to an exception occurrence.
|
|
324 -- It is Null_Address if there is no machine occurrence (in runtimes that
|
|
325 -- doesn't use GCC mechanism) or if it has been lost (Save_Occurrence
|
|
326 -- doesn't save the machine occurrence).
|
|
327
|
|
328 function EO_To_String (X : Exception_Occurrence) return String;
|
|
329 function String_To_EO (S : String) return Exception_Occurrence;
|
|
330 pragma Stream_Convert (Exception_Occurrence, String_To_EO, EO_To_String);
|
|
331 -- Functions for implementing Exception_Occurrence stream attributes
|
|
332
|
145
|
333 Null_Occurrence : constant Exception_Occurrence := (others => <>);
|
111
|
334
|
|
335 end Ada.Exceptions;
|