1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2011, 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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This version of Ada.Exceptions fully supports both Ada 95 and Ada 2005.
33 -- It is used in all situations except for the build of the compiler and
34 -- other basic tools. For these latter builds, we use an Ada 95-only version.
36 -- The reason for this splitting off of a separate version is that bootstrap
37 -- compilers often will be used that do not support Ada 2005 features, and
38 -- Ada.Exceptions is part of the compiler sources.
40 pragma Style_Checks (All_Checks);
41 -- No subprogram ordering check, due to logical grouping
44 -- We must turn polling off for this unit, because otherwise we get
45 -- elaboration circularities with System.Exception_Tables.
47 with System; use System;
48 with System.Exceptions; use System.Exceptions;
49 with System.Standard_Library; use System.Standard_Library;
50 with System.Soft_Links; use System.Soft_Links;
51 with System.WCh_Con; use System.WCh_Con;
52 with System.WCh_StW; use System.WCh_StW;
54 package body Ada.Exceptions is
56 pragma Suppress (All_Checks);
57 -- We definitely do not want exceptions occurring within this unit, or
58 -- we are in big trouble. If an exceptional situation does occur, better
59 -- that it not be raised, since raising it can cause confusing chaos.
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 -- Note: the exported subprograms in this package body are called directly
66 -- from C clients using the given external name, even though they are not
67 -- technically visible in the Ada sense.
69 function Code_Address_For_AAA return System.Address;
70 function Code_Address_For_ZZZ return System.Address;
71 -- Return start and end of procedures in this package
73 -- These procedures are used to provide exclusion bounds in
74 -- calls to Call_Chain at exception raise points from this unit. The
75 -- purpose is to arrange for the exception tracebacks not to include
76 -- frames from routines involved in the raise process, as these are
77 -- meaningless from the user's standpoint.
79 -- For these bounds to be meaningful, we need to ensure that the object
80 -- code for the routines involved in processing a raise is located after
81 -- the object code Code_Address_For_AAA and before the object code
82 -- Code_Address_For_ZZZ. This will indeed be the case as long as the
83 -- following rules are respected:
85 -- 1) The bodies of the subprograms involved in processing a raise
86 -- are located after the body of Code_Address_For_AAA and before the
87 -- body of Code_Address_For_ZZZ.
89 -- 2) No pragma Inline applies to any of these subprograms, as this
90 -- could delay the corresponding assembly output until the end of
93 procedure Call_Chain (Excep : EOA);
94 -- Store up to Max_Tracebacks in Excep, corresponding to the current
97 function Image (Index : Integer) return String;
98 -- Return string image corresponding to Index
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 Column : Integer := 0;
122 Msg2 : System.Address := System.Null_Address);
123 -- This routine is called to setup the exception referenced by the
124 -- Current_Excep field in the TSD to contain the indicated Id value
125 -- and message. Msg1 is a null terminated string which is generated
126 -- as the exception message. If line is non-zero, then a colon and
127 -- the decimal representation of this integer is appended to the
128 -- message. Ditto for Column. When Msg2 is non-null, a space and this
129 -- additional null terminated string is added to the message.
131 procedure Set_Exception_Msg
134 -- This routine is called to setup the exception referenced by the
135 -- Current_Excep field in the TSD to contain the indicated Id value
136 -- and message. Message is a string which is generated as the
137 -- exception message.
139 --------------------------------------
140 -- Exception information subprogram --
141 --------------------------------------
143 function Exception_Information (X : Exception_Occurrence) return String;
144 -- The format of the exception information is as follows:
146 -- Exception_Name: <exception name> (as in Exception_Name)
147 -- Message: <message> (only if Exception_Message is empty)
148 -- PID=nnnn (only if != 0)
149 -- Call stack traceback locations: (only if at least one location)
150 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
152 -- The lines are separated by a ASCII.LF character.
153 -- The nnnn is the partition Id given as decimal digits.
154 -- The 0x... line represents traceback program counter locations, in
155 -- execution order with the first one being the exception location. It
158 -- The Exception_Name and Message lines are omitted in the abort
159 -- signal case, since this is not really an exception.
161 -- !! If the format of the generated string is changed, please note
162 -- !! that an equivalent modification to the routine String_To_EO must
163 -- !! be made to preserve proper functioning of the stream attributes.
165 ---------------------------------------
166 -- Exception backtracing subprograms --
167 ---------------------------------------
169 -- What is automatically output when exception tracing is on is the
170 -- usual exception information with the call chain backtrace possibly
171 -- tailored by a backtrace decorator. Modifying Exception_Information
172 -- itself is not a good idea because the decorated output is completely
173 -- out of control and would break all our code related to the streaming
174 -- of exceptions. We then provide an alternative function to compute
175 -- the possibly tailored output, which is equivalent if no decorator is
178 function Tailored_Exception_Information
179 (X : Exception_Occurrence) return String;
180 -- Exception information to be output in the case of automatic tracing
181 -- requested through GNAT.Exception_Traces.
183 -- This is the same as Exception_Information if no backtrace decorator
184 -- is currently in place. Otherwise, this is Exception_Information with
185 -- the call chain raw addresses replaced by the result of a call to the
186 -- current decorator provided with the call chain addresses.
189 (Ada, Tailored_Exception_Information,
190 "__gnat_tailored_exception_information");
191 -- This is currently used by System.Tasking.Stages
195 package Exception_Traces is
198 -- Imports Tailored_Exception_Information
200 ----------------------------------------------
201 -- Run-Time Exception Notification Routines --
202 ----------------------------------------------
204 -- These subprograms provide a common run-time interface to trigger the
205 -- actions required when an exception is about to be propagated (e.g.
206 -- user specified actions or output of exception information). They are
207 -- exported to be usable by the Ada exception handling personality
208 -- routine when the GCC 3 mechanism is used.
210 procedure Notify_Handled_Exception;
212 (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
213 -- This routine is called for a handled occurrence is about to be
216 procedure Notify_Unhandled_Exception;
218 (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
219 -- This routine is called when an unhandled occurrence is about to be
222 procedure Unhandled_Exception_Terminate;
223 pragma No_Return (Unhandled_Exception_Terminate);
224 -- This procedure is called to terminate execution following an
225 -- unhandled exception. The exception information, including
226 -- traceback if available is output, and execution is then
227 -- terminated. Note that at the point where this routine is
228 -- called, the stack has typically been destroyed.
230 end Exception_Traces;
232 package Exception_Propagation is
234 use Exception_Traces;
235 -- Imports Notify_Unhandled_Exception and
236 -- Unhandled_Exception_Terminate
238 ------------------------------------
239 -- Exception propagation routines --
240 ------------------------------------
242 procedure Propagate_Exception
244 From_Signal_Handler : Boolean);
245 pragma No_Return (Propagate_Exception);
246 -- This procedure propagates the exception represented by the occurrence
247 -- referenced by Current_Excep in the TSD for the current task.
249 end Exception_Propagation;
251 package Stream_Attributes is
253 --------------------------------
254 -- Stream attributes routines --
255 --------------------------------
257 function EId_To_String (X : Exception_Id) return String;
258 function String_To_EId (S : String) return Exception_Id;
259 -- Functions for implementing Exception_Id stream attributes
261 function EO_To_String (X : Exception_Occurrence) return String;
262 function String_To_EO (S : String) return Exception_Occurrence;
263 -- Functions for implementing Exception_Occurrence stream
266 end Stream_Attributes;
268 procedure Raise_Current_Excep (E : Exception_Id);
269 pragma No_Return (Raise_Current_Excep);
270 pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
271 -- This is a simple wrapper to Exception_Propagation.Propagate_Exception
272 -- setting the From_Signal_Handler argument to False.
274 -- This external name for Raise_Current_Excep is historical, and probably
275 -- should be changed but for now we keep it, because gdb and gigi know
278 procedure Raise_Exception_No_Defer
279 (E : Exception_Id; Message : String := "");
281 (Ada, Raise_Exception_No_Defer,
282 "ada__exceptions__raise_exception_no_defer");
283 pragma No_Return (Raise_Exception_No_Defer);
284 -- Similar to Raise_Exception, but with no abort deferral
286 procedure Raise_With_Msg (E : Exception_Id);
287 pragma No_Return (Raise_With_Msg);
288 pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
289 -- Raises an exception with given exception id value. A message
290 -- is associated with the raise, and has already been stored in the
291 -- exception occurrence referenced by the Current_Excep in the TSD.
292 -- Abort is deferred before the raise call.
294 procedure Raise_With_Location_And_Msg
299 M : System.Address := System.Null_Address);
300 pragma No_Return (Raise_With_Location_And_Msg);
301 -- Raise an exception with given exception id value. A filename and line
302 -- number is associated with the raise and is stored in the exception
303 -- occurrence and in addition a column and a string message M may be
304 -- appended to this (if not null/0).
306 procedure Raise_Constraint_Error
307 (File : System.Address;
309 pragma No_Return (Raise_Constraint_Error);
311 (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
312 -- Raise constraint error with file:line information
314 procedure Raise_Constraint_Error_Msg
315 (File : System.Address;
318 Msg : System.Address);
319 pragma No_Return (Raise_Constraint_Error_Msg);
321 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
322 -- Raise constraint error with file:line:col + msg information
324 procedure Raise_Program_Error
325 (File : System.Address;
327 pragma No_Return (Raise_Program_Error);
329 (C, Raise_Program_Error, "__gnat_raise_program_error");
330 -- Raise program error with file:line information
332 procedure Raise_Program_Error_Msg
333 (File : System.Address;
335 Msg : System.Address);
336 pragma No_Return (Raise_Program_Error_Msg);
338 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
339 -- Raise program error with file:line + msg information
341 procedure Raise_Storage_Error
342 (File : System.Address;
344 pragma No_Return (Raise_Storage_Error);
346 (C, Raise_Storage_Error, "__gnat_raise_storage_error");
347 -- Raise storage error with file:line information
349 procedure Raise_Storage_Error_Msg
350 (File : System.Address;
352 Msg : System.Address);
353 pragma No_Return (Raise_Storage_Error_Msg);
355 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
356 -- Raise storage error with file:line + reason msg information
358 -- The exception raising process and the automatic tracing mechanism rely
359 -- on some careful use of flags attached to the exception occurrence. The
360 -- graph below illustrates the relations between the Raise_ subprograms
361 -- and identifies the points where basic flags such as Exception_Raised
364 -- (i) signs indicate the flags initialization points. R stands for Raise,
365 -- W for With, and E for Exception.
367 -- R_No_Msg R_E R_Pe R_Ce R_Se
369 -- +--+ +--+ +---+ | +---+
371 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
373 -- +------------+ | +-----------+ +--+
375 -- | | | Set_E_C_Msg(i)
377 -- Raise_Current_Excep
380 pragma No_Return (Reraise);
381 pragma Export (C, Reraise, "__gnat_reraise");
382 -- Reraises the exception referenced by the Current_Excep field of
383 -- the TSD (all fields of this exception occurrence are set). Abort
384 -- is deferred before the reraise operation.
386 -- Save_Occurrence variations: As the management of the private data
387 -- attached to occurrences is delicate, whether or not pointers to such
388 -- data has to be copied in various situations is better made explicit.
389 -- The following procedures provide an internal interface to help making
392 procedure Save_Occurrence_No_Private
393 (Target : out Exception_Occurrence;
394 Source : Exception_Occurrence);
395 -- Copy all the components of Source to Target, except the
396 -- Private_Data pointer.
398 procedure Transfer_Occurrence
399 (Target : Exception_Occurrence_Access;
400 Source : Exception_Occurrence);
401 pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
402 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
403 -- to setup Target from Source as an exception to be propagated in the
404 -- caller task. Target is expected to be a pointer to the fixed TSD
405 -- occurrence for this task.
407 -----------------------------
408 -- Run-Time Check Routines --
409 -----------------------------
411 -- These routines raise a specific exception with a reason message
412 -- attached. The parameters are the file name and line number in each
413 -- case. The names are keyed to the codes defined in types.ads and
414 -- a-types.h (for example, the name Rcheck_05 refers to the Reason
415 -- RT_Exception_Code'Val (5)).
417 procedure Rcheck_00 (File : System.Address; Line : Integer);
418 procedure Rcheck_01 (File : System.Address; Line : Integer);
419 procedure Rcheck_02 (File : System.Address; Line : Integer);
420 procedure Rcheck_03 (File : System.Address; Line : Integer);
421 procedure Rcheck_04 (File : System.Address; Line : Integer);
422 procedure Rcheck_05 (File : System.Address; Line : Integer);
423 procedure Rcheck_06 (File : System.Address; Line : Integer);
424 procedure Rcheck_07 (File : System.Address; Line : Integer);
425 procedure Rcheck_08 (File : System.Address; Line : Integer);
426 procedure Rcheck_09 (File : System.Address; Line : Integer);
427 procedure Rcheck_10 (File : System.Address; Line : Integer);
428 procedure Rcheck_11 (File : System.Address; Line : Integer);
429 procedure Rcheck_12 (File : System.Address; Line : Integer);
430 procedure Rcheck_13 (File : System.Address; Line : Integer);
431 procedure Rcheck_14 (File : System.Address; Line : Integer);
432 procedure Rcheck_15 (File : System.Address; Line : Integer);
433 procedure Rcheck_16 (File : System.Address; Line : Integer);
434 procedure Rcheck_17 (File : System.Address; Line : Integer);
435 procedure Rcheck_18 (File : System.Address; Line : Integer);
436 procedure Rcheck_19 (File : System.Address; Line : Integer);
437 procedure Rcheck_20 (File : System.Address; Line : Integer);
438 procedure Rcheck_21 (File : System.Address; Line : Integer);
439 procedure Rcheck_22 (File : System.Address; Line : Integer);
440 procedure Rcheck_23 (File : System.Address; Line : Integer);
441 procedure Rcheck_24 (File : System.Address; Line : Integer);
442 procedure Rcheck_25 (File : System.Address; Line : Integer);
443 procedure Rcheck_26 (File : System.Address; Line : Integer);
444 procedure Rcheck_27 (File : System.Address; Line : Integer);
445 procedure Rcheck_28 (File : System.Address; Line : Integer);
446 procedure Rcheck_29 (File : System.Address; Line : Integer);
447 procedure Rcheck_30 (File : System.Address; Line : Integer);
448 procedure Rcheck_31 (File : System.Address; Line : Integer);
449 procedure Rcheck_32 (File : System.Address; Line : Integer);
450 procedure Rcheck_33 (File : System.Address; Line : Integer);
451 procedure Rcheck_34 (File : System.Address; Line : Integer);
453 procedure Rcheck_00_Ext
454 (File : System.Address; Line, Column : Integer);
455 procedure Rcheck_05_Ext
456 (File : System.Address; Line, Column, Index, First, Last : Integer);
457 procedure Rcheck_06_Ext
458 (File : System.Address; Line, Column, Index, First, Last : Integer);
459 procedure Rcheck_12_Ext
460 (File : System.Address; Line, Column, Index, First, Last : Integer);
462 pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
463 pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
464 pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
465 pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
466 pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
467 pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
468 pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
469 pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
470 pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
471 pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
472 pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
473 pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
474 pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
475 pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
476 pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
477 pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
478 pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
479 pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
480 pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
481 pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
482 pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
483 pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
484 pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
485 pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
486 pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
487 pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
488 pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
489 pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
490 pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
491 pragma Export (C, Rcheck_29, "__gnat_rcheck_29");
492 pragma Export (C, Rcheck_30, "__gnat_rcheck_30");
493 pragma Export (C, Rcheck_31, "__gnat_rcheck_31");
494 pragma Export (C, Rcheck_32, "__gnat_rcheck_32");
495 pragma Export (C, Rcheck_33, "__gnat_rcheck_33");
496 pragma Export (C, Rcheck_34, "__gnat_rcheck_34");
498 pragma Export (C, Rcheck_00_Ext, "__gnat_rcheck_00_ext");
499 pragma Export (C, Rcheck_05_Ext, "__gnat_rcheck_05_ext");
500 pragma Export (C, Rcheck_06_Ext, "__gnat_rcheck_06_ext");
501 pragma Export (C, Rcheck_12_Ext, "__gnat_rcheck_12_ext");
503 -- None of these procedures ever returns (they raise an exception!). By
504 -- using pragma No_Return, we ensure that any junk code after the call,
505 -- such as normal return epilog stuff, can be eliminated).
507 pragma No_Return (Rcheck_00);
508 pragma No_Return (Rcheck_01);
509 pragma No_Return (Rcheck_02);
510 pragma No_Return (Rcheck_03);
511 pragma No_Return (Rcheck_04);
512 pragma No_Return (Rcheck_05);
513 pragma No_Return (Rcheck_06);
514 pragma No_Return (Rcheck_07);
515 pragma No_Return (Rcheck_08);
516 pragma No_Return (Rcheck_09);
517 pragma No_Return (Rcheck_10);
518 pragma No_Return (Rcheck_11);
519 pragma No_Return (Rcheck_12);
520 pragma No_Return (Rcheck_13);
521 pragma No_Return (Rcheck_14);
522 pragma No_Return (Rcheck_15);
523 pragma No_Return (Rcheck_16);
524 pragma No_Return (Rcheck_17);
525 pragma No_Return (Rcheck_18);
526 pragma No_Return (Rcheck_19);
527 pragma No_Return (Rcheck_20);
528 pragma No_Return (Rcheck_21);
529 pragma No_Return (Rcheck_22);
530 pragma No_Return (Rcheck_23);
531 pragma No_Return (Rcheck_24);
532 pragma No_Return (Rcheck_25);
533 pragma No_Return (Rcheck_26);
534 pragma No_Return (Rcheck_27);
535 pragma No_Return (Rcheck_28);
536 pragma No_Return (Rcheck_29);
537 pragma No_Return (Rcheck_30);
538 pragma No_Return (Rcheck_32);
539 pragma No_Return (Rcheck_33);
540 pragma No_Return (Rcheck_34);
542 pragma No_Return (Rcheck_00_Ext);
543 pragma No_Return (Rcheck_05_Ext);
544 pragma No_Return (Rcheck_06_Ext);
545 pragma No_Return (Rcheck_12_Ext);
547 ---------------------------------------------
548 -- Reason Strings for Run-Time Check Calls --
549 ---------------------------------------------
551 -- These strings are null-terminated and are used by Rcheck_nn. The
552 -- strings correspond to the definitions for Types.RT_Exception_Code.
556 Rmsg_00 : constant String := "access check failed" & NUL;
557 Rmsg_01 : constant String := "access parameter is null" & NUL;
558 Rmsg_02 : constant String := "discriminant check failed" & NUL;
559 Rmsg_03 : constant String := "divide by zero" & NUL;
560 Rmsg_04 : constant String := "explicit raise" & NUL;
561 Rmsg_05 : constant String := "index check failed" & NUL;
562 Rmsg_06 : constant String := "invalid data" & NUL;
563 Rmsg_07 : constant String := "length check failed" & NUL;
564 Rmsg_08 : constant String := "null Exception_Id" & NUL;
565 Rmsg_09 : constant String := "null-exclusion check failed" & NUL;
566 Rmsg_10 : constant String := "overflow check failed" & NUL;
567 Rmsg_11 : constant String := "partition check failed" & NUL;
568 Rmsg_12 : constant String := "range check failed" & NUL;
569 Rmsg_13 : constant String := "tag check failed" & NUL;
570 Rmsg_14 : constant String := "access before elaboration" & NUL;
571 Rmsg_15 : constant String := "accessibility check failed" & NUL;
572 Rmsg_16 : constant String := "attempt to take address of" &
573 " intrinsic subprogram" & NUL;
574 Rmsg_17 : constant String := "all guards closed" & NUL;
575 Rmsg_18 : constant String := "improper use of generic subtype" &
576 " with predicate" & NUL;
577 Rmsg_19 : constant String := "Current_Task referenced in entry" &
579 Rmsg_20 : constant String := "duplicated entry address" & NUL;
580 Rmsg_21 : constant String := "explicit raise" & NUL;
581 Rmsg_22 : constant String := "finalize/adjust raised exception" & NUL;
582 Rmsg_23 : constant String := "implicit return with No_Return" & NUL;
583 Rmsg_24 : constant String := "misaligned address value" & NUL;
584 Rmsg_25 : constant String := "missing return" & NUL;
585 Rmsg_26 : constant String := "overlaid controlled object" & NUL;
586 Rmsg_27 : constant String := "potentially blocking operation" & NUL;
587 Rmsg_28 : constant String := "stubbed subprogram called" & NUL;
588 Rmsg_29 : constant String := "unchecked union restriction" & NUL;
589 Rmsg_30 : constant String := "actual/returned class-wide" &
590 " value not transportable" & NUL;
591 Rmsg_31 : constant String := "empty storage pool" & NUL;
592 Rmsg_32 : constant String := "explicit raise" & NUL;
593 Rmsg_33 : constant String := "infinite recursion" & NUL;
594 Rmsg_34 : constant String := "object too large" & NUL;
596 -----------------------
597 -- Polling Interface --
598 -----------------------
600 type Unsigned is mod 2 ** 32;
602 Counter : Unsigned := 0;
603 pragma Warnings (Off, Counter);
604 -- This counter is provided for convenience. It can be used in Poll to
605 -- perform periodic but not systematic operations.
607 procedure Poll is separate;
608 -- The actual polling routine is separate, so that it can easily
609 -- be replaced with a target dependent version.
611 --------------------------
612 -- Code_Address_For_AAA --
613 --------------------------
615 -- This function gives us the start of the PC range for addresses
616 -- within the exception unit itself. We hope that gigi/gcc keep all the
617 -- procedures in their original order!
619 function Code_Address_For_AAA return System.Address is
621 -- We are using a label instead of merely using
622 -- Code_Address_For_AAA'Address because on some platforms the latter
623 -- does not yield the address we want, but the address of a stub or of
624 -- a descriptor instead. This is the case at least on Alpha-VMS and
628 return Start_Of_AAA'Address;
629 end Code_Address_For_AAA;
635 procedure Call_Chain (Excep : EOA) is separate;
636 -- The actual Call_Chain routine is separate, so that it can easily
637 -- be dummied out when no exception traceback information is needed.
639 ------------------------------
640 -- Current_Target_Exception --
641 ------------------------------
643 function Current_Target_Exception return Exception_Occurrence is
645 return Null_Occurrence;
646 end Current_Target_Exception;
652 function EId_To_String (X : Exception_Id) return String
653 renames Stream_Attributes.EId_To_String;
659 -- We use the null string to represent the null occurrence, otherwise
660 -- we output the Exception_Information string for the occurrence.
662 function EO_To_String (X : Exception_Occurrence) return String
663 renames Stream_Attributes.EO_To_String;
665 ------------------------
666 -- Exception_Identity --
667 ------------------------
669 function Exception_Identity
670 (X : Exception_Occurrence) return Exception_Id
673 -- Note that the following test used to be here for the original
674 -- Ada 95 semantics, but these were modified by AI-241 to require
675 -- returning Null_Id instead of raising Constraint_Error.
677 -- if X.Id = Null_Id then
678 -- raise Constraint_Error;
682 end Exception_Identity;
684 ---------------------------
685 -- Exception_Information --
686 ---------------------------
688 function Exception_Information (X : Exception_Occurrence) return String is
690 if X.Id = Null_Id then
691 raise Constraint_Error;
694 return Exception_Data.Exception_Information (X);
695 end Exception_Information;
697 -----------------------
698 -- Exception_Message --
699 -----------------------
701 function Exception_Message (X : Exception_Occurrence) return String is
703 if X.Id = Null_Id then
704 raise Constraint_Error;
707 return X.Msg (1 .. X.Msg_Length);
708 end Exception_Message;
714 function Exception_Name (Id : Exception_Id) return String is
717 raise Constraint_Error;
720 return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
723 function Exception_Name (X : Exception_Occurrence) return String is
725 return Exception_Name (X.Id);
728 ---------------------------
729 -- Exception_Name_Simple --
730 ---------------------------
732 function Exception_Name_Simple (X : Exception_Occurrence) return String is
733 Name : constant String := Exception_Name (X);
739 exit when Name (P - 1) = '.';
743 -- Return result making sure lower bound is 1
746 subtype Rname is String (1 .. Name'Length - P + 1);
748 return Rname (Name (P .. Name'Length));
750 end Exception_Name_Simple;
756 package body Exception_Data is separate;
757 -- This package can be easily dummied out if we do not want the
758 -- basic support for exception messages (such as in Ada 83).
760 ---------------------------
761 -- Exception_Propagation --
762 ---------------------------
764 package body Exception_Propagation is separate;
765 -- Depending on the actual exception mechanism used (front-end or
766 -- back-end based), the implementation will differ, which is why this
767 -- package is separated.
769 ----------------------
770 -- Exception_Traces --
771 ----------------------
773 package body Exception_Traces is separate;
774 -- Depending on the underlying support for IO the implementation
775 -- will differ. Moreover we would like to dummy out this package
776 -- in case we do not want any exception tracing support. This is
777 -- why this package is separated.
779 -----------------------
780 -- Stream Attributes --
781 -----------------------
783 package body Stream_Attributes is separate;
784 -- This package can be easily dummied out if we do not want the
785 -- support for streaming Exception_Ids and Exception_Occurrences.
787 ----------------------------
788 -- Raise_Constraint_Error --
789 ----------------------------
791 procedure Raise_Constraint_Error (File : System.Address; Line : Integer) is
793 Raise_With_Location_And_Msg (Constraint_Error_Def'Access, File, Line);
794 end Raise_Constraint_Error;
796 --------------------------------
797 -- Raise_Constraint_Error_Msg --
798 --------------------------------
800 procedure Raise_Constraint_Error_Msg
801 (File : System.Address;
804 Msg : System.Address)
807 Raise_With_Location_And_Msg
808 (Constraint_Error_Def'Access, File, Line, Column, Msg);
809 end Raise_Constraint_Error_Msg;
811 -------------------------
812 -- Raise_Current_Excep --
813 -------------------------
815 procedure Raise_Current_Excep (E : Exception_Id) is
817 Debug_Raise_Exception (E => SSL.Exception_Data_Ptr (E));
818 Exception_Propagation.Propagate_Exception
819 (E => E, From_Signal_Handler => False);
820 end Raise_Current_Excep;
822 ---------------------
823 -- Raise_Exception --
824 ---------------------
826 procedure Raise_Exception
828 Message : String := "")
830 EF : Exception_Id := E;
833 -- Raise CE if E = Null_ID (AI-446)
836 EF := Constraint_Error'Identity;
839 -- Go ahead and raise appropriate exception
841 Exception_Data.Set_Exception_Msg (EF, Message);
843 if not ZCX_By_Default then
847 Raise_Current_Excep (EF);
850 ----------------------------
851 -- Raise_Exception_Always --
852 ----------------------------
854 procedure Raise_Exception_Always
856 Message : String := "")
859 Exception_Data.Set_Exception_Msg (E, Message);
860 if not ZCX_By_Default then
863 Raise_Current_Excep (E);
864 end Raise_Exception_Always;
866 -------------------------------------
867 -- Raise_From_Controlled_Operation --
868 -------------------------------------
870 procedure Raise_From_Controlled_Operation
871 (X : Ada.Exceptions.Exception_Occurrence)
873 Prefix : constant String := "adjust/finalize raised ";
874 Orig_Msg : constant String := Exception_Message (X);
875 Orig_Prefix_Length : constant Natural :=
876 Integer'Min (Prefix'Length, Orig_Msg'Length);
877 Orig_Prefix : String renames Orig_Msg
879 Orig_Msg'First + Orig_Prefix_Length - 1);
881 -- Message already has the proper prefix, just re-raise
883 if Orig_Prefix = Prefix then
884 Raise_Exception_No_Defer
885 (E => Program_Error'Identity,
886 Message => Orig_Msg);
890 New_Msg : constant String := Prefix & Exception_Name (X);
893 -- No message present, just provide our own
895 if Orig_Msg = "" then
896 Raise_Exception_No_Defer
897 (E => Program_Error'Identity,
900 -- Message present, add informational prefix
903 Raise_Exception_No_Defer
904 (E => Program_Error'Identity,
905 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 if not ZCX_By_Default then
926 Debug_Raise_Exception (E => SSL.Exception_Data_Ptr (E));
927 Exception_Propagation.Propagate_Exception
928 (E => E, From_Signal_Handler => True);
929 end Raise_From_Signal_Handler;
931 -------------------------
932 -- Raise_Program_Error --
933 -------------------------
935 procedure Raise_Program_Error
936 (File : System.Address;
940 Raise_With_Location_And_Msg (Program_Error_Def'Access, File, Line);
941 end Raise_Program_Error;
943 -----------------------------
944 -- Raise_Program_Error_Msg --
945 -----------------------------
947 procedure Raise_Program_Error_Msg
948 (File : System.Address;
950 Msg : System.Address)
953 Raise_With_Location_And_Msg
954 (Program_Error_Def'Access, File, Line, M => Msg);
955 end Raise_Program_Error_Msg;
957 -------------------------
958 -- Raise_Storage_Error --
959 -------------------------
961 procedure Raise_Storage_Error
962 (File : System.Address;
966 Raise_With_Location_And_Msg (Storage_Error_Def'Access, File, Line);
967 end Raise_Storage_Error;
969 -----------------------------
970 -- Raise_Storage_Error_Msg --
971 -----------------------------
973 procedure Raise_Storage_Error_Msg
974 (File : System.Address;
976 Msg : System.Address)
979 Raise_With_Location_And_Msg
980 (Storage_Error_Def'Access, File, Line, M => Msg);
981 end Raise_Storage_Error_Msg;
983 ---------------------------------
984 -- Raise_With_Location_And_Msg --
985 ---------------------------------
987 procedure Raise_With_Location_And_Msg
992 M : System.Address := System.Null_Address)
995 Exception_Data.Set_Exception_C_Msg (E, F, L, C, M);
997 if not ZCX_By_Default then
1001 Raise_Current_Excep (E);
1002 end Raise_With_Location_And_Msg;
1004 --------------------
1005 -- Raise_With_Msg --
1006 --------------------
1008 procedure Raise_With_Msg (E : Exception_Id) is
1009 Excep : constant EOA := Get_Current_Excep.all;
1012 Excep.Exception_Raised := False;
1014 Excep.Num_Tracebacks := 0;
1015 Excep.Cleanup_Flag := False;
1016 Excep.Pid := Local_Partition_ID;
1018 -- The following is a common pattern, should be abstracted
1019 -- into a procedure call ???
1021 if not ZCX_By_Default then
1025 Raise_Current_Excep (E);
1032 function Image (Index : Integer) return String is
1033 Result : constant String := Integer'Image (Index);
1035 if Result (1) = ' ' then
1036 return Result (2 .. Result'Last);
1042 --------------------------------------
1043 -- Calls to Run-Time Check Routines --
1044 --------------------------------------
1046 procedure Rcheck_00 (File : System.Address; Line : Integer) is
1048 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_00'Address);
1051 procedure Rcheck_01 (File : System.Address; Line : Integer) is
1053 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_01'Address);
1056 procedure Rcheck_02 (File : System.Address; Line : Integer) is
1058 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_02'Address);
1061 procedure Rcheck_03 (File : System.Address; Line : Integer) is
1063 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_03'Address);
1066 procedure Rcheck_04 (File : System.Address; Line : Integer) is
1068 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_04'Address);
1071 procedure Rcheck_05 (File : System.Address; Line : Integer) is
1073 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_05'Address);
1076 procedure Rcheck_06 (File : System.Address; Line : Integer) is
1078 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_06'Address);
1081 procedure Rcheck_07 (File : System.Address; Line : Integer) is
1083 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_07'Address);
1086 procedure Rcheck_08 (File : System.Address; Line : Integer) is
1088 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_08'Address);
1091 procedure Rcheck_09 (File : System.Address; Line : Integer) is
1093 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_09'Address);
1096 procedure Rcheck_10 (File : System.Address; Line : Integer) is
1098 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_10'Address);
1101 procedure Rcheck_11 (File : System.Address; Line : Integer) is
1103 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_11'Address);
1106 procedure Rcheck_12 (File : System.Address; Line : Integer) is
1108 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_12'Address);
1111 procedure Rcheck_13 (File : System.Address; Line : Integer) is
1113 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_13'Address);
1116 procedure Rcheck_14 (File : System.Address; Line : Integer) is
1118 Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1121 procedure Rcheck_15 (File : System.Address; Line : Integer) is
1123 Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1126 procedure Rcheck_16 (File : System.Address; Line : Integer) is
1128 Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1131 procedure Rcheck_17 (File : System.Address; Line : Integer) is
1133 Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1136 procedure Rcheck_18 (File : System.Address; Line : Integer) is
1138 Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1141 procedure Rcheck_19 (File : System.Address; Line : Integer) is
1143 Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1146 procedure Rcheck_20 (File : System.Address; Line : Integer) is
1148 Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1151 procedure Rcheck_21 (File : System.Address; Line : Integer) is
1153 Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1156 procedure Rcheck_22 (File : System.Address; Line : Integer) is
1158 Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1161 procedure Rcheck_23 (File : System.Address; Line : Integer) is
1163 Raise_Program_Error_Msg (File, Line, Rmsg_23'Address);
1166 procedure Rcheck_24 (File : System.Address; Line : Integer) is
1168 Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1171 procedure Rcheck_25 (File : System.Address; Line : Integer) is
1173 Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1176 procedure Rcheck_26 (File : System.Address; Line : Integer) is
1178 Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1181 procedure Rcheck_27 (File : System.Address; Line : Integer) is
1183 Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1186 procedure Rcheck_28 (File : System.Address; Line : Integer) is
1188 Raise_Program_Error_Msg (File, Line, Rmsg_28'Address);
1191 procedure Rcheck_29 (File : System.Address; Line : Integer) is
1193 Raise_Program_Error_Msg (File, Line, Rmsg_29'Address);
1196 procedure Rcheck_30 (File : System.Address; Line : Integer) is
1198 Raise_Program_Error_Msg (File, Line, Rmsg_30'Address);
1201 procedure Rcheck_31 (File : System.Address; Line : Integer) is
1203 Raise_Storage_Error_Msg (File, Line, Rmsg_31'Address);
1206 procedure Rcheck_32 (File : System.Address; Line : Integer) is
1208 Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1211 procedure Rcheck_33 (File : System.Address; Line : Integer) is
1213 Raise_Storage_Error_Msg (File, Line, Rmsg_33'Address);
1216 procedure Rcheck_34 (File : System.Address; Line : Integer) is
1218 Raise_Storage_Error_Msg (File, Line, Rmsg_34'Address);
1221 procedure Rcheck_00_Ext (File : System.Address; Line, Column : Integer) is
1223 Raise_Constraint_Error_Msg (File, Line, Column, Rmsg_00'Address);
1226 procedure Rcheck_05_Ext
1227 (File : System.Address; Line, Column, Index, First, Last : Integer)
1229 Msg : constant String :=
1230 Rmsg_05 (Rmsg_05'First .. Rmsg_05'Last - 1) & ASCII.LF &
1231 "index " & Image (Index) & " not in " & Image (First) &
1232 ".." & Image (Last) & ASCII.NUL;
1234 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1237 procedure Rcheck_06_Ext
1238 (File : System.Address; Line, Column, Index, First, Last : Integer)
1240 Msg : constant String :=
1241 Rmsg_06 (Rmsg_06'First .. Rmsg_06'Last - 1) & ASCII.LF &
1242 "value " & Image (Index) & " not in " & Image (First) &
1243 ".." & Image (Last) & ASCII.NUL;
1245 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1248 procedure Rcheck_12_Ext
1249 (File : System.Address; Line, Column, Index, First, Last : Integer)
1251 Msg : constant String :=
1252 Rmsg_12 (Rmsg_12'First .. Rmsg_12'Last - 1) & ASCII.LF &
1253 "value " & Image (Index) & " not in " & Image (First) &
1254 ".." & Image (Last) & ASCII.NUL;
1256 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1263 procedure Reraise is
1264 Excep : constant EOA := Get_Current_Excep.all;
1266 if not ZCX_By_Default then
1269 Raise_Current_Excep (Excep.Id);
1272 ------------------------
1273 -- Reraise_Occurrence --
1274 ------------------------
1276 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1278 if X.Id /= null then
1279 if not ZCX_By_Default then
1283 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1284 Raise_Current_Excep (X.Id);
1286 end Reraise_Occurrence;
1288 -------------------------------
1289 -- Reraise_Occurrence_Always --
1290 -------------------------------
1292 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1294 if not ZCX_By_Default then
1298 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1299 Raise_Current_Excep (X.Id);
1300 end Reraise_Occurrence_Always;
1302 ---------------------------------
1303 -- Reraise_Occurrence_No_Defer --
1304 ---------------------------------
1306 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1308 Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1309 Raise_Current_Excep (X.Id);
1310 end Reraise_Occurrence_No_Defer;
1312 ---------------------
1313 -- Save_Occurrence --
1314 ---------------------
1316 procedure Save_Occurrence
1317 (Target : out Exception_Occurrence;
1318 Source : Exception_Occurrence)
1321 Save_Occurrence_No_Private (Target, Source);
1322 end Save_Occurrence;
1324 function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1325 Target : constant EOA := new Exception_Occurrence;
1327 Save_Occurrence (Target.all, Source);
1329 end Save_Occurrence;
1331 --------------------------------
1332 -- Save_Occurrence_No_Private --
1333 --------------------------------
1335 procedure Save_Occurrence_No_Private
1336 (Target : out Exception_Occurrence;
1337 Source : Exception_Occurrence)
1340 Target.Id := Source.Id;
1341 Target.Msg_Length := Source.Msg_Length;
1342 Target.Num_Tracebacks := Source.Num_Tracebacks;
1343 Target.Pid := Source.Pid;
1344 Target.Cleanup_Flag := Source.Cleanup_Flag;
1346 Target.Msg (1 .. Target.Msg_Length) :=
1347 Source.Msg (1 .. Target.Msg_Length);
1349 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1350 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1351 end Save_Occurrence_No_Private;
1353 -------------------------
1354 -- Transfer_Occurrence --
1355 -------------------------
1357 procedure Transfer_Occurrence
1358 (Target : Exception_Occurrence_Access;
1359 Source : Exception_Occurrence)
1362 Save_Occurrence_No_Private (Target.all, Source);
1363 end Transfer_Occurrence;
1369 function String_To_EId (S : String) return Exception_Id
1370 renames Stream_Attributes.String_To_EId;
1376 function String_To_EO (S : String) return Exception_Occurrence
1377 renames Stream_Attributes.String_To_EO;
1379 ------------------------------
1380 -- Raise_Exception_No_Defer --
1381 ------------------------------
1383 procedure Raise_Exception_No_Defer
1385 Message : String := "")
1388 Exception_Data.Set_Exception_Msg (E, Message);
1390 -- Do not call Abort_Defer.all, as specified by the spec
1392 Raise_Current_Excep (E);
1393 end Raise_Exception_No_Defer;
1399 procedure To_Stderr (C : Character) is
1400 type int is new Integer;
1402 procedure put_char_stderr (C : int);
1403 pragma Import (C, put_char_stderr, "put_char_stderr");
1406 put_char_stderr (Character'Pos (C));
1409 procedure To_Stderr (S : String) is
1411 for J in S'Range loop
1412 if S (J) /= ASCII.CR then
1418 -------------------------
1419 -- Wide_Exception_Name --
1420 -------------------------
1422 WC_Encoding : Character;
1423 pragma Import (C, WC_Encoding, "__gl_wc_encoding");
1424 -- Encoding method for source, as exported by binder
1426 function Wide_Exception_Name
1427 (Id : Exception_Id) return Wide_String
1429 S : constant String := Exception_Name (Id);
1430 W : Wide_String (1 .. S'Length);
1433 String_To_Wide_String
1434 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1436 end Wide_Exception_Name;
1438 function Wide_Exception_Name
1439 (X : Exception_Occurrence) return Wide_String
1441 S : constant String := Exception_Name (X);
1442 W : Wide_String (1 .. S'Length);
1445 String_To_Wide_String
1446 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1448 end Wide_Exception_Name;
1450 ----------------------------
1451 -- Wide_Wide_Exception_Name --
1452 -----------------------------
1454 function Wide_Wide_Exception_Name
1455 (Id : Exception_Id) return Wide_Wide_String
1457 S : constant String := Exception_Name (Id);
1458 W : Wide_Wide_String (1 .. S'Length);
1461 String_To_Wide_Wide_String
1462 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1464 end Wide_Wide_Exception_Name;
1466 function Wide_Wide_Exception_Name
1467 (X : Exception_Occurrence) return Wide_Wide_String
1469 S : constant String := Exception_Name (X);
1470 W : Wide_Wide_String (1 .. S'Length);
1473 String_To_Wide_Wide_String
1474 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1476 end Wide_Wide_Exception_Name;
1478 --------------------------
1479 -- Code_Address_For_ZZZ --
1480 --------------------------
1482 -- This function gives us the end of the PC range for addresses
1483 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1484 -- procedures in their original order!
1486 function Code_Address_For_ZZZ return System.Address is
1489 return Start_Of_ZZZ'Address;
1490 end Code_Address_For_ZZZ;