* dwarf2out.c, fold-const.c, ipa-type-escape.c,
[official-gcc.git] / gcc / ada / a-except.ads
blob73a6a29ee26160d34b8b83fb07c143dfa0c49c62
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 -- --
9 -- Copyright (C) 1992-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 ------------------------------------------------------------------------------
38 pragma Polling (Off);
39 -- We must turn polling off for this unit, because otherwise we get
40 -- elaboration circularities with ourself.
42 pragma Warnings (Off);
43 -- Allow withing of non-Preelaborated units in Ada 2005 mode where this
44 -- package will be categorized as Preelaborate. See AI-362 for details.
45 -- It is safe in the context of the run-time to violate the rules!
47 with System;
48 with System.Parameters;
49 with System.Standard_Library;
50 with System.Traceback_Entries;
51 pragma Warnings (On);
53 package Ada.Exceptions is
54 pragma Warnings (Off);
55 pragma Preelaborate_05 (Exceptions);
56 pragma Warnings (On);
57 -- In accordance with Ada 2005 AI-362. The warnings pragmas are so that we can
58 -- compile this using older compiler versions, which will ignore the pragma,
59 -- which is fine for the bootstrap.
61 type Exception_Id is private;
62 Null_Id : constant Exception_Id;
64 type Exception_Occurrence is limited private;
65 type Exception_Occurrence_Access is access all Exception_Occurrence;
67 Null_Occurrence : constant Exception_Occurrence;
69 function Exception_Name (X : Exception_Occurrence) return String;
70 -- Same as Exception_Name (Exception_Identity (X))
72 function Exception_Name (Id : Exception_Id) return String;
74 procedure Raise_Exception (E : Exception_Id; Message : String := "");
75 -- Note: it would be really nice to give a pragma No_Return for this
76 -- procedure, but it would be wrong, since Raise_Exception does return
77 -- if given the null exception. However we do special case the name in
78 -- the test in the compiler for issuing a warning for a missing return
79 -- after this call. Program_Error seems reasonable enough in such a case.
80 -- See also the routine Raise_Exception_Always in the private part.
82 function Exception_Message (X : Exception_Occurrence) return String;
84 procedure Reraise_Occurrence (X : Exception_Occurrence);
85 -- Note: it would be really nice to give a pragma No_Return for this
86 -- procedure, but it would be wrong, since Reraise_Occurrence does return
87 -- if the argument is the null exception occurrence. See also procedure
88 -- Reraise_Occurrence_Always in the private part of this package.
90 function Exception_Identity (X : Exception_Occurrence) return Exception_Id;
92 function Exception_Information (X : Exception_Occurrence) return String;
93 -- The format of the exception information is as follows:
95 -- exception name (as in Exception_Name)
96 -- message (or a null line if no message)
97 -- PID=nnnn
98 -- 0xyyyyyyyy 0xyyyyyyyy ...
100 -- The lines are separated by a ASCII.LF character
101 -- The nnnn is the partition Id given as decimal digits.
102 -- The 0x... line represents traceback program counter locations,
103 -- in order with the first one being the exception location.
105 -- Note on ordering: the compiler uses the Save_Occurrence procedure, but
106 -- not the function from Rtsfind, so it is important that the procedure
107 -- come first, since Rtsfind finds the first matching entity.
109 procedure Save_Occurrence
110 (Target : out Exception_Occurrence;
111 Source : Exception_Occurrence);
113 function Save_Occurrence
114 (Source : Exception_Occurrence)
115 return Exception_Occurrence_Access;
117 private
118 package SSL renames System.Standard_Library;
119 package SP renames System.Parameters;
121 subtype EOA is Exception_Occurrence_Access;
123 Exception_Msg_Max_Length : constant := SP.Default_Exception_Msg_Max_Length;
125 ------------------
126 -- Exception_Id --
127 ------------------
129 subtype Code_Loc is System.Address;
130 -- Code location used in building exception tables and for call
131 -- addresses when propagating an exception.
132 -- Values of this type are created by using Label'Address or
133 -- extracted from machine states using Get_Code_Loc.
135 Null_Loc : constant Code_Loc := System.Null_Address;
136 -- Null code location, used to flag outer level frame
138 type Exception_Id is new SSL.Exception_Data_Ptr;
140 function EId_To_String (X : Exception_Id) return String;
141 function String_To_EId (S : String) return Exception_Id;
142 pragma Stream_Convert (Exception_Id, String_To_EId, EId_To_String);
143 -- Functions for implementing Exception_Id stream attributes
145 Null_Id : constant Exception_Id := null;
147 -------------------------
148 -- Private Subprograms --
149 -------------------------
151 function Current_Target_Exception return Exception_Occurrence;
152 pragma Export
153 (Ada, Current_Target_Exception,
154 "__gnat_current_target_exception");
155 -- This routine should return the current raised exception on targets
156 -- which have built-in exception handling such as the Java Virtual
157 -- Machine. For other targets this routine is simply ignored. Currently,
158 -- only JGNAT uses this. See 4jexcept.ads for details. The pragma Export
159 -- allows this routine to be accessed elsewhere in the run-time, even
160 -- though it is in the private part of this package (it is not allowed
161 -- to be in the visible part, since this is set by the reference manual).
163 function Exception_Name_Simple (X : Exception_Occurrence) return String;
164 -- Like Exception_Name, but returns the simple non-qualified name of
165 -- the exception. This is used to implement the Exception_Name function
166 -- in Current_Exceptions (the DEC compatible unit). It is called from
167 -- the compiler generated code (using Rtsfind, which does not respect
168 -- the private barrier, so we can place this function in the private
169 -- part where the compiler can find it, but the spec is unchanged.)
171 procedure Raise_Exception_Always (E : Exception_Id; Message : String := "");
172 pragma No_Return (Raise_Exception_Always);
173 pragma Export (Ada, Raise_Exception_Always, "__gnat_raise_exception");
174 -- This differs from Raise_Exception only in that the caller has determined
175 -- that for sure the parameter E is not null, and that therefore the call
176 -- to this procedure cannot return. The expander converts Raise_Exception
177 -- calls to Raise_Exception_Always if it can determine this is the case.
178 -- The Export allows this routine to be accessed from Pure units.
180 procedure Raise_From_Signal_Handler
181 (E : Exception_Id;
182 M : SSL.Big_String_Ptr);
183 pragma Export
184 (Ada, Raise_From_Signal_Handler,
185 "ada__exceptions__raise_from_signal_handler");
186 pragma No_Return (Raise_From_Signal_Handler);
187 -- This routine is used to raise an exception from a signal handler.
188 -- The signal handler has already stored the machine state (i.e. the
189 -- state that corresponds to the location at which the signal was
190 -- raised). E is the Exception_Id specifying what exception is being
191 -- raised, and M is a pointer to a null-terminated string which is the
192 -- message to be raised. Note that this routine never returns, so it is
193 -- permissible to simply jump to this routine, rather than call it. This
194 -- may be appropriate for systems where the right way to get out of a
195 -- signal handler is to alter the PC value in the machine state or in
196 -- some other way ask the operating system to return here rather than
197 -- to the original location.
199 procedure Reraise_Occurrence_Always (X : Exception_Occurrence);
200 pragma No_Return (Reraise_Occurrence_Always);
201 -- This differs from Raise_Occurrence only in that the caller guarantees
202 -- that for sure the parameter X is not the null occurrence, and that
203 -- therefore this procedure cannot return. The expander uses this routine
204 -- in the translation of a raise statement with no parameter (reraise).
206 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence);
207 pragma No_Return (Reraise_Occurrence_No_Defer);
208 -- Exactly like Reraise_Occurrence, except that abort is not deferred
209 -- before the call and the parameter X is known not to be the null
210 -- occurrence. This is used in generated code when it is known
211 -- that abort is already deferred.
213 -----------------------
214 -- Polling Interface --
215 -----------------------
217 -- The GNAT compiler has an option to generate polling calls to the Poll
218 -- routine in this package. Specifying the -gnatP option for a compilation
219 -- causes a call to Ada.Exceptions.Poll to be generated on every subprogram
220 -- entry and on every iteration of a loop, thus avoiding the possibility of
221 -- a case of unbounded time between calls.
223 -- This polling interface may be used for instrumentation or debugging
224 -- purposes (e.g. implementing watchpoints in software or in the debugger).
226 -- In the GNAT technology itself, this interface is used to implement
227 -- immediate aynschronous transfer of control and immediate abort on
228 -- targets which do not provide for one thread interrupting another.
230 -- Note: this used to be in a separate unit called System.Poll, but that
231 -- caused horrible circular elaboration problems between System.Poll and
232 -- Ada.Exceptions. One way of solving such circularities is unification!
234 procedure Poll;
235 -- Check for asynchronous abort. Note that we do not inline the body.
236 -- This makes the interface more useful for debugging purposes.
238 --------------------------
239 -- Exception_Occurrence --
240 --------------------------
242 package TBE renames System.Traceback_Entries;
244 Max_Tracebacks : constant := 50;
245 -- Maximum number of trace backs stored in exception occurrence
247 type Tracebacks_Array is array (1 .. Max_Tracebacks) of TBE.Traceback_Entry;
248 -- Traceback array stored in exception occurrence
250 type Exception_Occurrence is record
251 Id : Exception_Id;
252 -- Exception_Identity for this exception occurrence
253 -- WARNING System.System.Finalization_Implementation.Finalize_List
254 -- relies on the fact that this field is always first in the exception
255 -- occurrence
257 Msg_Length : Natural := 0;
258 -- Length of message (zero = no message)
260 Msg : String (1 .. Exception_Msg_Max_Length);
261 -- Characters of message
263 Cleanup_Flag : Boolean;
264 -- The cleanup flag is normally False, it is set True for an exception
265 -- occurrence passed to a cleanup routine, and will still be set True
266 -- when the cleanup routine does a Reraise_Occurrence call using this
267 -- exception occurrence. This is used to avoid recording a bogus trace
268 -- back entry from this reraise call.
270 Exception_Raised : Boolean := False;
271 -- Set to true to indicate that this exception occurrence has actually
272 -- been raised. When an exception occurrence is first created, this is
273 -- set to False, then when it is processed by Raise_Current_Exception,
274 -- it is set to True. If Raise_Current_Exception is used to raise an
275 -- exception for which this flag is already True, then it knows that
276 -- it is dealing with the reraise case (which is useful to distinguish
277 -- for exception tracing purposes).
279 Pid : Natural;
280 -- Partition_Id for partition raising exception
282 Num_Tracebacks : Natural range 0 .. Max_Tracebacks := 0;
283 -- Number of traceback entries stored
285 Tracebacks : Tracebacks_Array;
286 -- Stored tracebacks (in Tracebacks (1 .. Num_Tracebacks))
288 Private_Data : System.Address := System.Null_Address;
289 -- Field used by low level exception mechanism to store specific data.
290 -- Currently used by the GCC exception mechanism to store a pointer to
291 -- a GNAT_GCC_Exception.
292 end record;
294 function "=" (Left, Right : Exception_Occurrence) return Boolean
295 is abstract;
296 -- Don't allow comparison on exception occurrences, we should not need
297 -- this, and it would not work right, because of the Msg and Tracebacks
298 -- fields which have unused entries not copied by Save_Occurrence.
300 function EO_To_String (X : Exception_Occurrence) return String;
301 function String_To_EO (S : String) return Exception_Occurrence;
302 pragma Stream_Convert (Exception_Occurrence, String_To_EO, EO_To_String);
303 -- Functions for implementing Exception_Occurrence stream attributes
305 pragma Warnings (Off);
306 -- Allow non-static constants in Ada 2005 mode where this package will be
307 -- implicitly categorized as Preelaborate. See AI-362 for details. It is
308 -- safe in the context of the run-time to violate the rules!
310 Null_Occurrence : constant Exception_Occurrence := (
311 Id => Null_Id,
312 Msg_Length => 0,
313 Msg => (others => ' '),
314 Cleanup_Flag => False,
315 Exception_Raised => False,
316 Pid => 0,
317 Num_Tracebacks => 0,
318 Tracebacks => (others => TBE.Null_TB_Entry),
319 Private_Data => System.Null_Address);
321 pragma Warnings (On);
323 end Ada.Exceptions;