1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
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 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2011, 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 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 |
|
|
|
36 |
|
|
-- This version of Ada.Exceptions is a full Ada 95 version. It omits Ada 2005
|
37 |
|
|
-- features such as the additional definitions of Exception_Name returning
|
38 |
|
|
-- Wide_[Wide_]String.
|
39 |
|
|
|
40 |
|
|
-- It is used for building the compiler and the basic tools, since these
|
41 |
|
|
-- builds may be done with bootstrap compilers that cannot handle these
|
42 |
|
|
-- additions. The full version of Ada.Exceptions can be found in the files
|
43 |
|
|
-- a-except-2005.ads/adb, and is used for all other builds where full Ada
|
44 |
|
|
-- 2005 functionality is required. In particular, it is used for building
|
45 |
|
|
-- run times on all targets.
|
46 |
|
|
|
47 |
|
|
pragma Compiler_Unit;
|
48 |
|
|
|
49 |
|
|
pragma Polling (Off);
|
50 |
|
|
-- We must turn polling off for this unit, because otherwise we get
|
51 |
|
|
-- elaboration circularities with ourself.
|
52 |
|
|
|
53 |
|
|
with System;
|
54 |
|
|
with System.Parameters;
|
55 |
|
|
with System.Standard_Library;
|
56 |
|
|
with System.Traceback_Entries;
|
57 |
|
|
|
58 |
|
|
package Ada.Exceptions is
|
59 |
|
|
pragma Warnings (Off);
|
60 |
|
|
pragma Preelaborate_05;
|
61 |
|
|
pragma Warnings (On);
|
62 |
|
|
-- We make this preelaborable in Ada 2005 mode. If we did not do this, then
|
63 |
|
|
-- run time units used by the compiler (e.g. s-soflin.ads) would run
|
64 |
|
|
-- into trouble. Conformance is not an issue, since this version is used
|
65 |
|
|
-- only by the compiler.
|
66 |
|
|
|
67 |
|
|
type Exception_Id is private;
|
68 |
|
|
|
69 |
|
|
Null_Id : constant Exception_Id;
|
70 |
|
|
|
71 |
|
|
type Exception_Occurrence is limited private;
|
72 |
|
|
|
73 |
|
|
type Exception_Occurrence_Access is access all Exception_Occurrence;
|
74 |
|
|
|
75 |
|
|
Null_Occurrence : constant Exception_Occurrence;
|
76 |
|
|
|
77 |
|
|
function Exception_Name (X : Exception_Occurrence) return String;
|
78 |
|
|
-- Same as Exception_Name (Exception_Identity (X))
|
79 |
|
|
|
80 |
|
|
function Exception_Name (Id : Exception_Id) return String;
|
81 |
|
|
|
82 |
|
|
procedure Raise_Exception (E : Exception_Id; Message : String := "");
|
83 |
|
|
pragma No_Return (Raise_Exception);
|
84 |
|
|
-- Note: In accordance with AI-466, CE is raised if E = Null_Id
|
85 |
|
|
|
86 |
|
|
function Exception_Message (X : Exception_Occurrence) return String;
|
87 |
|
|
|
88 |
|
|
procedure Reraise_Occurrence (X : Exception_Occurrence);
|
89 |
|
|
-- Note: it would be really nice to give a pragma No_Return for this
|
90 |
|
|
-- procedure, but it would be wrong, since Reraise_Occurrence does return
|
91 |
|
|
-- if the argument is the null exception occurrence. See also procedure
|
92 |
|
|
-- Reraise_Occurrence_Always in the private part of this package.
|
93 |
|
|
|
94 |
|
|
function Exception_Identity (X : Exception_Occurrence) return Exception_Id;
|
95 |
|
|
|
96 |
|
|
function Exception_Information (X : Exception_Occurrence) return String;
|
97 |
|
|
-- The format of the exception information is as follows:
|
98 |
|
|
--
|
99 |
|
|
-- exception name (as in Exception_Name)
|
100 |
|
|
-- message (or a null line if no message)
|
101 |
|
|
-- PID=nnnn
|
102 |
|
|
-- 0xyyyyyyyy 0xyyyyyyyy ...
|
103 |
|
|
--
|
104 |
|
|
-- The lines are separated by a ASCII.LF character
|
105 |
|
|
-- The nnnn is the partition Id given as decimal digits.
|
106 |
|
|
-- The 0x... line represents traceback program counter locations,
|
107 |
|
|
-- in order with the first one being the exception location.
|
108 |
|
|
|
109 |
|
|
-- Note on ordering: the compiler uses the Save_Occurrence procedure, but
|
110 |
|
|
-- not the function from Rtsfind, so it is important that the procedure
|
111 |
|
|
-- come first, since Rtsfind finds the first matching entity.
|
112 |
|
|
|
113 |
|
|
procedure Save_Occurrence
|
114 |
|
|
(Target : out Exception_Occurrence;
|
115 |
|
|
Source : Exception_Occurrence);
|
116 |
|
|
|
117 |
|
|
function Save_Occurrence
|
118 |
|
|
(Source : Exception_Occurrence)
|
119 |
|
|
return Exception_Occurrence_Access;
|
120 |
|
|
|
121 |
|
|
private
|
122 |
|
|
package SSL renames System.Standard_Library;
|
123 |
|
|
package SP renames System.Parameters;
|
124 |
|
|
|
125 |
|
|
subtype EOA is Exception_Occurrence_Access;
|
126 |
|
|
|
127 |
|
|
Exception_Msg_Max_Length : constant := SP.Default_Exception_Msg_Max_Length;
|
128 |
|
|
|
129 |
|
|
------------------
|
130 |
|
|
-- Exception_Id --
|
131 |
|
|
------------------
|
132 |
|
|
|
133 |
|
|
subtype Code_Loc is System.Address;
|
134 |
|
|
-- Code location used in building exception tables and for call addresses
|
135 |
|
|
-- when propagating an exception. Values of this type are created by using
|
136 |
|
|
-- Label'Address or extracted from machine states using Get_Code_Loc.
|
137 |
|
|
|
138 |
|
|
Null_Loc : constant Code_Loc := System.Null_Address;
|
139 |
|
|
-- Null code location, used to flag outer level frame
|
140 |
|
|
|
141 |
|
|
type Exception_Id is new SSL.Exception_Data_Ptr;
|
142 |
|
|
|
143 |
|
|
function EId_To_String (X : Exception_Id) return String;
|
144 |
|
|
function String_To_EId (S : String) return Exception_Id;
|
145 |
|
|
pragma Stream_Convert (Exception_Id, String_To_EId, EId_To_String);
|
146 |
|
|
-- Functions for implementing Exception_Id stream attributes
|
147 |
|
|
|
148 |
|
|
Null_Id : constant Exception_Id := null;
|
149 |
|
|
|
150 |
|
|
-------------------------
|
151 |
|
|
-- Private Subprograms --
|
152 |
|
|
-------------------------
|
153 |
|
|
|
154 |
|
|
function Current_Target_Exception return Exception_Occurrence;
|
155 |
|
|
pragma Export
|
156 |
|
|
(Ada, Current_Target_Exception,
|
157 |
|
|
"__gnat_current_target_exception");
|
158 |
|
|
-- This routine should return the current raised exception on targets
|
159 |
|
|
-- which have built-in exception handling such as the Java Virtual
|
160 |
|
|
-- Machine. For other targets this routine is simply ignored. Currently,
|
161 |
|
|
-- only JGNAT uses this. See 4jexcept.ads for details. The pragma Export
|
162 |
|
|
-- allows this routine to be accessed elsewhere in the run-time, even
|
163 |
|
|
-- though it is in the private part of this package (it is not allowed
|
164 |
|
|
-- to be in the visible part, since this is set by the reference manual).
|
165 |
|
|
|
166 |
|
|
function Exception_Name_Simple (X : Exception_Occurrence) return String;
|
167 |
|
|
-- Like Exception_Name, but returns the simple non-qualified name of the
|
168 |
|
|
-- exception. This is used to implement the Exception_Name function in
|
169 |
|
|
-- Current_Exceptions (the DEC compatible unit). It is called from the
|
170 |
|
|
-- compiler generated code (using Rtsfind, which does not respect the
|
171 |
|
|
-- private barrier, so we can place this function in the private part
|
172 |
|
|
-- where the compiler can find it, but the spec is unchanged.)
|
173 |
|
|
|
174 |
|
|
procedure Raise_Exception_Always (E : Exception_Id; Message : String := "");
|
175 |
|
|
pragma No_Return (Raise_Exception_Always);
|
176 |
|
|
pragma Export (Ada, Raise_Exception_Always, "__gnat_raise_exception");
|
177 |
|
|
-- This differs from Raise_Exception only in that the caller has determined
|
178 |
|
|
-- that for sure the parameter E is not null, and that therefore no check
|
179 |
|
|
-- for Null_Id is required. The expander converts Raise_Exception calls to
|
180 |
|
|
-- Raise_Exception_Always if it can determine this is the case. The Export
|
181 |
|
|
-- allows this routine to be accessed from Pure units.
|
182 |
|
|
|
183 |
|
|
procedure Raise_From_Signal_Handler
|
184 |
|
|
(E : Exception_Id;
|
185 |
|
|
M : System.Address);
|
186 |
|
|
pragma Export
|
187 |
|
|
(Ada, Raise_From_Signal_Handler,
|
188 |
|
|
"ada__exceptions__raise_from_signal_handler");
|
189 |
|
|
pragma No_Return (Raise_From_Signal_Handler);
|
190 |
|
|
-- This routine is used to raise an exception from a signal handler. The
|
191 |
|
|
-- signal handler has already stored the machine state (i.e. the state that
|
192 |
|
|
-- corresponds to the location at which the signal was raised). E is the
|
193 |
|
|
-- Exception_Id specifying what exception is being raised, and M is a
|
194 |
|
|
-- pointer to a null-terminated string which is the message to be raised.
|
195 |
|
|
-- Note that this routine never returns, so it is permissible to simply
|
196 |
|
|
-- jump to this routine, rather than call it. This may be appropriate for
|
197 |
|
|
-- systems where the right way to get out of signal handler is to alter the
|
198 |
|
|
-- PC value in the machine state or in some other way ask the operating
|
199 |
|
|
-- system to return here rather than to the original location.
|
200 |
|
|
|
201 |
|
|
procedure Raise_From_Controlled_Operation
|
202 |
|
|
(X : Ada.Exceptions.Exception_Occurrence);
|
203 |
|
|
pragma No_Return (Raise_From_Controlled_Operation);
|
204 |
|
|
pragma Export
|
205 |
|
|
(Ada, Raise_From_Controlled_Operation,
|
206 |
|
|
"__gnat_raise_from_controlled_operation");
|
207 |
|
|
-- Raise Program_Error, providing information about X (an exception raised
|
208 |
|
|
-- during a controlled operation) in the exception message.
|
209 |
|
|
|
210 |
|
|
procedure Reraise_Occurrence_Always (X : Exception_Occurrence);
|
211 |
|
|
pragma No_Return (Reraise_Occurrence_Always);
|
212 |
|
|
-- This differs from Raise_Occurrence only in that the caller guarantees
|
213 |
|
|
-- that for sure the parameter X is not the null occurrence, and that
|
214 |
|
|
-- therefore this procedure cannot return. The expander uses this routine
|
215 |
|
|
-- in the translation of a raise statement with no parameter (reraise).
|
216 |
|
|
|
217 |
|
|
procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence);
|
218 |
|
|
pragma No_Return (Reraise_Occurrence_No_Defer);
|
219 |
|
|
-- Exactly like Reraise_Occurrence, except that abort is not deferred
|
220 |
|
|
-- before the call and the parameter X is known not to be the null
|
221 |
|
|
-- occurrence. This is used in generated code when it is known that
|
222 |
|
|
-- abort is already deferred.
|
223 |
|
|
|
224 |
|
|
function Triggered_By_Abort return Boolean;
|
225 |
|
|
-- Determine whether the current exception (if it exists) is an instance of
|
226 |
|
|
-- Standard'Abort_Signal.
|
227 |
|
|
|
228 |
|
|
-----------------------
|
229 |
|
|
-- Polling Interface --
|
230 |
|
|
-----------------------
|
231 |
|
|
|
232 |
|
|
-- The GNAT compiler has an option to generate polling calls to the Poll
|
233 |
|
|
-- routine in this package. Specifying the -gnatP option for a compilation
|
234 |
|
|
-- causes a call to Ada.Exceptions.Poll to be generated on every subprogram
|
235 |
|
|
-- entry and on every iteration of a loop, thus avoiding the possibility of
|
236 |
|
|
-- a case of unbounded time between calls.
|
237 |
|
|
|
238 |
|
|
-- This polling interface may be used for instrumentation or debugging
|
239 |
|
|
-- purposes (e.g. implementing watchpoints in software or in the debugger).
|
240 |
|
|
|
241 |
|
|
-- In the GNAT technology itself, this interface is used to implement
|
242 |
|
|
-- immediate asynchronous transfer of control and immediate abort on
|
243 |
|
|
-- targets which do not provide for one thread interrupting another.
|
244 |
|
|
|
245 |
|
|
-- Note: this used to be in a separate unit called System.Poll, but that
|
246 |
|
|
-- caused horrible circular elaboration problems between System.Poll and
|
247 |
|
|
-- Ada.Exceptions. One way of solving such circularities is unification!
|
248 |
|
|
|
249 |
|
|
procedure Poll;
|
250 |
|
|
-- Check for asynchronous abort. Note that we do not inline the body.
|
251 |
|
|
-- This makes the interface more useful for debugging purposes.
|
252 |
|
|
|
253 |
|
|
--------------------------
|
254 |
|
|
-- Exception_Occurrence --
|
255 |
|
|
--------------------------
|
256 |
|
|
|
257 |
|
|
package TBE renames System.Traceback_Entries;
|
258 |
|
|
|
259 |
|
|
Max_Tracebacks : constant := 50;
|
260 |
|
|
-- Maximum number of trace backs stored in exception occurrence
|
261 |
|
|
|
262 |
|
|
type Tracebacks_Array is array (1 .. Max_Tracebacks) of TBE.Traceback_Entry;
|
263 |
|
|
-- Traceback array stored in exception occurrence
|
264 |
|
|
|
265 |
|
|
type Exception_Occurrence is record
|
266 |
|
|
Id : Exception_Id;
|
267 |
|
|
-- Exception_Identity for this exception occurrence
|
268 |
|
|
-- WARNING System.System.Finalization_Implementation.Finalize_List
|
269 |
|
|
-- relies on the fact that this field is always first in the exception
|
270 |
|
|
-- occurrence
|
271 |
|
|
|
272 |
|
|
Msg_Length : Natural := 0;
|
273 |
|
|
-- Length of message (zero = no message)
|
274 |
|
|
|
275 |
|
|
Msg : String (1 .. Exception_Msg_Max_Length);
|
276 |
|
|
-- Characters of message
|
277 |
|
|
|
278 |
|
|
Exception_Raised : Boolean := False;
|
279 |
|
|
-- Set to true to indicate that this exception occurrence has actually
|
280 |
|
|
-- been raised. When an exception occurrence is first created, this is
|
281 |
|
|
-- set to False, then when it is processed by Raise_Current_Exception,
|
282 |
|
|
-- it is set to True. If Raise_Current_Exception is used to raise an
|
283 |
|
|
-- exception for which this flag is already True, then it knows that
|
284 |
|
|
-- it is dealing with the reraise case (which is useful to distinguish
|
285 |
|
|
-- for exception tracing purposes).
|
286 |
|
|
|
287 |
|
|
Pid : Natural := 0;
|
288 |
|
|
-- Partition_Id for partition raising exception
|
289 |
|
|
|
290 |
|
|
Num_Tracebacks : Natural range 0 .. Max_Tracebacks := 0;
|
291 |
|
|
-- Number of traceback entries stored
|
292 |
|
|
|
293 |
|
|
Tracebacks : Tracebacks_Array;
|
294 |
|
|
-- Stored tracebacks (in Tracebacks (1 .. Num_Tracebacks))
|
295 |
|
|
end record;
|
296 |
|
|
|
297 |
|
|
function "=" (Left, Right : Exception_Occurrence) return Boolean
|
298 |
|
|
is abstract;
|
299 |
|
|
-- Don't allow comparison on exception occurrences, we should not need
|
300 |
|
|
-- this, and it would not work right, because of the Msg and Tracebacks
|
301 |
|
|
-- fields which have unused entries not copied by Save_Occurrence.
|
302 |
|
|
|
303 |
|
|
function EO_To_String (X : Exception_Occurrence) return String;
|
304 |
|
|
function String_To_EO (S : String) return Exception_Occurrence;
|
305 |
|
|
pragma Stream_Convert (Exception_Occurrence, String_To_EO, EO_To_String);
|
306 |
|
|
-- Functions for implementing Exception_Occurrence stream attributes
|
307 |
|
|
|
308 |
|
|
Null_Occurrence : constant Exception_Occurrence := (
|
309 |
|
|
Id => null,
|
310 |
|
|
Msg_Length => 0,
|
311 |
|
|
Msg => (others => ' '),
|
312 |
|
|
Exception_Raised => False,
|
313 |
|
|
Pid => 0,
|
314 |
|
|
Num_Tracebacks => 0,
|
315 |
|
|
Tracebacks => (others => TBE.Null_TB_Entry));
|
316 |
|
|
|
317 |
|
|
end Ada.Exceptions;
|