1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2020, 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 pragma Style_Checks (All_Checks);
33 -- No subprogram ordering check, due to logical grouping
36 -- We must turn polling off for this unit, because otherwise we get
37 -- elaboration circularities with System.Exception_Tables.
39 with System; use System;
40 with System.Exceptions; use System.Exceptions;
41 with System.Exceptions_Debug; use System.Exceptions_Debug;
42 with System.Standard_Library; use System.Standard_Library;
43 with System.Soft_Links; use System.Soft_Links;
44 with System.WCh_Con; use System.WCh_Con;
45 with System.WCh_StW; use System.WCh_StW;
47 pragma Warnings (Off);
48 -- Suppress complaints about Symbolic not being referenced, and about it not
49 -- having pragma Preelaborate.
50 with System.Traceback.Symbolic;
51 -- Bring Symbolic into the closure. If it is the s-trasym-dwarf.adb version,
52 -- it will install symbolic tracebacks as the default decorator. Otherwise,
53 -- symbolic tracebacks are not supported, and we fall back to hexadecimal
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 subprograms 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 subprograms involved in processing a raise is located
84 -- after the object code Code_Address_For_AAA and before the object
85 -- code Code_Address_For_ZZZ. This will indeed be the case as long as
86 -- the 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 function Image (Index : Integer) return String;
101 -- Return string image corresponding to Index
103 procedure To_Stderr (S : String);
104 pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
105 -- Little routine to output string to stderr that is also used
106 -- in the tasking run time.
108 procedure To_Stderr (C : Character);
109 pragma Inline (To_Stderr);
110 pragma Export (Ada, To_Stderr, "__gnat_to_stderr_char");
111 -- Little routine to output a character to stderr, used by some of
112 -- the separate units below.
114 package Exception_Data is
116 -----------------------------------
117 -- Exception Message Subprograms --
118 -----------------------------------
120 procedure Set_Exception_C_Msg
123 Msg1 : System.Address;
125 Column : Integer := 0;
126 Msg2 : System.Address := System.Null_Address);
127 -- This routine is called to setup the exception referenced by X
128 -- to contain the indicated Id value and message. Msg1 is a null
129 -- terminated string which is generated as the exception message. If
130 -- line is non-zero, then a colon and the decimal representation of
131 -- this integer is appended to the message. Ditto for Column. When Msg2
132 -- is non-null, a space and this additional null terminated string is
133 -- added to the message.
135 procedure Set_Exception_Msg
139 -- This routine is called to setup the exception referenced by X
140 -- to contain the indicated Id value and message. Message is a string
141 -- which is generated as the exception message.
143 ---------------------------------------
144 -- Exception Information Subprograms --
145 ---------------------------------------
147 function Untailored_Exception_Information
148 (X : Exception_Occurrence) return String;
149 -- This is used by Stream_Attributes.EO_To_String to convert an
150 -- Exception_Occurrence to a String for the stream attributes.
151 -- String_To_EO understands the format, as documented here.
153 -- The format of the string is as follows:
155 -- raised <exception name> : <message>
156 -- (" : <message>" is present only if Exception_Message is not empty)
157 -- PID=nnnn (only if nonzero)
158 -- Call stack traceback locations: (only if at least one location)
159 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
161 -- The lines are separated by a ASCII.LF character.
162 -- The nnnn is the partition Id given as decimal digits.
163 -- The 0x... line represents traceback program counter locations, in
164 -- execution order with the first one being the exception location.
166 -- The Exception_Name and Message lines are omitted in the abort
167 -- signal case, since this is not really an exception.
169 -- Note: If the format of the generated string is changed, please note
170 -- that an equivalent modification to the routine String_To_EO must be
171 -- made to preserve proper functioning of the stream attributes.
173 function Exception_Information (X : Exception_Occurrence) return String;
174 -- This is the implementation of Ada.Exceptions.Exception_Information,
175 -- as defined in the Ada RM.
177 -- If no traceback decorator (see GNAT.Exception_Traces) is currently
178 -- in place, this is the same as Untailored_Exception_Information.
179 -- Otherwise, the decorator is used to produce a symbolic traceback
180 -- instead of hexadecimal addresses.
182 -- Note that unlike Untailored_Exception_Information, there is no need
183 -- to keep the output of Exception_Information stable for streaming
184 -- purposes, and in fact the output differs across platforms.
188 package Exception_Traces is
190 -------------------------------------------------
191 -- Run-Time Exception Notification Subprograms --
192 -------------------------------------------------
194 -- These subprograms provide a common run-time interface to trigger the
195 -- actions required when an exception is about to be propagated (e.g.
196 -- user specified actions or output of exception information). They are
197 -- exported to be usable by the Ada exception handling personality
198 -- routine when the GCC 3 mechanism is used.
200 procedure Notify_Handled_Exception (Excep : EOA);
202 (C, Notify_Handled_Exception, "__gnat_notify_handled_exception");
203 -- This routine is called for a handled occurrence is about to be
206 procedure Notify_Unhandled_Exception (Excep : EOA);
208 (C, Notify_Unhandled_Exception, "__gnat_notify_unhandled_exception");
209 -- This routine is called when an unhandled occurrence is about to be
212 procedure Unhandled_Exception_Terminate (Excep : EOA);
213 pragma No_Return (Unhandled_Exception_Terminate);
214 -- This procedure is called to terminate execution following an
215 -- unhandled exception. The exception information, including
216 -- traceback if available is output, and execution is then
217 -- terminated. Note that at the point where this routine is
218 -- called, the stack has typically been destroyed.
220 end Exception_Traces;
222 package Exception_Propagation is
224 ---------------------------------------
225 -- Exception Propagation Subprograms --
226 ---------------------------------------
228 function Allocate_Occurrence return EOA;
229 -- Allocate an exception occurrence (as well as the machine occurrence)
231 procedure Propagate_Exception (Excep : Exception_Occurrence);
232 pragma No_Return (Propagate_Exception);
233 -- This procedure propagates the exception represented by Excep
235 end Exception_Propagation;
237 package Stream_Attributes is
239 ----------------------------------
240 -- Stream Attribute Subprograms --
241 ----------------------------------
243 function EId_To_String (X : Exception_Id) return String;
244 function String_To_EId (S : String) return Exception_Id;
245 -- Functions for implementing Exception_Id stream attributes
247 function EO_To_String (X : Exception_Occurrence) return String;
248 function String_To_EO (S : String) return Exception_Occurrence;
249 -- Functions for implementing Exception_Occurrence stream
252 end Stream_Attributes;
254 procedure Complete_Occurrence (X : EOA);
255 -- Finish building the occurrence: save the call chain and notify the
258 procedure Complete_And_Propagate_Occurrence (X : EOA);
259 pragma No_Return (Complete_And_Propagate_Occurrence);
260 -- This is a simple wrapper to Complete_Occurrence and
261 -- Exception_Propagation.Propagate_Exception.
263 function Create_Occurrence_From_Signal_Handler
265 M : System.Address) return EOA;
266 -- Create and build an exception occurrence using exception id E and
267 -- nul-terminated message M.
269 function Create_Machine_Occurrence_From_Signal_Handler
271 M : System.Address) return System.Address;
272 pragma Export (C, Create_Machine_Occurrence_From_Signal_Handler,
273 "__gnat_create_machine_occurrence_from_signal_handler");
274 -- Create and build an exception occurrence using exception id E and
275 -- nul-terminated message M. Return the machine occurrence.
277 procedure Raise_Exception_No_Defer
279 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 (File : System.Address; Line : Integer);
307 pragma No_Return (Raise_Constraint_Error);
308 pragma Export (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
309 -- Raise constraint error with file:line information
311 procedure Raise_Constraint_Error_Msg
312 (File : System.Address;
315 Msg : System.Address);
316 pragma No_Return (Raise_Constraint_Error_Msg);
318 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
319 -- Raise constraint error with file:line:col + msg information
321 procedure Raise_Program_Error (File : System.Address; Line : Integer);
322 pragma No_Return (Raise_Program_Error);
323 pragma Export (C, Raise_Program_Error, "__gnat_raise_program_error");
324 -- Raise program error with file:line information
326 procedure Raise_Program_Error_Msg
327 (File : System.Address;
329 Msg : System.Address);
330 pragma No_Return (Raise_Program_Error_Msg);
332 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
333 -- Raise program error with file:line + msg information
335 procedure Raise_Storage_Error (File : System.Address; Line : Integer);
336 pragma No_Return (Raise_Storage_Error);
337 pragma Export (C, Raise_Storage_Error, "__gnat_raise_storage_error");
338 -- Raise storage error with file:line information
340 procedure Raise_Storage_Error_Msg
341 (File : System.Address;
343 Msg : System.Address);
344 pragma No_Return (Raise_Storage_Error_Msg);
346 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
347 -- Raise storage error with file:line + reason msg information
349 -- The exception raising process and the automatic tracing mechanism rely
350 -- on some careful use of flags attached to the exception occurrence. The
351 -- graph below illustrates the relations between the Raise_ subprograms
352 -- and identifies the points where basic flags such as Exception_Raised
355 -- (i) signs indicate the flags initialization points. R stands for Raise,
356 -- W for With, and E for Exception.
358 -- R_No_Msg R_E R_Pe R_Ce R_Se
360 -- +--+ +--+ +---+ | +---+
362 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
364 -- +------------+ | +-----------+ +--+
366 -- | | | Set_E_C_Msg(i)
368 -- Complete_And_Propagate_Occurrence
371 pragma No_Return (Reraise);
372 pragma Export (C, Reraise, "__gnat_reraise");
373 -- Reraises the exception referenced by the Current_Excep field
374 -- of the TSD (all fields of this exception occurrence are set).
375 -- Abort is deferred before the reraise operation. Called from
376 -- System.Tasking.RendezVous.Exceptional_Complete_RendezVous
378 procedure Transfer_Occurrence
379 (Target : Exception_Occurrence_Access;
380 Source : Exception_Occurrence);
381 pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
382 -- Called from s-tasren.adb:Local_Complete_RendezVous and
383 -- s-tpobop.adb:Exceptional_Complete_Entry_Body to setup Target from
384 -- Source as an exception to be propagated in the caller task. Target is
385 -- expected to be a pointer to the fixed TSD occurrence for this task.
387 --------------------------------
388 -- Run-Time Check Subprograms --
389 --------------------------------
391 -- These subprograms raise a specific exception with a reason message
392 -- attached. The parameters are the file name and line number in each
393 -- case. The names are defined by Exp_Ch11.Get_RT_Exception_Name.
395 procedure Rcheck_CE_Access_Check
396 (File : System.Address; Line : Integer);
397 procedure Rcheck_CE_Null_Access_Parameter
398 (File : System.Address; Line : Integer);
399 procedure Rcheck_CE_Discriminant_Check
400 (File : System.Address; Line : Integer);
401 procedure Rcheck_CE_Divide_By_Zero
402 (File : System.Address; Line : Integer);
403 procedure Rcheck_CE_Explicit_Raise
404 (File : System.Address; Line : Integer);
405 procedure Rcheck_CE_Index_Check
406 (File : System.Address; Line : Integer);
407 procedure Rcheck_CE_Invalid_Data
408 (File : System.Address; Line : Integer);
409 procedure Rcheck_CE_Length_Check
410 (File : System.Address; Line : Integer);
411 procedure Rcheck_CE_Null_Exception_Id
412 (File : System.Address; Line : Integer);
413 procedure Rcheck_CE_Null_Not_Allowed
414 (File : System.Address; Line : Integer);
415 procedure Rcheck_CE_Overflow_Check
416 (File : System.Address; Line : Integer);
417 procedure Rcheck_CE_Partition_Check
418 (File : System.Address; Line : Integer);
419 procedure Rcheck_CE_Range_Check
420 (File : System.Address; Line : Integer);
421 procedure Rcheck_CE_Tag_Check
422 (File : System.Address; Line : Integer);
423 procedure Rcheck_PE_Access_Before_Elaboration
424 (File : System.Address; Line : Integer);
425 procedure Rcheck_PE_Accessibility_Check
426 (File : System.Address; Line : Integer);
427 procedure Rcheck_PE_Address_Of_Intrinsic
428 (File : System.Address; Line : Integer);
429 procedure Rcheck_PE_Aliased_Parameters
430 (File : System.Address; Line : Integer);
431 procedure Rcheck_PE_All_Guards_Closed
432 (File : System.Address; Line : Integer);
433 procedure Rcheck_PE_Bad_Predicated_Generic_Type
434 (File : System.Address; Line : Integer);
435 procedure Rcheck_PE_Build_In_Place_Mismatch
436 (File : System.Address; Line : Integer);
437 procedure Rcheck_PE_Current_Task_In_Entry_Body
438 (File : System.Address; Line : Integer);
439 procedure Rcheck_PE_Duplicated_Entry_Address
440 (File : System.Address; Line : Integer);
441 procedure Rcheck_PE_Explicit_Raise
442 (File : System.Address; Line : Integer);
443 procedure Rcheck_PE_Implicit_Return
444 (File : System.Address; Line : Integer);
445 procedure Rcheck_PE_Misaligned_Address_Value
446 (File : System.Address; Line : Integer);
447 procedure Rcheck_PE_Missing_Return
448 (File : System.Address; Line : Integer);
449 procedure Rcheck_PE_Non_Transportable_Actual
450 (File : System.Address; Line : Integer);
451 procedure Rcheck_PE_Overlaid_Controlled_Object
452 (File : System.Address; Line : Integer);
453 procedure Rcheck_PE_Potentially_Blocking_Operation
454 (File : System.Address; Line : Integer);
455 procedure Rcheck_PE_Stubbed_Subprogram_Called
456 (File : System.Address; Line : Integer);
457 procedure Rcheck_PE_Unchecked_Union_Restriction
458 (File : System.Address; Line : Integer);
459 procedure Rcheck_SE_Empty_Storage_Pool
460 (File : System.Address; Line : Integer);
461 procedure Rcheck_SE_Explicit_Raise
462 (File : System.Address; Line : Integer);
463 procedure Rcheck_SE_Infinite_Recursion
464 (File : System.Address; Line : Integer);
465 procedure Rcheck_SE_Object_Too_Large
466 (File : System.Address; Line : Integer);
467 procedure Rcheck_PE_Stream_Operation_Not_Allowed
468 (File : System.Address; Line : Integer);
469 procedure Rcheck_CE_Access_Check_Ext
470 (File : System.Address; Line, Column : Integer);
471 procedure Rcheck_CE_Index_Check_Ext
472 (File : System.Address; Line, Column, Index, First, Last : Integer);
473 procedure Rcheck_CE_Invalid_Data_Ext
474 (File : System.Address; Line, Column, Index, First, Last : Integer);
475 procedure Rcheck_CE_Range_Check_Ext
476 (File : System.Address; Line, Column, Index, First, Last : Integer);
478 procedure Rcheck_PE_Finalize_Raised_Exception
479 (File : System.Address; Line : Integer);
480 -- This routine is separated out because it has quite different behavior
481 -- from the others. This is the "finalize/adjust raised exception". This
482 -- subprogram is always called with abort deferred, unlike all other
483 -- Rcheck_* subprograms, it needs to call Raise_Exception_No_Defer.
485 pragma Export (C, Rcheck_CE_Access_Check,
486 "__gnat_rcheck_CE_Access_Check");
487 pragma Export (C, Rcheck_CE_Null_Access_Parameter,
488 "__gnat_rcheck_CE_Null_Access_Parameter");
489 pragma Export (C, Rcheck_CE_Discriminant_Check,
490 "__gnat_rcheck_CE_Discriminant_Check");
491 pragma Export (C, Rcheck_CE_Divide_By_Zero,
492 "__gnat_rcheck_CE_Divide_By_Zero");
493 pragma Export (C, Rcheck_CE_Explicit_Raise,
494 "__gnat_rcheck_CE_Explicit_Raise");
495 pragma Export (C, Rcheck_CE_Index_Check,
496 "__gnat_rcheck_CE_Index_Check");
497 pragma Export (C, Rcheck_CE_Invalid_Data,
498 "__gnat_rcheck_CE_Invalid_Data");
499 pragma Export (C, Rcheck_CE_Length_Check,
500 "__gnat_rcheck_CE_Length_Check");
501 pragma Export (C, Rcheck_CE_Null_Exception_Id,
502 "__gnat_rcheck_CE_Null_Exception_Id");
503 pragma Export (C, Rcheck_CE_Null_Not_Allowed,
504 "__gnat_rcheck_CE_Null_Not_Allowed");
505 pragma Export (C, Rcheck_CE_Overflow_Check,
506 "__gnat_rcheck_CE_Overflow_Check");
507 pragma Export (C, Rcheck_CE_Partition_Check,
508 "__gnat_rcheck_CE_Partition_Check");
509 pragma Export (C, Rcheck_CE_Range_Check,
510 "__gnat_rcheck_CE_Range_Check");
511 pragma Export (C, Rcheck_CE_Tag_Check,
512 "__gnat_rcheck_CE_Tag_Check");
513 pragma Export (C, Rcheck_PE_Access_Before_Elaboration,
514 "__gnat_rcheck_PE_Access_Before_Elaboration");
515 pragma Export (C, Rcheck_PE_Accessibility_Check,
516 "__gnat_rcheck_PE_Accessibility_Check");
517 pragma Export (C, Rcheck_PE_Address_Of_Intrinsic,
518 "__gnat_rcheck_PE_Address_Of_Intrinsic");
519 pragma Export (C, Rcheck_PE_Aliased_Parameters,
520 "__gnat_rcheck_PE_Aliased_Parameters");
521 pragma Export (C, Rcheck_PE_All_Guards_Closed,
522 "__gnat_rcheck_PE_All_Guards_Closed");
523 pragma Export (C, Rcheck_PE_Bad_Predicated_Generic_Type,
524 "__gnat_rcheck_PE_Bad_Predicated_Generic_Type");
525 pragma Export (C, Rcheck_PE_Build_In_Place_Mismatch,
526 "__gnat_rcheck_PE_Build_In_Place_Mismatch");
527 pragma Export (C, Rcheck_PE_Current_Task_In_Entry_Body,
528 "__gnat_rcheck_PE_Current_Task_In_Entry_Body");
529 pragma Export (C, Rcheck_PE_Duplicated_Entry_Address,
530 "__gnat_rcheck_PE_Duplicated_Entry_Address");
531 pragma Export (C, Rcheck_PE_Explicit_Raise,
532 "__gnat_rcheck_PE_Explicit_Raise");
533 pragma Export (C, Rcheck_PE_Finalize_Raised_Exception,
534 "__gnat_rcheck_PE_Finalize_Raised_Exception");
535 pragma Export (C, Rcheck_PE_Implicit_Return,
536 "__gnat_rcheck_PE_Implicit_Return");
537 pragma Export (C, Rcheck_PE_Misaligned_Address_Value,
538 "__gnat_rcheck_PE_Misaligned_Address_Value");
539 pragma Export (C, Rcheck_PE_Missing_Return,
540 "__gnat_rcheck_PE_Missing_Return");
541 pragma Export (C, Rcheck_PE_Non_Transportable_Actual,
542 "__gnat_rcheck_PE_Non_Transportable_Actual");
543 pragma Export (C, Rcheck_PE_Overlaid_Controlled_Object,
544 "__gnat_rcheck_PE_Overlaid_Controlled_Object");
545 pragma Export (C, Rcheck_PE_Potentially_Blocking_Operation,
546 "__gnat_rcheck_PE_Potentially_Blocking_Operation");
547 pragma Export (C, Rcheck_PE_Stream_Operation_Not_Allowed,
548 "__gnat_rcheck_PE_Stream_Operation_Not_Allowed");
549 pragma Export (C, Rcheck_PE_Stubbed_Subprogram_Called,
550 "__gnat_rcheck_PE_Stubbed_Subprogram_Called");
551 pragma Export (C, Rcheck_PE_Unchecked_Union_Restriction,
552 "__gnat_rcheck_PE_Unchecked_Union_Restriction");
553 pragma Export (C, Rcheck_SE_Empty_Storage_Pool,
554 "__gnat_rcheck_SE_Empty_Storage_Pool");
555 pragma Export (C, Rcheck_SE_Explicit_Raise,
556 "__gnat_rcheck_SE_Explicit_Raise");
557 pragma Export (C, Rcheck_SE_Infinite_Recursion,
558 "__gnat_rcheck_SE_Infinite_Recursion");
559 pragma Export (C, Rcheck_SE_Object_Too_Large,
560 "__gnat_rcheck_SE_Object_Too_Large");
562 pragma Export (C, Rcheck_CE_Access_Check_Ext,
563 "__gnat_rcheck_CE_Access_Check_ext");
564 pragma Export (C, Rcheck_CE_Index_Check_Ext,
565 "__gnat_rcheck_CE_Index_Check_ext");
566 pragma Export (C, Rcheck_CE_Invalid_Data_Ext,
567 "__gnat_rcheck_CE_Invalid_Data_ext");
568 pragma Export (C, Rcheck_CE_Range_Check_Ext,
569 "__gnat_rcheck_CE_Range_Check_ext");
571 -- None of these procedures ever returns (they raise an exception). By
572 -- using pragma No_Return, we ensure that any junk code after the call,
573 -- such as normal return epilogue stuff, can be eliminated).
575 pragma No_Return (Rcheck_CE_Access_Check);
576 pragma No_Return (Rcheck_CE_Null_Access_Parameter);
577 pragma No_Return (Rcheck_CE_Discriminant_Check);
578 pragma No_Return (Rcheck_CE_Divide_By_Zero);
579 pragma No_Return (Rcheck_CE_Explicit_Raise);
580 pragma No_Return (Rcheck_CE_Index_Check);
581 pragma No_Return (Rcheck_CE_Invalid_Data);
582 pragma No_Return (Rcheck_CE_Length_Check);
583 pragma No_Return (Rcheck_CE_Null_Exception_Id);
584 pragma No_Return (Rcheck_CE_Null_Not_Allowed);
585 pragma No_Return (Rcheck_CE_Overflow_Check);
586 pragma No_Return (Rcheck_CE_Partition_Check);
587 pragma No_Return (Rcheck_CE_Range_Check);
588 pragma No_Return (Rcheck_CE_Tag_Check);
589 pragma No_Return (Rcheck_PE_Access_Before_Elaboration);
590 pragma No_Return (Rcheck_PE_Accessibility_Check);
591 pragma No_Return (Rcheck_PE_Address_Of_Intrinsic);
592 pragma No_Return (Rcheck_PE_Aliased_Parameters);
593 pragma No_Return (Rcheck_PE_All_Guards_Closed);
594 pragma No_Return (Rcheck_PE_Bad_Predicated_Generic_Type);
595 pragma No_Return (Rcheck_PE_Build_In_Place_Mismatch);
596 pragma No_Return (Rcheck_PE_Current_Task_In_Entry_Body);
597 pragma No_Return (Rcheck_PE_Duplicated_Entry_Address);
598 pragma No_Return (Rcheck_PE_Explicit_Raise);
599 pragma No_Return (Rcheck_PE_Implicit_Return);
600 pragma No_Return (Rcheck_PE_Misaligned_Address_Value);
601 pragma No_Return (Rcheck_PE_Missing_Return);
602 pragma No_Return (Rcheck_PE_Non_Transportable_Actual);
603 pragma No_Return (Rcheck_PE_Overlaid_Controlled_Object);
604 pragma No_Return (Rcheck_PE_Potentially_Blocking_Operation);
605 pragma No_Return (Rcheck_PE_Stream_Operation_Not_Allowed);
606 pragma No_Return (Rcheck_PE_Stubbed_Subprogram_Called);
607 pragma No_Return (Rcheck_PE_Unchecked_Union_Restriction);
608 pragma No_Return (Rcheck_PE_Finalize_Raised_Exception);
609 pragma No_Return (Rcheck_SE_Empty_Storage_Pool);
610 pragma No_Return (Rcheck_SE_Explicit_Raise);
611 pragma No_Return (Rcheck_SE_Infinite_Recursion);
612 pragma No_Return (Rcheck_SE_Object_Too_Large);
614 pragma No_Return (Rcheck_CE_Access_Check_Ext);
615 pragma No_Return (Rcheck_CE_Index_Check_Ext);
616 pragma No_Return (Rcheck_CE_Invalid_Data_Ext);
617 pragma No_Return (Rcheck_CE_Range_Check_Ext);
619 ---------------------------------------------
620 -- Reason Strings for Run-Time Check Calls --
621 ---------------------------------------------
623 -- These strings are null-terminated and are used by Rcheck_nn. The
624 -- strings correspond to the definitions for Types.RT_Exception_Code.
628 Rmsg_00 : constant String := "access check failed" & NUL;
629 Rmsg_01 : constant String := "access parameter is null" & NUL;
630 Rmsg_02 : constant String := "discriminant check failed" & NUL;
631 Rmsg_03 : constant String := "divide by zero" & NUL;
632 Rmsg_04 : constant String := "explicit raise" & NUL;
633 Rmsg_05 : constant String := "index check failed" & NUL;
634 Rmsg_06 : constant String := "invalid data" & NUL;
635 Rmsg_07 : constant String := "length check failed" & NUL;
636 Rmsg_08 : constant String := "null Exception_Id" & NUL;
637 Rmsg_09 : constant String := "null-exclusion check failed" & NUL;
638 Rmsg_10 : constant String := "overflow check failed" & NUL;
639 Rmsg_11 : constant String := "partition check failed" & NUL;
640 Rmsg_12 : constant String := "range check failed" & NUL;
641 Rmsg_13 : constant String := "tag check failed" & NUL;
642 Rmsg_14 : constant String := "access before elaboration" & NUL;
643 Rmsg_15 : constant String := "accessibility check failed" & NUL;
644 Rmsg_16 : constant String := "attempt to take address of" &
645 " intrinsic subprogram" & NUL;
646 Rmsg_17 : constant String := "aliased parameters" & NUL;
647 Rmsg_18 : constant String := "all guards closed" & NUL;
648 Rmsg_19 : constant String := "improper use of generic subtype" &
649 " with predicate" & NUL;
650 Rmsg_20 : constant String := "Current_Task referenced in entry" &
652 Rmsg_21 : constant String := "duplicated entry address" & NUL;
653 Rmsg_22 : constant String := "explicit raise" & NUL;
654 Rmsg_23 : constant String := "finalize/adjust raised exception" & NUL;
655 Rmsg_24 : constant String := "implicit return with No_Return" & NUL;
656 Rmsg_25 : constant String := "misaligned address value" & NUL;
657 Rmsg_26 : constant String := "missing return" & NUL;
658 Rmsg_27 : constant String := "overlaid controlled object" & NUL;
659 Rmsg_28 : constant String := "potentially blocking operation" & NUL;
660 Rmsg_29 : constant String := "stubbed subprogram called" & NUL;
661 Rmsg_30 : constant String := "unchecked union restriction" & NUL;
662 Rmsg_31 : constant String := "actual/returned class-wide" &
663 " value not transportable" & NUL;
664 Rmsg_32 : constant String := "empty storage pool" & NUL;
665 Rmsg_33 : constant String := "explicit raise" & NUL;
666 Rmsg_34 : constant String := "infinite recursion" & NUL;
667 Rmsg_35 : constant String := "object too large" & NUL;
668 Rmsg_36 : constant String := "stream operation not allowed" & NUL;
669 Rmsg_37 : constant String := "build-in-place mismatch" & NUL;
671 -----------------------
672 -- Polling Interface --
673 -----------------------
675 type Unsigned is mod 2 ** 32;
677 Counter : Unsigned := 0;
678 pragma Warnings (Off, Counter);
679 -- This counter is provided for convenience. It can be used in Poll to
680 -- perform periodic but not systematic operations.
682 procedure Poll is separate;
683 -- The actual polling routine is separate, so that it can easily be
684 -- replaced with a target dependent version.
686 --------------------------
687 -- Code_Address_For_AAA --
688 --------------------------
690 -- This function gives us the start of the PC range for addresses within
691 -- the exception unit itself. We hope that gigi/gcc keep all the procedures
692 -- in their original order.
694 function Code_Address_For_AAA return System.Address is
696 -- We are using a label instead of Code_Address_For_AAA'Address because
697 -- on some platforms the latter does not yield the address we want, but
698 -- the address of a stub or of a descriptor instead. This is the case at
702 return Start_Of_AAA'Address;
703 end Code_Address_For_AAA;
709 procedure Call_Chain (Excep : EOA) is separate;
710 -- The actual Call_Chain routine is separate, so that it can easily
711 -- be dummied out when no exception traceback information is needed.
717 function EId_To_String (X : Exception_Id) return String
718 renames Stream_Attributes.EId_To_String;
724 -- We use the null string to represent the null occurrence, otherwise we
725 -- output the Untailored_Exception_Information string for the occurrence.
727 function EO_To_String (X : Exception_Occurrence) return String
728 renames Stream_Attributes.EO_To_String;
730 ------------------------
731 -- Exception_Identity --
732 ------------------------
734 function Exception_Identity
735 (X : Exception_Occurrence) return Exception_Id
738 -- Note that the following test used to be here for the original
739 -- Ada 95 semantics, but these were modified by AI-241 to require
740 -- returning Null_Id instead of raising Constraint_Error.
742 -- if X.Id = Null_Id then
743 -- raise Constraint_Error;
747 end Exception_Identity;
749 ---------------------------
750 -- Exception_Information --
751 ---------------------------
753 function Exception_Information (X : Exception_Occurrence) return String is
755 if X.Id = Null_Id then
756 raise Constraint_Error;
758 return Exception_Data.Exception_Information (X);
760 end Exception_Information;
762 -----------------------
763 -- Exception_Message --
764 -----------------------
766 function Exception_Message (X : Exception_Occurrence) return String is
768 if X.Id = Null_Id then
769 raise Constraint_Error;
771 return X.Msg (1 .. X.Msg_Length);
773 end Exception_Message;
779 function Exception_Name (Id : Exception_Id) return String is
782 raise Constraint_Error;
784 return To_Ptr (Id.Full_Name) (1 .. Id.Name_Length - 1);
788 function Exception_Name (X : Exception_Occurrence) return String is
790 return Exception_Name (X.Id);
793 ---------------------------
794 -- Exception_Name_Simple --
795 ---------------------------
797 function Exception_Name_Simple (X : Exception_Occurrence) return String is
798 Name : constant String := Exception_Name (X);
804 exit when Name (P - 1) = '.';
808 -- Return result making sure lower bound is 1
811 subtype Rname is String (1 .. Name'Length - P + 1);
813 return Rname (Name (P .. Name'Length));
815 end Exception_Name_Simple;
821 package body Exception_Data is separate;
822 -- This package can be easily dummied out if we do not want the basic
823 -- support for exception messages (such as in Ada 83).
825 ---------------------------
826 -- Exception_Propagation --
827 ---------------------------
829 package body Exception_Propagation is separate;
830 -- Depending on the actual exception mechanism used (front-end or
831 -- back-end based), the implementation will differ, which is why this
832 -- package is separated.
834 ----------------------
835 -- Exception_Traces --
836 ----------------------
838 package body Exception_Traces is separate;
839 -- Depending on the underlying support for IO the implementation will
840 -- differ. Moreover we would like to dummy out this package in case we
841 -- do not want any exception tracing support. This is why this package
844 --------------------------------------
845 -- Get_Exception_Machine_Occurrence --
846 --------------------------------------
848 function Get_Exception_Machine_Occurrence
849 (X : Exception_Occurrence) return System.Address
852 return X.Machine_Occurrence;
853 end Get_Exception_Machine_Occurrence;
859 function Image (Index : Integer) return String is
860 Result : constant String := Integer'Image (Index);
862 if Result (1) = ' ' then
863 return Result (2 .. Result'Last);
869 -----------------------
870 -- Stream Attributes --
871 -----------------------
873 package body Stream_Attributes is separate;
874 -- This package can be easily dummied out if we do not want the
875 -- support for streaming Exception_Ids and Exception_Occurrences.
877 ----------------------------
878 -- Raise_Constraint_Error --
879 ----------------------------
881 procedure Raise_Constraint_Error (File : System.Address; Line : Integer) is
883 Raise_With_Location_And_Msg (Constraint_Error_Def'Access, File, Line);
884 end Raise_Constraint_Error;
886 --------------------------------
887 -- Raise_Constraint_Error_Msg --
888 --------------------------------
890 procedure Raise_Constraint_Error_Msg
891 (File : System.Address;
894 Msg : System.Address)
897 Raise_With_Location_And_Msg
898 (Constraint_Error_Def'Access, File, Line, Column, Msg);
899 end Raise_Constraint_Error_Msg;
901 -------------------------
902 -- Complete_Occurrence --
903 -------------------------
905 procedure Complete_Occurrence (X : EOA) is
907 -- Compute the backtrace for this occurrence if the corresponding
908 -- binder option has been set. Call_Chain takes care of the reraise
911 -- ??? Using Call_Chain here means we are going to walk up the stack
912 -- once only for backtracing purposes before doing it again for the
913 -- propagation per se.
915 -- The first inspection is much lighter, though, as it only requires
916 -- partial unwinding of each frame. Additionally, although we could use
917 -- the personality routine to record the addresses while propagating,
918 -- this method has two drawbacks:
920 -- 1) the trace is incomplete if the exception is handled since we
921 -- don't walk past the frame with the handler,
925 -- 2) we would miss the frames for which our personality routine is not
926 -- called, e.g. if C or C++ calls are on the way.
930 -- Notify the debugger
931 Debug_Raise_Exception
932 (E => SSL.Exception_Data_Ptr (X.Id),
933 Message => X.Msg (1 .. X.Msg_Length));
934 end Complete_Occurrence;
936 ---------------------------------------
937 -- Complete_And_Propagate_Occurrence --
938 ---------------------------------------
940 procedure Complete_And_Propagate_Occurrence (X : EOA) is
942 Complete_Occurrence (X);
943 Exception_Propagation.Propagate_Exception (X.all);
944 end Complete_And_Propagate_Occurrence;
946 ---------------------
947 -- Raise_Exception --
948 ---------------------
950 procedure Raise_Exception
952 Message : String := "")
954 EF : Exception_Id := E;
956 -- Raise CE if E = Null_ID (AI-446)
959 EF := Constraint_Error'Identity;
962 -- Go ahead and raise appropriate exception
964 Raise_Exception_Always (EF, Message);
967 ----------------------------
968 -- Raise_Exception_Always --
969 ----------------------------
971 procedure Raise_Exception_Always
973 Message : String := "")
975 X : constant EOA := Exception_Propagation.Allocate_Occurrence;
978 Exception_Data.Set_Exception_Msg (X, E, Message);
980 if not ZCX_By_Default then
984 Complete_And_Propagate_Occurrence (X);
985 end Raise_Exception_Always;
987 ------------------------------
988 -- Raise_Exception_No_Defer --
989 ------------------------------
991 procedure Raise_Exception_No_Defer
993 Message : String := "")
995 X : constant EOA := Exception_Propagation.Allocate_Occurrence;
998 Exception_Data.Set_Exception_Msg (X, E, Message);
1000 -- Do not call Abort_Defer.all, as specified by the spec
1002 Complete_And_Propagate_Occurrence (X);
1003 end Raise_Exception_No_Defer;
1005 -------------------------------------
1006 -- Raise_From_Controlled_Operation --
1007 -------------------------------------
1009 procedure Raise_From_Controlled_Operation
1010 (X : Ada.Exceptions.Exception_Occurrence)
1012 Prefix : constant String := "adjust/finalize raised ";
1013 Orig_Msg : constant String := Exception_Message (X);
1014 Orig_Prefix_Length : constant Natural :=
1015 Integer'Min (Prefix'Length, Orig_Msg'Length);
1017 Orig_Prefix : String renames
1018 Orig_Msg (Orig_Msg'First .. Orig_Msg'First + Orig_Prefix_Length - 1);
1021 -- Message already has the proper prefix, just re-raise
1023 if Orig_Prefix = Prefix then
1024 Raise_Exception_No_Defer
1025 (E => Program_Error'Identity,
1026 Message => Orig_Msg);
1030 New_Msg : constant String := Prefix & Exception_Name (X);
1033 -- No message present, just provide our own
1035 if Orig_Msg = "" then
1036 Raise_Exception_No_Defer
1037 (E => Program_Error'Identity,
1038 Message => New_Msg);
1040 -- Message present, add informational prefix
1043 Raise_Exception_No_Defer
1044 (E => Program_Error'Identity,
1045 Message => New_Msg & ": " & Orig_Msg);
1049 end Raise_From_Controlled_Operation;
1051 -------------------------------------------
1052 -- Create_Occurrence_From_Signal_Handler --
1053 -------------------------------------------
1055 function Create_Occurrence_From_Signal_Handler
1057 M : System.Address) return EOA
1059 X : constant EOA := Exception_Propagation.Allocate_Occurrence;
1062 Exception_Data.Set_Exception_C_Msg (X, E, M);
1064 if not ZCX_By_Default then
1068 Complete_Occurrence (X);
1070 end Create_Occurrence_From_Signal_Handler;
1072 ---------------------------------------------------
1073 -- Create_Machine_Occurrence_From_Signal_Handler --
1074 ---------------------------------------------------
1076 function Create_Machine_Occurrence_From_Signal_Handler
1078 M : System.Address) return System.Address
1081 return Create_Occurrence_From_Signal_Handler (E, M).Machine_Occurrence;
1082 end Create_Machine_Occurrence_From_Signal_Handler;
1084 -------------------------------
1085 -- Raise_From_Signal_Handler --
1086 -------------------------------
1088 procedure Raise_From_Signal_Handler
1093 Exception_Propagation.Propagate_Exception
1094 (Create_Occurrence_From_Signal_Handler (E, M).all);
1095 end Raise_From_Signal_Handler;
1097 -------------------------
1098 -- Raise_Program_Error --
1099 -------------------------
1101 procedure Raise_Program_Error
1102 (File : System.Address;
1106 Raise_With_Location_And_Msg (Program_Error_Def'Access, File, Line);
1107 end Raise_Program_Error;
1109 -----------------------------
1110 -- Raise_Program_Error_Msg --
1111 -----------------------------
1113 procedure Raise_Program_Error_Msg
1114 (File : System.Address;
1116 Msg : System.Address)
1119 Raise_With_Location_And_Msg
1120 (Program_Error_Def'Access, File, Line, M => Msg);
1121 end Raise_Program_Error_Msg;
1123 -------------------------
1124 -- Raise_Storage_Error --
1125 -------------------------
1127 procedure Raise_Storage_Error
1128 (File : System.Address;
1132 Raise_With_Location_And_Msg (Storage_Error_Def'Access, File, Line);
1133 end Raise_Storage_Error;
1135 -----------------------------
1136 -- Raise_Storage_Error_Msg --
1137 -----------------------------
1139 procedure Raise_Storage_Error_Msg
1140 (File : System.Address;
1142 Msg : System.Address)
1145 Raise_With_Location_And_Msg
1146 (Storage_Error_Def'Access, File, Line, M => Msg);
1147 end Raise_Storage_Error_Msg;
1149 ---------------------------------
1150 -- Raise_With_Location_And_Msg --
1151 ---------------------------------
1153 procedure Raise_With_Location_And_Msg
1158 M : System.Address := System.Null_Address)
1160 X : constant EOA := Exception_Propagation.Allocate_Occurrence;
1162 Exception_Data.Set_Exception_C_Msg (X, E, F, L, C, M);
1164 if not ZCX_By_Default then
1168 Complete_And_Propagate_Occurrence (X);
1169 end Raise_With_Location_And_Msg;
1171 --------------------
1172 -- Raise_With_Msg --
1173 --------------------
1175 procedure Raise_With_Msg (E : Exception_Id) is
1176 Excep : constant EOA := Exception_Propagation.Allocate_Occurrence;
1177 Ex : constant Exception_Occurrence_Access := Get_Current_Excep.all;
1179 Excep.Exception_Raised := False;
1181 Excep.Num_Tracebacks := 0;
1182 Excep.Pid := Local_Partition_ID;
1184 -- Copy the message from the current exception
1185 -- Change the interface to be called with an occurrence ???
1187 Excep.Msg_Length := Ex.Msg_Length;
1188 Excep.Msg (1 .. Excep.Msg_Length) := Ex.Msg (1 .. Ex.Msg_Length);
1190 -- The following is a common pattern, should be abstracted
1191 -- into a procedure call ???
1193 if not ZCX_By_Default then
1197 Complete_And_Propagate_Occurrence (Excep);
1200 -----------------------------------------
1201 -- Calls to Run-Time Check Subprograms --
1202 -----------------------------------------
1204 procedure Rcheck_CE_Access_Check
1205 (File : System.Address; Line : Integer)
1208 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_00'Address);
1209 end Rcheck_CE_Access_Check;
1211 procedure Rcheck_CE_Null_Access_Parameter
1212 (File : System.Address; Line : Integer)
1215 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_01'Address);
1216 end Rcheck_CE_Null_Access_Parameter;
1218 procedure Rcheck_CE_Discriminant_Check
1219 (File : System.Address; Line : Integer)
1222 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_02'Address);
1223 end Rcheck_CE_Discriminant_Check;
1225 procedure Rcheck_CE_Divide_By_Zero
1226 (File : System.Address; Line : Integer)
1229 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_03'Address);
1230 end Rcheck_CE_Divide_By_Zero;
1232 procedure Rcheck_CE_Explicit_Raise
1233 (File : System.Address; Line : Integer)
1236 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_04'Address);
1237 end Rcheck_CE_Explicit_Raise;
1239 procedure Rcheck_CE_Index_Check
1240 (File : System.Address; Line : Integer)
1243 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_05'Address);
1244 end Rcheck_CE_Index_Check;
1246 procedure Rcheck_CE_Invalid_Data
1247 (File : System.Address; Line : Integer)
1250 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_06'Address);
1251 end Rcheck_CE_Invalid_Data;
1253 procedure Rcheck_CE_Length_Check
1254 (File : System.Address; Line : Integer)
1257 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_07'Address);
1258 end Rcheck_CE_Length_Check;
1260 procedure Rcheck_CE_Null_Exception_Id
1261 (File : System.Address; Line : Integer)
1264 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_08'Address);
1265 end Rcheck_CE_Null_Exception_Id;
1267 procedure Rcheck_CE_Null_Not_Allowed
1268 (File : System.Address; Line : Integer)
1271 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_09'Address);
1272 end Rcheck_CE_Null_Not_Allowed;
1274 procedure Rcheck_CE_Overflow_Check
1275 (File : System.Address; Line : Integer)
1278 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_10'Address);
1279 end Rcheck_CE_Overflow_Check;
1281 procedure Rcheck_CE_Partition_Check
1282 (File : System.Address; Line : Integer)
1285 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_11'Address);
1286 end Rcheck_CE_Partition_Check;
1288 procedure Rcheck_CE_Range_Check
1289 (File : System.Address; Line : Integer)
1292 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_12'Address);
1293 end Rcheck_CE_Range_Check;
1295 procedure Rcheck_CE_Tag_Check
1296 (File : System.Address; Line : Integer)
1299 Raise_Constraint_Error_Msg (File, Line, 0, Rmsg_13'Address);
1300 end Rcheck_CE_Tag_Check;
1302 procedure Rcheck_PE_Access_Before_Elaboration
1303 (File : System.Address; Line : Integer)
1306 Raise_Program_Error_Msg (File, Line, Rmsg_14'Address);
1307 end Rcheck_PE_Access_Before_Elaboration;
1309 procedure Rcheck_PE_Accessibility_Check
1310 (File : System.Address; Line : Integer)
1313 Raise_Program_Error_Msg (File, Line, Rmsg_15'Address);
1314 end Rcheck_PE_Accessibility_Check;
1316 procedure Rcheck_PE_Address_Of_Intrinsic
1317 (File : System.Address; Line : Integer)
1320 Raise_Program_Error_Msg (File, Line, Rmsg_16'Address);
1321 end Rcheck_PE_Address_Of_Intrinsic;
1323 procedure Rcheck_PE_Aliased_Parameters
1324 (File : System.Address; Line : Integer)
1327 Raise_Program_Error_Msg (File, Line, Rmsg_17'Address);
1328 end Rcheck_PE_Aliased_Parameters;
1330 procedure Rcheck_PE_All_Guards_Closed
1331 (File : System.Address; Line : Integer)
1334 Raise_Program_Error_Msg (File, Line, Rmsg_18'Address);
1335 end Rcheck_PE_All_Guards_Closed;
1337 procedure Rcheck_PE_Bad_Predicated_Generic_Type
1338 (File : System.Address; Line : Integer)
1341 Raise_Program_Error_Msg (File, Line, Rmsg_19'Address);
1342 end Rcheck_PE_Bad_Predicated_Generic_Type;
1344 procedure Rcheck_PE_Build_In_Place_Mismatch
1345 (File : System.Address; Line : Integer)
1348 Raise_Program_Error_Msg (File, Line, Rmsg_37'Address);
1349 end Rcheck_PE_Build_In_Place_Mismatch;
1351 procedure Rcheck_PE_Current_Task_In_Entry_Body
1352 (File : System.Address; Line : Integer)
1355 Raise_Program_Error_Msg (File, Line, Rmsg_20'Address);
1356 end Rcheck_PE_Current_Task_In_Entry_Body;
1358 procedure Rcheck_PE_Duplicated_Entry_Address
1359 (File : System.Address; Line : Integer)
1362 Raise_Program_Error_Msg (File, Line, Rmsg_21'Address);
1363 end Rcheck_PE_Duplicated_Entry_Address;
1365 procedure Rcheck_PE_Explicit_Raise
1366 (File : System.Address; Line : Integer)
1369 Raise_Program_Error_Msg (File, Line, Rmsg_22'Address);
1370 end Rcheck_PE_Explicit_Raise;
1372 procedure Rcheck_PE_Implicit_Return
1373 (File : System.Address; Line : Integer)
1376 Raise_Program_Error_Msg (File, Line, Rmsg_24'Address);
1377 end Rcheck_PE_Implicit_Return;
1379 procedure Rcheck_PE_Misaligned_Address_Value
1380 (File : System.Address; Line : Integer)
1383 Raise_Program_Error_Msg (File, Line, Rmsg_25'Address);
1384 end Rcheck_PE_Misaligned_Address_Value;
1386 procedure Rcheck_PE_Missing_Return
1387 (File : System.Address; Line : Integer)
1390 Raise_Program_Error_Msg (File, Line, Rmsg_26'Address);
1391 end Rcheck_PE_Missing_Return;
1393 procedure Rcheck_PE_Non_Transportable_Actual
1394 (File : System.Address; Line : Integer)
1397 Raise_Program_Error_Msg (File, Line, Rmsg_31'Address);
1398 end Rcheck_PE_Non_Transportable_Actual;
1400 procedure Rcheck_PE_Overlaid_Controlled_Object
1401 (File : System.Address; Line : Integer)
1404 Raise_Program_Error_Msg (File, Line, Rmsg_27'Address);
1405 end Rcheck_PE_Overlaid_Controlled_Object;
1407 procedure Rcheck_PE_Potentially_Blocking_Operation
1408 (File : System.Address; Line : Integer)
1411 Raise_Program_Error_Msg (File, Line, Rmsg_28'Address);
1412 end Rcheck_PE_Potentially_Blocking_Operation;
1414 procedure Rcheck_PE_Stream_Operation_Not_Allowed
1415 (File : System.Address; Line : Integer)
1418 Raise_Program_Error_Msg (File, Line, Rmsg_36'Address);
1419 end Rcheck_PE_Stream_Operation_Not_Allowed;
1421 procedure Rcheck_PE_Stubbed_Subprogram_Called
1422 (File : System.Address; Line : Integer)
1425 Raise_Program_Error_Msg (File, Line, Rmsg_29'Address);
1426 end Rcheck_PE_Stubbed_Subprogram_Called;
1428 procedure Rcheck_PE_Unchecked_Union_Restriction
1429 (File : System.Address; Line : Integer)
1432 Raise_Program_Error_Msg (File, Line, Rmsg_30'Address);
1433 end Rcheck_PE_Unchecked_Union_Restriction;
1435 procedure Rcheck_SE_Empty_Storage_Pool
1436 (File : System.Address; Line : Integer)
1439 Raise_Storage_Error_Msg (File, Line, Rmsg_32'Address);
1440 end Rcheck_SE_Empty_Storage_Pool;
1442 procedure Rcheck_SE_Explicit_Raise
1443 (File : System.Address; Line : Integer)
1446 Raise_Storage_Error_Msg (File, Line, Rmsg_33'Address);
1447 end Rcheck_SE_Explicit_Raise;
1449 procedure Rcheck_SE_Infinite_Recursion
1450 (File : System.Address; Line : Integer)
1453 Raise_Storage_Error_Msg (File, Line, Rmsg_34'Address);
1454 end Rcheck_SE_Infinite_Recursion;
1456 procedure Rcheck_SE_Object_Too_Large
1457 (File : System.Address; Line : Integer)
1460 Raise_Storage_Error_Msg (File, Line, Rmsg_35'Address);
1461 end Rcheck_SE_Object_Too_Large;
1463 procedure Rcheck_CE_Access_Check_Ext
1464 (File : System.Address; Line, Column : Integer)
1467 Raise_Constraint_Error_Msg (File, Line, Column, Rmsg_00'Address);
1468 end Rcheck_CE_Access_Check_Ext;
1470 procedure Rcheck_CE_Index_Check_Ext
1471 (File : System.Address; Line, Column, Index, First, Last : Integer)
1473 Msg : constant String :=
1474 Rmsg_05 (Rmsg_05'First .. Rmsg_05'Last - 1) & ASCII.LF
1475 & "index " & Image (Index) & " not in " & Image (First)
1476 & ".." & Image (Last) & ASCII.NUL;
1478 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1479 end Rcheck_CE_Index_Check_Ext;
1481 procedure Rcheck_CE_Invalid_Data_Ext
1482 (File : System.Address; Line, Column, Index, First, Last : Integer)
1484 Msg : constant String :=
1485 Rmsg_06 (Rmsg_06'First .. Rmsg_06'Last - 1) & ASCII.LF
1486 & "value " & Image (Index) & " not in " & Image (First)
1487 & ".." & Image (Last) & ASCII.NUL;
1489 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1490 end Rcheck_CE_Invalid_Data_Ext;
1492 procedure Rcheck_CE_Range_Check_Ext
1493 (File : System.Address; Line, Column, Index, First, Last : Integer)
1495 Msg : constant String :=
1496 Rmsg_12 (Rmsg_12'First .. Rmsg_12'Last - 1) & ASCII.LF
1497 & "value " & Image (Index) & " not in " & Image (First)
1498 & ".." & Image (Last) & ASCII.NUL;
1500 Raise_Constraint_Error_Msg (File, Line, Column, Msg'Address);
1501 end Rcheck_CE_Range_Check_Ext;
1503 procedure Rcheck_PE_Finalize_Raised_Exception
1504 (File : System.Address; Line : Integer)
1506 X : constant EOA := Exception_Propagation.Allocate_Occurrence;
1509 -- This is "finalize/adjust raised exception". This subprogram is always
1510 -- called with abort deferred, unlike all other Rcheck_* subprograms, it
1511 -- needs to call Raise_Exception_No_Defer.
1513 -- This is consistent with Raise_From_Controlled_Operation
1515 Exception_Data.Set_Exception_C_Msg
1516 (X, Program_Error_Def'Access, File, Line, 0, Rmsg_23'Address);
1517 Complete_And_Propagate_Occurrence (X);
1518 end Rcheck_PE_Finalize_Raised_Exception;
1524 procedure Reraise is
1525 Excep : constant EOA := Exception_Propagation.Allocate_Occurrence;
1526 Saved_MO : constant System.Address := Excep.Machine_Occurrence;
1529 if not ZCX_By_Default then
1533 Save_Occurrence (Excep.all, Get_Current_Excep.all.all);
1534 Excep.Machine_Occurrence := Saved_MO;
1535 Complete_And_Propagate_Occurrence (Excep);
1538 --------------------------------------
1539 -- Reraise_Library_Exception_If_Any --
1540 --------------------------------------
1542 procedure Reraise_Library_Exception_If_Any is
1543 LE : Exception_Occurrence;
1546 if Library_Exception_Set then
1547 LE := Library_Exception;
1549 if LE.Id = Null_Id then
1550 Raise_Exception_No_Defer
1551 (E => Program_Error'Identity,
1552 Message => "finalize/adjust raised exception");
1554 Raise_From_Controlled_Operation (LE);
1557 end Reraise_Library_Exception_If_Any;
1559 ------------------------
1560 -- Reraise_Occurrence --
1561 ------------------------
1563 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1568 Reraise_Occurrence_Always (X);
1570 end Reraise_Occurrence;
1572 -------------------------------
1573 -- Reraise_Occurrence_Always --
1574 -------------------------------
1576 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1578 if not ZCX_By_Default then
1582 Reraise_Occurrence_No_Defer (X);
1583 end Reraise_Occurrence_Always;
1585 ---------------------------------
1586 -- Reraise_Occurrence_No_Defer --
1587 ---------------------------------
1589 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1591 -- If we have a Machine_Occurrence at hand already, e.g. when we are
1592 -- reraising a foreign exception, just repropagate. Otherwise, e.g.
1593 -- when reraising a GNAT exception or an occurrence read back from a
1594 -- stream, set up a new occurrence with its own Machine block first.
1596 if X.Machine_Occurrence /= System.Null_Address then
1597 Exception_Propagation.Propagate_Exception (X);
1600 Excep : constant EOA
1601 := Exception_Propagation.Allocate_Occurrence;
1602 Saved_MO : constant System.Address := Excep.Machine_Occurrence;
1604 Save_Occurrence (Excep.all, X);
1605 Excep.Machine_Occurrence := Saved_MO;
1606 Complete_And_Propagate_Occurrence (Excep);
1609 end Reraise_Occurrence_No_Defer;
1611 ---------------------
1612 -- Save_Occurrence --
1613 ---------------------
1615 procedure Save_Occurrence
1616 (Target : out Exception_Occurrence;
1617 Source : Exception_Occurrence)
1620 -- As the machine occurrence might be a data that must be finalized
1621 -- (outside any Ada mechanism), do not copy it
1623 Target.Id := Source.Id;
1624 Target.Machine_Occurrence := System.Null_Address;
1625 Target.Msg_Length := Source.Msg_Length;
1626 Target.Num_Tracebacks := Source.Num_Tracebacks;
1627 Target.Exception_Raised := Source.Exception_Raised;
1628 Target.Pid := Source.Pid;
1630 Target.Msg (1 .. Target.Msg_Length) :=
1631 Source.Msg (1 .. Target.Msg_Length);
1633 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1634 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1635 end Save_Occurrence;
1637 function Save_Occurrence (Source : Exception_Occurrence) return EOA is
1638 Target : constant EOA := new Exception_Occurrence;
1640 Save_Occurrence (Target.all, Source);
1642 end Save_Occurrence;
1648 function String_To_EId (S : String) return Exception_Id
1649 renames Stream_Attributes.String_To_EId;
1655 function String_To_EO (S : String) return Exception_Occurrence
1656 renames Stream_Attributes.String_To_EO;
1662 procedure To_Stderr (C : Character) is
1663 procedure Put_Char_Stderr (C : Character);
1664 pragma Import (C, Put_Char_Stderr, "put_char_stderr");
1666 Put_Char_Stderr (C);
1669 procedure To_Stderr (S : String) is
1671 for J in S'Range loop
1672 if S (J) /= ASCII.CR then
1678 -------------------------
1679 -- Transfer_Occurrence --
1680 -------------------------
1682 procedure Transfer_Occurrence
1683 (Target : Exception_Occurrence_Access;
1684 Source : Exception_Occurrence)
1687 Save_Occurrence (Target.all, Source);
1688 end Transfer_Occurrence;
1690 ------------------------
1691 -- Triggered_By_Abort --
1692 ------------------------
1694 function Triggered_By_Abort return Boolean is
1695 Ex : constant Exception_Occurrence_Access := Get_Current_Excep.all;
1698 and then Exception_Identity (Ex.all) = Standard'Abort_Signal'Identity;
1699 end Triggered_By_Abort;
1701 -------------------------
1702 -- Wide_Exception_Name --
1703 -------------------------
1705 WC_Encoding : Character;
1706 pragma Import (C, WC_Encoding, "__gl_wc_encoding");
1707 -- Encoding method for source, as exported by binder
1709 function Wide_Exception_Name
1710 (Id : Exception_Id) return Wide_String
1712 S : constant String := Exception_Name (Id);
1713 W : Wide_String (1 .. S'Length);
1716 String_To_Wide_String
1717 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1719 end Wide_Exception_Name;
1721 function Wide_Exception_Name
1722 (X : Exception_Occurrence) return Wide_String
1724 S : constant String := Exception_Name (X);
1725 W : Wide_String (1 .. S'Length);
1728 String_To_Wide_String
1729 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1731 end Wide_Exception_Name;
1733 ----------------------------
1734 -- Wide_Wide_Exception_Name --
1735 -----------------------------
1737 function Wide_Wide_Exception_Name
1738 (Id : Exception_Id) return Wide_Wide_String
1740 S : constant String := Exception_Name (Id);
1741 W : Wide_Wide_String (1 .. S'Length);
1744 String_To_Wide_Wide_String
1745 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1747 end Wide_Wide_Exception_Name;
1749 function Wide_Wide_Exception_Name
1750 (X : Exception_Occurrence) return Wide_Wide_String
1752 S : constant String := Exception_Name (X);
1753 W : Wide_Wide_String (1 .. S'Length);
1756 String_To_Wide_Wide_String
1757 (S, W, L, Get_WC_Encoding_Method (WC_Encoding));
1759 end Wide_Wide_Exception_Name;
1761 --------------------------
1762 -- Code_Address_For_ZZZ --
1763 --------------------------
1765 -- This function gives us the end of the PC range for addresses
1766 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1767 -- procedures in their original order.
1769 function Code_Address_For_ZZZ return System.Address is
1772 return Start_Of_ZZZ'Address;
1773 end Code_Address_For_ZZZ;