1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This version is used for all Ada 2005 builds. It differs from a-except.ads
35 -- only with respect to the addition of Wide_[Wide]Exception_Name functions.
37 -- The reason for this splitting off of a separate version is that bootstrap
38 -- compilers often will be used that do not support Ada 2005 features, and
39 -- Ada.Exceptions is part of the compiler sources.
41 -- The base version of this unit Ada.Exceptions omits the Wide version of
42 -- Exception_Name and is used to build the compiler and other basic tools.
44 pragma Style_Checks (All_Checks);
45 -- No subprogram ordering check, due to logical grouping
48 -- We must turn polling off for this unit, because otherwise we get
49 -- elaboration circularities with System.Exception_Tables.
51 with System; use System;
52 with System.Standard_Library; use System.Standard_Library;
53 with System.Soft_Links; use System.Soft_Links;
54 with System.WCh_Con; use System.WCh_Con;
55 with System.WCh_StW; use System.WCh_StW;
57 package body Ada.Exceptions is
59 pragma Suppress (All_Checks);
60 -- We definitely do not want exceptions occurring within this unit, or
61 -- we are in big trouble. If an exceptional situation does occur, better
62 -- that it not be raised, since raising it can cause confusing chaos.
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 -- Note: the exported subprograms in this package body are called directly
69 -- from C clients using the given external name, even though they are not
70 -- technically visible in the Ada sense.
72 function Code_Address_For_AAA return System.Address;
73 function Code_Address_For_ZZZ return System.Address;
74 -- Return start and end of procedures in this package
76 -- These procedures are used to provide exclusion bounds in
77 -- calls to Call_Chain at exception raise points from this unit. The
78 -- purpose is to arrange for the exception tracebacks not to include
79 -- frames from routines involved in the raise process, as these are
80 -- meaningless from the user's standpoint.
82 -- For these bounds to be meaningful, we need to ensure that the object
83 -- code for the routines involved in processing a raise is located after
84 -- the object code Code_Address_For_AAA and before the object code
85 -- Code_Address_For_ZZZ. This will indeed be the case as long as the
86 -- following rules are respected:
88 -- 1) The bodies of the subprograms involved in processing a raise
89 -- are located after the body of Code_Address_For_AAA and before the
90 -- body of Code_Address_For_ZZZ.
92 -- 2) No pragma Inline applies to any of these subprograms, as this
93 -- could delay the corresponding assembly output until the end of
96 procedure Call_Chain (Excep : EOA);
97 -- Store up to Max_Tracebacks in Excep, corresponding to the current
100 procedure To_Stderr (S : String);
101 pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
102 -- Little routine to output string to stderr that is also used
103 -- in the tasking run time.
105 procedure To_Stderr (C : Character);
106 pragma Inline (To_Stderr);
107 pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
108 -- Little routine to output a character to stderr, used by some of
109 -- the separate units below.
111 package Exception_Data is
113 ---------------------------------
114 -- Exception messages routines --
115 ---------------------------------
117 procedure Set_Exception_C_Msg
119 Msg1 : System.Address;
121 Msg2 : System.Address := System.Null_Address);
122 -- This routine is called to setup the exception referenced by the
123 -- Current_Excep field in the TSD to contain the indicated Id value
124 -- and message. Msg1 is a null terminated string which is generated
125 -- as the exception message. If line is non-zero, then a colon and
126 -- the decimal representation of this integer is appended to the
127 -- message. When Msg2 is non-null, a space and this additional null
128 -- terminated string is added to the message.
130 procedure Set_Exception_Msg
133 -- This routine is called to setup the exception referenced by the
134 -- Current_Excep field in the TSD to contain the indicated Id value
135 -- and message. Message is a string which is generated as the
136 -- exception message.
138 --------------------------------------
139 -- Exception information subprogram --
140 --------------------------------------
142 function Exception_Information (X : Exception_Occurrence) return String;
143 -- The format of the exception information is as follows:
145 -- Exception_Name: <exception name> (as in Exception_Name)
146 -- Message: <message> (only if Exception_Message is empty)
147 -- PID=nnnn (only if != 0)
148 -- Call stack traceback locations: (only if at least one location)
149 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
151 -- The lines are separated by a ASCII.LF character.
152 -- The nnnn is the partition Id given as decimal digits.
153 -- The 0x... line represents traceback program counter locations, in
154 -- execution order with the first one being the exception location. It
157 -- The Exception_Name and Message lines are omitted in the abort
158 -- signal case, since this is not really an exception.
160 -- !! If the format of the generated string is changed, please note
161 -- !! that an equivalent modification to the routine String_To_EO must
162 -- !! be made to preserve proper functioning of the stream attributes.
164 ---------------------------------------
165 -- Exception backtracing subprograms --
166 ---------------------------------------
168 -- What is automatically output when exception tracing is on is the
169 -- usual exception information with the call chain backtrace possibly
170 -- tailored by a backtrace decorator. Modifying Exception_Information
171 -- itself is not a good idea because the decorated output is completely
172 -- out of control and would break all our code related to the streaming
173 -- of exceptions. We then provide an alternative function to compute
174 -- the possibly tailored output, which is equivalent if no decorator is
177 function Tailored_Exception_Information
178 (X : Exception_Occurrence) return String;
179 -- Exception information to be output in the case of automatic tracing
180 -- requested through GNAT.Exception_Traces.
182 -- This is the same as Exception_Information if no backtrace decorator
183 -- is currently in place. Otherwise, this is Exception_Information with
184 -- the call chain raw addresses replaced by the result of a call to the
185 -- current decorator provided with the call chain addresses.
188 (Ada, Tailored_Exception_Information,
189 "__gnat_tailored_exception_information");
190 -- This is currently used by System.Tasking.Stages
194 package Exception_Traces is
197 -- Imports Tailored_Exception_Information
199 ----------------------------------------------
200 -- Run-Time Exception Notification Routines --
201 ----------------------------------------------
203 -- These subprograms provide a common run-time interface to trigger the
204 -- actions required when an exception is about to be propagated (e.g.
205 -- user specified actions or output of exception information). They are
206 -- exported to be usable by the Ada exception handling personality
207 -- routine when the GCC 3 mechanism is used.
209 procedure Notify_Handled_Exception;
211 (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
212 -- This routine is called for a handled occurrence is about to be
215 procedure Notify_Unhandled_Exception;
217 (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
218 -- This routine is called when an unhandled occurrence is about to be
221 procedure Unhandled_Exception_Terminate;
222 pragma No_Return (Unhandled_Exception_Terminate);
223 -- This procedure is called to terminate execution following an
224 -- unhandled exception. The exception information, including
225 -- traceback if available is output, and execution is then
226 -- terminated. Note that at the point where this routine is
227 -- called, the stack has typically been destroyed.
229 end Exception_Traces;
231 package Exception_Propagation is
233 use Exception_Traces;
234 -- Imports Notify_Unhandled_Exception and
235 -- Unhandled_Exception_Terminate
237 ------------------------------------
238 -- Exception propagation routines --
239 ------------------------------------
241 procedure Setup_Exception
244 Reraised : Boolean := False);
245 -- Perform the necessary operations to prepare the propagation of Excep
246 -- in a task where Current is the current occurrence. Excep is assumed
247 -- to be a valid (non null) pointer.
249 -- This should be called before any (re-)setting of the current
250 -- occurrence. Any such (re-)setting shall take care *not* to clobber
251 -- the Private_Data component.
253 -- Having Current provided as an argument (instead of retrieving it via
254 -- Get_Current_Excep internally) is required to allow one task to setup
255 -- an exception for another task, which is used by Transfer_Occurrence.
257 procedure Propagate_Exception
259 From_Signal_Handler : Boolean);
260 pragma No_Return (Propagate_Exception);
261 -- This procedure propagates the exception represented by the occurrence
262 -- referenced by Current_Excep in the TSD for the current task.
264 end Exception_Propagation;
266 package Stream_Attributes is
268 --------------------------------
269 -- Stream attributes routines --
270 --------------------------------
272 function EId_To_String (X : Exception_Id) return String;
273 function String_To_EId (S : String) return Exception_Id;
274 -- Functions for implementing Exception_Id stream attributes
276 function EO_To_String (X : Exception_Occurrence) return String;
277 function String_To_EO (S : String) return Exception_Occurrence;
278 -- Functions for implementing Exception_Occurrence stream
281 end Stream_Attributes;
283 procedure Raise_Current_Excep (E : Exception_Id);
284 pragma No_Return (Raise_Current_Excep);
285 pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
286 -- This is a simple wrapper to Exception_Propagation.Propagate_Exception
287 -- setting the From_Signal_Handler argument to False.
289 -- This external name for Raise_Current_Excep is historical, and probably
290 -- should be changed but for now we keep it, because gdb and gigi know
293 procedure Raise_Exception_No_Defer
294 (E : Exception_Id; Message : String := "");
296 (Ada, Raise_Exception_No_Defer,
297 "ada__exceptions__raise_exception_no_defer");
298 pragma No_Return (Raise_Exception_No_Defer);
299 -- Similar to Raise_Exception, but with no abort deferral
301 procedure Raise_With_Msg (E : Exception_Id);
302 pragma No_Return (Raise_With_Msg);
303 pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
304 -- Raises an exception with given exception id value. A message
305 -- is associated with the raise, and has already been stored in the
306 -- exception occurrence referenced by the Current_Excep in the TSD.
307 -- Abort is deferred before the raise call.
309 procedure Raise_With_Location_And_Msg
313 M : System.Address := System.Null_Address);
314 pragma No_Return (Raise_With_Location_And_Msg);
315 -- Raise an exception with given exception id value. A filename and line
316 -- number is associated with the raise and is stored in the exception
317 -- occurrence and in addition a string message M is appended to
318 -- this (if M is not null).
320 procedure Raise_Constraint_Error
321 (File : System.Address;
323 pragma No_Return (Raise_Constraint_Error);
325 (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
326 -- Raise constraint error with file:line information
328 procedure Raise_Constraint_Error_Msg
329 (File : System.Address;
331 Msg : System.Address);
332 pragma No_Return (Raise_Constraint_Error_Msg);
334 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
335 -- Raise constraint error with file:line + msg information
337 procedure Raise_Program_Error
338 (File : System.Address;
340 pragma No_Return (Raise_Program_Error);
342 (C, Raise_Program_Error, "__gnat_raise_program_error");
343 -- Raise program error with file:line information
345 procedure Raise_Program_Error_Msg
346 (File : System.Address;
348 Msg : System.Address);
349 pragma No_Return (Raise_Program_Error_Msg);
351 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
352 -- Raise program error with file:line + msg information
354 procedure Raise_Storage_Error
355 (File : System.Address;
357 pragma No_Return (Raise_Storage_Error);
359 (C, Raise_Storage_Error, "__gnat_raise_storage_error");
360 -- Raise storage error with file:line information
362 procedure Raise_Storage_Error_Msg
363 (File : System.Address;
365 Msg : System.Address);
366 pragma No_Return (Raise_Storage_Error_Msg);
368 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
369 -- Raise storage error with file:line + reason msg information
371 -- The exception raising process and the automatic tracing mechanism rely
372 -- on some careful use of flags attached to the exception occurrence. The
373 -- graph below illustrates the relations between the Raise_ subprograms
374 -- and identifies the points where basic flags such as Exception_Raised
377 -- (i) signs indicate the flags initialization points. R stands for Raise,
378 -- W for With, and E for Exception.
380 -- R_No_Msg R_E R_Pe R_Ce R_Se
382 -- +--+ +--+ +---+ | +---+
384 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
386 -- +------------+ | +-----------+ +--+
388 -- | | | Set_E_C_Msg(i)
390 -- Raise_Current_Excep
393 pragma No_Return (Reraise);
394 pragma Export (C, Reraise, "__gnat_reraise");
395 -- Reraises the exception referenced by the Current_Excep field of
396 -- the TSD (all fields of this exception occurrence are set). Abort
397 -- is deferred before the reraise operation.
399 -- Save_Occurrence variations: As the management of the private data
400 -- attached to occurrences is delicate, wether or not pointers to such
401 -- data has to be copied in various situations is better made explicit.
402 -- The following procedures provide an internal interface to help making
405 procedure Save_Occurrence_No_Private
406 (Target : out Exception_Occurrence;
407 Source : Exception_Occurrence);
408 -- Copy all the components of Source to Target, except the
409 -- Private_Data pointer.
411 procedure Transfer_Occurrence
412 (Target : Exception_Occurrence_Access;
413 Source : Exception_Occurrence);
414 pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
415 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
416 -- to setup Target from Source as an exception to be propagated in the
417 -- caller task. Target is expected to be a pointer to the fixed TSD
418 -- occurrence for this task.
420 -----------------------------
421 -- Run-Time Check Routines --
422 -----------------------------
424 -- These routines are called from the runtime to raise a specific
425 -- exception with a reason message attached. The parameters are
426 -- the file name and line number in each case. The names are keyed
427 -- to the codes defined in Types.ads and a-types.h (for example,
428 -- the name Rcheck_05 refers to the Reason whose Pos code is 5).
430 procedure Rcheck_00 (File : System.Address; Line : Integer);
431 procedure Rcheck_01 (File : System.Address; Line : Integer);
432 procedure Rcheck_02 (File : System.Address; Line : Integer);
433 procedure Rcheck_03 (File : System.Address; Line : Integer);
434 procedure Rcheck_04 (File : System.Address; Line : Integer);
435 procedure Rcheck_05 (File : System.Address; Line : Integer);
436 procedure Rcheck_06 (File : System.Address; Line : Integer);
437 procedure Rcheck_07 (File : System.Address; Line : Integer);
438 procedure Rcheck_08 (File : System.Address; Line : Integer);
439 procedure Rcheck_09 (File : System.Address; Line : Integer);
440 procedure Rcheck_10 (File : System.Address; Line : Integer);
441 procedure Rcheck_11 (File : System.Address; Line : Integer);
442 procedure Rcheck_12 (File : System.Address; Line : Integer);
443 procedure Rcheck_13 (File : System.Address; Line : Integer);
444 procedure Rcheck_14 (File : System.Address; Line : Integer);
445 procedure Rcheck_15 (File : System.Address; Line : Integer);
446 procedure Rcheck_16 (File : System.Address; Line : Integer);
447 procedure Rcheck_17 (File : System.Address; Line : Integer);
448 procedure Rcheck_18 (File : System.Address; Line : Integer);
449 procedure Rcheck_19 (File : System.Address; Line : Integer);
450 procedure Rcheck_20 (File : System.Address; Line : Integer);
451 procedure Rcheck_21 (File : System.Address; Line : Integer);
452 procedure Rcheck_22 (File : System.Address; Line : Integer);
453 procedure Rcheck_23 (File : System.Address; Line : Integer);
454 procedure Rcheck_24 (File : System.Address; Line : Integer);
455 procedure Rcheck_25 (File : System.Address; Line : Integer);
456 procedure Rcheck_26 (File : System.Address; Line : Integer);
457 procedure Rcheck_27 (File : System.Address; Line : Integer);
458 procedure Rcheck_28 (File : System.Address; Line : Integer);
459 procedure Rcheck_29 (File : System.Address; Line : Integer);
460 procedure Rcheck_30 (File : System.Address; Line : Integer);
461 procedure Rcheck_31 (File : System.Address; Line : Integer);
462 procedure Rcheck_32 (File : System.Address; Line : Integer);
464 pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
465 pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
466 pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
467 pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
468 pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
469 pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
470 pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
471 pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
472 pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
473 pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
474 pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
475 pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
476 pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
477 pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
478 pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
479 pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
480 pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
481 pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
482 pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
483 pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
484 pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
485 pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
486 pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
487 pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
488 pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
489 pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
490 pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
491 pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
492 pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
493 pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
494 pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
495 pragma Export (C, Rcheck_31, "__gnat_rcheck_31");
496 pragma Export (C, Rcheck_32, "__gnat_rcheck_32");
498 -- None of these procedures ever returns (they raise an exception!). By
499 -- using pragma No_Return, we ensure that any junk code after the call,
500 -- such as normal return epilog stuff, can be eliminated).
502 pragma No_Return (Rcheck_00);
503 pragma No_Return (Rcheck_01);
504 pragma No_Return (Rcheck_02);
505 pragma No_Return (Rcheck_03);
506 pragma No_Return (Rcheck_04);
507 pragma No_Return (Rcheck_05);
508 pragma No_Return (Rcheck_06);
509 pragma No_Return (Rcheck_07);
510 pragma No_Return (Rcheck_08);
511 pragma No_Return (Rcheck_09);
512 pragma No_Return (Rcheck_10);
513 pragma No_Return (Rcheck_11);
514 pragma No_Return (Rcheck_12);
515 pragma No_Return (Rcheck_13);
516 pragma No_Return (Rcheck_14);
517 pragma No_Return (Rcheck_15);
518 pragma No_Return (Rcheck_16);
519 pragma No_Return (Rcheck_17);
520 pragma No_Return (Rcheck_18);
521 pragma No_Return (Rcheck_19);
522 pragma No_Return (Rcheck_20);
523 pragma No_Return (Rcheck_21);
524 pragma No_Return (Rcheck_22);
525 pragma No_Return (Rcheck_23);
526 pragma No_Return (Rcheck_24);
527 pragma No_Return (Rcheck_25);
528 pragma No_Return (Rcheck_26);
529 pragma No_Return (Rcheck_27);
530 pragma No_Return (Rcheck_28);
531 pragma No_Return (Rcheck_29);
532 pragma No_Return (Rcheck_30);
533 pragma No_Return (Rcheck_32);
535 ---------------------------------------------
536 -- Reason Strings for Run-Time Check Calls --
537 ---------------------------------------------
539 -- These strings are null-terminated and are used by Rcheck_nn. The
540 -- strings correspond to the definitions for Types.RT_Exception_Code.
544 Rmsg_00 : constant String := "access check failed" & NUL;
545 Rmsg_01 : constant String := "access parameter is null" & NUL;
546 Rmsg_02 : constant String := "discriminant check failed" & NUL;
547 Rmsg_03 : constant String := "divide by zero" & NUL;
548 Rmsg_04 : constant String := "explicit raise" & NUL;
549 Rmsg_05 : constant String := "index check failed" & NUL;
550 Rmsg_06 : constant String := "invalid data" & NUL;
551 Rmsg_07 : constant String := "length check failed" & NUL;
552 Rmsg_08 : constant String := "null Exception_Id" & NUL;
553 Rmsg_09 : constant String := "null-exclusion check failed" & NUL;
554 Rmsg_10 : constant String := "overflow check failed" & NUL;
555 Rmsg_11 : constant String := "partition check failed" & NUL;
556 Rmsg_12 : constant String := "range check failed" & NUL;
557 Rmsg_13 : constant String := "tag check failed" & NUL;
558 Rmsg_14 : constant String := "access before elaboration" & NUL;
559 Rmsg_15 : constant String := "accessibility check failed" & NUL;
560 Rmsg_16 : constant String := "all guards closed" & NUL;
561 Rmsg_17 : constant String := "Current_Task referenced in entry" &
563 Rmsg_18 : constant String := "duplicated entry address" & NUL;
564 Rmsg_19 : constant String := "explicit raise" & NUL;
565 Rmsg_20 : constant String := "finalize/adjust raised exception" & NUL;
566 Rmsg_21 : constant String := "implicit return with No_Return" & NUL;
567 Rmsg_22 : constant String := "misaligned address value" & NUL;
568 Rmsg_23 : constant String := "missing return" & NUL;
569 Rmsg_24 : constant String := "overlaid controlled object" & NUL;
570 Rmsg_25 : constant String := "potentially blocking operation" & NUL;
571 Rmsg_26 : constant String := "stubbed subprogram called" & NUL;
572 Rmsg_27 : constant String := "unchecked union restriction" & NUL;
573 Rmsg_28 : constant String := "illegal use of remote access-to-" &
574 "class-wide type, see RM E.4(18)" & NUL;
575 Rmsg_29 : constant String := "empty storage pool" & NUL;
576 Rmsg_30 : constant String := "explicit raise" & NUL;
577 Rmsg_31 : constant String := "infinite recursion" & NUL;
578 Rmsg_32 : constant String := "object too large" & NUL;
580 -----------------------
581 -- Polling Interface --
582 -----------------------
584 type Unsigned is mod 2 ** 32;
586 Counter : Unsigned := 0;
587 pragma Warnings (Off, Counter);
588 -- This counter is provided for convenience. It can be used in Poll to
589 -- perform periodic but not systematic operations.
591 procedure Poll is separate;
592 -- The actual polling routine is separate, so that it can easily
593 -- be replaced with a target dependent version.
595 --------------------------
596 -- Code_Address_For_AAA --
597 --------------------------
599 -- This function gives us the start of the PC range for addresses
600 -- within the exception unit itself. We hope that gigi/gcc keep all the
601 -- procedures in their original order!
603 function Code_Address_For_AAA return System.Address is
605 -- We are using a label instead of merely using
606 -- Code_Address_For_AAA'Address because on some platforms the latter
607 -- does not yield the address we want, but the address of a stub or of
608 -- a descriptor instead. This is the case at least on Alpha-VMS and
612 return Start_Of_AAA'Address;
613 end Code_Address_For_AAA;
619 procedure Call_Chain (Excep : EOA) is separate;
620 -- The actual Call_Chain routine is separate, so that it can easily
621 -- be dummied out when no exception traceback information is needed.
623 ------------------------------
624 -- Current_Target_Exception --
625 ------------------------------
627 function Current_Target_Exception return Exception_Occurrence is
629 return Null_Occurrence;
630 end Current_Target_Exception;
636 function EId_To_String (X : Exception_Id) return String
637 renames Stream_Attributes.EId_To_String;
643 -- We use the null string to represent the null occurrence, otherwise
644 -- we output the Exception_Information string for the occurrence.
646 function EO_To_String (X : Exception_Occurrence) return String
647 renames Stream_Attributes.EO_To_String;
649 ------------------------
650 -- Exception_Identity --
651 ------------------------
653 function Exception_Identity
654 (X : Exception_Occurrence) return Exception_Id
657 -- Note that the following test used to be here for the original
658 -- Ada 95 semantics, but these were modified by AI-241 to require
659 -- returning Null_Id instead of raising Constraint_Error.
661 -- if X.Id = Null_Id then
662 -- raise Constraint_Error;
666 end Exception_Identity;
668 ---------------------------
669 -- Exception_Information --
670 ---------------------------
672 function Exception_Information (X : Exception_Occurrence) return String is
674 if X.Id = Null_Id then
675 raise Constraint_Error;
678 return Exception_Data.Exception_Information (X);
679 end Exception_Information;
681 -----------------------
682 -- Exception_Message --
683 -----------------------
685 function Exception_Message (X : Exception_Occurrence) return String is
687 if X.Id = Null_Id then
688 raise Constraint_Error;
691 return X.Msg (1 .. X.Msg_Length);
692 end Exception_Message;
698 function Exception_Name (Id : Exception_Id) return String is
701 raise Constraint_Error;
704 return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
707 function Exception_Name (X : Exception_Occurrence) return String is
709 return Exception_Name (X.Id);
712 ---------------------------
713 -- Exception_Name_Simple --
714 ---------------------------
716 function Exception_Name_Simple (X : Exception_Occurrence) return String is
717 Name : constant String := Exception_Name (X);
723 exit when Name (P - 1) = '.';
727 -- Return result making sure lower bound is 1
730 subtype Rname is String (1 .. Name'Length - P + 1);
732 return Rname (Name (P .. Name'Length));
734 end Exception_Name_Simple;
740 package body Exception_Data is separate;
741 -- This package can be easily dummied out if we do not want the
742 -- basic support for exception messages (such as in Ada 83).
744 ---------------------------
745 -- Exception_Propagation --
746 ---------------------------
748 package body Exception_Propagation is separate;
749 -- Depending on the actual exception mechanism used (front-end or
750 -- back-end based), the implementation will differ, which is why this
751 -- package is separated.
753 ----------------------
754 -- Exception_Traces --
755 ----------------------
757 package body Exception_Traces is separate;
758 -- Depending on the underlying support for IO the implementation
759 -- will differ. Moreover we would like to dummy out this package
760 -- in case we do not want any exception tracing support. This is
761 -- why this package is separated.
767 procedure Local_Raise (Excep : Exception_Id) is
768 pragma Warnings (Off, Excep);
773 -----------------------
774 -- Stream Attributes --
775 -----------------------
777 package body Stream_Attributes is separate;
778 -- This package can be easily dummied out if we do not want the
779 -- support for streaming Exception_Ids and Exception_Occurrences.
781 ----------------------------
782 -- Raise_Constraint_Error --
783 ----------------------------
785 procedure Raise_Constraint_Error
786 (File : System.Address;
790 Raise_With_Location_And_Msg
791 (Constraint_Error_Def'Access, File, Line);
792 end Raise_Constraint_Error;
794 --------------------------------
795 -- Raise_Constraint_Error_Msg --
796 --------------------------------
798 procedure Raise_Constraint_Error_Msg
799 (File : System.Address;
801 Msg : System.Address)
804 Raise_With_Location_And_Msg
805 (Constraint_Error_Def'Access, File, Line, Msg);
806 end Raise_Constraint_Error_Msg;
808 -------------------------
809 -- Raise_Current_Excep --
810 -------------------------
812 procedure Raise_Current_Excep (E : Exception_Id) is
814 pragma Inspection_Point (E);
815 -- This is so the debugger can reliably inspect the parameter when
816 -- inserting a breakpoint at the start of this procedure.
818 Id : Exception_Id := E;
819 pragma Volatile (Id);
820 pragma Warnings (Off, Id);
821 -- In order to provide support for breakpoints on unhandled exceptions,
822 -- the debugger will also need to be able to inspect the value of E from
823 -- another (inner) frame. So we need to make sure that if E is passed in
824 -- a register, its value is also spilled on stack. For this, we store
825 -- the parameter value in a local variable, and add a pragma Volatile to
826 -- make sure it is spilled. The pragma Warnings (Off) is needed because
827 -- the compiler knows that Id is not referenced and that this use of
828 -- pragma Volatile is peculiar!
831 Exception_Propagation.Propagate_Exception
832 (E => E, From_Signal_Handler => False);
833 end Raise_Current_Excep;
835 ---------------------
836 -- Raise_Exception --
837 ---------------------
839 procedure Raise_Exception
841 Message : String := "")
845 Exception_Data.Set_Exception_Msg (E, Message);
847 Raise_Current_Excep (E);
850 -- Note: if E is null, then we simply return, which is correct Ada 95
851 -- semantics. If we are operating in Ada 2005 mode, then the expander
852 -- generates a raise Constraint_Error immediately following the call
853 -- to provide the required Ada 2005 semantics (see AI-329). We do it
854 -- this way to avoid having run time dependencies on the Ada version.
859 ----------------------------
860 -- Raise_Exception_Always --
861 ----------------------------
863 procedure Raise_Exception_Always
865 Message : String := "")
868 Exception_Data.Set_Exception_Msg (E, Message);
870 Raise_Current_Excep (E);
871 end Raise_Exception_Always;
873 -------------------------------
874 -- Raise_From_Signal_Handler --
875 -------------------------------
877 procedure Raise_From_Signal_Handler
882 Exception_Data.Set_Exception_C_Msg (E, M);
884 Exception_Propagation.Propagate_Exception
885 (E => E, From_Signal_Handler => True);
886 end Raise_From_Signal_Handler;
888 -------------------------
889 -- Raise_Program_Error --
890 -------------------------
892 procedure Raise_Program_Error
893 (File : System.Address;
897 Raise_With_Location_And_Msg
898 (Program_Error_Def'Access, File, Line);
899 end Raise_Program_Error;
901 -----------------------------
902 -- Raise_Program_Error_Msg --
903 -----------------------------
905 procedure Raise_Program_Error_Msg
906 (File : System.Address;
908 Msg : System.Address)
911 Raise_With_Location_And_Msg
912 (Program_Error_Def'Access, File, Line, Msg);
913 end Raise_Program_Error_Msg;
915 -------------------------
916 -- Raise_Storage_Error --
917 -------------------------
919 procedure Raise_Storage_Error
920 (File : System.Address;
924 Raise_With_Location_And_Msg
925 (Storage_Error_Def'Access, File, Line);
926 end Raise_Storage_Error;
928 -----------------------------
929 -- Raise_Storage_Error_Msg --
930 -----------------------------
932 procedure Raise_Storage_Error_Msg
933 (File : System.Address;
935 Msg : System.Address)
938 Raise_With_Location_And_Msg
939 (Storage_Error_Def'Access, File, Line, Msg);
940 end Raise_Storage_Error_Msg;
942 ---------------------------------
943 -- Raise_With_Location_And_Msg --
944 ---------------------------------
946 procedure Raise_With_Location_And_Msg
950 M : System.Address := System.Null_Address)
953 Exception_Data.Set_Exception_C_Msg (E, F, L, M);
955 Raise_Current_Excep (E);
956 end Raise_With_Location_And_Msg;
962 procedure Raise_With_Msg (E : Exception_Id) is
963 Excep : constant EOA := Get_Current_Excep.all;
966 Exception_Propagation.Setup_Exception (Excep, Excep);
968 Excep.Exception_Raised := False;
970 Excep.Num_Tracebacks := 0;
971 Excep.Cleanup_Flag := False;
972 Excep.Pid := Local_Partition_ID;
974 Raise_Current_Excep (E);
977 --------------------------------------
978 -- Calls to Run-Time Check Routines --
979 --------------------------------------
981 procedure Rcheck_00 (File : System.Address; Line : Integer) is
983 Raise_Constraint_Error_Msg (File, Line, Rmsg_00'Address);
986 procedure Rcheck_01 (File : System.Address; Line : Integer) is
988 Raise_Constraint_Error_Msg (File, Line, Rmsg_01'Address);
991 procedure Rcheck_02 (File : System.Address; Line : Integer) is
993 Raise_Constraint_Error_Msg (File, Line, Rmsg_02'Address);
996 procedure Rcheck_03 (File : System.Address; Line : Integer) is
998 Raise_Constraint_Error_Msg (File, Line, Rmsg_03'Address);
1001 procedure Rcheck_04 (File : System.Address; Line : Integer) is
1003 Raise_Constraint_Error_Msg (File, Line, Rmsg_04'Address);
1006 procedure Rcheck_05 (File : System.Address; Line : Integer) is
1008 Raise_Constraint_Error_Msg (File, Line, Rmsg_05'Address);
1011 procedure Rcheck_06 (File : System.Address; Line : Integer) is
1013 Raise_Constraint_Error_Msg (File, Line, Rmsg_06'Address);
1016 procedure Rcheck_07 (File : System.Address; Line : Integer) is
1018 Raise_Constraint_Error_Msg (File, Line, Rmsg_07'Address);
1021 procedure Rcheck_08 (File : System.Address; Line : Integer) is
1023 Raise_Constraint_Error_Msg (File, Line, Rmsg_08'Address);
1026 procedure Rcheck_09 (File : System.Address; Line : Integer) is
1028 Raise_Constraint_Error_Msg (File, Line, Rmsg_09'Address);
1031 procedure Rcheck_10 (File : System.Address; Line : Integer) is
1033 Raise_Constraint_Error_Msg (File, Line, Rmsg_10'Address);
1036 procedure Rcheck_11 (File : System.Address; Line : Integer) is
1038 Raise_Constraint_Error_Msg (File, Line, Rmsg_11'Address);
1041 procedure Rcheck_12 (File : System.Address; Line : Integer) is
1043 Raise_Constraint_Error_Msg (File, Line, Rmsg_12'Address);
1046 procedure Rcheck_13 (File : System.Address; Line : Integer) is
1048 Raise_Constraint_Error_Msg (File, Line, Rmsg_13'Address);
1051 procedure Rcheck_14 (File : System.Address; Line : Integer) is
1053 Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1056 procedure Rcheck_15 (File : System.Address; Line : Integer) is
1058 Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1061 procedure Rcheck_16 (File : System.Address; Line : Integer) is
1063 Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1066 procedure Rcheck_17 (File : System.Address; Line : Integer) is
1068 Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1071 procedure Rcheck_18 (File : System.Address; Line : Integer) is
1073 Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1076 procedure Rcheck_19 (File : System.Address; Line : Integer) is
1078 Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1081 procedure Rcheck_20 (File : System.Address; Line : Integer) is
1083 Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1086 procedure Rcheck_21 (File : System.Address; Line : Integer) is
1088 Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1091 procedure Rcheck_22 (File : System.Address; Line : Integer) is
1093 Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1096 procedure Rcheck_23 (File : System.Address; Line : Integer) is
1098 Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1101 procedure Rcheck_24 (File : System.Address; Line : Integer) is
1103 Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1106 procedure Rcheck_25 (File : System.Address; Line : Integer) is
1108 Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1111 procedure Rcheck_26 (File : System.Address; Line : Integer) is
1113 Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1116 procedure Rcheck_27 (File : System.Address; Line : Integer) is
1118 Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1121 procedure Rcheck_28 (File : System.Address; Line : Integer) is
1123 Raise_Program_Error_Msg (File, Line, Rmsg_28'Address);
1126 procedure Rcheck_29 (File : System.Address; Line : Integer) is
1128 Raise_Storage_Error_Msg (File, Line, Rmsg_29'Address);
1131 procedure Rcheck_30 (File : System.Address; Line : Integer) is
1133 Raise_Storage_Error_Msg (File, Line, Rmsg_30'Address);
1136 procedure Rcheck_31 (File : System.Address; Line : Integer) is
1138 Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address);
1141 procedure Rcheck_32 (File : System.Address; Line : Integer) is
1143 Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1150 procedure Reraise is
1151 Excep : constant EOA := Get_Current_Excep.all;
1155 Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1156 Raise_Current_Excep (Excep.Id);
1159 ------------------------
1160 -- Reraise_Occurrence --
1161 ------------------------
1163 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1165 if X.Id /= null then
1167 Exception_Propagation.Setup_Exception
1168 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1169 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1170 Raise_Current_Excep (X.Id);
1172 end Reraise_Occurrence;
1174 -------------------------------
1175 -- Reraise_Occurrence_Always --
1176 -------------------------------
1178 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1181 Exception_Propagation.Setup_Exception
1182 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1183 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1184 Raise_Current_Excep (X.Id);
1185 end Reraise_Occurrence_Always;
1187 ---------------------------------
1188 -- Reraise_Occurrence_No_Defer --
1189 ---------------------------------
1191 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1193 Exception_Propagation.Setup_Exception
1194 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1195 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1196 Raise_Current_Excep (X.Id);
1197 end Reraise_Occurrence_No_Defer;
1199 ---------------------
1200 -- Save_Occurrence --
1201 ---------------------
1203 procedure Save_Occurrence
1204 (Target : out Exception_Occurrence;
1205 Source : Exception_Occurrence)
1208 Save_Occurrence_No_Private (Target, Source);
1209 end Save_Occurrence;
1211 function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1212 Target : constant EOA := new Exception_Occurrence;
1214 Save_Occurrence (Target.all, Source);
1216 end Save_Occurrence;
1218 --------------------------------
1219 -- Save_Occurrence_No_Private --
1220 --------------------------------
1222 procedure Save_Occurrence_No_Private
1223 (Target : out Exception_Occurrence;
1224 Source : Exception_Occurrence)
1227 Target.Id := Source.Id;
1228 Target.Msg_Length := Source.Msg_Length;
1229 Target.Num_Tracebacks := Source.Num_Tracebacks;
1230 Target.Pid := Source.Pid;
1231 Target.Cleanup_Flag := Source.Cleanup_Flag;
1233 Target.Msg (1 .. Target.Msg_Length) :=
1234 Source.Msg (1 .. Target.Msg_Length);
1236 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1237 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1238 end Save_Occurrence_No_Private;
1240 -------------------------
1241 -- Transfer_Occurrence --
1242 -------------------------
1244 procedure Transfer_Occurrence
1245 (Target : Exception_Occurrence_Access;
1246 Source : Exception_Occurrence)
1249 -- Setup Target as an exception to be propagated in the calling task
1250 -- (rendezvous-wise), taking care not to clobber the associated private
1251 -- data. Target is expected to be a pointer to the calling task's
1252 -- fixed TSD occurrence, which is very different from Get_Current_Excep
1253 -- here because this subprogram is called from the called task.
1255 Exception_Propagation.Setup_Exception (Target, Target);
1256 Save_Occurrence_No_Private (Target.all, Source);
1257 end Transfer_Occurrence;
1263 function String_To_EId (S : String) return Exception_Id
1264 renames Stream_Attributes.String_To_EId;
1270 function String_To_EO (S : String) return Exception_Occurrence
1271 renames Stream_Attributes.String_To_EO;
1273 ------------------------------
1274 -- Raise_Exception_No_Defer --
1275 ------------------------------
1277 procedure Raise_Exception_No_Defer
1279 Message : String := "")
1282 Exception_Data.Set_Exception_Msg (E, Message);
1284 -- Do not call Abort_Defer.all, as specified by the spec
1286 Raise_Current_Excep (E);
1287 end Raise_Exception_No_Defer;
1293 procedure To_Stderr (C : Character) is
1295 type int is new Integer;
1297 procedure put_char_stderr (C : int);
1298 pragma Import (C, put_char_stderr, "put_char_stderr");
1301 put_char_stderr (Character'Pos (C));
1304 procedure To_Stderr (S : String) is
1306 for J in S'Range loop
1307 if S (J) /= ASCII.CR then
1313 -------------------------
1314 -- Wide_Exception_Name --
1315 -------------------------
1317 WC_Encoding : Character;
1318 pragma Import (C, WC_Encoding, "__gl_wc_encoding");
1319 -- Encoding method for source, as exported by binder
1321 function Wide_Exception_Name
1322 (Id : Exception_Id) return Wide_String is
1324 return String_To_Wide_String
1325 (Exception_Name (Id), Get_WC_Encoding_Method (WC_Encoding));
1326 end Wide_Exception_Name;
1328 function Wide_Exception_Name
1329 (X : Exception_Occurrence) return Wide_String is
1331 return String_To_Wide_String
1332 (Exception_Name (X), Get_WC_Encoding_Method (WC_Encoding));
1333 end Wide_Exception_Name;
1335 ----------------------------
1336 -- Wide_Wide_Exception_Name --
1337 -----------------------------
1339 function Wide_Wide_Exception_Name
1340 (Id : Exception_Id) return Wide_Wide_String
1343 return String_To_Wide_Wide_String
1344 (Exception_Name (Id), Get_WC_Encoding_Method (WC_Encoding));
1345 end Wide_Wide_Exception_Name;
1347 function Wide_Wide_Exception_Name
1348 (X : Exception_Occurrence) return Wide_Wide_String
1351 return String_To_Wide_Wide_String
1352 (Exception_Name (X), Get_WC_Encoding_Method (WC_Encoding));
1353 end Wide_Wide_Exception_Name;
1355 --------------------------
1356 -- Code_Address_For_ZZZ --
1357 --------------------------
1359 -- This function gives us the end of the PC range for addresses
1360 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1361 -- procedures in their original order!
1363 function Code_Address_For_ZZZ return System.Address is
1366 return Start_Of_ZZZ'Address;
1367 end Code_Address_For_ZZZ;