2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / a-except.adb
blobfb14eda5b087f81bb089699e2ee4ec3e4bc9402f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- A D A . E X C E P T I O N S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 pragma Polling (Off);
35 -- We must turn polling off for this unit, because otherwise we get
36 -- elaboration circularities with System.Exception_Tables.
38 with System; use System;
39 with System.Standard_Library; use System.Standard_Library;
40 with System.Soft_Links; use System.Soft_Links;
42 package body Ada.Exceptions is
44 pragma Suppress (All_Checks);
45 -- We definitely do not want exceptions occurring within this unit, or
46 -- we are in big trouble. If an exceptional situation does occur, better
47 -- that it not be raised, since raising it can cause confusing chaos.
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 -- Note: the exported subprograms in this package body are called directly
54 -- from C clients using the given external name, even though they are not
55 -- technically visible in the Ada sense.
57 function Code_Address_For_AAA return System.Address;
58 function Code_Address_For_ZZZ return System.Address;
59 -- Return start and end of procedures in this package
61 -- These procedures are used to provide exclusion bounds in
62 -- calls to Call_Chain at exception raise points from this unit. The
63 -- purpose is to arrange for the exception tracebacks not to include
64 -- frames from routines involved in the raise process, as these are
65 -- meaningless from the user's standpoint.
67 -- For these bounds to be meaningful, we need to ensure that the object
68 -- code for the routines involved in processing a raise is located after
69 -- the object code Code_Address_For_AAA and before the object code
70 -- Code_Address_For_ZZZ. This will indeed be the case as long as the
71 -- following rules are respected:
73 -- 1) The bodies of the subprograms involved in processing a raise
74 -- are located after the body of Code_Address_For_AAA and before the
75 -- body of Code_Address_For_ZZZ.
77 -- 2) No pragma Inline applies to any of these subprograms, as this
78 -- could delay the corresponding assembly output until the end of
79 -- the unit.
81 procedure Call_Chain (Excep : EOA);
82 -- Store up to Max_Tracebacks in Excep, corresponding to the current
83 -- call chain.
85 procedure Process_Raise_Exception
86 (E : Exception_Id;
87 From_Signal_Handler : Boolean);
88 pragma No_Return (Process_Raise_Exception);
89 -- This is the lowest level raise routine. It raises the exception
90 -- referenced by Current_Excep.all in the TSD, without deferring abort
91 -- (the caller must ensure that abort is deferred on entry).
93 -- This is the common implementation for Raise_Current_Excep and
94 -- Raise_From_Signal_Handler. The origin of the call is indicated by the
95 -- From_Signal_Handler argument.
97 procedure To_Stderr (S : String);
98 pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
99 -- Little routine to output string to stderr that is also used
100 -- in the tasking run time.
102 procedure To_Stderr (C : Character);
103 pragma Inline (To_Stderr);
104 pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
105 -- Little routine to output a character to stderr, used by some of
106 -- the separate units below.
108 package Exception_Data is
110 ---------------------------------
111 -- Exception messages routines --
112 ---------------------------------
114 procedure Set_Exception_C_Msg
115 (Id : Exception_Id;
116 Msg1 : System.Address;
117 Line : Integer := 0;
118 Msg2 : System.Address := System.Null_Address);
119 -- This routine is called to setup the exception referenced by the
120 -- Current_Excep field in the TSD to contain the indicated Id value
121 -- and message. Msg1 is a null terminated string which is generated
122 -- as the exception message. If line is non-zero, then a colon and
123 -- the decimal representation of this integer is appended to the
124 -- message. When Msg2 is non-null, a space and this additional null
125 -- terminated string is added to the message.
127 procedure Set_Exception_Msg
128 (Id : Exception_Id;
129 Message : String);
130 -- This routine is called to setup the exception referenced by the
131 -- Current_Excep field in the TSD to contain the indicated Id value
132 -- and message. Message is a string which is generated as the
133 -- exception message.
135 --------------------------------------
136 -- Exception information subprogram --
137 --------------------------------------
139 function Exception_Information (X : Exception_Occurrence) return String;
140 -- The format of the exception information is as follows:
142 -- Exception_Name: <exception name> (as in Exception_Name)
143 -- Message: <message> (only if Exception_Message is empty)
144 -- PID=nnnn (only if != 0)
145 -- Call stack traceback locations: (only if at least one location)
146 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
148 -- The lines are separated by a ASCII.LF character.
149 -- The nnnn is the partition Id given as decimal digits.
150 -- The 0x... line represents traceback program counter locations, in
151 -- execution order with the first one being the exception location. It
152 -- is present only
154 -- The Exception_Name and Message lines are omitted in the abort
155 -- signal case, since this is not really an exception.
157 -- !! If the format of the generated string is changed, please note
158 -- !! that an equivalent modification to the routine String_To_EO must
159 -- !! be made to preserve proper functioning of the stream attributes.
161 ---------------------------------------
162 -- Exception backtracing subprograms --
163 ---------------------------------------
165 -- What is automatically output when exception tracing is on is the
166 -- usual exception information with the call chain backtrace possibly
167 -- tailored by a backtrace decorator. Modifying Exception_Information
168 -- itself is not a good idea because the decorated output is completely
169 -- out of control and would break all our code related to the streaming
170 -- of exceptions. We then provide an alternative function to compute
171 -- the possibly tailored output, which is equivalent if no decorator is
172 -- currently set:
174 function Tailored_Exception_Information
175 (X : Exception_Occurrence) return String;
176 -- Exception information to be output in the case of automatic tracing
177 -- requested through GNAT.Exception_Traces.
179 -- This is the same as Exception_Information if no backtrace decorator
180 -- is currently in place. Otherwise, this is Exception_Information with
181 -- the call chain raw addresses replaced by the result of a call to the
182 -- current decorator provided with the call chain addresses.
184 pragma Export
185 (Ada, Tailored_Exception_Information,
186 "__gnat_tailored_exception_information");
187 -- This is currently used by System.Tasking.Stages
189 end Exception_Data;
191 package Exception_Traces is
193 use Exception_Data;
194 -- Imports Tailored_Exception_Information
196 ----------------------------------------------
197 -- Run-Time Exception Notification Routines --
198 ----------------------------------------------
200 -- These subprograms provide a common run-time interface to trigger the
201 -- actions required when an exception is about to be propagated (e.g.
202 -- user specified actions or output of exception information). They are
203 -- exported to be usable by the Ada exception handling personality
204 -- routine when the GCC 3 mechanism is used.
206 procedure Notify_Handled_Exception;
207 pragma Export
208 (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
209 -- This routine is called for a handled occurrence is about to be
210 -- propagated.
212 procedure Notify_Unhandled_Exception;
213 pragma Export
214 (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
215 -- This routine is called when an unhandled occurrence is about to be
216 -- propagated.
218 procedure Unhandled_Exception_Terminate;
219 pragma No_Return (Unhandled_Exception_Terminate);
220 -- This procedure is called to terminate execution following an
221 -- unhandled exception. The exception information, including
222 -- traceback if available is output, and execution is then
223 -- terminated. Note that at the point where this routine is
224 -- called, the stack has typically been destroyed.
226 end Exception_Traces;
228 package Exception_Propagation is
230 use Exception_Traces;
231 -- Imports Notify_Unhandled_Exception and
232 -- Unhandled_Exception_Terminate
234 ------------------------------------
235 -- Exception propagation routines --
236 ------------------------------------
238 procedure Setup_Exception
239 (Excep : EOA;
240 Current : EOA;
241 Reraised : Boolean := False);
242 -- Perform the necessary operations to prepare the propagation of Excep
243 -- in a task where Current is the current occurrence. Excep is assumed
244 -- to be a valid (non null) pointer.
246 -- This should be called before any (re-)setting of the current
247 -- occurrence. Any such (re-)setting shall take care *not* to clobber
248 -- the Private_Data component.
250 -- Having Current provided as an argument (instead of retrieving it via
251 -- Get_Current_Excep internally) is required to allow one task to setup
252 -- an exception for another task, which is used by Transfer_Occurrence.
254 procedure Propagate_Exception (From_Signal_Handler : Boolean);
255 pragma No_Return (Propagate_Exception);
256 -- This procedure propagates the exception represented by the occurrence
257 -- referenced by Current_Excep in the TSD for the current task.
259 end Exception_Propagation;
261 package Stream_Attributes is
263 --------------------------------
264 -- Stream attributes routines --
265 --------------------------------
267 function EId_To_String (X : Exception_Id) return String;
268 function String_To_EId (S : String) return Exception_Id;
269 -- Functions for implementing Exception_Id stream attributes
271 function EO_To_String (X : Exception_Occurrence) return String;
272 function String_To_EO (S : String) return Exception_Occurrence;
273 -- Functions for implementing Exception_Occurrence stream
274 -- attributes
276 end Stream_Attributes;
278 procedure Raise_Current_Excep (E : Exception_Id);
279 pragma No_Return (Raise_Current_Excep);
280 pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
281 -- This is a simple wrapper to Process_Raise_Exception setting the
282 -- From_Signal_Handler argument to False.
284 -- This external name for Raise_Current_Excep is historical, and probably
285 -- should be changed but for now we keep it, because gdb and gigi know
286 -- about it.
288 procedure Raise_Exception_No_Defer
289 (E : Exception_Id; Message : String := "");
290 pragma Export
291 (Ada, Raise_Exception_No_Defer,
292 "ada__exceptions__raise_exception_no_defer");
293 pragma No_Return (Raise_Exception_No_Defer);
294 -- Similar to Raise_Exception, but with no abort deferral
296 procedure Raise_With_Msg (E : Exception_Id);
297 pragma No_Return (Raise_With_Msg);
298 pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
299 -- Raises an exception with given exception id value. A message
300 -- is associated with the raise, and has already been stored in the
301 -- exception occurrence referenced by the Current_Excep in the TSD.
302 -- Abort is deferred before the raise call.
304 procedure Raise_With_Location_And_Msg
305 (E : Exception_Id;
306 F : System.Address;
307 L : Integer;
308 M : System.Address := System.Null_Address);
309 pragma No_Return (Raise_With_Location_And_Msg);
310 -- Raise an exception with given exception id value. A filename and line
311 -- number is associated with the raise and is stored in the exception
312 -- occurrence and in addition a string message M is appended to
313 -- this (if M is not null).
315 procedure Raise_Constraint_Error
316 (File : System.Address;
317 Line : Integer);
318 pragma No_Return (Raise_Constraint_Error);
319 pragma Export
320 (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
321 -- Raise constraint error with file:line information
323 procedure Raise_Constraint_Error_Msg
324 (File : System.Address;
325 Line : Integer;
326 Msg : System.Address);
327 pragma No_Return (Raise_Constraint_Error_Msg);
328 pragma Export
329 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
330 -- Raise constraint error with file:line + msg information
332 procedure Raise_Program_Error
333 (File : System.Address;
334 Line : Integer);
335 pragma No_Return (Raise_Program_Error);
336 pragma Export
337 (C, Raise_Program_Error, "__gnat_raise_program_error");
338 -- Raise program error with file:line information
340 procedure Raise_Program_Error_Msg
341 (File : System.Address;
342 Line : Integer;
343 Msg : System.Address);
344 pragma No_Return (Raise_Program_Error_Msg);
345 pragma Export
346 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
347 -- Raise program error with file:line + msg information
349 procedure Raise_Storage_Error
350 (File : System.Address;
351 Line : Integer);
352 pragma No_Return (Raise_Storage_Error);
353 pragma Export
354 (C, Raise_Storage_Error, "__gnat_raise_storage_error");
355 -- Raise storage error with file:line information
357 procedure Raise_Storage_Error_Msg
358 (File : System.Address;
359 Line : Integer;
360 Msg : System.Address);
361 pragma No_Return (Raise_Storage_Error_Msg);
362 pragma Export
363 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
364 -- Raise storage error with file:line + reason msg information
366 -- The exception raising process and the automatic tracing mechanism rely
367 -- on some careful use of flags attached to the exception occurrence. The
368 -- graph below illustrates the relations between the Raise_ subprograms
369 -- and identifies the points where basic flags such as Exception_Raised
370 -- are initialized.
372 -- (i) signs indicate the flags initialization points. R stands for Raise,
373 -- W for With, and E for Exception.
375 -- R_No_Msg R_E R_Pe R_Ce R_Se
376 -- | | | | |
377 -- +--+ +--+ +---+ | +---+
378 -- | | | | |
379 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
380 -- | | | |
381 -- +------------+ | +-----------+ +--+
382 -- | | | |
383 -- | | | Set_E_C_Msg(i)
384 -- | | |
385 -- Raise_Current_Excep
387 procedure Reraise;
388 pragma No_Return (Reraise);
389 pragma Export (C, Reraise, "__gnat_reraise");
390 -- Reraises the exception referenced by the Current_Excep field of
391 -- the TSD (all fields of this exception occurrence are set). Abort
392 -- is deferred before the reraise operation.
394 -- Save_Occurrence variations: As the management of the private data
395 -- attached to occurrences is delicate, wether or not pointers to such
396 -- data has to be copied in various situations is better made explicit.
397 -- The following procedures provide an internal interface to help making
398 -- this explicit.
400 procedure Save_Occurrence_No_Private
401 (Target : out Exception_Occurrence;
402 Source : Exception_Occurrence);
403 -- Copy all the components of Source to Target, except the
404 -- Private_Data pointer.
406 procedure Transfer_Occurrence
407 (Target : Exception_Occurrence_Access;
408 Source : Exception_Occurrence);
409 pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
410 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
411 -- to setup Target from Source as an exception to be propagated in the
412 -- caller task. Target is expected to be a pointer to the fixed TSD
413 -- occurrence for this task.
415 -----------------------------
416 -- Run-Time Check Routines --
417 -----------------------------
419 -- These routines are called from the runtime to raise a specific
420 -- exception with a reason message attached. The parameters are
421 -- the file name and line number in each case. The names are keyed
422 -- to the codes defined in Types.ads and a-types.h (for example,
423 -- the name Rcheck_05 refers to the Reason whose Pos code is 5).
425 procedure Rcheck_00 (File : System.Address; Line : Integer);
426 procedure Rcheck_01 (File : System.Address; Line : Integer);
427 procedure Rcheck_02 (File : System.Address; Line : Integer);
428 procedure Rcheck_03 (File : System.Address; Line : Integer);
429 procedure Rcheck_04 (File : System.Address; Line : Integer);
430 procedure Rcheck_05 (File : System.Address; Line : Integer);
431 procedure Rcheck_06 (File : System.Address; Line : Integer);
432 procedure Rcheck_07 (File : System.Address; Line : Integer);
433 procedure Rcheck_08 (File : System.Address; Line : Integer);
434 procedure Rcheck_09 (File : System.Address; Line : Integer);
435 procedure Rcheck_10 (File : System.Address; Line : Integer);
436 procedure Rcheck_11 (File : System.Address; Line : Integer);
437 procedure Rcheck_12 (File : System.Address; Line : Integer);
438 procedure Rcheck_13 (File : System.Address; Line : Integer);
439 procedure Rcheck_14 (File : System.Address; Line : Integer);
440 procedure Rcheck_15 (File : System.Address; Line : Integer);
441 procedure Rcheck_16 (File : System.Address; Line : Integer);
442 procedure Rcheck_17 (File : System.Address; Line : Integer);
443 procedure Rcheck_18 (File : System.Address; Line : Integer);
444 procedure Rcheck_19 (File : System.Address; Line : Integer);
445 procedure Rcheck_20 (File : System.Address; Line : Integer);
446 procedure Rcheck_21 (File : System.Address; Line : Integer);
447 procedure Rcheck_22 (File : System.Address; Line : Integer);
448 procedure Rcheck_23 (File : System.Address; Line : Integer);
449 procedure Rcheck_24 (File : System.Address; Line : Integer);
450 procedure Rcheck_25 (File : System.Address; Line : Integer);
451 procedure Rcheck_26 (File : System.Address; Line : Integer);
452 procedure Rcheck_27 (File : System.Address; Line : Integer);
453 procedure Rcheck_28 (File : System.Address; Line : Integer);
454 procedure Rcheck_29 (File : System.Address; Line : Integer);
455 procedure Rcheck_30 (File : System.Address; Line : Integer);
457 pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
458 pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
459 pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
460 pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
461 pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
462 pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
463 pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
464 pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
465 pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
466 pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
467 pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
468 pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
469 pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
470 pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
471 pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
472 pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
473 pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
474 pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
475 pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
476 pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
477 pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
478 pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
479 pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
480 pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
481 pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
482 pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
483 pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
484 pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
485 pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
486 pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
487 pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
489 -- None of these procedures ever returns (they raise an exception!). By
490 -- using pragma No_Return, we ensure that any junk code after the call,
491 -- such as normal return epilog stuff, can be eliminated).
493 pragma No_Return (Rcheck_00);
494 pragma No_Return (Rcheck_01);
495 pragma No_Return (Rcheck_02);
496 pragma No_Return (Rcheck_03);
497 pragma No_Return (Rcheck_04);
498 pragma No_Return (Rcheck_05);
499 pragma No_Return (Rcheck_06);
500 pragma No_Return (Rcheck_07);
501 pragma No_Return (Rcheck_08);
502 pragma No_Return (Rcheck_09);
503 pragma No_Return (Rcheck_10);
504 pragma No_Return (Rcheck_11);
505 pragma No_Return (Rcheck_12);
506 pragma No_Return (Rcheck_13);
507 pragma No_Return (Rcheck_14);
508 pragma No_Return (Rcheck_15);
509 pragma No_Return (Rcheck_16);
510 pragma No_Return (Rcheck_17);
511 pragma No_Return (Rcheck_18);
512 pragma No_Return (Rcheck_19);
513 pragma No_Return (Rcheck_20);
514 pragma No_Return (Rcheck_21);
515 pragma No_Return (Rcheck_22);
516 pragma No_Return (Rcheck_23);
517 pragma No_Return (Rcheck_24);
518 pragma No_Return (Rcheck_25);
519 pragma No_Return (Rcheck_26);
520 pragma No_Return (Rcheck_27);
521 pragma No_Return (Rcheck_28);
522 pragma No_Return (Rcheck_29);
523 pragma No_Return (Rcheck_30);
525 ---------------------------------------------
526 -- Reason Strings for Run-Time Check Calls --
527 ---------------------------------------------
529 -- These strings are null-terminated and are used by Rcheck_nn. The
530 -- strings correspond to the definitions for Types.RT_Exception_Code.
532 use ASCII;
534 Rmsg_00 : constant String := "access check failed" & NUL;
535 Rmsg_01 : constant String := "access parameter is null" & NUL;
536 Rmsg_02 : constant String := "discriminant check failed" & NUL;
537 Rmsg_03 : constant String := "divide by zero" & NUL;
538 Rmsg_04 : constant String := "explicit raise" & NUL;
539 Rmsg_05 : constant String := "index check failed" & NUL;
540 Rmsg_06 : constant String := "invalid data" & NUL;
541 Rmsg_07 : constant String := "length check failed" & NUL;
542 Rmsg_08 : constant String := "null-exclusion check failed" & NUL;
543 Rmsg_09 : constant String := "overflow check failed" & NUL;
544 Rmsg_10 : constant String := "partition check failed" & NUL;
545 Rmsg_11 : constant String := "range check failed" & NUL;
546 Rmsg_12 : constant String := "tag check failed" & NUL;
547 Rmsg_13 : constant String := "access before elaboration" & NUL;
548 Rmsg_14 : constant String := "accessibility check failed" & NUL;
549 Rmsg_15 : constant String := "all guards closed" & NUL;
550 Rmsg_16 : constant String := "duplicated entry address" & NUL;
551 Rmsg_17 : constant String := "explicit raise" & NUL;
552 Rmsg_18 : constant String := "finalize/adjust raised exception" & NUL;
553 Rmsg_19 : constant String := "misaligned address value" & NUL;
554 Rmsg_20 : constant String := "missing return" & NUL;
555 Rmsg_21 : constant String := "overlaid controlled object" & NUL;
556 Rmsg_22 : constant String := "potentially blocking operation" & NUL;
557 Rmsg_23 : constant String := "stubbed subprogram called" & NUL;
558 Rmsg_24 : constant String := "unchecked union restriction" & NUL;
559 Rmsg_25 : constant String := "illegal use of"
560 & " remote access-to-class-wide type, see RM E.4(18)" & NUL;
561 Rmsg_26 : constant String := "empty storage pool" & NUL;
562 Rmsg_27 : constant String := "explicit raise" & NUL;
563 Rmsg_28 : constant String := "infinite recursion" & NUL;
564 Rmsg_29 : constant String := "object too large" & NUL;
565 Rmsg_30 : constant String := "restriction violation" & NUL;
567 -----------------------
568 -- Polling Interface --
569 -----------------------
571 type Unsigned is mod 2 ** 32;
573 Counter : Unsigned := 0;
574 pragma Warnings (Off, Counter);
575 -- This counter is provided for convenience. It can be used in Poll to
576 -- perform periodic but not systematic operations.
578 procedure Poll is separate;
579 -- The actual polling routine is separate, so that it can easily
580 -- be replaced with a target dependent version.
582 --------------------------
583 -- Code_Address_For_AAA --
584 --------------------------
586 -- This function gives us the start of the PC range for addresses
587 -- within the exception unit itself. We hope that gigi/gcc keep all the
588 -- procedures in their original order!
590 function Code_Address_For_AAA return System.Address is
591 begin
592 -- We are using a label instead of merely using
593 -- Code_Address_For_AAA'Address because on some platforms the latter
594 -- does not yield the address we want, but the address of a stub or of
595 -- a descriptor instead. This is the case at least on Alpha-VMS and
596 -- PA-HPUX.
598 <<Start_Of_AAA>>
599 return Start_Of_AAA'Address;
600 end Code_Address_For_AAA;
602 ----------------
603 -- Call_Chain --
604 ----------------
606 procedure Call_Chain (Excep : EOA) is separate;
607 -- The actual Call_Chain routine is separate, so that it can easily
608 -- be dummied out when no exception traceback information is needed.
610 ------------------------------
611 -- Current_Target_Exception --
612 ------------------------------
614 function Current_Target_Exception return Exception_Occurrence is
615 begin
616 return Null_Occurrence;
617 end Current_Target_Exception;
619 -------------------
620 -- EId_To_String --
621 -------------------
623 function EId_To_String (X : Exception_Id) return String
624 renames Stream_Attributes.EId_To_String;
626 ------------------
627 -- EO_To_String --
628 ------------------
630 -- We use the null string to represent the null occurrence, otherwise
631 -- we output the Exception_Information string for the occurrence.
633 function EO_To_String (X : Exception_Occurrence) return String
634 renames Stream_Attributes.EO_To_String;
636 ------------------------
637 -- Exception_Identity --
638 ------------------------
640 function Exception_Identity
641 (X : Exception_Occurrence) return Exception_Id
643 begin
644 -- Note that the following test used to be here for the original
645 -- Ada 95 semantics, but these were modified by AI-241 to require
646 -- returning Null_Id instead of raising Constraint_Error.
648 -- if X.Id = Null_Id then
649 -- raise Constraint_Error;
650 -- end if;
652 return X.Id;
653 end Exception_Identity;
655 ---------------------------
656 -- Exception_Information --
657 ---------------------------
659 function Exception_Information (X : Exception_Occurrence) return String is
660 begin
661 if X.Id = Null_Id then
662 raise Constraint_Error;
663 end if;
665 return Exception_Data.Exception_Information (X);
666 end Exception_Information;
668 -----------------------
669 -- Exception_Message --
670 -----------------------
672 function Exception_Message (X : Exception_Occurrence) return String is
673 begin
674 if X.Id = Null_Id then
675 raise Constraint_Error;
676 end if;
678 return X.Msg (1 .. X.Msg_Length);
679 end Exception_Message;
681 --------------------
682 -- Exception_Name --
683 --------------------
685 function Exception_Name (Id : Exception_Id) return String is
686 begin
687 if Id = null then
688 raise Constraint_Error;
689 end if;
691 return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
692 end Exception_Name;
694 function Exception_Name (X : Exception_Occurrence) return String is
695 begin
696 return Exception_Name (X.Id);
697 end Exception_Name;
699 ---------------------------
700 -- Exception_Name_Simple --
701 ---------------------------
703 function Exception_Name_Simple (X : Exception_Occurrence) return String is
704 Name : constant String := Exception_Name (X);
705 P : Natural;
707 begin
708 P := Name'Length;
709 while P > 1 loop
710 exit when Name (P - 1) = '.';
711 P := P - 1;
712 end loop;
714 -- Return result making sure lower bound is 1
716 declare
717 subtype Rname is String (1 .. Name'Length - P + 1);
718 begin
719 return Rname (Name (P .. Name'Length));
720 end;
721 end Exception_Name_Simple;
723 --------------------
724 -- Exception_Data --
725 --------------------
727 package body Exception_Data is separate;
728 -- This package can be easily dummied out if we do not want the
729 -- basic support for exception messages (such as in Ada 83).
731 ---------------------------
732 -- Exception_Propagation --
733 ---------------------------
735 package body Exception_Propagation is separate;
736 -- Depending on the actual exception mechanism used (front-end or
737 -- back-end based), the implementation will differ, which is why this
738 -- package is separated.
740 ----------------------
741 -- Exception_Traces --
742 ----------------------
744 package body Exception_Traces is separate;
745 -- Depending on the underlying support for IO the implementation
746 -- will differ. Moreover we would like to dummy out this package
747 -- in case we do not want any exception tracing support. This is
748 -- why this package is separated.
750 -----------------------
751 -- Stream Attributes --
752 -----------------------
754 package body Stream_Attributes is separate;
755 -- This package can be easily dummied out if we do not want the
756 -- support for streaming Exception_Ids and Exception_Occurrences.
758 -----------------------------
759 -- Process_Raise_Exception --
760 -----------------------------
762 procedure Process_Raise_Exception
763 (E : Exception_Id;
764 From_Signal_Handler : Boolean)
766 pragma Inspection_Point (E);
767 -- This is so the debugger can reliably inspect the parameter
768 begin
769 -- WARNING: There should be no exception handler for this body
770 -- because this would cause gigi to prepend a setup for a new
771 -- jmpbuf to the sequence of statements in case of built-in sjljl.
772 -- We would then always get this new buf in Jumpbuf_Ptr instead of the
773 -- one for the exception we are handling, which would completely break
774 -- the whole design of this procedure.
776 Exception_Propagation.Propagate_Exception (From_Signal_Handler);
777 end Process_Raise_Exception;
779 ----------------------------
780 -- Raise_Constraint_Error --
781 ----------------------------
783 procedure Raise_Constraint_Error
784 (File : System.Address;
785 Line : Integer)
787 begin
788 Raise_With_Location_And_Msg
789 (Constraint_Error_Def'Access, File, Line);
790 end Raise_Constraint_Error;
792 --------------------------------
793 -- Raise_Constraint_Error_Msg --
794 --------------------------------
796 procedure Raise_Constraint_Error_Msg
797 (File : System.Address;
798 Line : Integer;
799 Msg : System.Address)
801 begin
802 Raise_With_Location_And_Msg
803 (Constraint_Error_Def'Access, File, Line, Msg);
804 end Raise_Constraint_Error_Msg;
806 -------------------------
807 -- Raise_Current_Excep --
808 -------------------------
810 procedure Raise_Current_Excep (E : Exception_Id) is
812 pragma Inspection_Point (E);
813 -- This is so the debugger can reliably inspect the parameter when
814 -- inserting a breakpoint at the start of this procedure.
816 Id : Exception_Id := E;
817 pragma Volatile (Id);
818 pragma Warnings (Off, Id);
819 -- In order to provide support for breakpoints on unhandled exceptions,
820 -- the debugger will also need to be able to inspect the value of E from
821 -- another (inner) frame. So we need to make sure that if E is passed in
822 -- a register, its value is also spilled on stack. For this, we store
823 -- the parameter value in a local variable, and add a pragma Volatile to
824 -- make sure it is spilled. The pragma Warnings (Off) is needed because
825 -- the compiler knows that Id is not referenced and that this use of
826 -- pragma Volatile is peculiar!
828 begin
829 Process_Raise_Exception (E => E, From_Signal_Handler => False);
830 end Raise_Current_Excep;
832 ---------------------
833 -- Raise_Exception --
834 ---------------------
836 procedure Raise_Exception
837 (E : Exception_Id;
838 Message : String := "")
840 begin
841 if E /= null then
842 Exception_Data.Set_Exception_Msg (E, Message);
843 Abort_Defer.all;
844 Raise_Current_Excep (E);
845 end if;
846 end Raise_Exception;
848 ----------------------------
849 -- Raise_Exception_Always --
850 ----------------------------
852 procedure Raise_Exception_Always
853 (E : Exception_Id;
854 Message : String := "")
856 begin
857 Exception_Data.Set_Exception_Msg (E, Message);
858 Abort_Defer.all;
859 Raise_Current_Excep (E);
860 end Raise_Exception_Always;
862 -------------------------------
863 -- Raise_From_Signal_Handler --
864 -------------------------------
866 procedure Raise_From_Signal_Handler
867 (E : Exception_Id;
868 M : System.Address)
870 begin
871 Exception_Data.Set_Exception_C_Msg (E, M);
872 Abort_Defer.all;
873 Process_Raise_Exception (E => E, From_Signal_Handler => True);
874 end Raise_From_Signal_Handler;
876 -------------------------
877 -- Raise_Program_Error --
878 -------------------------
880 procedure Raise_Program_Error
881 (File : System.Address;
882 Line : Integer)
884 begin
885 Raise_With_Location_And_Msg
886 (Program_Error_Def'Access, File, Line);
887 end Raise_Program_Error;
889 -----------------------------
890 -- Raise_Program_Error_Msg --
891 -----------------------------
893 procedure Raise_Program_Error_Msg
894 (File : System.Address;
895 Line : Integer;
896 Msg : System.Address)
898 begin
899 Raise_With_Location_And_Msg
900 (Program_Error_Def'Access, File, Line, Msg);
901 end Raise_Program_Error_Msg;
903 -------------------------
904 -- Raise_Storage_Error --
905 -------------------------
907 procedure Raise_Storage_Error
908 (File : System.Address;
909 Line : Integer)
911 begin
912 Raise_With_Location_And_Msg
913 (Storage_Error_Def'Access, File, Line);
914 end Raise_Storage_Error;
916 -----------------------------
917 -- Raise_Storage_Error_Msg --
918 -----------------------------
920 procedure Raise_Storage_Error_Msg
921 (File : System.Address;
922 Line : Integer;
923 Msg : System.Address)
925 begin
926 Raise_With_Location_And_Msg
927 (Storage_Error_Def'Access, File, Line, Msg);
928 end Raise_Storage_Error_Msg;
930 ---------------------------------
931 -- Raise_With_Location_And_Msg --
932 ---------------------------------
934 procedure Raise_With_Location_And_Msg
935 (E : Exception_Id;
936 F : System.Address;
937 L : Integer;
938 M : System.Address := System.Null_Address)
940 begin
941 Exception_Data.Set_Exception_C_Msg (E, F, L, M);
942 Abort_Defer.all;
943 Raise_Current_Excep (E);
944 end Raise_With_Location_And_Msg;
946 --------------------
947 -- Raise_With_Msg --
948 --------------------
950 procedure Raise_With_Msg (E : Exception_Id) is
951 Excep : constant EOA := Get_Current_Excep.all;
953 begin
954 Exception_Propagation.Setup_Exception (Excep, Excep);
956 Excep.Exception_Raised := False;
957 Excep.Id := E;
958 Excep.Num_Tracebacks := 0;
959 Excep.Cleanup_Flag := False;
960 Excep.Pid := Local_Partition_ID;
961 Abort_Defer.all;
962 Raise_Current_Excep (E);
963 end Raise_With_Msg;
965 --------------------------------------
966 -- Calls to Run-Time Check Routines --
967 --------------------------------------
969 procedure Rcheck_00 (File : System.Address; Line : Integer) is
970 begin
971 Raise_Constraint_Error_Msg (File, Line, Rmsg_00'Address);
972 end Rcheck_00;
974 procedure Rcheck_01 (File : System.Address; Line : Integer) is
975 begin
976 Raise_Constraint_Error_Msg (File, Line, Rmsg_01'Address);
977 end Rcheck_01;
979 procedure Rcheck_02 (File : System.Address; Line : Integer) is
980 begin
981 Raise_Constraint_Error_Msg (File, Line, Rmsg_02'Address);
982 end Rcheck_02;
984 procedure Rcheck_03 (File : System.Address; Line : Integer) is
985 begin
986 Raise_Constraint_Error_Msg (File, Line, Rmsg_03'Address);
987 end Rcheck_03;
989 procedure Rcheck_04 (File : System.Address; Line : Integer) is
990 begin
991 Raise_Constraint_Error_Msg (File, Line, Rmsg_04'Address);
992 end Rcheck_04;
994 procedure Rcheck_05 (File : System.Address; Line : Integer) is
995 begin
996 Raise_Constraint_Error_Msg (File, Line, Rmsg_05'Address);
997 end Rcheck_05;
999 procedure Rcheck_06 (File : System.Address; Line : Integer) is
1000 begin
1001 Raise_Constraint_Error_Msg (File, Line, Rmsg_06'Address);
1002 end Rcheck_06;
1004 procedure Rcheck_07 (File : System.Address; Line : Integer) is
1005 begin
1006 Raise_Constraint_Error_Msg (File, Line, Rmsg_07'Address);
1007 end Rcheck_07;
1009 procedure Rcheck_08 (File : System.Address; Line : Integer) is
1010 begin
1011 Raise_Constraint_Error_Msg (File, Line, Rmsg_08'Address);
1012 end Rcheck_08;
1014 procedure Rcheck_09 (File : System.Address; Line : Integer) is
1015 begin
1016 Raise_Constraint_Error_Msg (File, Line, Rmsg_09'Address);
1017 end Rcheck_09;
1019 procedure Rcheck_10 (File : System.Address; Line : Integer) is
1020 begin
1021 Raise_Constraint_Error_Msg (File, Line, Rmsg_10'Address);
1022 end Rcheck_10;
1024 procedure Rcheck_11 (File : System.Address; Line : Integer) is
1025 begin
1026 Raise_Constraint_Error_Msg (File, Line, Rmsg_11'Address);
1027 end Rcheck_11;
1029 procedure Rcheck_12 (File : System.Address; Line : Integer) is
1030 begin
1031 Raise_Constraint_Error_Msg (File, Line, Rmsg_12'Address);
1032 end Rcheck_12;
1034 procedure Rcheck_13 (File : System.Address; Line : Integer) is
1035 begin
1036 Raise_Program_Error_Msg (File, Line, Rmsg_13'Address);
1037 end Rcheck_13;
1039 procedure Rcheck_14 (File : System.Address; Line : Integer) is
1040 begin
1041 Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1042 end Rcheck_14;
1044 procedure Rcheck_15 (File : System.Address; Line : Integer) is
1045 begin
1046 Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1047 end Rcheck_15;
1049 procedure Rcheck_16 (File : System.Address; Line : Integer) is
1050 begin
1051 Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1052 end Rcheck_16;
1054 procedure Rcheck_17 (File : System.Address; Line : Integer) is
1055 begin
1056 Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1057 end Rcheck_17;
1059 procedure Rcheck_18 (File : System.Address; Line : Integer) is
1060 begin
1061 Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1062 end Rcheck_18;
1064 procedure Rcheck_19 (File : System.Address; Line : Integer) is
1065 begin
1066 Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1067 end Rcheck_19;
1069 procedure Rcheck_20 (File : System.Address; Line : Integer) is
1070 begin
1071 Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1072 end Rcheck_20;
1074 procedure Rcheck_21 (File : System.Address; Line : Integer) is
1075 begin
1076 Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1077 end Rcheck_21;
1079 procedure Rcheck_22 (File : System.Address; Line : Integer) is
1080 begin
1081 Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1082 end Rcheck_22;
1084 procedure Rcheck_23 (File : System.Address; Line : Integer) is
1085 begin
1086 Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1087 end Rcheck_23;
1089 procedure Rcheck_24 (File : System.Address; Line : Integer) is
1090 begin
1091 Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1092 end Rcheck_24;
1094 procedure Rcheck_25 (File : System.Address; Line : Integer) is
1095 begin
1096 Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1097 end Rcheck_25;
1099 procedure Rcheck_26 (File : System.Address; Line : Integer) is
1100 begin
1101 Raise_Storage_Error_Msg (File, Line, Rmsg_26'Address);
1102 end Rcheck_26;
1104 procedure Rcheck_27 (File : System.Address; Line : Integer) is
1105 begin
1106 Raise_Storage_Error_Msg (File, Line, Rmsg_27'Address);
1107 end Rcheck_27;
1109 procedure Rcheck_28 (File : System.Address; Line : Integer) is
1110 begin
1111 Raise_Storage_Error_Msg (File, Line, Rmsg_28'Address);
1112 end Rcheck_28;
1114 procedure Rcheck_29 (File : System.Address; Line : Integer) is
1115 begin
1116 Raise_Storage_Error_Msg (File, Line, Rmsg_29'Address);
1117 end Rcheck_29;
1119 procedure Rcheck_30 (File : System.Address; Line : Integer) is
1120 begin
1121 Raise_Storage_Error_Msg (File, Line, Rmsg_30'Address);
1122 end Rcheck_30;
1124 -------------
1125 -- Reraise --
1126 -------------
1128 procedure Reraise is
1129 Excep : constant EOA := Get_Current_Excep.all;
1131 begin
1132 Abort_Defer.all;
1133 Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1134 Raise_Current_Excep (Excep.Id);
1135 end Reraise;
1137 ------------------------
1138 -- Reraise_Occurrence --
1139 ------------------------
1141 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1142 begin
1143 if X.Id /= null then
1144 Abort_Defer.all;
1145 Exception_Propagation.Setup_Exception
1146 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1147 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1148 Raise_Current_Excep (X.Id);
1149 end if;
1150 end Reraise_Occurrence;
1152 -------------------------------
1153 -- Reraise_Occurrence_Always --
1154 -------------------------------
1156 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1157 begin
1158 Abort_Defer.all;
1159 Exception_Propagation.Setup_Exception
1160 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1161 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1162 Raise_Current_Excep (X.Id);
1163 end Reraise_Occurrence_Always;
1165 ---------------------------------
1166 -- Reraise_Occurrence_No_Defer --
1167 ---------------------------------
1169 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1170 begin
1171 Exception_Propagation.Setup_Exception
1172 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1173 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1174 Raise_Current_Excep (X.Id);
1175 end Reraise_Occurrence_No_Defer;
1177 ---------------------
1178 -- Save_Occurrence --
1179 ---------------------
1181 procedure Save_Occurrence
1182 (Target : out Exception_Occurrence;
1183 Source : Exception_Occurrence)
1185 begin
1186 Save_Occurrence_No_Private (Target, Source);
1187 end Save_Occurrence;
1189 function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1190 Target : constant EOA := new Exception_Occurrence;
1191 begin
1192 Save_Occurrence (Target.all, Source);
1193 return Target;
1194 end Save_Occurrence;
1196 --------------------------------
1197 -- Save_Occurrence_No_Private --
1198 --------------------------------
1200 procedure Save_Occurrence_No_Private
1201 (Target : out Exception_Occurrence;
1202 Source : Exception_Occurrence)
1204 begin
1205 Target.Id := Source.Id;
1206 Target.Msg_Length := Source.Msg_Length;
1207 Target.Num_Tracebacks := Source.Num_Tracebacks;
1208 Target.Pid := Source.Pid;
1209 Target.Cleanup_Flag := Source.Cleanup_Flag;
1211 Target.Msg (1 .. Target.Msg_Length) :=
1212 Source.Msg (1 .. Target.Msg_Length);
1214 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1215 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1216 end Save_Occurrence_No_Private;
1218 -------------------------
1219 -- Transfer_Occurrence --
1220 -------------------------
1222 procedure Transfer_Occurrence
1223 (Target : Exception_Occurrence_Access;
1224 Source : Exception_Occurrence)
1226 begin
1227 -- Setup Target as an exception to be propagated in the calling task
1228 -- (rendezvous-wise), taking care not to clobber the associated private
1229 -- data. Target is expected to be a pointer to the calling task's
1230 -- fixed TSD occurrence, which is very different from Get_Current_Excep
1231 -- here because this subprogram is called from the called task.
1233 Exception_Propagation.Setup_Exception (Target, Target);
1234 Save_Occurrence_No_Private (Target.all, Source);
1235 end Transfer_Occurrence;
1237 -------------------
1238 -- String_To_EId --
1239 -------------------
1241 function String_To_EId (S : String) return Exception_Id
1242 renames Stream_Attributes.String_To_EId;
1244 ------------------
1245 -- String_To_EO --
1246 ------------------
1248 function String_To_EO (S : String) return Exception_Occurrence
1249 renames Stream_Attributes.String_To_EO;
1251 ------------------------------
1252 -- Raise_Exception_No_Defer --
1253 ------------------------------
1255 procedure Raise_Exception_No_Defer
1256 (E : Exception_Id;
1257 Message : String := "")
1259 begin
1260 Exception_Data.Set_Exception_Msg (E, Message);
1262 -- Do not call Abort_Defer.all, as specified by the spec
1264 Raise_Current_Excep (E);
1265 end Raise_Exception_No_Defer;
1267 ---------------
1268 -- To_Stderr --
1269 ---------------
1271 procedure To_Stderr (C : Character) is
1273 type int is new Integer;
1275 procedure put_char_stderr (C : int);
1276 pragma Import (C, put_char_stderr, "put_char_stderr");
1278 begin
1279 put_char_stderr (Character'Pos (C));
1280 end To_Stderr;
1282 procedure To_Stderr (S : String) is
1283 begin
1284 for J in S'Range loop
1285 if S (J) /= ASCII.CR then
1286 To_Stderr (S (J));
1287 end if;
1288 end loop;
1289 end To_Stderr;
1291 --------------------------
1292 -- Code_Address_For_ZZZ --
1293 --------------------------
1295 -- This function gives us the end of the PC range for addresses
1296 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1297 -- procedures in their original order!
1299 function Code_Address_For_ZZZ return System.Address is
1300 begin
1301 <<Start_Of_ZZZ>>
1302 return Start_Of_ZZZ'Address;
1303 end Code_Address_For_ZZZ;
1305 end Ada.Exceptions;