1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2008, 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 of Ada.Exceptions fully supports both Ada 95 and Ada 2005.
35 -- It is used in all situations except for the build of the compiler and
36 -- other basic tools. For these latter builds, we use an Ada 95-only version.
38 -- The reason for this splitting off of a separate version is that bootstrap
39 -- compilers often will be used that do not support Ada 2005 features, and
40 -- Ada.Exceptions is part of the compiler sources.
42 pragma Style_Checks (All_Checks);
43 -- No subprogram ordering check, due to logical grouping
46 -- We must turn polling off for this unit, because otherwise we get
47 -- elaboration circularities with System.Exception_Tables.
49 with System; use System;
50 with System.Exceptions; use System.Exceptions;
51 with System.Standard_Library; use System.Standard_Library;
52 with System.Soft_Links; use System.Soft_Links;
53 with System.WCh_Con; use System.WCh_Con;
54 with System.WCh_StW; use System.WCh_StW;
56 package body Ada.Exceptions is
58 pragma Suppress (All_Checks);
59 -- We definitely do not want exceptions occurring within this unit, or
60 -- we are in big trouble. If an exceptional situation does occur, better
61 -- that it not be raised, since raising it can cause confusing chaos.
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 -- Note: the exported subprograms in this package body are called directly
68 -- from C clients using the given external name, even though they are not
69 -- technically visible in the Ada sense.
71 function Code_Address_For_AAA return System.Address;
72 function Code_Address_For_ZZZ return System.Address;
73 -- Return start and end of procedures in this package
75 -- These procedures are used to provide exclusion bounds in
76 -- calls to Call_Chain at exception raise points from this unit. The
77 -- purpose is to arrange for the exception tracebacks not to include
78 -- frames from routines involved in the raise process, as these are
79 -- meaningless from the user's standpoint.
81 -- For these bounds to be meaningful, we need to ensure that the object
82 -- code for the routines involved in processing a raise is located after
83 -- the object code Code_Address_For_AAA and before the object code
84 -- Code_Address_For_ZZZ. This will indeed be the case as long as the
85 -- following rules are respected:
87 -- 1) The bodies of the subprograms involved in processing a raise
88 -- are located after the body of Code_Address_For_AAA and before the
89 -- body of Code_Address_For_ZZZ.
91 -- 2) No pragma Inline applies to any of these subprograms, as this
92 -- could delay the corresponding assembly output until the end of
95 procedure Call_Chain (Excep : EOA);
96 -- Store up to Max_Tracebacks in Excep, corresponding to the current
99 procedure To_Stderr (S : String);
100 pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
101 -- Little routine to output string to stderr that is also used
102 -- in the tasking run time.
104 procedure To_Stderr (C : Character);
105 pragma Inline (To_Stderr);
106 pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
107 -- Little routine to output a character to stderr, used by some of
108 -- the separate units below.
110 package Exception_Data is
112 ---------------------------------
113 -- Exception messages routines --
114 ---------------------------------
116 procedure Set_Exception_C_Msg
118 Msg1 : System.Address;
120 Msg2 : System.Address := System.Null_Address);
121 -- This routine is called to setup the exception referenced by the
122 -- Current_Excep field in the TSD to contain the indicated Id value
123 -- and message. Msg1 is a null terminated string which is generated
124 -- as the exception message. If line is non-zero, then a colon and
125 -- the decimal representation of this integer is appended to the
126 -- message. When Msg2 is non-null, a space and this additional null
127 -- terminated string is added to the message.
129 procedure Set_Exception_Msg
132 -- This routine is called to setup the exception referenced by the
133 -- Current_Excep field in the TSD to contain the indicated Id value
134 -- and message. Message is a string which is generated as the
135 -- exception message.
137 --------------------------------------
138 -- Exception information subprogram --
139 --------------------------------------
141 function Exception_Information (X : Exception_Occurrence) return String;
142 -- The format of the exception information is as follows:
144 -- Exception_Name: <exception name> (as in Exception_Name)
145 -- Message: <message> (only if Exception_Message is empty)
146 -- PID=nnnn (only if != 0)
147 -- Call stack traceback locations: (only if at least one location)
148 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
150 -- The lines are separated by a ASCII.LF character.
151 -- The nnnn is the partition Id given as decimal digits.
152 -- The 0x... line represents traceback program counter locations, in
153 -- execution order with the first one being the exception location. It
156 -- The Exception_Name and Message lines are omitted in the abort
157 -- signal case, since this is not really an exception.
159 -- !! If the format of the generated string is changed, please note
160 -- !! that an equivalent modification to the routine String_To_EO must
161 -- !! be made to preserve proper functioning of the stream attributes.
163 ---------------------------------------
164 -- Exception backtracing subprograms --
165 ---------------------------------------
167 -- What is automatically output when exception tracing is on is the
168 -- usual exception information with the call chain backtrace possibly
169 -- tailored by a backtrace decorator. Modifying Exception_Information
170 -- itself is not a good idea because the decorated output is completely
171 -- out of control and would break all our code related to the streaming
172 -- of exceptions. We then provide an alternative function to compute
173 -- the possibly tailored output, which is equivalent if no decorator is
176 function Tailored_Exception_Information
177 (X : Exception_Occurrence) return String;
178 -- Exception information to be output in the case of automatic tracing
179 -- requested through GNAT.Exception_Traces.
181 -- This is the same as Exception_Information if no backtrace decorator
182 -- is currently in place. Otherwise, this is Exception_Information with
183 -- the call chain raw addresses replaced by the result of a call to the
184 -- current decorator provided with the call chain addresses.
187 (Ada, Tailored_Exception_Information,
188 "__gnat_tailored_exception_information");
189 -- This is currently used by System.Tasking.Stages
193 package Exception_Traces is
196 -- Imports Tailored_Exception_Information
198 ----------------------------------------------
199 -- Run-Time Exception Notification Routines --
200 ----------------------------------------------
202 -- These subprograms provide a common run-time interface to trigger the
203 -- actions required when an exception is about to be propagated (e.g.
204 -- user specified actions or output of exception information). They are
205 -- exported to be usable by the Ada exception handling personality
206 -- routine when the GCC 3 mechanism is used.
208 procedure Notify_Handled_Exception;
210 (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
211 -- This routine is called for a handled occurrence is about to be
214 procedure Notify_Unhandled_Exception;
216 (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
217 -- This routine is called when an unhandled occurrence is about to be
220 procedure Unhandled_Exception_Terminate;
221 pragma No_Return (Unhandled_Exception_Terminate);
222 -- This procedure is called to terminate execution following an
223 -- unhandled exception. The exception information, including
224 -- traceback if available is output, and execution is then
225 -- terminated. Note that at the point where this routine is
226 -- called, the stack has typically been destroyed.
228 end Exception_Traces;
230 package Exception_Propagation is
232 use Exception_Traces;
233 -- Imports Notify_Unhandled_Exception and
234 -- Unhandled_Exception_Terminate
236 ------------------------------------
237 -- Exception propagation routines --
238 ------------------------------------
240 procedure Setup_Exception
243 Reraised : Boolean := False);
244 -- Perform the necessary operations to prepare the propagation of Excep
245 -- in a task where Current is the current occurrence. Excep is assumed
246 -- to be a valid (non null) pointer.
248 -- This should be called before any (re-)setting of the current
249 -- occurrence. Any such (re-)setting shall take care *not* to clobber
250 -- the Private_Data component.
252 -- Having Current provided as an argument (instead of retrieving it via
253 -- Get_Current_Excep internally) is required to allow one task to setup
254 -- an exception for another task, which is used by Transfer_Occurrence.
256 procedure Propagate_Exception
258 From_Signal_Handler : Boolean);
259 pragma No_Return (Propagate_Exception);
260 -- This procedure propagates the exception represented by the occurrence
261 -- referenced by Current_Excep in the TSD for the current task.
263 end Exception_Propagation;
265 package Stream_Attributes is
267 --------------------------------
268 -- Stream attributes routines --
269 --------------------------------
271 function EId_To_String (X : Exception_Id) return String;
272 function String_To_EId (S : String) return Exception_Id;
273 -- Functions for implementing Exception_Id stream attributes
275 function EO_To_String (X : Exception_Occurrence) return String;
276 function String_To_EO (S : String) return Exception_Occurrence;
277 -- Functions for implementing Exception_Occurrence stream
280 end Stream_Attributes;
282 procedure Raise_Current_Excep (E : Exception_Id);
283 pragma No_Return (Raise_Current_Excep);
284 pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
285 -- This is a simple wrapper to Exception_Propagation.Propagate_Exception
286 -- setting the From_Signal_Handler argument to False.
288 -- This external name for Raise_Current_Excep is historical, and probably
289 -- should be changed but for now we keep it, because gdb and gigi know
292 procedure Raise_Exception_No_Defer
293 (E : Exception_Id; Message : String := "");
295 (Ada, Raise_Exception_No_Defer,
296 "ada__exceptions__raise_exception_no_defer");
297 pragma No_Return (Raise_Exception_No_Defer);
298 -- Similar to Raise_Exception, but with no abort deferral
300 procedure Raise_With_Msg (E : Exception_Id);
301 pragma No_Return (Raise_With_Msg);
302 pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
303 -- Raises an exception with given exception id value. A message
304 -- is associated with the raise, and has already been stored in the
305 -- exception occurrence referenced by the Current_Excep in the TSD.
306 -- Abort is deferred before the raise call.
308 procedure Raise_With_Location_And_Msg
312 M : System.Address := System.Null_Address);
313 pragma No_Return (Raise_With_Location_And_Msg);
314 -- Raise an exception with given exception id value. A filename and line
315 -- number is associated with the raise and is stored in the exception
316 -- occurrence and in addition a string message M is appended to
317 -- this (if M is not null).
319 procedure Raise_Constraint_Error
320 (File : System.Address;
322 pragma No_Return (Raise_Constraint_Error);
324 (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
325 -- Raise constraint error with file:line information
327 procedure Raise_Constraint_Error_Msg
328 (File : System.Address;
330 Msg : System.Address);
331 pragma No_Return (Raise_Constraint_Error_Msg);
333 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
334 -- Raise constraint error with file:line + msg information
336 procedure Raise_Program_Error
337 (File : System.Address;
339 pragma No_Return (Raise_Program_Error);
341 (C, Raise_Program_Error, "__gnat_raise_program_error");
342 -- Raise program error with file:line information
344 procedure Raise_Program_Error_Msg
345 (File : System.Address;
347 Msg : System.Address);
348 pragma No_Return (Raise_Program_Error_Msg);
350 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
351 -- Raise program error with file:line + msg information
353 procedure Raise_Storage_Error
354 (File : System.Address;
356 pragma No_Return (Raise_Storage_Error);
358 (C, Raise_Storage_Error, "__gnat_raise_storage_error");
359 -- Raise storage error with file:line information
361 procedure Raise_Storage_Error_Msg
362 (File : System.Address;
364 Msg : System.Address);
365 pragma No_Return (Raise_Storage_Error_Msg);
367 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
368 -- Raise storage error with file:line + reason msg information
370 -- The exception raising process and the automatic tracing mechanism rely
371 -- on some careful use of flags attached to the exception occurrence. The
372 -- graph below illustrates the relations between the Raise_ subprograms
373 -- and identifies the points where basic flags such as Exception_Raised
376 -- (i) signs indicate the flags initialization points. R stands for Raise,
377 -- W for With, and E for Exception.
379 -- R_No_Msg R_E R_Pe R_Ce R_Se
381 -- +--+ +--+ +---+ | +---+
383 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
385 -- +------------+ | +-----------+ +--+
387 -- | | | Set_E_C_Msg(i)
389 -- Raise_Current_Excep
392 pragma No_Return (Reraise);
393 pragma Export (C, Reraise, "__gnat_reraise");
394 -- Reraises the exception referenced by the Current_Excep field of
395 -- the TSD (all fields of this exception occurrence are set). Abort
396 -- is deferred before the reraise operation.
398 -- Save_Occurrence variations: As the management of the private data
399 -- attached to occurrences is delicate, whether or not pointers to such
400 -- data has to be copied in various situations is better made explicit.
401 -- The following procedures provide an internal interface to help making
404 procedure Save_Occurrence_No_Private
405 (Target : out Exception_Occurrence;
406 Source : Exception_Occurrence);
407 -- Copy all the components of Source to Target, except the
408 -- Private_Data pointer.
410 procedure Transfer_Occurrence
411 (Target : Exception_Occurrence_Access;
412 Source : Exception_Occurrence);
413 pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
414 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
415 -- to setup Target from Source as an exception to be propagated in the
416 -- caller task. Target is expected to be a pointer to the fixed TSD
417 -- occurrence for this task.
419 -----------------------------
420 -- Run-Time Check Routines --
421 -----------------------------
423 -- These routines raise a specific exception with a reason message
424 -- attached. The parameters are the file name and line number in each
425 -- case. The names are keyed to the codes defined in types.ads and
426 -- a-types.h (for example, the name Rcheck_05 refers to the Reason
427 -- RT_Exception_Code'Val (5)).
429 procedure Rcheck_00 (File : System.Address; Line : Integer);
430 procedure Rcheck_01 (File : System.Address; Line : Integer);
431 procedure Rcheck_02 (File : System.Address; Line : Integer);
432 procedure Rcheck_03 (File : System.Address; Line : Integer);
433 procedure Rcheck_04 (File : System.Address; Line : Integer);
434 procedure Rcheck_05 (File : System.Address; Line : Integer);
435 procedure Rcheck_06 (File : System.Address; Line : Integer);
436 procedure Rcheck_07 (File : System.Address; Line : Integer);
437 procedure Rcheck_08 (File : System.Address; Line : Integer);
438 procedure Rcheck_09 (File : System.Address; Line : Integer);
439 procedure Rcheck_10 (File : System.Address; Line : Integer);
440 procedure Rcheck_11 (File : System.Address; Line : Integer);
441 procedure Rcheck_12 (File : System.Address; Line : Integer);
442 procedure Rcheck_13 (File : System.Address; Line : Integer);
443 procedure Rcheck_14 (File : System.Address; Line : Integer);
444 procedure Rcheck_15 (File : System.Address; Line : Integer);
445 procedure Rcheck_16 (File : System.Address; Line : Integer);
446 procedure Rcheck_17 (File : System.Address; Line : Integer);
447 procedure Rcheck_18 (File : System.Address; Line : Integer);
448 procedure Rcheck_19 (File : System.Address; Line : Integer);
449 procedure Rcheck_20 (File : System.Address; Line : Integer);
450 procedure Rcheck_21 (File : System.Address; Line : Integer);
451 procedure Rcheck_22 (File : System.Address; Line : Integer);
452 procedure Rcheck_23 (File : System.Address; Line : Integer);
453 procedure Rcheck_24 (File : System.Address; Line : Integer);
454 procedure Rcheck_25 (File : System.Address; Line : Integer);
455 procedure Rcheck_26 (File : System.Address; Line : Integer);
456 procedure Rcheck_27 (File : System.Address; Line : Integer);
457 procedure Rcheck_28 (File : System.Address; Line : Integer);
458 procedure Rcheck_29 (File : System.Address; Line : Integer);
459 procedure Rcheck_30 (File : System.Address; Line : Integer);
460 procedure Rcheck_31 (File : System.Address; Line : Integer);
461 procedure Rcheck_32 (File : System.Address; Line : Integer);
463 pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
464 pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
465 pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
466 pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
467 pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
468 pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
469 pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
470 pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
471 pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
472 pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
473 pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
474 pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
475 pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
476 pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
477 pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
478 pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
479 pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
480 pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
481 pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
482 pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
483 pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
484 pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
485 pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
486 pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
487 pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
488 pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
489 pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
490 pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
491 pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
492 pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
493 pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
494 pragma Export (C, Rcheck_31, "__gnat_rcheck_31");
495 pragma Export (C, Rcheck_32, "__gnat_rcheck_32");
497 -- None of these procedures ever returns (they raise an exception!). By
498 -- using pragma No_Return, we ensure that any junk code after the call,
499 -- such as normal return epilog stuff, can be eliminated).
501 pragma No_Return (Rcheck_00);
502 pragma No_Return (Rcheck_01);
503 pragma No_Return (Rcheck_02);
504 pragma No_Return (Rcheck_03);
505 pragma No_Return (Rcheck_04);
506 pragma No_Return (Rcheck_05);
507 pragma No_Return (Rcheck_06);
508 pragma No_Return (Rcheck_07);
509 pragma No_Return (Rcheck_08);
510 pragma No_Return (Rcheck_09);
511 pragma No_Return (Rcheck_10);
512 pragma No_Return (Rcheck_11);
513 pragma No_Return (Rcheck_12);
514 pragma No_Return (Rcheck_13);
515 pragma No_Return (Rcheck_14);
516 pragma No_Return (Rcheck_15);
517 pragma No_Return (Rcheck_16);
518 pragma No_Return (Rcheck_17);
519 pragma No_Return (Rcheck_18);
520 pragma No_Return (Rcheck_19);
521 pragma No_Return (Rcheck_20);
522 pragma No_Return (Rcheck_21);
523 pragma No_Return (Rcheck_22);
524 pragma No_Return (Rcheck_23);
525 pragma No_Return (Rcheck_24);
526 pragma No_Return (Rcheck_25);
527 pragma No_Return (Rcheck_26);
528 pragma No_Return (Rcheck_27);
529 pragma No_Return (Rcheck_28);
530 pragma No_Return (Rcheck_29);
531 pragma No_Return (Rcheck_30);
532 pragma No_Return (Rcheck_32);
534 ---------------------------------------------
535 -- Reason Strings for Run-Time Check Calls --
536 ---------------------------------------------
538 -- These strings are null-terminated and are used by Rcheck_nn. The
539 -- strings correspond to the definitions for Types.RT_Exception_Code.
543 Rmsg_00 : constant String := "access check failed" & NUL;
544 Rmsg_01 : constant String := "access parameter is null" & NUL;
545 Rmsg_02 : constant String := "discriminant check failed" & NUL;
546 Rmsg_03 : constant String := "divide by zero" & NUL;
547 Rmsg_04 : constant String := "explicit raise" & NUL;
548 Rmsg_05 : constant String := "index check failed" & NUL;
549 Rmsg_06 : constant String := "invalid data" & NUL;
550 Rmsg_07 : constant String := "length check failed" & NUL;
551 Rmsg_08 : constant String := "null Exception_Id" & NUL;
552 Rmsg_09 : constant String := "null-exclusion check failed" & NUL;
553 Rmsg_10 : constant String := "overflow check failed" & NUL;
554 Rmsg_11 : constant String := "partition check failed" & NUL;
555 Rmsg_12 : constant String := "range check failed" & NUL;
556 Rmsg_13 : constant String := "tag check failed" & NUL;
557 Rmsg_14 : constant String := "access before elaboration" & NUL;
558 Rmsg_15 : constant String := "accessibility check failed" & NUL;
559 Rmsg_16 : constant String := "all guards closed" & NUL;
560 Rmsg_17 : constant String := "Current_Task referenced in entry" &
562 Rmsg_18 : constant String := "duplicated entry address" & NUL;
563 Rmsg_19 : constant String := "explicit raise" & NUL;
564 Rmsg_20 : constant String := "finalize/adjust raised exception" & NUL;
565 Rmsg_21 : constant String := "implicit return with No_Return" & NUL;
566 Rmsg_22 : constant String := "misaligned address value" & NUL;
567 Rmsg_23 : constant String := "missing return" & NUL;
568 Rmsg_24 : constant String := "overlaid controlled object" & NUL;
569 Rmsg_25 : constant String := "potentially blocking operation" & NUL;
570 Rmsg_26 : constant String := "stubbed subprogram called" & NUL;
571 Rmsg_27 : constant String := "unchecked union restriction" & NUL;
572 Rmsg_28 : constant String := "actual/returned class-wide value "
573 & "not transportable" & NUL;
574 Rmsg_29 : constant String := "empty storage pool" & NUL;
575 Rmsg_30 : constant String := "explicit raise" & NUL;
576 Rmsg_31 : constant String := "infinite recursion" & NUL;
577 Rmsg_32 : constant String := "object too large" & NUL;
579 -----------------------
580 -- Polling Interface --
581 -----------------------
583 type Unsigned is mod 2 ** 32;
585 Counter : Unsigned := 0;
586 pragma Warnings (Off, Counter);
587 -- This counter is provided for convenience. It can be used in Poll to
588 -- perform periodic but not systematic operations.
590 procedure Poll is separate;
591 -- The actual polling routine is separate, so that it can easily
592 -- be replaced with a target dependent version.
594 --------------------------
595 -- Code_Address_For_AAA --
596 --------------------------
598 -- This function gives us the start of the PC range for addresses
599 -- within the exception unit itself. We hope that gigi/gcc keep all the
600 -- procedures in their original order!
602 function Code_Address_For_AAA return System.Address is
604 -- We are using a label instead of merely using
605 -- Code_Address_For_AAA'Address because on some platforms the latter
606 -- does not yield the address we want, but the address of a stub or of
607 -- a descriptor instead. This is the case at least on Alpha-VMS and
611 return Start_Of_AAA'Address;
612 end Code_Address_For_AAA;
618 procedure Call_Chain (Excep : EOA) is separate;
619 -- The actual Call_Chain routine is separate, so that it can easily
620 -- be dummied out when no exception traceback information is needed.
622 ------------------------------
623 -- Current_Target_Exception --
624 ------------------------------
626 function Current_Target_Exception return Exception_Occurrence is
628 return Null_Occurrence;
629 end Current_Target_Exception;
635 function EId_To_String (X : Exception_Id) return String
636 renames Stream_Attributes.EId_To_String;
642 -- We use the null string to represent the null occurrence, otherwise
643 -- we output the Exception_Information string for the occurrence.
645 function EO_To_String (X : Exception_Occurrence) return String
646 renames Stream_Attributes.EO_To_String;
648 ------------------------
649 -- Exception_Identity --
650 ------------------------
652 function Exception_Identity
653 (X : Exception_Occurrence) return Exception_Id
656 -- Note that the following test used to be here for the original
657 -- Ada 95 semantics, but these were modified by AI-241 to require
658 -- returning Null_Id instead of raising Constraint_Error.
660 -- if X.Id = Null_Id then
661 -- raise Constraint_Error;
665 end Exception_Identity;
667 ---------------------------
668 -- Exception_Information --
669 ---------------------------
671 function Exception_Information (X : Exception_Occurrence) return String is
673 if X.Id = Null_Id then
674 raise Constraint_Error;
677 return Exception_Data.Exception_Information (X);
678 end Exception_Information;
680 -----------------------
681 -- Exception_Message --
682 -----------------------
684 function Exception_Message (X : Exception_Occurrence) return String is
686 if X.Id = Null_Id then
687 raise Constraint_Error;
690 return X.Msg (1 .. X.Msg_Length);
691 end Exception_Message;
697 function Exception_Name (Id : Exception_Id) return String is
700 raise Constraint_Error;
703 return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
706 function Exception_Name (X : Exception_Occurrence) return String is
708 return Exception_Name (X.Id);
711 ---------------------------
712 -- Exception_Name_Simple --
713 ---------------------------
715 function Exception_Name_Simple (X : Exception_Occurrence) return String is
716 Name : constant String := Exception_Name (X);
722 exit when Name (P - 1) = '.';
726 -- Return result making sure lower bound is 1
729 subtype Rname is String (1 .. Name'Length - P + 1);
731 return Rname (Name (P .. Name'Length));
733 end Exception_Name_Simple;
739 package body Exception_Data is separate;
740 -- This package can be easily dummied out if we do not want the
741 -- basic support for exception messages (such as in Ada 83).
743 ---------------------------
744 -- Exception_Propagation --
745 ---------------------------
747 package body Exception_Propagation is separate;
748 -- Depending on the actual exception mechanism used (front-end or
749 -- back-end based), the implementation will differ, which is why this
750 -- package is separated.
752 ----------------------
753 -- Exception_Traces --
754 ----------------------
756 package body Exception_Traces is separate;
757 -- Depending on the underlying support for IO the implementation
758 -- will differ. Moreover we would like to dummy out this package
759 -- in case we do not want any exception tracing support. This is
760 -- why this package is separated.
762 -----------------------
763 -- Stream Attributes --
764 -----------------------
766 package body Stream_Attributes is separate;
767 -- This package can be easily dummied out if we do not want the
768 -- support for streaming Exception_Ids and Exception_Occurrences.
770 ----------------------------
771 -- Raise_Constraint_Error --
772 ----------------------------
774 procedure Raise_Constraint_Error
775 (File : System.Address;
779 Raise_With_Location_And_Msg
780 (Constraint_Error_Def'Access, File, Line);
781 end Raise_Constraint_Error;
783 --------------------------------
784 -- Raise_Constraint_Error_Msg --
785 --------------------------------
787 procedure Raise_Constraint_Error_Msg
788 (File : System.Address;
790 Msg : System.Address)
793 Raise_With_Location_And_Msg
794 (Constraint_Error_Def'Access, File, Line, Msg);
795 end Raise_Constraint_Error_Msg;
797 -------------------------
798 -- Raise_Current_Excep --
799 -------------------------
801 procedure Raise_Current_Excep (E : Exception_Id) is
803 pragma Inspection_Point (E);
804 -- This is so the debugger can reliably inspect the parameter when
805 -- inserting a breakpoint at the start of this procedure.
807 -- To provide support for breakpoints on unhandled exceptions, the
808 -- debugger will also need to be able to inspect the value of E from
809 -- inner frames so we need to make sure that its value is also spilled
810 -- on stack. We take the address and dereference using volatile local
811 -- objects for this purpose.
813 -- The pragma Warnings (Off) are needed because the compiler knows that
814 -- these locals are not referenced and that this use of pragma Volatile
817 type EID_Access is access Exception_Id;
819 Access_To_E : EID_Access := E'Unrestricted_Access;
820 pragma Volatile (Access_To_E);
821 pragma Warnings (Off, Access_To_E);
823 Id : Exception_Id := Access_To_E.all;
824 pragma Volatile (Id);
825 pragma Warnings (Off, Id);
828 Debug_Raise_Exception (E => SSL.Exception_Data_Ptr (E));
829 Exception_Propagation.Propagate_Exception
830 (E => E, From_Signal_Handler => False);
831 end Raise_Current_Excep;
833 ---------------------
834 -- Raise_Exception --
835 ---------------------
837 procedure Raise_Exception
839 Message : String := "")
841 EF : Exception_Id := E;
844 -- Raise CE if E = Null_ID (AI-446)
847 EF := Constraint_Error'Identity;
850 -- Go ahead and raise appropriate exception
852 Exception_Data.Set_Exception_Msg (EF, Message);
854 Raise_Current_Excep (EF);
857 ----------------------------
858 -- Raise_Exception_Always --
859 ----------------------------
861 procedure Raise_Exception_Always
863 Message : String := "")
866 Exception_Data.Set_Exception_Msg (E, Message);
868 Raise_Current_Excep (E);
869 end Raise_Exception_Always;
871 -------------------------------------
872 -- Raise_From_Controlled_Operation --
873 -------------------------------------
875 procedure Raise_From_Controlled_Operation
876 (X : Ada.Exceptions.Exception_Occurrence)
878 Prefix : constant String := "adjust/finalize raised ";
879 Orig_Msg : constant String := Exception_Message (X);
880 New_Msg : constant String := Prefix & Exception_Name (X);
883 if Orig_Msg'Length >= Prefix'Length
885 Orig_Msg (Orig_Msg'First .. Orig_Msg'First + Prefix'Length - 1) =
888 -- Message already has proper prefix, just re-reraise PROGRAM_ERROR
890 Raise_Exception_No_Defer
891 (E => Program_Error'Identity,
892 Message => Orig_Msg);
894 elsif Orig_Msg = "" then
896 -- No message present: just provide our own
898 Raise_Exception_No_Defer
899 (E => Program_Error'Identity,
903 -- Message present, add informational prefix
905 Raise_Exception_No_Defer
906 (E => Program_Error'Identity,
907 Message => New_Msg & ": " & Orig_Msg);
909 end Raise_From_Controlled_Operation;
911 -------------------------------
912 -- Raise_From_Signal_Handler --
913 -------------------------------
915 procedure Raise_From_Signal_Handler
920 Exception_Data.Set_Exception_C_Msg (E, M);
922 Exception_Propagation.Propagate_Exception
923 (E => E, From_Signal_Handler => True);
924 end Raise_From_Signal_Handler;
926 -------------------------
927 -- Raise_Program_Error --
928 -------------------------
930 procedure Raise_Program_Error
931 (File : System.Address;
935 Raise_With_Location_And_Msg
936 (Program_Error_Def'Access, File, Line);
937 end Raise_Program_Error;
939 -----------------------------
940 -- Raise_Program_Error_Msg --
941 -----------------------------
943 procedure Raise_Program_Error_Msg
944 (File : System.Address;
946 Msg : System.Address)
949 Raise_With_Location_And_Msg
950 (Program_Error_Def'Access, File, Line, Msg);
951 end Raise_Program_Error_Msg;
953 -------------------------
954 -- Raise_Storage_Error --
955 -------------------------
957 procedure Raise_Storage_Error
958 (File : System.Address;
962 Raise_With_Location_And_Msg
963 (Storage_Error_Def'Access, File, Line);
964 end Raise_Storage_Error;
966 -----------------------------
967 -- Raise_Storage_Error_Msg --
968 -----------------------------
970 procedure Raise_Storage_Error_Msg
971 (File : System.Address;
973 Msg : System.Address)
976 Raise_With_Location_And_Msg
977 (Storage_Error_Def'Access, File, Line, Msg);
978 end Raise_Storage_Error_Msg;
980 ---------------------------------
981 -- Raise_With_Location_And_Msg --
982 ---------------------------------
984 procedure Raise_With_Location_And_Msg
988 M : System.Address := System.Null_Address)
991 Exception_Data.Set_Exception_C_Msg (E, F, L, M);
993 Raise_Current_Excep (E);
994 end Raise_With_Location_And_Msg;
1000 procedure Raise_With_Msg (E : Exception_Id) is
1001 Excep : constant EOA := Get_Current_Excep.all;
1004 Exception_Propagation.Setup_Exception (Excep, Excep);
1006 Excep.Exception_Raised := False;
1008 Excep.Num_Tracebacks := 0;
1009 Excep.Cleanup_Flag := False;
1010 Excep.Pid := Local_Partition_ID;
1012 Raise_Current_Excep (E);
1015 --------------------------------------
1016 -- Calls to Run-Time Check Routines --
1017 --------------------------------------
1019 procedure Rcheck_00 (File : System.Address; Line : Integer) is
1021 Raise_Constraint_Error_Msg (File, Line, Rmsg_00'Address);
1024 procedure Rcheck_01 (File : System.Address; Line : Integer) is
1026 Raise_Constraint_Error_Msg (File, Line, Rmsg_01'Address);
1029 procedure Rcheck_02 (File : System.Address; Line : Integer) is
1031 Raise_Constraint_Error_Msg (File, Line, Rmsg_02'Address);
1034 procedure Rcheck_03 (File : System.Address; Line : Integer) is
1036 Raise_Constraint_Error_Msg (File, Line, Rmsg_03'Address);
1039 procedure Rcheck_04 (File : System.Address; Line : Integer) is
1041 Raise_Constraint_Error_Msg (File, Line, Rmsg_04'Address);
1044 procedure Rcheck_05 (File : System.Address; Line : Integer) is
1046 Raise_Constraint_Error_Msg (File, Line, Rmsg_05'Address);
1049 procedure Rcheck_06 (File : System.Address; Line : Integer) is
1051 Raise_Constraint_Error_Msg (File, Line, Rmsg_06'Address);
1054 procedure Rcheck_07 (File : System.Address; Line : Integer) is
1056 Raise_Constraint_Error_Msg (File, Line, Rmsg_07'Address);
1059 procedure Rcheck_08 (File : System.Address; Line : Integer) is
1061 Raise_Constraint_Error_Msg (File, Line, Rmsg_08'Address);
1064 procedure Rcheck_09 (File : System.Address; Line : Integer) is
1066 Raise_Constraint_Error_Msg (File, Line, Rmsg_09'Address);
1069 procedure Rcheck_10 (File : System.Address; Line : Integer) is
1071 Raise_Constraint_Error_Msg (File, Line, Rmsg_10'Address);
1074 procedure Rcheck_11 (File : System.Address; Line : Integer) is
1076 Raise_Constraint_Error_Msg (File, Line, Rmsg_11'Address);
1079 procedure Rcheck_12 (File : System.Address; Line : Integer) is
1081 Raise_Constraint_Error_Msg (File, Line, Rmsg_12'Address);
1084 procedure Rcheck_13 (File : System.Address; Line : Integer) is
1086 Raise_Constraint_Error_Msg (File, Line, Rmsg_13'Address);
1089 procedure Rcheck_14 (File : System.Address; Line : Integer) is
1091 Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1094 procedure Rcheck_15 (File : System.Address; Line : Integer) is
1096 Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1099 procedure Rcheck_16 (File : System.Address; Line : Integer) is
1101 Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1104 procedure Rcheck_17 (File : System.Address; Line : Integer) is
1106 Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1109 procedure Rcheck_18 (File : System.Address; Line : Integer) is
1111 Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1114 procedure Rcheck_19 (File : System.Address; Line : Integer) is
1116 Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1119 procedure Rcheck_20 (File : System.Address; Line : Integer) is
1121 Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1124 procedure Rcheck_21 (File : System.Address; Line : Integer) is
1126 Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1129 procedure Rcheck_22 (File : System.Address; Line : Integer) is
1131 Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1134 procedure Rcheck_23 (File : System.Address; Line : Integer) is
1136 Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1139 procedure Rcheck_24 (File : System.Address; Line : Integer) is
1141 Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1144 procedure Rcheck_25 (File : System.Address; Line : Integer) is
1146 Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1149 procedure Rcheck_26 (File : System.Address; Line : Integer) is
1151 Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1154 procedure Rcheck_27 (File : System.Address; Line : Integer) is
1156 Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1159 procedure Rcheck_28 (File : System.Address; Line : Integer) is
1161 Raise_Program_Error_Msg (File, Line, Rmsg_28'Address);
1164 procedure Rcheck_29 (File : System.Address; Line : Integer) is
1166 Raise_Storage_Error_Msg (File, Line, Rmsg_29'Address);
1169 procedure Rcheck_30 (File : System.Address; Line : Integer) is
1171 Raise_Storage_Error_Msg (File, Line, Rmsg_30'Address);
1174 procedure Rcheck_31 (File : System.Address; Line : Integer) is
1176 Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address);
1179 procedure Rcheck_32 (File : System.Address; Line : Integer) is
1181 Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1188 procedure Reraise is
1189 Excep : constant EOA := Get_Current_Excep.all;
1193 Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1194 Raise_Current_Excep (Excep.Id);
1197 ------------------------
1198 -- Reraise_Occurrence --
1199 ------------------------
1201 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1203 if X.Id /= null then
1205 Exception_Propagation.Setup_Exception
1206 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1207 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1208 Raise_Current_Excep (X.Id);
1210 end Reraise_Occurrence;
1212 -------------------------------
1213 -- Reraise_Occurrence_Always --
1214 -------------------------------
1216 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1219 Exception_Propagation.Setup_Exception
1220 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1221 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1222 Raise_Current_Excep (X.Id);
1223 end Reraise_Occurrence_Always;
1225 ---------------------------------
1226 -- Reraise_Occurrence_No_Defer --
1227 ---------------------------------
1229 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1231 Exception_Propagation.Setup_Exception
1232 (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1233 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1234 Raise_Current_Excep (X.Id);
1235 end Reraise_Occurrence_No_Defer;
1237 ---------------------
1238 -- Save_Occurrence --
1239 ---------------------
1241 procedure Save_Occurrence
1242 (Target : out Exception_Occurrence;
1243 Source : Exception_Occurrence)
1246 Save_Occurrence_No_Private (Target, Source);
1247 end Save_Occurrence;
1249 function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1250 Target : constant EOA := new Exception_Occurrence;
1252 Save_Occurrence (Target.all, Source);
1254 end Save_Occurrence;
1256 --------------------------------
1257 -- Save_Occurrence_No_Private --
1258 --------------------------------
1260 procedure Save_Occurrence_No_Private
1261 (Target : out Exception_Occurrence;
1262 Source : Exception_Occurrence)
1265 Target.Id := Source.Id;
1266 Target.Msg_Length := Source.Msg_Length;
1267 Target.Num_Tracebacks := Source.Num_Tracebacks;
1268 Target.Pid := Source.Pid;
1269 Target.Cleanup_Flag := Source.Cleanup_Flag;
1271 Target.Msg (1 .. Target.Msg_Length) :=
1272 Source.Msg (1 .. Target.Msg_Length);
1274 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1275 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1276 end Save_Occurrence_No_Private;
1278 -------------------------
1279 -- Transfer_Occurrence --
1280 -------------------------
1282 procedure Transfer_Occurrence
1283 (Target : Exception_Occurrence_Access;
1284 Source : Exception_Occurrence)
1287 -- Setup Target as an exception to be propagated in the calling task
1288 -- (rendezvous-wise), taking care not to clobber the associated private
1289 -- data. Target is expected to be a pointer to the calling task's
1290 -- fixed TSD occurrence, which is very different from Get_Current_Excep
1291 -- here because this subprogram is called from the called task.
1293 Exception_Propagation.Setup_Exception (Target, Target);
1294 Save_Occurrence_No_Private (Target.all, Source);
1295 end Transfer_Occurrence;
1301 function String_To_EId (S : String) return Exception_Id
1302 renames Stream_Attributes.String_To_EId;
1308 function String_To_EO (S : String) return Exception_Occurrence
1309 renames Stream_Attributes.String_To_EO;
1311 ------------------------------
1312 -- Raise_Exception_No_Defer --
1313 ------------------------------
1315 procedure Raise_Exception_No_Defer
1317 Message : String := "")
1320 Exception_Data.Set_Exception_Msg (E, Message);
1322 -- Do not call Abort_Defer.all, as specified by the spec
1324 Raise_Current_Excep (E);
1325 end Raise_Exception_No_Defer;
1331 procedure To_Stderr (C : Character) is
1333 type int is new Integer;
1335 procedure put_char_stderr (C : int);
1336 pragma Import (C, put_char_stderr, "put_char_stderr");
1339 put_char_stderr (Character'Pos (C));
1342 procedure To_Stderr (S : String) is
1344 for J in S'Range loop
1345 if S (J) /= ASCII.CR then
1351 -------------------------
1352 -- Wide_Exception_Name --
1353 -------------------------
1355 WC_Encoding : Character;
1356 pragma Import (C, WC_Encoding, "__gl_wc_encoding");
1357 -- Encoding method for source, as exported by binder
1359 function Wide_Exception_Name
1360 (Id : Exception_Id) return Wide_String
1362 S : constant String := Exception_Name (Id);
1363 W : Wide_String (1 .. S'Length);
1366 String_To_Wide_String
1367 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1369 end Wide_Exception_Name;
1371 function Wide_Exception_Name
1372 (X : Exception_Occurrence) return Wide_String
1374 S : constant String := Exception_Name (X);
1375 W : Wide_String (1 .. S'Length);
1378 String_To_Wide_String
1379 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1381 end Wide_Exception_Name;
1383 ----------------------------
1384 -- Wide_Wide_Exception_Name --
1385 -----------------------------
1387 function Wide_Wide_Exception_Name
1388 (Id : Exception_Id) return Wide_Wide_String
1390 S : constant String := Exception_Name (Id);
1391 W : Wide_Wide_String (1 .. S'Length);
1394 String_To_Wide_Wide_String
1395 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1397 end Wide_Wide_Exception_Name;
1399 function Wide_Wide_Exception_Name
1400 (X : Exception_Occurrence) return Wide_Wide_String
1402 S : constant String := Exception_Name (X);
1403 W : Wide_Wide_String (1 .. S'Length);
1406 String_To_Wide_Wide_String
1407 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1409 end Wide_Wide_Exception_Name;
1411 --------------------------
1412 -- Code_Address_For_ZZZ --
1413 --------------------------
1415 -- This function gives us the end of the PC range for addresses
1416 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1417 -- procedures in their original order!
1419 function Code_Address_For_ZZZ return System.Address is
1422 return Start_Of_ZZZ'Address;
1423 end Code_Address_For_ZZZ;