OSDN Git Service

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