* dwarf2out.c (loc_descriptor_from_tree, case CONSTRUCTOR): New case.
[official-gcc.git] / gcc / ada / a-except.ads
blobc9a0b11e1f8a440a50ec37b0d210be65cb45f2c4
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-2002 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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, 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 with System;
43 with System.Standard_Library;
45 package Ada.Exceptions is
47 type Exception_Id is private;
48 Null_Id : constant Exception_Id;
50 type Exception_Occurrence is limited private;
51 type Exception_Occurrence_Access is access all Exception_Occurrence;
53 Null_Occurrence : constant Exception_Occurrence;
55 function Exception_Name (X : Exception_Occurrence) return String;
56 -- Same as Exception_Name (Exception_Identity (X))
58 function Exception_Name (Id : Exception_Id) return String;
60 procedure Raise_Exception (E : Exception_Id; Message : String := "");
61 -- Note: it would be really nice to give a pragma No_Return for this
62 -- procedure, but it would be wrong, since Raise_Exception does return
63 -- if given the null exception. However we do special case the name in
64 -- the test in the compiler for issuing a warning for a missing return
65 -- after this call. Program_Error seems reasonable enough in such a case.
66 -- See also the routine Raise_Exception_Always in the private part.
68 function Exception_Message (X : Exception_Occurrence) return String;
70 procedure Reraise_Occurrence (X : Exception_Occurrence);
71 -- Note: it would be really nice to give a pragma No_Return for this
72 -- procedure, but it would be wrong, since Reraise_Occurrence does return
73 -- if the argument is the null exception occurrence. See also procedure
74 -- Reraise_Occurrence_Always in the private part of this package.
76 function Exception_Identity (X : Exception_Occurrence) return Exception_Id;
78 function Exception_Information (X : Exception_Occurrence) return String;
79 -- The format of the exception information is as follows:
81 -- exception name (as in Exception_Name)
82 -- message (or a null line if no message)
83 -- PID=nnnn
84 -- 0xyyyyyyyy 0xyyyyyyyy ...
86 -- The lines are separated by a ASCII.LF character
87 -- The nnnn is the partition Id given as decimal digits.
88 -- The 0x... line represents traceback program counter locations,
89 -- in order with the first one being the exception location.
91 -- Note on ordering: the compiler uses the Save_Occurrence procedure, but
92 -- not the function from Rtsfind, so it is important that the procedure
93 -- come first, since Rtsfind finds the first matching entity.
95 procedure Save_Occurrence
96 (Target : out Exception_Occurrence;
97 Source : Exception_Occurrence);
99 function Save_Occurrence
100 (Source : Exception_Occurrence)
101 return Exception_Occurrence_Access;
103 private
104 package SSL renames System.Standard_Library;
106 subtype EOA is Exception_Occurrence_Access;
108 Exception_Msg_Max_Length : constant := 200;
110 ------------------
111 -- Exception_Id --
112 ------------------
114 subtype Code_Loc is System.Address;
115 -- Code location used in building exception tables and for call
116 -- addresses when propagating an exception (also traceback table)
117 -- Values of this type are created by using Label'Address or
118 -- extracted from machine states using Get_Code_Loc.
120 Null_Loc : constant Code_Loc := System.Null_Address;
121 -- Null code location, used to flag outer level frame
123 type Exception_Id is new SSL.Exception_Data_Ptr;
125 function EId_To_String (X : Exception_Id) return String;
126 function String_To_EId (S : String) return Exception_Id;
127 pragma Stream_Convert (Exception_Id, String_To_EId, EId_To_String);
128 -- Functions for implementing Exception_Id stream attributes
130 Null_Id : constant Exception_Id := null;
132 -------------------------
133 -- Private Subprograms --
134 -------------------------
136 function Current_Target_Exception return Exception_Occurrence;
137 pragma Export
138 (Ada, Current_Target_Exception,
139 "__gnat_current_target_exception");
140 -- This routine should return the current raised exception on targets
141 -- which have built-in exception handling such as the Java Virtual
142 -- Machine. For other targets this routine is simply ignored. Currently,
143 -- only JGNAT uses this. See 4jexcept.ads for details. The pragma Export
144 -- allows this routine to be accessed elsewhere in the run-time, even
145 -- though it is in the private part of this package (it is not allowed
146 -- to be in the visible part, since this is set by the reference manual).
148 function Exception_Name_Simple (X : Exception_Occurrence) return String;
149 -- Like Exception_Name, but returns the simple non-qualified name of
150 -- the exception. This is used to implement the Exception_Name function
151 -- in Current_Exceptions (the DEC compatible unit). It is called from
152 -- the compiler generated code (using Rtsfind, which does not respect
153 -- the private barrier, so we can place this function in the private
154 -- part where the compiler can find it, but the spec is unchanged.)
156 procedure Raise_Exception_Always (E : Exception_Id; Message : String := "");
157 pragma No_Return (Raise_Exception_Always);
158 pragma Export (Ada, Raise_Exception_Always, "__gnat_raise_exception");
159 -- This differs from Raise_Exception only in that the caller has determined
160 -- that for sure the parameter E is not null, and that therefore the call
161 -- to this procedure cannot return. The expander converts Raise_Exception
162 -- calls to Raise_Exception_Always if it can determine this is the case.
163 -- The Export allows this routine to be accessed from Pure units.
165 procedure Raise_No_Msg (E : Exception_Id);
166 pragma No_Return (Raise_No_Msg);
167 -- Raises an exception with no message with given exception id value.
168 -- Abort is deferred before the raise call.
170 procedure Raise_From_Signal_Handler
171 (E : Exception_Id;
172 M : SSL.Big_String_Ptr);
173 pragma Export
174 (Ada, Raise_From_Signal_Handler,
175 "ada__exceptions__raise_from_signal_handler");
176 pragma No_Return (Raise_From_Signal_Handler);
177 -- This routine is used to raise an exception from a signal handler.
178 -- The signal handler has already stored the machine state (i.e. the
179 -- state that corresponds to the location at which the signal was
180 -- raised). E is the Exception_Id specifying what exception is being
181 -- raised, and M is a pointer to a null-terminated string which is the
182 -- message to be raised. Note that this routine never returns, so it is
183 -- permissible to simply jump to this routine, rather than call it. This
184 -- may be appropriate for systems where the right way to get out of a
185 -- signal handler is to alter the PC value in the machine state or in
186 -- some other way ask the operating system to return here rather than
187 -- to the original location.
189 procedure Raise_With_C_Msg
190 (E : Exception_Id;
191 M : SSL.Big_String_Ptr);
192 pragma Export (Ada, Raise_With_C_Msg, "ada__exceptions__raise_with_c_msg");
193 pragma No_Return (Raise_With_C_Msg);
194 -- Raises an exception with with given exception id value and message.
195 -- M is a null terminated string with the message to be raised. Abort
196 -- is deferred before the raise call.
198 procedure Reraise_Occurrence_Always (X : Exception_Occurrence);
199 pragma No_Return (Reraise_Occurrence_Always);
200 -- This differs from Raise_Occurrence only in that the caller guarantees
201 -- that for sure the parameter X is not the null occurrence, and that
202 -- therefore this procedure cannot return. The expander uses this routine
203 -- in the translation of a raise statement with no parameter (reraise).
205 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence);
206 pragma No_Return (Reraise_Occurrence_No_Defer);
207 -- Exactly like Reraise_Occurrence, except that abort is not deferred
208 -- before the call and the parameter X is known not to be the null
209 -- occurrence. This is used in generated code when it is known
210 -- that abort is already deferred.
212 procedure SDP_Table_Build
213 (SDP_Addresses : System.Address;
214 SDP_Count : Natural;
215 Elab_Addresses : System.Address;
216 Elab_Addr_Count : Natural);
217 pragma Export (C, SDP_Table_Build, "__gnat_SDP_Table_Build");
218 -- This is the routine that is called to build and sort the list of
219 -- subprogram descriptor pointers. In the normal case it is called
220 -- once at the start of execution, but it can also be called as part
221 -- of the explicit initialization routine (adainit) when there is no
222 -- Ada main program. In particular, in the case where multiple Ada
223 -- libraries are present, this routine can be called more than once
224 -- for each library, in which case it augments the previously set
225 -- table with the new entries specified by the parameters.
227 -- SDP_Addresses Address of the start of the list of addresses of
228 -- __gnat_unit_name__SDP values constructed for each
229 -- unit, (see System.Exceptions).
231 -- SDP_Count Number of entries in SDP_Addresses
233 -- Elab_Addresses Address of the start of a list of addresses of
234 -- generated Ada elaboration routines, as well as
235 -- one extra entry for the generated main program.
236 -- These are used to generate the dummy SDP's that
237 -- mark the outer scope.
239 -- Elab_Addr_Count Number of entries in Elab_Addresses
241 procedure Break_Start;
242 pragma Export (C, Break_Start, "__gnat_break_start");
243 -- This is a dummy procedure that is called at the start of execution.
244 -- Its sole purpose is to provide a well defined point for the placement
245 -- of a main program breakpoint. We put the routine in Ada.Exceptions so
246 -- that the standard mechanism of always stepping up from breakpoints
247 -- within Ada.Exceptions leaves us sitting in the main program.
249 -----------------------
250 -- Polling Interface --
251 -----------------------
253 -- The GNAT compiler has an option to generate polling calls to the Poll
254 -- routine in this package. Specifying the -gnatP option for a compilation
255 -- causes a call to Ada.Exceptions.Poll to be generated on every subprogram
256 -- entry and on every iteration of a loop, thus avoiding the possibility of
257 -- a case of unbounded time between calls.
259 -- This polling interface may be used for instrumentation or debugging
260 -- purposes (e.g. implementing watchpoints in software or in the debugger).
262 -- In the GNAT technology itself, this interface is used to implement
263 -- immediate aynschronous transfer of control and immediate abort on
264 -- targets which do not provide for one thread interrupting another.
266 -- Note: this used to be in a separate unit called System.Poll, but that
267 -- caused horrible circular elaboration problems between System.Poll and
268 -- Ada.Exceptions. One way of solving such circularities is unification!
270 procedure Poll;
271 -- Check for asynchronous abort. Note that we do not inline the body.
272 -- This makes the interface more useful for debugging purposes.
274 --------------------------
275 -- Exception_Occurrence --
276 --------------------------
278 Max_Tracebacks : constant := 50;
279 -- Maximum number of trace backs stored in exception occurrence
281 type Tracebacks_Array is array (1 .. Max_Tracebacks) of Code_Loc;
282 -- Traceback array stored in exception occurrence
284 type Exception_Occurrence is record
285 Id : Exception_Id;
286 -- Exception_Identity for this exception occurrence
287 -- WARNING System.System.Finalization_Implementation.Finalize_List
288 -- relies on the fact that this field is always first in the exception
289 -- occurrence
291 Msg_Length : Natural := 0;
292 -- Length of message (zero = no message)
294 Msg : String (1 .. Exception_Msg_Max_Length);
295 -- Characters of message
297 Cleanup_Flag : Boolean;
298 -- The cleanup flag is normally False, it is set True for an exception
299 -- occurrence passed to a cleanup routine, and will still be set True
300 -- when the cleanup routine does a Reraise_Occurrence call using this
301 -- exception occurrence. This is used to avoid recording a bogus trace
302 -- back entry from this reraise call.
304 Exception_Raised : Boolean := False;
305 -- Set to true to indicate that this exception occurrence has actually
306 -- been raised. When an exception occurrence is first created, this is
307 -- set to False, then when it is processed by Raise_Current_Exception,
308 -- it is set to True. If Raise_Current_Exception is used to raise an
309 -- exception for which this flag is already True, then it knows that
310 -- it is dealing with the reraise case (which is useful to distinguish
311 -- for exception tracing purposes).
313 Pid : Natural;
314 -- Partition_Id for partition raising exception
316 Num_Tracebacks : Natural range 0 .. Max_Tracebacks := 0;
317 -- Number of traceback entries stored
319 Tracebacks : Tracebacks_Array;
320 -- Stored tracebacks (in Tracebacks (1 .. Num_Tracebacks))
321 end record;
323 function "=" (Left, Right : Exception_Occurrence) return Boolean
324 is abstract;
325 -- Don't allow comparison on exception occurrences, we should not need
326 -- this, and it would not work right, because of the Msg and Tracebacks
327 -- fields which have unused entries not copied by Save_Occurrence.
329 function EO_To_String (X : Exception_Occurrence) return String;
330 function String_To_EO (S : String) return Exception_Occurrence;
331 pragma Stream_Convert (Exception_Occurrence, String_To_EO, EO_To_String);
332 -- Functions for implementing Exception_Occurrence stream attributes
334 Null_Occurrence : constant Exception_Occurrence := (
335 Id => Null_Id,
336 Msg_Length => 0,
337 Msg => (others => ' '),
338 Cleanup_Flag => False,
339 Exception_Raised => False,
340 Pid => 0,
341 Num_Tracebacks => 0,
342 Tracebacks => (others => Null_Loc));
344 end Ada.Exceptions;