OSDN Git Service

2004-04-05 Vincent Celier <celier@gnat.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-except.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       A D A . E X C E P T I O N S                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 pragma Polling (Off);
35 --  We must turn polling off for this unit, because otherwise we get
36 --  elaboration circularities with System.Exception_Tables.
37
38 pragma Warnings (Off);
39 --  Since several constructs give warnings in 3.14a1, including unreferenced
40 --  variables and pragma Unreferenced itself.
41
42 with System;                  use System;
43 with System.Standard_Library; use System.Standard_Library;
44 with System.Soft_Links;       use System.Soft_Links;
45 with System.Machine_State_Operations; use System.Machine_State_Operations;
46
47 package body Ada.Exceptions is
48
49    procedure builtin_longjmp (buffer : Address; Flag : Integer);
50    pragma No_Return (builtin_longjmp);
51    pragma Import (C, builtin_longjmp, "_gnat_builtin_longjmp");
52
53    pragma Suppress (All_Checks);
54    --  We definitely do not want exceptions occurring within this unit, or
55    --  we are in big trouble. If an exceptional situation does occur, better
56    --  that it not be raised, since raising it can cause confusing chaos.
57
58    Zero_Cost_Exceptions : Integer;
59    pragma Import (C, Zero_Cost_Exceptions, "__gl_zero_cost_exceptions");
60    --  Boolean indicating if we are handling exceptions using a zero cost
61    --  mechanism.
62    --
63    --  Note that although we currently do not support it, the GCC3 back-end
64    --  tables are also potentially useable for setjmp/longjmp processing.
65
66    -----------------------
67    -- Local Subprograms --
68    -----------------------
69
70    --  Note: the exported subprograms in this package body are called directly
71    --  from C clients using the given external name, even though they are not
72    --  technically visible in the Ada sense.
73
74    procedure AAA;
75    procedure ZZZ;
76    --  Mark start and end of procedures in this package
77    --
78    --  The AAA and ZZZ procedures are used to provide exclusion bounds in
79    --  calls to Call_Chain at exception raise points from this unit. The
80    --  purpose is to arrange for the exception tracebacks not to include
81    --  frames from routines involved in the raise process, as these are
82    --  meaningless from the user's standpoint.
83    --
84    --  For these bounds to be meaningful, we need to ensure that the object
85    --  code for the routines involved in processing a raise is located after
86    --  the object code for AAA and before the object code for ZZZ. This will
87    --  indeed be the case as long as the following rules are respected:
88    --
89    --  1) The bodies of the subprograms involved in processing a raise
90    --     are located after the body of AAA and before the body of ZZZ.
91    --
92    --  2) No pragma Inline applies to any of these subprograms, as this
93    --     could delay the corresponding assembly output until the end of
94    --     the unit.
95
96    Code_Address_For_AAA, Code_Address_For_ZZZ : System.Address;
97    --  Used to represent addresses really inside the code range for AAA and
98    --  ZZZ, initialized to the address of a label inside the corresponding
99    --  procedure. This is initialization takes place inside the procedures
100    --  themselves, which are called as part of the elaboration code.
101    --
102    --  We are doing this instead of merely using Proc'Address because on some
103    --  platforms the latter does not yield the address we want, but the
104    --  address of a stub or of a descriptor instead. This is the case at least
105    --  on Alpha-VMS and PA-HPUX.
106
107    procedure Call_Chain (Excep : EOA);
108    --  Store up to Max_Tracebacks in Excep, corresponding to the current
109    --  call chain.
110
111    procedure Process_Raise_Exception
112      (E                   : Exception_Id;
113       From_Signal_Handler : Boolean);
114    pragma No_Return (Process_Raise_Exception);
115    --  This is the lowest level raise routine. It raises the exception
116    --  referenced by Current_Excep.all in the TSD, without deferring abort
117    --  (the caller must ensure that abort is deferred on entry).
118    --
119    --  This is the common implementation for Raise_Current_Excep and
120    --  Raise_From_Signal_Handler. The origin of the call is indicated by the
121    --  From_Signal_Handler argument.
122
123    package Exception_Data is
124
125       ----------------------------------
126       --  Exception messages routines --
127       ----------------------------------
128
129       procedure Set_Exception_C_Msg
130         (Id   : Exception_Id;
131          Msg1 : Big_String_Ptr;
132          Line : Integer        := 0;
133          Msg2 : Big_String_Ptr := null);
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. Msg1 is a null terminated string which is generated
137       --  as the exception message. If line is non-zero, then a colon and
138       --  the decimal representation of this integer is appended to the
139       --  message. When Msg2 is non-null, a space and this additional null
140       --  terminated string is added to the message.
141
142       procedure Set_Exception_Msg
143         (Id      : Exception_Id;
144          Message : String);
145       --  This routine is called to setup the exception referenced by the
146       --  Current_Excep field in the TSD to contain the indicated Id value
147       --  and message. Message is a string which is generated as the
148       --  exception message.
149
150       --------------------------------------
151       -- Exception information subprogram --
152       --------------------------------------
153
154       function Exception_Information (X : Exception_Occurrence) return String;
155       --  The format of the exception information is as follows:
156       --
157       --    exception name (as in Exception_Name)
158       --    message (or a null line if no message)
159       --    PID=nnnn
160       --    0xyyyyyyyy 0xyyyyyyyy ...
161       --
162       --  The lines are separated by a ASCII.LF character
163       --  The nnnn is the partition Id given as decimal digits.
164       --  The 0x... line represents traceback program counter locations,
165       --  in order with the first one being the exception location.
166
167       ---------------------------------------
168       -- Exception backtracing subprograms --
169       ---------------------------------------
170
171       --  What is automatically output when exception tracing is on basically
172       --  corresponds to the usual exception information, but with the call
173       --  chain backtrace possibly tailored by a backtrace decorator. Modifying
174       --  Exception_Information itself is not a good idea because the decorated
175       --  output is completely out of control and would break all our code
176       --  related to the streaming of exceptions.
177       --
178       --  We then provide an alternative function to Exception_Information to
179       --  compute the possibly tailored output, which is equivalent if no
180       --  decorator is currently set.
181
182       function Tailored_Exception_Information
183         (X    : Exception_Occurrence)
184         return String;
185       --  Exception information to be output in the case of automatic tracing
186       --  requested through GNAT.Exception_Traces.
187       --
188       --  This is the same as Exception_Information if no backtrace decorator
189       --  is currently in place. Otherwise, this is Exception_Information with
190       --  the call chain raw addresses replaced by the result of a call to the
191       --  current decorator provided with the call chain addresses.
192
193       pragma Export
194         (Ada, Tailored_Exception_Information,
195            "__gnat_tailored_exception_information");
196       --  This function is used within this package but also from within
197       --  System.Tasking.Stages.
198       --
199       --  The output of Exception_Information and
200       --  Tailored_Exception_Information share a common part which was
201       --  formerly built using local procedures within
202       --  Exception_Information. These procedures have been extracted
203       --  from their original place to be available to
204       --  Tailored_Exception_Information also.
205       --
206       --  Each of these procedures appends some input to an
207       --  information string currently being built. The Ptr argument
208       --  represents the last position in this string at which a
209       --  character has been written.
210
211       procedure Tailored_Exception_Information
212         (X    : Exception_Occurrence;
213          Buff : in out String;
214          Last : in out Integer);
215       --  Procedural version of the above function. Instead of returning the
216       --  result, this one is put in Buff (Buff'first .. Buff'first + Last)
217       --  And what happens on overflow ???
218
219    end Exception_Data;
220
221    package Exception_Traces is
222
223       use Exception_Data;
224       --  Imports Tailored_Exception_Information
225
226       ----------------------------------------------
227       -- Run-Time Exception Notification Routines --
228       ----------------------------------------------
229
230       --  These subprograms provide a common run-time interface to trigger the
231       --  actions required when an exception is about to be propagated (e.g.
232       --  user specified actions or output of exception information). They are
233       --  exported to be usable by the Ada exception handling personality
234       --  routine when the GCC 3 mechanism is used.
235
236       procedure Notify_Handled_Exception;
237       pragma Export (C, Notify_Handled_Exception,
238                        "__gnat_notify_handled_exception");
239       --  This routine is called for a handled occurrence is about to be
240       --  propagated.
241
242       procedure Notify_Unhandled_Exception;
243       pragma Export (C, Notify_Unhandled_Exception,
244                        "__gnat_notify_unhandled_exception");
245       --  This routine is called when an unhandled occurrence is about to be
246       --  propagated.
247
248       procedure Unhandled_Exception_Terminate;
249       pragma No_Return (Unhandled_Exception_Terminate);
250       --  This procedure is called to terminate execution following an
251       --  unhandled exception. The exception information, including
252       --  traceback if available is output, and execution is then
253       --  terminated. Note that at the point where this routine is
254       --  called, the stack has typically been destroyed.
255
256    end Exception_Traces;
257
258    package Exception_Propagation is
259
260       use Exception_Traces;
261       --  Imports Notify_Unhandled_Exception and
262       --  Unhandled_Exception_Terminate
263
264       ------------------------------------
265       -- Exception propagation routines --
266       ------------------------------------
267
268       procedure Setup_Exception
269         (Excep    : EOA;
270          Current  : EOA;
271          Reraised : Boolean := False);
272       --  Perform the necessary operations to prepare the propagation of Excep
273       --  in a task where Current is the current occurrence. Excep is assumed
274       --  to be a valid (non null) pointer.
275       --
276       --  This should be called before any (re-)setting of the current
277       --  occurrence. Any such (re-)setting shall take care *not* to clobber
278       --  the Private_Data component.
279       --
280       --  Having Current provided as an argument (instead of retrieving it via
281       --  Get_Current_Excep internally) is required to allow one task to setup
282       --  an exception for another task, which is used by Transfer_Occurrence.
283
284       procedure Propagate_Exception (From_Signal_Handler : Boolean);
285       pragma No_Return (Propagate_Exception);
286       --  This procedure propagates the exception represented by the occurrence
287       --  referenced by Current_Excep in the TSD for the current task.
288
289    end Exception_Propagation;
290
291    package Stream_Attributes is
292
293       --------------------------------
294       -- Stream attributes routines --
295       --------------------------------
296
297       function EId_To_String (X : Exception_Id) return String;
298       function String_To_EId (S : String) return Exception_Id;
299       --  Functions for implementing Exception_Id stream attributes
300
301       function EO_To_String (X : Exception_Occurrence) return String;
302       function String_To_EO (S : String) return Exception_Occurrence;
303       --  Functions for implementing Exception_Occurrence stream
304       --  attributes
305
306    end Stream_Attributes;
307
308    procedure Raise_Current_Excep (E : Exception_Id);
309    pragma No_Return (Raise_Current_Excep);
310    pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
311    --  This is a simple wrapper to Process_Raise_Exception setting the
312    --  From_Signal_Handler argument to False.
313    --
314    --  This external name for Raise_Current_Excep is historical, and probably
315    --  should be changed but for now we keep it, because gdb and gigi know
316    --  about it.
317
318    procedure Raise_Exception_No_Defer
319       (E : Exception_Id; Message : String := "");
320    pragma Export
321     (Ada, Raise_Exception_No_Defer,
322      "ada__exceptions__raise_exception_no_defer");
323    pragma No_Return (Raise_Exception_No_Defer);
324    --  Similar to Raise_Exception, but with no abort deferral
325
326    procedure Raise_With_Msg (E : Exception_Id);
327    pragma No_Return (Raise_With_Msg);
328    pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
329    --  Raises an exception with given exception id value. A message
330    --  is associated with the raise, and has already been stored in the
331    --  exception occurrence referenced by the Current_Excep in the TSD.
332    --  Abort is deferred before the raise call.
333
334    procedure Raise_With_Msg (E : Exception_Id; Setup : Boolean);
335    pragma No_Return (Raise_With_Msg);
336    --  Similar to above, with an extra parameter to indicate wether
337    --  Setup_Exception has been called already.
338
339    procedure Raise_After_Setup (E : Exception_Id);
340    pragma No_Return (Raise_After_Setup);
341    pragma Export (C, Raise_After_Setup, "__gnat_raise_after_setup");
342    --  Wrapper to Raise_With_Msg and Setup set to True.
343    --
344    --  This is called by System.Tasking.Entry_Calls.Check_Exception when an
345    --  exception has occured during an entry call. The exception to propagate
346    --  has been setup and initialized via Transfer_Occurrence in this case.
347
348    procedure Raise_With_Location_And_Msg
349      (E : Exception_Id;
350       F : Big_String_Ptr;
351       L : Integer;
352       M : Big_String_Ptr := null);
353    pragma No_Return (Raise_With_Location_And_Msg);
354    --  Raise an exception with given exception id value. A filename and line
355    --  number is associated with the raise and is stored in the exception
356    --  occurrence and in addition a string message M is appended to
357    --  this (if M is not null).
358
359    procedure Raise_Constraint_Error
360      (File : Big_String_Ptr;
361       Line : Integer);
362    pragma No_Return (Raise_Constraint_Error);
363    pragma Export
364      (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
365    --  Raise constraint error with file:line information
366
367    procedure Raise_Constraint_Error_Msg
368      (File : Big_String_Ptr;
369       Line : Integer;
370       Msg  : Big_String_Ptr);
371    pragma No_Return (Raise_Constraint_Error_Msg);
372    pragma Export
373      (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
374    --  Raise constraint error with file:line + msg information
375
376    procedure Raise_Program_Error
377      (File : Big_String_Ptr;
378       Line : Integer);
379    pragma No_Return (Raise_Program_Error);
380    pragma Export
381      (C, Raise_Program_Error, "__gnat_raise_program_error");
382    --  Raise program error with file:line information
383
384    procedure Raise_Program_Error_Msg
385      (File : Big_String_Ptr;
386       Line : Integer;
387       Msg  : Big_String_Ptr);
388    pragma No_Return (Raise_Program_Error_Msg);
389    pragma Export
390      (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
391    --  Raise program error with file:line + msg information
392
393    procedure Raise_Storage_Error
394      (File : Big_String_Ptr;
395       Line : Integer);
396    pragma No_Return (Raise_Storage_Error);
397    pragma Export
398      (C, Raise_Storage_Error, "__gnat_raise_storage_error");
399    --  Raise storage error with file:line information
400
401    procedure Raise_Storage_Error_Msg
402      (File : Big_String_Ptr;
403       Line : Integer;
404       Msg  : Big_String_Ptr);
405    pragma No_Return (Raise_Storage_Error_Msg);
406    pragma Export
407      (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
408    --  Raise storage error with file:line + reason msg information
409
410    --  The exception raising process and the automatic tracing mechanism rely
411    --  on some careful use of flags attached to the exception occurrence. The
412    --  graph below illustrates the relations between the Raise_ subprograms
413    --  and identifies the points where basic flags such as Exception_Raised
414    --  are initialized.
415    --
416    --  (i) signs indicate the flags initialization points. R stands for Raise,
417    --  W for With, and E for Exception.
418    --
419    --                   R_No_Msg    R_E   R_Pe  R_Ce  R_Se
420    --                       |        |     |     |     |
421    --                       +--+  +--+     +---+ | +---+
422    --                          |  |            | | |
423    --     R_E_No_Defer(i)    R_W_Msg(i)       R_W_Loc
424    --           |               |              |   |
425    --           +------------+  |  +-----------+   +--+
426    --                        |  |  |                  |
427    --                        |  |  |             Set_E_C_Msg(i)
428    --                        |  |  |
429    --                   Raise_Current_Excep
430
431    procedure Reraise;
432    pragma No_Return (Reraise);
433    pragma Export (C, Reraise, "__gnat_reraise");
434    --  Reraises the exception referenced by the Current_Excep field of
435    --  the TSD (all fields of this exception occurrence are set). Abort
436    --  is deferred before the reraise operation.
437
438    --  Save_Occurrence variations: As the management of the private data
439    --  attached to occurrences is delicate, wether or not pointers to such
440    --  data has to be copied in various situations is better made explicit.
441    --  The following procedures provide an internal interface to help making
442    --  this explicit.
443
444    procedure Save_Occurrence_And_Private
445      (Target : out Exception_Occurrence;
446       Source : Exception_Occurrence);
447    --  Copy all the components of Source to Target as well as the
448    --  Private_Data pointer.
449
450    procedure Save_Occurrence_No_Private
451      (Target : out Exception_Occurrence;
452       Source : Exception_Occurrence);
453    --  Copy all the components of Source to Target, except the
454    --  Private_Data pointer.
455
456    procedure Transfer_Occurrence
457      (Target : Exception_Occurrence_Access;
458       Source : Exception_Occurrence);
459    pragma Export (C, Transfer_Occurrence, "__gnat_transfer_occurrence");
460    --  Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
461    --  to setup Target from Source as an exception to be propagated in the
462    --  caller task. Target is expected to be a pointer to the fixed TSD
463    --  occurrence for this task.
464
465    -----------------------------
466    -- Run-Time Check Routines --
467    -----------------------------
468
469    --  These routines are called from the runtime to raise a specific
470    --  exception with a reason message attached. The parameters are
471    --  the file name and line number in each case. The names are keyed
472    --  to the codes defined in Types.ads and a-types.h (for example,
473    --  the name Rcheck_05 refers to the Reason whose Pos code is 5).
474
475    procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer);
476    procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer);
477    procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer);
478    procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer);
479    procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer);
480    procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer);
481    procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer);
482    procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer);
483    procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer);
484    procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer);
485    procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer);
486    procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer);
487    procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer);
488    procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer);
489    procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer);
490    procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer);
491    procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer);
492    procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer);
493    procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer);
494    procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer);
495    procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer);
496    procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer);
497    procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer);
498    procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer);
499    procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer);
500    procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer);
501    procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer);
502    procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer);
503    procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer);
504
505    pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
506    pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
507    pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
508    pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
509    pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
510    pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
511    pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
512    pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
513    pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
514    pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
515    pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
516    pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
517    pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
518    pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
519    pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
520    pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
521    pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
522    pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
523    pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
524    pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
525    pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
526    pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
527    pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
528    pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
529    pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
530    pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
531    pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
532    pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
533    pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
534
535    ---------------------------------------------
536    -- Reason Strings for Run-Time Check Calls --
537    ---------------------------------------------
538
539    --  These strings are null-terminated and are used by Rcheck_nn. The
540    --  strings correspond to the definitions for Types.RT_Exception_Code.
541
542    use ASCII;
543
544    Rmsg_00 : constant String := "access check failed"              & NUL;
545    Rmsg_01 : constant String := "access parameter is null"         & NUL;
546    Rmsg_02 : constant String := "discriminant check failed"        & NUL;
547    Rmsg_03 : constant String := "divide by zero"                   & NUL;
548    Rmsg_04 : constant String := "explicit raise"                   & NUL;
549    Rmsg_05 : constant String := "index check failed"               & NUL;
550    Rmsg_06 : constant String := "invalid data"                     & NUL;
551    Rmsg_07 : constant String := "length check failed"              & NUL;
552    Rmsg_08 : constant String := "overflow check failed"            & NUL;
553    Rmsg_09 : constant String := "partition check failed"           & NUL;
554    Rmsg_10 : constant String := "range check failed"               & NUL;
555    Rmsg_11 : constant String := "tag check failed"                 & NUL;
556    Rmsg_12 : constant String := "access before elaboration"        & NUL;
557    Rmsg_13 : constant String := "accessibility check failed"       & NUL;
558    Rmsg_14 : constant String := "all guards closed"                & NUL;
559    Rmsg_15 : constant String := "duplicated entry address"         & NUL;
560    Rmsg_16 : constant String := "explicit raise"                   & NUL;
561    Rmsg_17 : constant String := "finalize/adjust raised exception" & NUL;
562    Rmsg_18 : constant String := "misaligned address value"         & NUL;
563    Rmsg_19 : constant String := "missing return"                   & NUL;
564    Rmsg_20 : constant String := "overlaid controlled object"       & NUL;
565    Rmsg_21 : constant String := "potentially blocking operation"   & NUL;
566    Rmsg_22 : constant String := "stubbed subprogram called"        & NUL;
567    Rmsg_23 : constant String := "unchecked union restriction"      & NUL;
568    Rmsg_24 : constant String := "empty storage pool"               & NUL;
569    Rmsg_25 : constant String := "explicit raise"                   & NUL;
570    Rmsg_26 : constant String := "infinite recursion"               & NUL;
571    Rmsg_27 : constant String := "object too large"                 & NUL;
572    Rmsg_28 : constant String := "restriction violation"            & NUL;
573
574    -----------------------
575    -- Polling Interface --
576    -----------------------
577
578    type Unsigned is mod 2 ** 32;
579
580    Counter : Unsigned := 0;
581    pragma Warnings (Off, Counter);
582    --  This counter is provided for convenience. It can be used in Poll to
583    --  perform periodic but not systematic operations.
584
585    procedure Poll is separate;
586    --  The actual polling routine is separate, so that it can easily
587    --  be replaced with a target dependent version.
588
589    ---------
590    -- AAA --
591    ---------
592
593    --  This dummy procedure gives us the start of the PC range for addresses
594    --  within the exception unit itself. We hope that gigi/gcc keep all the
595    --  procedures in their original order!
596
597    procedure AAA is
598    begin
599       <<Start_Of_AAA>>
600       Code_Address_For_AAA := Start_Of_AAA'Address;
601    end AAA;
602
603    ----------------
604    -- Call_Chain --
605    ----------------
606
607    procedure Call_Chain (Excep : EOA) is separate;
608    --  The actual Call_Chain routine is separate, so that it can easily
609    --  be dummied out when no exception traceback information is needed.
610
611    ------------------------------
612    -- Current_Target_Exception --
613    ------------------------------
614
615    function Current_Target_Exception return Exception_Occurrence is
616    begin
617       return Null_Occurrence;
618    end Current_Target_Exception;
619
620    -------------------
621    -- EId_To_String --
622    -------------------
623
624    function EId_To_String (X : Exception_Id) return String
625      renames Stream_Attributes.EId_To_String;
626
627    ------------------
628    -- EO_To_String --
629    ------------------
630
631    --  We use the null string to represent the null occurrence, otherwise
632    --  we output the Exception_Information string for the occurrence.
633
634    function EO_To_String (X : Exception_Occurrence) return String
635      renames Stream_Attributes.EO_To_String;
636
637    ------------------------
638    -- Exception_Identity --
639    ------------------------
640
641    function Exception_Identity
642      (X    : Exception_Occurrence)
643       return Exception_Id
644    is
645    begin
646       if X.Id = Null_Id then
647          raise Constraint_Error;
648       else
649          return X.Id;
650       end if;
651    end Exception_Identity;
652
653    ---------------------------
654    -- Exception_Information --
655    ---------------------------
656
657    function Exception_Information (X : Exception_Occurrence) return String
658      renames Exception_Data.Exception_Information;
659
660    -----------------------
661    -- Exception_Message --
662    -----------------------
663
664    function Exception_Message (X : Exception_Occurrence) return String is
665    begin
666       if X.Id = Null_Id then
667          raise Constraint_Error;
668       end if;
669
670       return X.Msg (1 .. X.Msg_Length);
671    end Exception_Message;
672
673    --------------------
674    -- Exception_Name --
675    --------------------
676
677    function Exception_Name (Id : Exception_Id) return String is
678    begin
679       if Id = null then
680          raise Constraint_Error;
681       end if;
682
683       return Id.Full_Name.all (1 .. Id.Name_Length - 1);
684    end Exception_Name;
685
686    function Exception_Name (X : Exception_Occurrence) return String is
687    begin
688       return Exception_Name (X.Id);
689    end Exception_Name;
690
691    ---------------------------
692    -- Exception_Name_Simple --
693    ---------------------------
694
695    function Exception_Name_Simple (X : Exception_Occurrence) return String is
696       Name : constant String := Exception_Name (X);
697       P    : Natural;
698
699    begin
700       P := Name'Length;
701       while P > 1 loop
702          exit when Name (P - 1) = '.';
703          P := P - 1;
704       end loop;
705
706       --  Return result making sure lower bound is 1
707
708       declare
709          subtype Rname is String (1 .. Name'Length - P + 1);
710       begin
711          return Rname (Name (P .. Name'Length));
712       end;
713    end Exception_Name_Simple;
714
715    --------------------
716    -- Exception_Data --
717    --------------------
718
719    package body Exception_Data is separate;
720    --  This package can be easily dummied out if we do not want the
721    --  basic support for exception messages (such as in Ada 83).
722
723    ---------------------------
724    -- Exception_Propagation --
725    ---------------------------
726
727    package body Exception_Propagation is separate;
728    --  Depending on the actual exception mechanism used (front-end or
729    --  back-end based), the implementation will differ, which is why this
730    --  package is separated.
731
732    ----------------------
733    -- Exception_Traces --
734    ----------------------
735
736    package body Exception_Traces is separate;
737    --  Depending on the underlying support for IO the implementation
738    --  will differ. Moreover we would like to dummy out this package
739    --  in case we do not want any exception tracing support. This is
740    --  why this package is separated.
741
742    -----------------------
743    -- Stream Attributes --
744    -----------------------
745
746    package body Stream_Attributes is separate;
747    --  This package can be easily dummied out if we do not want the
748    --  support for streaming Exception_Ids and Exception_Occurrences.
749
750    -----------------------------
751    -- Process_Raise_Exception --
752    -----------------------------
753
754    procedure Process_Raise_Exception
755      (E                   : Exception_Id;
756       From_Signal_Handler : Boolean)
757    is
758       pragma Inspection_Point (E);
759       --  This is so the debugger can reliably inspect the parameter
760
761       Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
762       Excep       : EOA := Get_Current_Excep.all;
763
764    begin
765       --  WARNING : There should be no exception handler for this body
766       --  because this would cause gigi to prepend a setup for a new
767       --  jmpbuf to the sequence of statements. We would then always get
768       --  this new buf in Jumpbuf_Ptr instead of the one for the exception
769       --  we are handling, which would completely break the whole design
770       --  of this procedure.
771
772       --  Processing varies between zero cost and setjmp/lonjmp processing.
773
774       if Zero_Cost_Exceptions /= 0 then
775
776          --  Use the front-end tables to propagate if we have them, otherwise
777          --  resort to the GCC back-end alternative. Backtrace computation is
778          --  performed, if required, by the underlying routine. Notifications
779          --  for the debugger are also not performed here, because we do not
780          --  yet know if the exception is handled.
781
782          Exception_Propagation.Propagate_Exception (From_Signal_Handler);
783
784       else
785          --  Compute the backtrace for this occurrence if the corresponding
786          --  binder option has been set. Call_Chain takes care of the reraise
787          --  case.
788
789          Call_Chain (Excep);
790          --  We used to only do this if From_Signal_Handler was not set,
791          --  based on the assumption that backtracing from a signal handler
792          --  would not work due to stack layout oddities. However, since
793          --
794          --   1. The flag is never set in tasking programs (Notify_Exception
795          --      performs regular raise statements), and
796          --
797          --   2. No problem has shown up in tasking programs around here so
798          --      far, this turned out to be too strong an assumption.
799          --
800          --  As, in addition, the test was
801          --
802          --   1. preventing the production of backtraces in non-tasking
803          --      programs, and
804          --
805          --   2. introducing a behavior inconsistency between
806          --      the tasking and non-tasking cases,
807          --
808          --  we have simply removed it.
809
810          --  If the jump buffer pointer is non-null, transfer control using
811          --  it. Otherwise announce an unhandled exception (note that this
812          --  means that we have no finalizations to do other than at the outer
813          --  level). Perform the necessary notification tasks in both cases.
814
815          if Jumpbuf_Ptr /= Null_Address then
816
817             if not Excep.Exception_Raised then
818                Excep.Exception_Raised := True;
819                Exception_Traces.Notify_Handled_Exception;
820             end if;
821
822             builtin_longjmp (Jumpbuf_Ptr, 1);
823
824          else
825             --  The pragma Inspection point here ensures that the debugger
826             --  can inspect the parameter.
827
828             pragma Inspection_Point (E);
829
830             Exception_Traces.Notify_Unhandled_Exception;
831             Exception_Traces.Unhandled_Exception_Terminate;
832          end if;
833       end if;
834    end Process_Raise_Exception;
835
836    ----------------------------
837    -- Raise_Constraint_Error --
838    ----------------------------
839
840    procedure Raise_Constraint_Error
841      (File : Big_String_Ptr;
842       Line : Integer)
843    is
844    begin
845       Raise_With_Location_And_Msg
846         (Constraint_Error_Def'Access, File, Line);
847    end Raise_Constraint_Error;
848
849    --------------------------------
850    -- Raise_Constraint_Error_Msg --
851    --------------------------------
852
853    procedure Raise_Constraint_Error_Msg
854      (File : Big_String_Ptr;
855       Line : Integer;
856       Msg  : Big_String_Ptr)
857    is
858    begin
859       Raise_With_Location_And_Msg
860         (Constraint_Error_Def'Access, File, Line, Msg);
861    end Raise_Constraint_Error_Msg;
862
863    -------------------------
864    -- Raise_Current_Excep --
865    -------------------------
866
867    procedure Raise_Current_Excep (E : Exception_Id) is
868       pragma Inspection_Point (E);
869       --  This is so the debugger can reliably inspect the parameter
870    begin
871       Process_Raise_Exception (E => E, From_Signal_Handler => False);
872    end Raise_Current_Excep;
873
874    ---------------------
875    -- Raise_Exception --
876    ---------------------
877
878    procedure Raise_Exception
879      (E       : Exception_Id;
880       Message : String := "")
881    is
882    begin
883       if E /= null then
884          Exception_Data.Set_Exception_Msg (E, Message);
885          Abort_Defer.all;
886          Raise_Current_Excep (E);
887       end if;
888    end Raise_Exception;
889
890    ----------------------------
891    -- Raise_Exception_Always --
892    ----------------------------
893
894    procedure Raise_Exception_Always
895      (E       : Exception_Id;
896       Message : String := "")
897    is
898    begin
899       Exception_Data.Set_Exception_Msg (E, Message);
900       Abort_Defer.all;
901       Raise_Current_Excep (E);
902    end Raise_Exception_Always;
903
904    -------------------------------
905    -- Raise_From_Signal_Handler --
906    -------------------------------
907
908    procedure Raise_From_Signal_Handler
909      (E : Exception_Id;
910       M : Big_String_Ptr)
911    is
912    begin
913       Exception_Data.Set_Exception_C_Msg (E, M);
914       Abort_Defer.all;
915       Process_Raise_Exception (E => E, From_Signal_Handler => True);
916    end Raise_From_Signal_Handler;
917
918    -------------------------
919    -- Raise_Program_Error --
920    -------------------------
921
922    procedure Raise_Program_Error
923      (File : Big_String_Ptr;
924       Line : Integer)
925    is
926    begin
927       Raise_With_Location_And_Msg
928         (Program_Error_Def'Access, File, Line);
929    end Raise_Program_Error;
930
931    -----------------------------
932    -- Raise_Program_Error_Msg --
933    -----------------------------
934
935    procedure Raise_Program_Error_Msg
936      (File : Big_String_Ptr;
937       Line : Integer;
938       Msg  : Big_String_Ptr)
939    is
940    begin
941       Raise_With_Location_And_Msg
942         (Program_Error_Def'Access, File, Line, Msg);
943    end Raise_Program_Error_Msg;
944
945    -------------------------
946    -- Raise_Storage_Error --
947    -------------------------
948
949    procedure Raise_Storage_Error
950      (File : Big_String_Ptr;
951       Line : Integer)
952    is
953    begin
954       Raise_With_Location_And_Msg
955         (Storage_Error_Def'Access, File, Line);
956    end Raise_Storage_Error;
957
958    -----------------------------
959    -- Raise_Storage_Error_Msg --
960    -----------------------------
961
962    procedure Raise_Storage_Error_Msg
963      (File : Big_String_Ptr;
964       Line : Integer;
965       Msg  : Big_String_Ptr)
966    is
967    begin
968       Raise_With_Location_And_Msg
969         (Storage_Error_Def'Access, File, Line, Msg);
970    end Raise_Storage_Error_Msg;
971
972    ---------------------------------
973    -- Raise_With_Location_And_Msg --
974    ---------------------------------
975
976    procedure Raise_With_Location_And_Msg
977      (E : Exception_Id;
978       F : Big_String_Ptr;
979       L : Integer;
980       M : Big_String_Ptr := null)
981    is
982    begin
983       Exception_Data.Set_Exception_C_Msg (E, F, L, M);
984       Abort_Defer.all;
985       Raise_Current_Excep (E);
986    end Raise_With_Location_And_Msg;
987
988    --------------------
989    -- Raise_With_Msg --
990    --------------------
991
992    procedure Raise_With_Msg (E : Exception_Id; Setup : Boolean) is
993       Excep : constant EOA := Get_Current_Excep.all;
994
995    begin
996       if not Setup then
997          Exception_Propagation.Setup_Exception (Excep, Excep);
998       end if;
999
1000       Excep.Exception_Raised := False;
1001       Excep.Id               := E;
1002       Excep.Num_Tracebacks   := 0;
1003       Excep.Cleanup_Flag     := False;
1004       Excep.Pid              := Local_Partition_ID;
1005       Abort_Defer.all;
1006       Raise_Current_Excep (E);
1007    end Raise_With_Msg;
1008
1009    procedure Raise_With_Msg (E : Exception_Id) is
1010    begin
1011       Raise_With_Msg (E, Setup => False);
1012    end Raise_With_Msg;
1013
1014    -----------------------
1015    -- Raise_After_Setup --
1016    -----------------------
1017
1018    procedure Raise_After_Setup (E : Exception_Id) is
1019    begin
1020       Raise_With_Msg (E, Setup => True);
1021    end Raise_After_Setup;
1022
1023    --------------------------------------
1024    -- Calls to Run-Time Check Routines --
1025    --------------------------------------
1026
1027    procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer) is
1028    begin
1029       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_00'Address));
1030    end Rcheck_00;
1031
1032    procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer) is
1033    begin
1034       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_01'Address));
1035    end Rcheck_01;
1036
1037    procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer) is
1038    begin
1039       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_02'Address));
1040    end Rcheck_02;
1041
1042    procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer) is
1043    begin
1044       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_03'Address));
1045    end Rcheck_03;
1046
1047    procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer) is
1048    begin
1049       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_04'Address));
1050    end Rcheck_04;
1051
1052    procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer) is
1053    begin
1054       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_05'Address));
1055    end Rcheck_05;
1056
1057    procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer) is
1058    begin
1059       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_06'Address));
1060    end Rcheck_06;
1061
1062    procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer) is
1063    begin
1064       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_07'Address));
1065    end Rcheck_07;
1066
1067    procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer) is
1068    begin
1069       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_08'Address));
1070    end Rcheck_08;
1071
1072    procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer) is
1073    begin
1074       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_09'Address));
1075    end Rcheck_09;
1076
1077    procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer) is
1078    begin
1079       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_10'Address));
1080    end Rcheck_10;
1081
1082    procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer) is
1083    begin
1084       Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_11'Address));
1085    end Rcheck_11;
1086
1087    procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer) is
1088    begin
1089       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_12'Address));
1090    end Rcheck_12;
1091
1092    procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer) is
1093    begin
1094       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_13'Address));
1095    end Rcheck_13;
1096
1097    procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer) is
1098    begin
1099       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_14'Address));
1100    end Rcheck_14;
1101
1102    procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer) is
1103    begin
1104       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_15'Address));
1105    end Rcheck_15;
1106
1107    procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer) is
1108    begin
1109       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_16'Address));
1110    end Rcheck_16;
1111
1112    procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer) is
1113    begin
1114       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_17'Address));
1115    end Rcheck_17;
1116
1117    procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer) is
1118    begin
1119       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_18'Address));
1120    end Rcheck_18;
1121
1122    procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer) is
1123    begin
1124       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_19'Address));
1125    end Rcheck_19;
1126
1127    procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer) is
1128    begin
1129       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_20'Address));
1130    end Rcheck_20;
1131
1132    procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer) is
1133    begin
1134       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_21'Address));
1135    end Rcheck_21;
1136
1137    procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer) is
1138    begin
1139       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_22'Address));
1140    end Rcheck_22;
1141
1142    procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer) is
1143    begin
1144       Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_23'Address));
1145    end Rcheck_23;
1146
1147    procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer) is
1148    begin
1149       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_24'Address));
1150    end Rcheck_24;
1151
1152    procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer) is
1153    begin
1154       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_25'Address));
1155    end Rcheck_25;
1156
1157    procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer) is
1158    begin
1159       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_26'Address));
1160    end Rcheck_26;
1161
1162    procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer) is
1163    begin
1164       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_27'Address));
1165    end Rcheck_27;
1166
1167    procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer) is
1168    begin
1169       Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_28'Address));
1170    end Rcheck_28;
1171
1172    -------------
1173    -- Reraise --
1174    -------------
1175
1176    procedure Reraise is
1177       Excep : constant EOA := Get_Current_Excep.all;
1178
1179    begin
1180       Abort_Defer.all;
1181       Exception_Propagation.Setup_Exception (Excep, Excep, Reraised => True);
1182       Raise_Current_Excep (Excep.Id);
1183    end Reraise;
1184
1185    ------------------------
1186    -- Reraise_Occurrence --
1187    ------------------------
1188
1189    procedure Reraise_Occurrence (X : Exception_Occurrence) is
1190    begin
1191       if X.Id /= null then
1192          Abort_Defer.all;
1193          Exception_Propagation.Setup_Exception
1194            (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1195          Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1196          Raise_Current_Excep (X.Id);
1197       end if;
1198    end Reraise_Occurrence;
1199
1200    -------------------------------
1201    -- Reraise_Occurrence_Always --
1202    -------------------------------
1203
1204    procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1205    begin
1206       Abort_Defer.all;
1207       Exception_Propagation.Setup_Exception
1208         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1209       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1210       Raise_Current_Excep (X.Id);
1211    end Reraise_Occurrence_Always;
1212
1213    ---------------------------------
1214    -- Reraise_Occurrence_No_Defer --
1215    ---------------------------------
1216
1217    procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1218    begin
1219       Exception_Propagation.Setup_Exception
1220         (X'Unrestricted_Access, Get_Current_Excep.all, Reraised => True);
1221       Save_Occurrence_No_Private (Get_Current_Excep.all.all, X);
1222       Raise_Current_Excep (X.Id);
1223    end Reraise_Occurrence_No_Defer;
1224
1225    ---------------------
1226    -- Save_Occurrence --
1227    ---------------------
1228
1229    procedure Save_Occurrence
1230      (Target : out Exception_Occurrence;
1231       Source : Exception_Occurrence)
1232    is
1233    begin
1234       Save_Occurrence_No_Private (Target, Source);
1235    end Save_Occurrence;
1236
1237    function Save_Occurrence
1238      (Source : Exception_Occurrence)
1239       return   EOA
1240    is
1241       Target : EOA := new Exception_Occurrence;
1242
1243    begin
1244       Save_Occurrence (Target.all, Source);
1245       return Target;
1246    end Save_Occurrence;
1247
1248    --------------------------------
1249    -- Save_Occurrence_And_Private --
1250    --------------------------------
1251
1252    procedure Save_Occurrence_And_Private
1253      (Target : out Exception_Occurrence;
1254       Source : Exception_Occurrence)
1255    is
1256    begin
1257       Save_Occurrence_No_Private (Target, Source);
1258       Target.Private_Data := Source.Private_Data;
1259    end Save_Occurrence_And_Private;
1260
1261    --------------------------------
1262    -- Save_Occurrence_No_Private --
1263    --------------------------------
1264
1265    procedure Save_Occurrence_No_Private
1266      (Target : out Exception_Occurrence;
1267       Source : Exception_Occurrence)
1268    is
1269    begin
1270       Target.Id             := Source.Id;
1271       Target.Msg_Length     := Source.Msg_Length;
1272       Target.Num_Tracebacks := Source.Num_Tracebacks;
1273       Target.Pid            := Source.Pid;
1274       Target.Cleanup_Flag   := Source.Cleanup_Flag;
1275
1276       Target.Msg (1 .. Target.Msg_Length) :=
1277         Source.Msg (1 .. Target.Msg_Length);
1278
1279       Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1280         Source.Tracebacks (1 .. Target.Num_Tracebacks);
1281    end Save_Occurrence_No_Private;
1282
1283    -------------------------
1284    -- Transfer_Occurrence --
1285    -------------------------
1286
1287    procedure Transfer_Occurrence
1288      (Target : Exception_Occurrence_Access;
1289       Source : Exception_Occurrence)
1290    is
1291    begin
1292       --  Setup Target as an exception to be propagated in the calling task
1293       --  (rendezvous-wise), taking care not to clobber the associated private
1294       --  data.  Target is expected to be a pointer to the calling task's
1295       --  fixed TSD occurrence, which is very different from Get_Current_Excep
1296       --  here because this subprogram is called from the called task.
1297
1298       Exception_Propagation.Setup_Exception (Target, Target);
1299       Save_Occurrence_No_Private (Target.all, Source);
1300    end Transfer_Occurrence;
1301
1302    -------------------
1303    -- String_To_EId --
1304    -------------------
1305
1306    function String_To_EId (S : String) return Exception_Id
1307      renames Stream_Attributes.String_To_EId;
1308
1309    ------------------
1310    -- String_To_EO --
1311    ------------------
1312
1313    function String_To_EO (S : String) return Exception_Occurrence
1314      renames Stream_Attributes.String_To_EO;
1315
1316    ------------------------------
1317    -- Raise_Exception_No_Defer --
1318    ------------------------------
1319
1320    procedure Raise_Exception_No_Defer
1321      (E       : Exception_Id;
1322       Message : String := "")
1323    is
1324    begin
1325       Exception_Data.Set_Exception_Msg (E, Message);
1326
1327       --  DO NOT CALL Abort_Defer.all; !!!!
1328       --  why not??? would be nice to have more comments here
1329
1330       Raise_Current_Excep (E);
1331    end Raise_Exception_No_Defer;
1332
1333    ---------
1334    -- ZZZ --
1335    ---------
1336
1337    --  This dummy procedure gives us the end of the PC range for addresses
1338    --  within the exception unit itself. We hope that gigi/gcc keeps all the
1339    --  procedures in their original order!
1340
1341    procedure ZZZ is
1342    begin
1343       <<Start_Of_ZZZ>>
1344       Code_Address_For_ZZZ := Start_Of_ZZZ'Address;
1345    end ZZZ;
1346
1347 begin
1348    --  Allocate the Non-Tasking Machine_State
1349
1350    Set_Machine_State_Addr_NT (System.Address (Allocate_Machine_State));
1351
1352    --  Call the AAA/ZZZ routines to setup the code addresses for the
1353    --  bounds of this unit.
1354
1355    AAA;
1356    ZZZ;
1357 end Ada.Exceptions;