1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This version 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.
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.
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.
45 -- We must turn polling off for this unit, because otherwise we get
46 -- elaboration circularities with System.Exception_Tables.
48 with System
; use System
;
49 with System
.Standard_Library
; use System
.Standard_Library
;
50 with System
.Soft_Links
; use System
.Soft_Links
;
51 with System
.WCh_Con
; use System
.WCh_Con
;
52 with System
.WCh_StW
; use System
.WCh_StW
;
54 package body Ada
.Exceptions
is
56 pragma Suppress
(All_Checks
);
57 -- We definitely do not want exceptions occurring within this unit, or
58 -- we are in big trouble. If an exceptional situation does occur, better
59 -- that it not be raised, since raising it can cause confusing chaos.
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 -- Note: the exported subprograms in this package body are called directly
66 -- from C clients using the given external name, even though they are not
67 -- technically visible in the Ada sense.
69 function Code_Address_For_AAA
return System
.Address
;
70 function Code_Address_For_ZZZ
return System
.Address
;
71 -- Return start and end of procedures in this package
73 -- These procedures are used to provide exclusion bounds in
74 -- calls to Call_Chain at exception raise points from this unit. The
75 -- purpose is to arrange for the exception tracebacks not to include
76 -- frames from routines involved in the raise process, as these are
77 -- meaningless from the user's standpoint.
79 -- For these bounds to be meaningful, we need to ensure that the object
80 -- code for the routines involved in processing a raise is located after
81 -- the object code Code_Address_For_AAA and before the object code
82 -- Code_Address_For_ZZZ. This will indeed be the case as long as the
83 -- following rules are respected:
85 -- 1) The bodies of the subprograms involved in processing a raise
86 -- are located after the body of Code_Address_For_AAA and before the
87 -- body of Code_Address_For_ZZZ.
89 -- 2) No pragma Inline applies to any of these subprograms, as this
90 -- could delay the corresponding assembly output until the end of
93 procedure Call_Chain
(Excep
: EOA
);
94 -- Store up to Max_Tracebacks in Excep, corresponding to the current
97 procedure To_Stderr
(S
: String);
98 pragma Export
(Ada
, To_Stderr
, "__gnat_to_stderr");
99 -- Little routine to output string to stderr that is also used
100 -- in the tasking run time.
102 procedure To_Stderr
(C
: Character);
103 pragma Inline
(To_Stderr
);
104 pragma Export
(Ada
, To_Stderr
, "__gnat_to_stderr_char");
105 -- Little routine to output a character to stderr, used by some of
106 -- the separate units below.
108 package Exception_Data
is
110 ---------------------------------
111 -- Exception messages routines --
112 ---------------------------------
114 procedure Set_Exception_C_Msg
116 Msg1
: System
.Address
;
118 Msg2
: System
.Address
:= System
.Null_Address
);
119 -- This routine is called to setup the exception referenced by the
120 -- Current_Excep field in the TSD to contain the indicated Id value
121 -- and message. Msg1 is a null terminated string which is generated
122 -- as the exception message. If line is non-zero, then a colon and
123 -- the decimal representation of this integer is appended to the
124 -- message. When Msg2 is non-null, a space and this additional null
125 -- terminated string is added to the message.
127 procedure Set_Exception_Msg
130 -- This routine is called to setup the exception referenced by the
131 -- Current_Excep field in the TSD to contain the indicated Id value
132 -- and message. Message is a string which is generated as the
133 -- exception message.
135 --------------------------------------
136 -- Exception information subprogram --
137 --------------------------------------
139 function Exception_Information
(X
: Exception_Occurrence
) return String;
140 -- The format of the exception information is as follows:
142 -- Exception_Name: <exception name> (as in Exception_Name)
143 -- Message: <message> (only if Exception_Message is empty)
144 -- PID=nnnn (only if != 0)
145 -- Call stack traceback locations: (only if at least one location)
146 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
148 -- The lines are separated by a ASCII.LF character.
149 -- The nnnn is the partition Id given as decimal digits.
150 -- The 0x... line represents traceback program counter locations, in
151 -- execution order with the first one being the exception location. It
154 -- The Exception_Name and Message lines are omitted in the abort
155 -- signal case, since this is not really an exception.
157 -- !! If the format of the generated string is changed, please note
158 -- !! that an equivalent modification to the routine String_To_EO must
159 -- !! be made to preserve proper functioning of the stream attributes.
161 ---------------------------------------
162 -- Exception backtracing subprograms --
163 ---------------------------------------
165 -- What is automatically output when exception tracing is on is the
166 -- usual exception information with the call chain backtrace possibly
167 -- tailored by a backtrace decorator. Modifying Exception_Information
168 -- itself is not a good idea because the decorated output is completely
169 -- out of control and would break all our code related to the streaming
170 -- of exceptions. We then provide an alternative function to compute
171 -- the possibly tailored output, which is equivalent if no decorator is
174 function Tailored_Exception_Information
175 (X
: Exception_Occurrence
) return String;
176 -- Exception information to be output in the case of automatic tracing
177 -- requested through GNAT.Exception_Traces.
179 -- This is the same as Exception_Information if no backtrace decorator
180 -- is currently in place. Otherwise, this is Exception_Information with
181 -- the call chain raw addresses replaced by the result of a call to the
182 -- current decorator provided with the call chain addresses.
185 (Ada
, Tailored_Exception_Information
,
186 "__gnat_tailored_exception_information");
187 -- This is currently used by System.Tasking.Stages
191 package Exception_Traces
is
194 -- Imports Tailored_Exception_Information
196 ----------------------------------------------
197 -- Run-Time Exception Notification Routines --
198 ----------------------------------------------
200 -- These subprograms provide a common run-time interface to trigger the
201 -- actions required when an exception is about to be propagated (e.g.
202 -- user specified actions or output of exception information). They are
203 -- exported to be usable by the Ada exception handling personality
204 -- routine when the GCC 3 mechanism is used.
206 procedure Notify_Handled_Exception
;
208 (C
, Notify_Handled_Exception
, "__gnat_notify_handled_exception");
209 -- This routine is called for a handled occurrence is about to be
212 procedure Notify_Unhandled_Exception
;
214 (C
, Notify_Unhandled_Exception
, "__gnat_notify_unhandled_exception");
215 -- This routine is called when an unhandled occurrence is about to be
218 procedure Unhandled_Exception_Terminate
;
219 pragma No_Return
(Unhandled_Exception_Terminate
);
220 -- This procedure is called to terminate execution following an
221 -- unhandled exception. The exception information, including
222 -- traceback if available is output, and execution is then
223 -- terminated. Note that at the point where this routine is
224 -- called, the stack has typically been destroyed.
226 end Exception_Traces
;
228 package Exception_Propagation
is
230 use Exception_Traces
;
231 -- Imports Notify_Unhandled_Exception and
232 -- Unhandled_Exception_Terminate
234 ------------------------------------
235 -- Exception propagation routines --
236 ------------------------------------
238 procedure Setup_Exception
241 Reraised
: Boolean := False);
242 -- Perform the necessary operations to prepare the propagation of Excep
243 -- in a task where Current is the current occurrence. Excep is assumed
244 -- to be a valid (non null) pointer.
246 -- This should be called before any (re-)setting of the current
247 -- occurrence. Any such (re-)setting shall take care *not* to clobber
248 -- the Private_Data component.
250 -- Having Current provided as an argument (instead of retrieving it via
251 -- Get_Current_Excep internally) is required to allow one task to setup
252 -- an exception for another task, which is used by Transfer_Occurrence.
254 procedure Propagate_Exception
256 From_Signal_Handler
: Boolean);
257 pragma No_Return
(Propagate_Exception
);
258 -- This procedure propagates the exception represented by the occurrence
259 -- referenced by Current_Excep in the TSD for the current task.
261 end Exception_Propagation
;
263 package Stream_Attributes
is
265 --------------------------------
266 -- Stream attributes routines --
267 --------------------------------
269 function EId_To_String
(X
: Exception_Id
) return String;
270 function String_To_EId
(S
: String) return Exception_Id
;
271 -- Functions for implementing Exception_Id stream attributes
273 function EO_To_String
(X
: Exception_Occurrence
) return String;
274 function String_To_EO
(S
: String) return Exception_Occurrence
;
275 -- Functions for implementing Exception_Occurrence stream
278 end Stream_Attributes
;
280 procedure Raise_Current_Excep
(E
: Exception_Id
);
281 pragma No_Return
(Raise_Current_Excep
);
282 pragma Export
(C
, Raise_Current_Excep
, "__gnat_raise_nodefer_with_msg");
283 -- This is a simple wrapper to Exception_Propagation.Propagate_Exception
284 -- setting the From_Signal_Handler argument to False.
286 -- This external name for Raise_Current_Excep is historical, and probably
287 -- should be changed but for now we keep it, because gdb and gigi know
290 procedure Raise_Exception_No_Defer
291 (E
: Exception_Id
; Message
: String := "");
293 (Ada
, Raise_Exception_No_Defer
,
294 "ada__exceptions__raise_exception_no_defer");
295 pragma No_Return
(Raise_Exception_No_Defer
);
296 -- Similar to Raise_Exception, but with no abort deferral
298 procedure Raise_With_Msg
(E
: Exception_Id
);
299 pragma No_Return
(Raise_With_Msg
);
300 pragma Export
(C
, Raise_With_Msg
, "__gnat_raise_with_msg");
301 -- Raises an exception with given exception id value. A message
302 -- is associated with the raise, and has already been stored in the
303 -- exception occurrence referenced by the Current_Excep in the TSD.
304 -- Abort is deferred before the raise call.
306 procedure Raise_With_Location_And_Msg
310 M
: System
.Address
:= System
.Null_Address
);
311 pragma No_Return
(Raise_With_Location_And_Msg
);
312 -- Raise an exception with given exception id value. A filename and line
313 -- number is associated with the raise and is stored in the exception
314 -- occurrence and in addition a string message M is appended to
315 -- this (if M is not null).
317 procedure Raise_Constraint_Error
318 (File
: System
.Address
;
320 pragma No_Return
(Raise_Constraint_Error
);
322 (C
, Raise_Constraint_Error
, "__gnat_raise_constraint_error");
323 -- Raise constraint error with file:line information
325 procedure Raise_Constraint_Error_Msg
326 (File
: System
.Address
;
328 Msg
: System
.Address
);
329 pragma No_Return
(Raise_Constraint_Error_Msg
);
331 (C
, Raise_Constraint_Error_Msg
, "__gnat_raise_constraint_error_msg");
332 -- Raise constraint error with file:line + msg information
334 procedure Raise_Program_Error
335 (File
: System
.Address
;
337 pragma No_Return
(Raise_Program_Error
);
339 (C
, Raise_Program_Error
, "__gnat_raise_program_error");
340 -- Raise program error with file:line information
342 procedure Raise_Program_Error_Msg
343 (File
: System
.Address
;
345 Msg
: System
.Address
);
346 pragma No_Return
(Raise_Program_Error_Msg
);
348 (C
, Raise_Program_Error_Msg
, "__gnat_raise_program_error_msg");
349 -- Raise program error with file:line + msg information
351 procedure Raise_Storage_Error
352 (File
: System
.Address
;
354 pragma No_Return
(Raise_Storage_Error
);
356 (C
, Raise_Storage_Error
, "__gnat_raise_storage_error");
357 -- Raise storage error with file:line information
359 procedure Raise_Storage_Error_Msg
360 (File
: System
.Address
;
362 Msg
: System
.Address
);
363 pragma No_Return
(Raise_Storage_Error_Msg
);
365 (C
, Raise_Storage_Error_Msg
, "__gnat_raise_storage_error_msg");
366 -- Raise storage error with file:line + reason msg information
368 -- The exception raising process and the automatic tracing mechanism rely
369 -- on some careful use of flags attached to the exception occurrence. The
370 -- graph below illustrates the relations between the Raise_ subprograms
371 -- and identifies the points where basic flags such as Exception_Raised
374 -- (i) signs indicate the flags initialization points. R stands for Raise,
375 -- W for With, and E for Exception.
377 -- R_No_Msg R_E R_Pe R_Ce R_Se
379 -- +--+ +--+ +---+ | +---+
381 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
383 -- +------------+ | +-----------+ +--+
385 -- | | | Set_E_C_Msg(i)
387 -- Raise_Current_Excep
390 pragma No_Return
(Reraise
);
391 pragma Export
(C
, Reraise
, "__gnat_reraise");
392 -- Reraises the exception referenced by the Current_Excep field of
393 -- the TSD (all fields of this exception occurrence are set). Abort
394 -- is deferred before the reraise operation.
396 -- Save_Occurrence variations: As the management of the private data
397 -- attached to occurrences is delicate, wether or not pointers to such
398 -- data has to be copied in various situations is better made explicit.
399 -- The following procedures provide an internal interface to help making
402 procedure Save_Occurrence_No_Private
403 (Target
: out Exception_Occurrence
;
404 Source
: Exception_Occurrence
);
405 -- Copy all the components of Source to Target, except the
406 -- Private_Data pointer.
408 procedure Transfer_Occurrence
409 (Target
: Exception_Occurrence_Access
;
410 Source
: Exception_Occurrence
);
411 pragma Export
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
412 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
413 -- to setup Target from Source as an exception to be propagated in the
414 -- caller task. Target is expected to be a pointer to the fixed TSD
415 -- occurrence for this task.
417 -----------------------------
418 -- Run-Time Check Routines --
419 -----------------------------
421 -- These routines are called from the runtime to raise a specific
422 -- exception with a reason message attached. The parameters are
423 -- the file name and line number in each case. The names are keyed
424 -- to the codes defined in Types.ads and a-types.h (for example,
425 -- the name Rcheck_05 refers to the Reason whose Pos code is 5).
427 procedure Rcheck_00
(File
: System
.Address
; Line
: Integer);
428 procedure Rcheck_01
(File
: System
.Address
; Line
: Integer);
429 procedure Rcheck_02
(File
: System
.Address
; Line
: Integer);
430 procedure Rcheck_03
(File
: System
.Address
; Line
: Integer);
431 procedure Rcheck_04
(File
: System
.Address
; Line
: Integer);
432 procedure Rcheck_05
(File
: System
.Address
; Line
: Integer);
433 procedure Rcheck_06
(File
: System
.Address
; Line
: Integer);
434 procedure Rcheck_07
(File
: System
.Address
; Line
: Integer);
435 procedure Rcheck_08
(File
: System
.Address
; Line
: Integer);
436 procedure Rcheck_09
(File
: System
.Address
; Line
: Integer);
437 procedure Rcheck_10
(File
: System
.Address
; Line
: Integer);
438 procedure Rcheck_11
(File
: System
.Address
; Line
: Integer);
439 procedure Rcheck_12
(File
: System
.Address
; Line
: Integer);
440 procedure Rcheck_13
(File
: System
.Address
; Line
: Integer);
441 procedure Rcheck_14
(File
: System
.Address
; Line
: Integer);
442 procedure Rcheck_15
(File
: System
.Address
; Line
: Integer);
443 procedure Rcheck_16
(File
: System
.Address
; Line
: Integer);
444 procedure Rcheck_17
(File
: System
.Address
; Line
: Integer);
445 procedure Rcheck_18
(File
: System
.Address
; Line
: Integer);
446 procedure Rcheck_19
(File
: System
.Address
; Line
: Integer);
447 procedure Rcheck_20
(File
: System
.Address
; Line
: Integer);
448 procedure Rcheck_21
(File
: System
.Address
; Line
: Integer);
449 procedure Rcheck_22
(File
: System
.Address
; Line
: Integer);
450 procedure Rcheck_23
(File
: System
.Address
; Line
: Integer);
451 procedure Rcheck_24
(File
: System
.Address
; Line
: Integer);
452 procedure Rcheck_25
(File
: System
.Address
; Line
: Integer);
453 procedure Rcheck_26
(File
: System
.Address
; Line
: Integer);
454 procedure Rcheck_27
(File
: System
.Address
; Line
: Integer);
455 procedure Rcheck_28
(File
: System
.Address
; Line
: Integer);
456 procedure Rcheck_29
(File
: System
.Address
; Line
: Integer);
457 procedure Rcheck_30
(File
: System
.Address
; Line
: Integer);
458 procedure Rcheck_31
(File
: System
.Address
; Line
: Integer);
459 procedure Rcheck_32
(File
: System
.Address
; Line
: Integer);
461 pragma Export
(C
, Rcheck_00
, "__gnat_rcheck_00");
462 pragma Export
(C
, Rcheck_01
, "__gnat_rcheck_01");
463 pragma Export
(C
, Rcheck_02
, "__gnat_rcheck_02");
464 pragma Export
(C
, Rcheck_03
, "__gnat_rcheck_03");
465 pragma Export
(C
, Rcheck_04
, "__gnat_rcheck_04");
466 pragma Export
(C
, Rcheck_05
, "__gnat_rcheck_05");
467 pragma Export
(C
, Rcheck_06
, "__gnat_rcheck_06");
468 pragma Export
(C
, Rcheck_07
, "__gnat_rcheck_07");
469 pragma Export
(C
, Rcheck_08
, "__gnat_rcheck_08");
470 pragma Export
(C
, Rcheck_09
, "__gnat_rcheck_09");
471 pragma Export
(C
, Rcheck_10
, "__gnat_rcheck_10");
472 pragma Export
(C
, Rcheck_11
, "__gnat_rcheck_11");
473 pragma Export
(C
, Rcheck_12
, "__gnat_rcheck_12");
474 pragma Export
(C
, Rcheck_13
, "__gnat_rcheck_13");
475 pragma Export
(C
, Rcheck_14
, "__gnat_rcheck_14");
476 pragma Export
(C
, Rcheck_15
, "__gnat_rcheck_15");
477 pragma Export
(C
, Rcheck_16
, "__gnat_rcheck_16");
478 pragma Export
(C
, Rcheck_17
, "__gnat_rcheck_17");
479 pragma Export
(C
, Rcheck_18
, "__gnat_rcheck_18");
480 pragma Export
(C
, Rcheck_19
, "__gnat_rcheck_19");
481 pragma Export
(C
, Rcheck_20
, "__gnat_rcheck_20");
482 pragma Export
(C
, Rcheck_21
, "__gnat_rcheck_21");
483 pragma Export
(C
, Rcheck_22
, "__gnat_rcheck_22");
484 pragma Export
(C
, Rcheck_23
, "__gnat_rcheck_23");
485 pragma Export
(C
, Rcheck_24
, "__gnat_rcheck_24");
486 pragma Export
(C
, Rcheck_25
, "__gnat_rcheck_25");
487 pragma Export
(C
, Rcheck_26
, "__gnat_rcheck_26");
488 pragma Export
(C
, Rcheck_27
, "__gnat_rcheck_27");
489 pragma Export
(C
, Rcheck_28
, "__gnat_rcheck_28");
490 pragma Export
(C
, Rcheck_29
, "__gnat_rcheck_29");
491 pragma Export
(C
, Rcheck_30
, "__gnat_rcheck_30");
492 pragma Export
(C
, Rcheck_31
, "__gnat_rcheck_31");
493 pragma Export
(C
, Rcheck_32
, "__gnat_rcheck_32");
495 -- None of these procedures ever returns (they raise an exception!). By
496 -- using pragma No_Return, we ensure that any junk code after the call,
497 -- such as normal return epilog stuff, can be eliminated).
499 pragma No_Return
(Rcheck_00
);
500 pragma No_Return
(Rcheck_01
);
501 pragma No_Return
(Rcheck_02
);
502 pragma No_Return
(Rcheck_03
);
503 pragma No_Return
(Rcheck_04
);
504 pragma No_Return
(Rcheck_05
);
505 pragma No_Return
(Rcheck_06
);
506 pragma No_Return
(Rcheck_07
);
507 pragma No_Return
(Rcheck_08
);
508 pragma No_Return
(Rcheck_09
);
509 pragma No_Return
(Rcheck_10
);
510 pragma No_Return
(Rcheck_11
);
511 pragma No_Return
(Rcheck_12
);
512 pragma No_Return
(Rcheck_13
);
513 pragma No_Return
(Rcheck_14
);
514 pragma No_Return
(Rcheck_15
);
515 pragma No_Return
(Rcheck_16
);
516 pragma No_Return
(Rcheck_17
);
517 pragma No_Return
(Rcheck_18
);
518 pragma No_Return
(Rcheck_19
);
519 pragma No_Return
(Rcheck_20
);
520 pragma No_Return
(Rcheck_21
);
521 pragma No_Return
(Rcheck_22
);
522 pragma No_Return
(Rcheck_23
);
523 pragma No_Return
(Rcheck_24
);
524 pragma No_Return
(Rcheck_25
);
525 pragma No_Return
(Rcheck_26
);
526 pragma No_Return
(Rcheck_27
);
527 pragma No_Return
(Rcheck_28
);
528 pragma No_Return
(Rcheck_29
);
529 pragma No_Return
(Rcheck_30
);
530 pragma No_Return
(Rcheck_32
);
532 ---------------------------------------------
533 -- Reason Strings for Run-Time Check Calls --
534 ---------------------------------------------
536 -- These strings are null-terminated and are used by Rcheck_nn. The
537 -- strings correspond to the definitions for Types.RT_Exception_Code.
541 Rmsg_00
: constant String := "access check failed" & NUL
;
542 Rmsg_01
: constant String := "access parameter is null" & NUL
;
543 Rmsg_02
: constant String := "discriminant check failed" & NUL
;
544 Rmsg_03
: constant String := "divide by zero" & NUL
;
545 Rmsg_04
: constant String := "explicit raise" & NUL
;
546 Rmsg_05
: constant String := "index check failed" & NUL
;
547 Rmsg_06
: constant String := "invalid data" & NUL
;
548 Rmsg_07
: constant String := "length check failed" & NUL
;
549 Rmsg_08
: constant String := "null Exception_Id" & NUL
;
550 Rmsg_09
: constant String := "null-exclusion check failed" & NUL
;
551 Rmsg_10
: constant String := "overflow check failed" & NUL
;
552 Rmsg_11
: constant String := "partition check failed" & NUL
;
553 Rmsg_12
: constant String := "range check failed" & NUL
;
554 Rmsg_13
: constant String := "tag check failed" & NUL
;
555 Rmsg_14
: constant String := "access before elaboration" & NUL
;
556 Rmsg_15
: constant String := "accessibility check failed" & NUL
;
557 Rmsg_16
: constant String := "all guards closed" & NUL
;
558 Rmsg_17
: constant String := "duplicated entry address" & NUL
;
559 Rmsg_18
: constant String := "explicit raise" & NUL
;
560 Rmsg_19
: constant String := "finalize/adjust raised exception" & NUL
;
561 Rmsg_20
: constant String := "implicit return with No_Return" & NUL
;
562 Rmsg_21
: constant String := "misaligned address value" & NUL
;
563 Rmsg_22
: constant String := "missing return" & NUL
;
564 Rmsg_23
: constant String := "overlaid controlled object" & NUL
;
565 Rmsg_24
: constant String := "potentially blocking operation" & NUL
;
566 Rmsg_25
: constant String := "stubbed subprogram called" & NUL
;
567 Rmsg_26
: constant String := "unchecked union restriction" & NUL
;
568 Rmsg_27
: constant String := "illegal use of remote access-to-" &
569 "class-wide type, see RM E.4(18)" & NUL
;
570 Rmsg_28
: constant String := "empty storage pool" & NUL
;
571 Rmsg_29
: constant String := "explicit raise" & NUL
;
572 Rmsg_30
: constant String := "infinite recursion" & NUL
;
573 Rmsg_31
: constant String := "object too large" & NUL
;
574 Rmsg_32
: constant String := "restriction violation" & NUL
;
576 -----------------------
577 -- Polling Interface --
578 -----------------------
580 type Unsigned
is mod 2 ** 32;
582 Counter
: Unsigned
:= 0;
583 pragma Warnings
(Off
, Counter
);
584 -- This counter is provided for convenience. It can be used in Poll to
585 -- perform periodic but not systematic operations.
587 procedure Poll
is separate;
588 -- The actual polling routine is separate, so that it can easily
589 -- be replaced with a target dependent version.
591 --------------------------
592 -- Code_Address_For_AAA --
593 --------------------------
595 -- This function gives us the start of the PC range for addresses
596 -- within the exception unit itself. We hope that gigi/gcc keep all the
597 -- procedures in their original order!
599 function Code_Address_For_AAA
return System
.Address
is
601 -- We are using a label instead of merely using
602 -- Code_Address_For_AAA'Address because on some platforms the latter
603 -- does not yield the address we want, but the address of a stub or of
604 -- a descriptor instead. This is the case at least on Alpha-VMS and
608 return Start_Of_AAA
'Address;
609 end Code_Address_For_AAA
;
615 procedure Call_Chain
(Excep
: EOA
) is separate;
616 -- The actual Call_Chain routine is separate, so that it can easily
617 -- be dummied out when no exception traceback information is needed.
619 ------------------------------
620 -- Current_Target_Exception --
621 ------------------------------
623 function Current_Target_Exception
return Exception_Occurrence
is
625 return Null_Occurrence
;
626 end Current_Target_Exception
;
632 function EId_To_String
(X
: Exception_Id
) return String
633 renames Stream_Attributes
.EId_To_String
;
639 -- We use the null string to represent the null occurrence, otherwise
640 -- we output the Exception_Information string for the occurrence.
642 function EO_To_String
(X
: Exception_Occurrence
) return String
643 renames Stream_Attributes
.EO_To_String
;
645 ------------------------
646 -- Exception_Identity --
647 ------------------------
649 function Exception_Identity
650 (X
: Exception_Occurrence
) return Exception_Id
653 -- Note that the following test used to be here for the original
654 -- Ada 95 semantics, but these were modified by AI-241 to require
655 -- returning Null_Id instead of raising Constraint_Error.
657 -- if X.Id = Null_Id then
658 -- raise Constraint_Error;
662 end Exception_Identity
;
664 ---------------------------
665 -- Exception_Information --
666 ---------------------------
668 function Exception_Information
(X
: Exception_Occurrence
) return String is
670 if X
.Id
= Null_Id
then
671 raise Constraint_Error
;
674 return Exception_Data
.Exception_Information
(X
);
675 end Exception_Information
;
677 -----------------------
678 -- Exception_Message --
679 -----------------------
681 function Exception_Message
(X
: Exception_Occurrence
) return String is
683 if X
.Id
= Null_Id
then
684 raise Constraint_Error
;
687 return X
.Msg
(1 .. X
.Msg_Length
);
688 end Exception_Message
;
694 function Exception_Name
(Id
: Exception_Id
) return String is
697 raise Constraint_Error
;
700 return To_Ptr
(Id
.Full_Name
) (1 .. Id
.Name_Length
- 1);
703 function Exception_Name
(X
: Exception_Occurrence
) return String is
705 return Exception_Name
(X
.Id
);
708 ---------------------------
709 -- Exception_Name_Simple --
710 ---------------------------
712 function Exception_Name_Simple
(X
: Exception_Occurrence
) return String is
713 Name
: constant String := Exception_Name
(X
);
719 exit when Name
(P
- 1) = '.';
723 -- Return result making sure lower bound is 1
726 subtype Rname
is String (1 .. Name
'Length - P
+ 1);
728 return Rname
(Name
(P
.. Name
'Length));
730 end Exception_Name_Simple
;
736 package body Exception_Data
is separate;
737 -- This package can be easily dummied out if we do not want the
738 -- basic support for exception messages (such as in Ada 83).
740 ---------------------------
741 -- Exception_Propagation --
742 ---------------------------
744 package body Exception_Propagation
is separate;
745 -- Depending on the actual exception mechanism used (front-end or
746 -- back-end based), the implementation will differ, which is why this
747 -- package is separated.
749 ----------------------
750 -- Exception_Traces --
751 ----------------------
753 package body Exception_Traces
is separate;
754 -- Depending on the underlying support for IO the implementation
755 -- will differ. Moreover we would like to dummy out this package
756 -- in case we do not want any exception tracing support. This is
757 -- why this package is separated.
759 -----------------------
760 -- Stream Attributes --
761 -----------------------
763 package body Stream_Attributes
is separate;
764 -- This package can be easily dummied out if we do not want the
765 -- support for streaming Exception_Ids and Exception_Occurrences.
767 ----------------------------
768 -- Raise_Constraint_Error --
769 ----------------------------
771 procedure Raise_Constraint_Error
772 (File
: System
.Address
;
776 Raise_With_Location_And_Msg
777 (Constraint_Error_Def
'Access, File
, Line
);
778 end Raise_Constraint_Error
;
780 --------------------------------
781 -- Raise_Constraint_Error_Msg --
782 --------------------------------
784 procedure Raise_Constraint_Error_Msg
785 (File
: System
.Address
;
787 Msg
: System
.Address
)
790 Raise_With_Location_And_Msg
791 (Constraint_Error_Def
'Access, File
, Line
, Msg
);
792 end Raise_Constraint_Error_Msg
;
794 -------------------------
795 -- Raise_Current_Excep --
796 -------------------------
798 procedure Raise_Current_Excep
(E
: Exception_Id
) is
800 pragma Inspection_Point
(E
);
801 -- This is so the debugger can reliably inspect the parameter when
802 -- inserting a breakpoint at the start of this procedure.
804 Id
: Exception_Id
:= E
;
805 pragma Volatile
(Id
);
806 pragma Warnings
(Off
, Id
);
807 -- In order to provide support for breakpoints on unhandled exceptions,
808 -- the debugger will also need to be able to inspect the value of E from
809 -- another (inner) frame. So we need to make sure that if E is passed in
810 -- a register, its value is also spilled on stack. For this, we store
811 -- the parameter value in a local variable, and add a pragma Volatile to
812 -- make sure it is spilled. The pragma Warnings (Off) is needed because
813 -- the compiler knows that Id is not referenced and that this use of
814 -- pragma Volatile is peculiar!
817 Exception_Propagation
.Propagate_Exception
818 (E
=> E
, From_Signal_Handler
=> False);
819 end Raise_Current_Excep
;
821 ---------------------
822 -- Raise_Exception --
823 ---------------------
825 procedure Raise_Exception
827 Message
: String := "")
831 Exception_Data
.Set_Exception_Msg
(E
, Message
);
833 Raise_Current_Excep
(E
);
836 -- Note: if E is null, then we simply return, which is correct Ada 95
837 -- semantics. If we are operating in Ada 2005 mode, then the expander
838 -- generates a raise Constraint_Error immediately following the call
839 -- to provide the required Ada 2005 semantics (see AI-329). We do it
840 -- this way to avoid having run time dependencies on the Ada version.
845 ----------------------------
846 -- Raise_Exception_Always --
847 ----------------------------
849 procedure Raise_Exception_Always
851 Message
: String := "")
854 Exception_Data
.Set_Exception_Msg
(E
, Message
);
856 Raise_Current_Excep
(E
);
857 end Raise_Exception_Always
;
859 -------------------------------
860 -- Raise_From_Signal_Handler --
861 -------------------------------
863 procedure Raise_From_Signal_Handler
868 Exception_Data
.Set_Exception_C_Msg
(E
, M
);
870 Exception_Propagation
.Propagate_Exception
871 (E
=> E
, From_Signal_Handler
=> True);
872 end Raise_From_Signal_Handler
;
874 -------------------------
875 -- Raise_Program_Error --
876 -------------------------
878 procedure Raise_Program_Error
879 (File
: System
.Address
;
883 Raise_With_Location_And_Msg
884 (Program_Error_Def
'Access, File
, Line
);
885 end Raise_Program_Error
;
887 -----------------------------
888 -- Raise_Program_Error_Msg --
889 -----------------------------
891 procedure Raise_Program_Error_Msg
892 (File
: System
.Address
;
894 Msg
: System
.Address
)
897 Raise_With_Location_And_Msg
898 (Program_Error_Def
'Access, File
, Line
, Msg
);
899 end Raise_Program_Error_Msg
;
901 -------------------------
902 -- Raise_Storage_Error --
903 -------------------------
905 procedure Raise_Storage_Error
906 (File
: System
.Address
;
910 Raise_With_Location_And_Msg
911 (Storage_Error_Def
'Access, File
, Line
);
912 end Raise_Storage_Error
;
914 -----------------------------
915 -- Raise_Storage_Error_Msg --
916 -----------------------------
918 procedure Raise_Storage_Error_Msg
919 (File
: System
.Address
;
921 Msg
: System
.Address
)
924 Raise_With_Location_And_Msg
925 (Storage_Error_Def
'Access, File
, Line
, Msg
);
926 end Raise_Storage_Error_Msg
;
928 ---------------------------------
929 -- Raise_With_Location_And_Msg --
930 ---------------------------------
932 procedure Raise_With_Location_And_Msg
936 M
: System
.Address
:= System
.Null_Address
)
939 Exception_Data
.Set_Exception_C_Msg
(E
, F
, L
, M
);
941 Raise_Current_Excep
(E
);
942 end Raise_With_Location_And_Msg
;
948 procedure Raise_With_Msg
(E
: Exception_Id
) is
949 Excep
: constant EOA
:= Get_Current_Excep
.all;
952 Exception_Propagation
.Setup_Exception
(Excep
, Excep
);
954 Excep
.Exception_Raised
:= False;
956 Excep
.Num_Tracebacks
:= 0;
957 Excep
.Cleanup_Flag
:= False;
958 Excep
.Pid
:= Local_Partition_ID
;
960 Raise_Current_Excep
(E
);
963 --------------------------------------
964 -- Calls to Run-Time Check Routines --
965 --------------------------------------
967 procedure Rcheck_00
(File
: System
.Address
; Line
: Integer) is
969 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_00
'Address);
972 procedure Rcheck_01
(File
: System
.Address
; Line
: Integer) is
974 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_01
'Address);
977 procedure Rcheck_02
(File
: System
.Address
; Line
: Integer) is
979 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_02
'Address);
982 procedure Rcheck_03
(File
: System
.Address
; Line
: Integer) is
984 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_03
'Address);
987 procedure Rcheck_04
(File
: System
.Address
; Line
: Integer) is
989 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_04
'Address);
992 procedure Rcheck_05
(File
: System
.Address
; Line
: Integer) is
994 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_05
'Address);
997 procedure Rcheck_06
(File
: System
.Address
; Line
: Integer) is
999 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_06
'Address);
1002 procedure Rcheck_07
(File
: System
.Address
; Line
: Integer) is
1004 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_07
'Address);
1007 procedure Rcheck_08
(File
: System
.Address
; Line
: Integer) is
1009 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_08
'Address);
1012 procedure Rcheck_09
(File
: System
.Address
; Line
: Integer) is
1014 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_09
'Address);
1017 procedure Rcheck_10
(File
: System
.Address
; Line
: Integer) is
1019 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_10
'Address);
1022 procedure Rcheck_11
(File
: System
.Address
; Line
: Integer) is
1024 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_11
'Address);
1027 procedure Rcheck_12
(File
: System
.Address
; Line
: Integer) is
1029 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_12
'Address);
1032 procedure Rcheck_13
(File
: System
.Address
; Line
: Integer) is
1034 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_13
'Address);
1037 procedure Rcheck_14
(File
: System
.Address
; Line
: Integer) is
1039 Raise_Program_Error_Msg
(File
, Line
, Rmsg_14
'Address);
1042 procedure Rcheck_15
(File
: System
.Address
; Line
: Integer) is
1044 Raise_Program_Error_Msg
(File
, Line
, Rmsg_15
'Address);
1047 procedure Rcheck_16
(File
: System
.Address
; Line
: Integer) is
1049 Raise_Program_Error_Msg
(File
, Line
, Rmsg_16
'Address);
1052 procedure Rcheck_17
(File
: System
.Address
; Line
: Integer) is
1054 Raise_Program_Error_Msg
(File
, Line
, Rmsg_17
'Address);
1057 procedure Rcheck_18
(File
: System
.Address
; Line
: Integer) is
1059 Raise_Program_Error_Msg
(File
, Line
, Rmsg_18
'Address);
1062 procedure Rcheck_19
(File
: System
.Address
; Line
: Integer) is
1064 Raise_Program_Error_Msg
(File
, Line
, Rmsg_19
'Address);
1067 procedure Rcheck_20
(File
: System
.Address
; Line
: Integer) is
1069 Raise_Program_Error_Msg
(File
, Line
, Rmsg_20
'Address);
1072 procedure Rcheck_21
(File
: System
.Address
; Line
: Integer) is
1074 Raise_Program_Error_Msg
(File
, Line
, Rmsg_21
'Address);
1077 procedure Rcheck_22
(File
: System
.Address
; Line
: Integer) is
1079 Raise_Program_Error_Msg
(File
, Line
, Rmsg_22
'Address);
1082 procedure Rcheck_23
(File
: System
.Address
; Line
: Integer) is
1084 Raise_Program_Error_Msg
(File
, Line
, Rmsg_23
'Address);
1087 procedure Rcheck_24
(File
: System
.Address
; Line
: Integer) is
1089 Raise_Program_Error_Msg
(File
, Line
, Rmsg_24
'Address);
1092 procedure Rcheck_25
(File
: System
.Address
; Line
: Integer) is
1094 Raise_Program_Error_Msg
(File
, Line
, Rmsg_25
'Address);
1097 procedure Rcheck_26
(File
: System
.Address
; Line
: Integer) is
1099 Raise_Program_Error_Msg
(File
, Line
, Rmsg_26
'Address);
1102 procedure Rcheck_27
(File
: System
.Address
; Line
: Integer) is
1104 Raise_Program_Error_Msg
(File
, Line
, Rmsg_27
'Address);
1107 procedure Rcheck_28
(File
: System
.Address
; Line
: Integer) is
1109 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_28
'Address);
1112 procedure Rcheck_29
(File
: System
.Address
; Line
: Integer) is
1114 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_29
'Address);
1117 procedure Rcheck_30
(File
: System
.Address
; Line
: Integer) is
1119 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_30
'Address);
1122 procedure Rcheck_31
(File
: System
.Address
; Line
: Integer) is
1124 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_31
'Address);
1127 procedure Rcheck_32
(File
: System
.Address
; Line
: Integer) is
1129 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_32
'Address);
1136 procedure Reraise
is
1137 Excep
: constant EOA
:= Get_Current_Excep
.all;
1141 Exception_Propagation
.Setup_Exception
(Excep
, Excep
, Reraised
=> True);
1142 Raise_Current_Excep
(Excep
.Id
);
1145 ------------------------
1146 -- Reraise_Occurrence --
1147 ------------------------
1149 procedure Reraise_Occurrence
(X
: Exception_Occurrence
) is
1151 if X
.Id
/= null then
1153 Exception_Propagation
.Setup_Exception
1154 (X
'Unrestricted_Access, Get_Current_Excep
.all, Reraised
=> True);
1155 Save_Occurrence_No_Private
(Get_Current_Excep
.all.all, X
);
1156 Raise_Current_Excep
(X
.Id
);
1158 end Reraise_Occurrence
;
1160 -------------------------------
1161 -- Reraise_Occurrence_Always --
1162 -------------------------------
1164 procedure Reraise_Occurrence_Always
(X
: Exception_Occurrence
) is
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 Reraise_Occurrence_Always
;
1173 ---------------------------------
1174 -- Reraise_Occurrence_No_Defer --
1175 ---------------------------------
1177 procedure Reraise_Occurrence_No_Defer
(X
: Exception_Occurrence
) is
1179 Exception_Propagation
.Setup_Exception
1180 (X
'Unrestricted_Access, Get_Current_Excep
.all, Reraised
=> True);
1181 Save_Occurrence_No_Private
(Get_Current_Excep
.all.all, X
);
1182 Raise_Current_Excep
(X
.Id
);
1183 end Reraise_Occurrence_No_Defer
;
1185 ---------------------
1186 -- Save_Occurrence --
1187 ---------------------
1189 procedure Save_Occurrence
1190 (Target
: out Exception_Occurrence
;
1191 Source
: Exception_Occurrence
)
1194 Save_Occurrence_No_Private
(Target
, Source
);
1195 end Save_Occurrence
;
1197 function Save_Occurrence
(Source
: Exception_Occurrence
) return EOA
is
1198 Target
: constant EOA
:= new Exception_Occurrence
;
1200 Save_Occurrence
(Target
.all, Source
);
1202 end Save_Occurrence
;
1204 --------------------------------
1205 -- Save_Occurrence_No_Private --
1206 --------------------------------
1208 procedure Save_Occurrence_No_Private
1209 (Target
: out Exception_Occurrence
;
1210 Source
: Exception_Occurrence
)
1213 Target
.Id
:= Source
.Id
;
1214 Target
.Msg_Length
:= Source
.Msg_Length
;
1215 Target
.Num_Tracebacks
:= Source
.Num_Tracebacks
;
1216 Target
.Pid
:= Source
.Pid
;
1217 Target
.Cleanup_Flag
:= Source
.Cleanup_Flag
;
1219 Target
.Msg
(1 .. Target
.Msg_Length
) :=
1220 Source
.Msg
(1 .. Target
.Msg_Length
);
1222 Target
.Tracebacks
(1 .. Target
.Num_Tracebacks
) :=
1223 Source
.Tracebacks
(1 .. Target
.Num_Tracebacks
);
1224 end Save_Occurrence_No_Private
;
1226 -------------------------
1227 -- Transfer_Occurrence --
1228 -------------------------
1230 procedure Transfer_Occurrence
1231 (Target
: Exception_Occurrence_Access
;
1232 Source
: Exception_Occurrence
)
1235 -- Setup Target as an exception to be propagated in the calling task
1236 -- (rendezvous-wise), taking care not to clobber the associated private
1237 -- data. Target is expected to be a pointer to the calling task's
1238 -- fixed TSD occurrence, which is very different from Get_Current_Excep
1239 -- here because this subprogram is called from the called task.
1241 Exception_Propagation
.Setup_Exception
(Target
, Target
);
1242 Save_Occurrence_No_Private
(Target
.all, Source
);
1243 end Transfer_Occurrence
;
1249 function String_To_EId
(S
: String) return Exception_Id
1250 renames Stream_Attributes
.String_To_EId
;
1256 function String_To_EO
(S
: String) return Exception_Occurrence
1257 renames Stream_Attributes
.String_To_EO
;
1259 ------------------------------
1260 -- Raise_Exception_No_Defer --
1261 ------------------------------
1263 procedure Raise_Exception_No_Defer
1265 Message
: String := "")
1268 Exception_Data
.Set_Exception_Msg
(E
, Message
);
1270 -- Do not call Abort_Defer.all, as specified by the spec
1272 Raise_Current_Excep
(E
);
1273 end Raise_Exception_No_Defer
;
1279 procedure To_Stderr
(C
: Character) is
1281 type int
is new Integer;
1283 procedure put_char_stderr
(C
: int
);
1284 pragma Import
(C
, put_char_stderr
, "put_char_stderr");
1287 put_char_stderr
(Character'Pos (C
));
1290 procedure To_Stderr
(S
: String) is
1292 for J
in S
'Range loop
1293 if S
(J
) /= ASCII
.CR
then
1299 -------------------------
1300 -- Wide_Exception_Name --
1301 -------------------------
1303 WC_Encoding
: Character;
1304 pragma Import
(C
, WC_Encoding
, "__gl_wc_encoding");
1305 -- Encoding method for source, as exported by binder
1307 function Wide_Exception_Name
1308 (Id
: Exception_Id
) return Wide_String is
1310 return String_To_Wide_String
1311 (Exception_Name
(Id
), Get_WC_Encoding_Method
(WC_Encoding
));
1312 end Wide_Exception_Name
;
1314 function Wide_Exception_Name
1315 (X
: Exception_Occurrence
) return Wide_String is
1317 return String_To_Wide_String
1318 (Exception_Name
(X
), Get_WC_Encoding_Method
(WC_Encoding
));
1319 end Wide_Exception_Name
;
1321 ----------------------------
1322 -- Wide_Wide_Exception_Name --
1323 -----------------------------
1325 function Wide_Wide_Exception_Name
1326 (Id
: Exception_Id
) return Wide_Wide_String
1329 return String_To_Wide_Wide_String
1330 (Exception_Name
(Id
), Get_WC_Encoding_Method
(WC_Encoding
));
1331 end Wide_Wide_Exception_Name
;
1333 function Wide_Wide_Exception_Name
1334 (X
: Exception_Occurrence
) return Wide_Wide_String
1337 return String_To_Wide_Wide_String
1338 (Exception_Name
(X
), Get_WC_Encoding_Method
(WC_Encoding
));
1339 end Wide_Wide_Exception_Name
;
1341 --------------------------
1342 -- Code_Address_For_ZZZ --
1343 --------------------------
1345 -- This function gives us the end of the PC range for addresses
1346 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1347 -- procedures in their original order!
1349 function Code_Address_For_ZZZ
return System
.Address
is
1352 return Start_Of_ZZZ
'Address;
1353 end Code_Address_For_ZZZ
;