1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
9 -- Copyright (C) 1992-2005 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 ------------------------------------------------------------------------------
35 -- We must turn polling off for this unit, because otherwise we get
36 -- elaboration circularities with System.Exception_Tables.
38 with System
; use System
;
39 with System
.Standard_Library
; use System
.Standard_Library
;
40 with System
.Soft_Links
; use System
.Soft_Links
;
42 package body Ada
.Exceptions
is
44 procedure builtin_longjmp
(buffer
: Address
; Flag
: Integer);
45 pragma No_Return
(builtin_longjmp
);
46 pragma Import
(C
, builtin_longjmp
, "_gnat_builtin_longjmp");
48 pragma Suppress
(All_Checks
);
49 -- We definitely do not want exceptions occurring within this unit, or
50 -- we are in big trouble. If an exceptional situation does occur, better
51 -- that it not be raised, since raising it can cause confusing chaos.
53 Zero_Cost_Exceptions
: Integer;
54 pragma Import
(C
, Zero_Cost_Exceptions
, "__gl_zero_cost_exceptions");
55 -- Boolean indicating if we are handling exceptions using a zero cost
58 -- Note that although we currently do not support it, the GCC3 back-end
59 -- tables are also potentially useable for setjmp/longjmp processing.
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 Process_Raise_Exception
99 From_Signal_Handler
: Boolean);
100 pragma No_Return
(Process_Raise_Exception
);
101 -- This is the lowest level raise routine. It raises the exception
102 -- referenced by Current_Excep.all in the TSD, without deferring abort
103 -- (the caller must ensure that abort is deferred on entry).
105 -- This is the common implementation for Raise_Current_Excep and
106 -- Raise_From_Signal_Handler. The origin of the call is indicated by the
107 -- From_Signal_Handler argument.
109 procedure To_Stderr
(S
: String);
110 pragma Export
(Ada
, To_Stderr
, "__gnat_to_stderr");
111 -- Little routine to output string to stderr that is also used
112 -- in the tasking run time.
114 procedure To_Stderr
(C
: Character);
115 pragma Inline
(To_Stderr
);
116 pragma Export
(Ada
, To_Stderr
, "__gnat_to_stderr_char");
117 -- Little routine to output a character to stderr, used by some of
118 -- the separate units below.
120 package Exception_Data
is
122 ---------------------------------
123 -- Exception messages routines --
124 ---------------------------------
126 procedure Set_Exception_C_Msg
128 Msg1
: System
.Address
;
130 Msg2
: System
.Address
:= System
.Null_Address
);
131 -- This routine is called to setup the exception referenced by the
132 -- Current_Excep field in the TSD to contain the indicated Id value
133 -- and message. Msg1 is a null terminated string which is generated
134 -- as the exception message. If line is non-zero, then a colon and
135 -- the decimal representation of this integer is appended to the
136 -- message. When Msg2 is non-null, a space and this additional null
137 -- terminated string is added to the message.
139 procedure Set_Exception_Msg
142 -- This routine is called to setup the exception referenced by the
143 -- Current_Excep field in the TSD to contain the indicated Id value
144 -- and message. Message is a string which is generated as the
145 -- exception message.
147 --------------------------------------
148 -- Exception information subprogram --
149 --------------------------------------
151 function Exception_Information
(X
: Exception_Occurrence
) return String;
152 -- The format of the exception information is as follows:
154 -- Exception_Name: <exception name> (as in Exception_Name)
155 -- Message: <message> (only if Exception_Message is empty)
156 -- PID=nnnn (only if != 0)
157 -- Call stack traceback locations: (only if at least one location)
158 -- <0xyyyyyyyy 0xyyyyyyyy ...> (is recorded)
160 -- The lines are separated by a ASCII.LF character.
161 -- The nnnn is the partition Id given as decimal digits.
162 -- The 0x... line represents traceback program counter locations, in
163 -- execution order with the first one being the exception location. It
166 -- The Exception_Name and Message lines are omitted in the abort
167 -- signal case, since this is not really an exception.
169 -- !! If the format of the generated string is changed, please note
170 -- !! that an equivalent modification to the routine String_To_EO must
171 -- !! be made to preserve proper functioning of the stream attributes.
173 ---------------------------------------
174 -- Exception backtracing subprograms --
175 ---------------------------------------
177 -- What is automatically output when exception tracing is on is the
178 -- usual exception information with the call chain backtrace possibly
179 -- tailored by a backtrace decorator. Modifying Exception_Information
180 -- itself is not a good idea because the decorated output is completely
181 -- out of control and would break all our code related to the streaming
182 -- of exceptions. We then provide an alternative function to compute
183 -- the possibly tailored output, which is equivalent if no decorator is
186 function Tailored_Exception_Information
187 (X
: Exception_Occurrence
) return String;
188 -- Exception information to be output in the case of automatic tracing
189 -- requested through GNAT.Exception_Traces.
191 -- This is the same as Exception_Information if no backtrace decorator
192 -- is currently in place. Otherwise, this is Exception_Information with
193 -- the call chain raw addresses replaced by the result of a call to the
194 -- current decorator provided with the call chain addresses.
197 (Ada
, Tailored_Exception_Information
,
198 "__gnat_tailored_exception_information");
199 -- This is currently used by System.Tasking.Stages
203 package Exception_Traces
is
206 -- Imports Tailored_Exception_Information
208 ----------------------------------------------
209 -- Run-Time Exception Notification Routines --
210 ----------------------------------------------
212 -- These subprograms provide a common run-time interface to trigger the
213 -- actions required when an exception is about to be propagated (e.g.
214 -- user specified actions or output of exception information). They are
215 -- exported to be usable by the Ada exception handling personality
216 -- routine when the GCC 3 mechanism is used.
218 procedure Notify_Handled_Exception
;
220 (C
, Notify_Handled_Exception
, "__gnat_notify_handled_exception");
221 -- This routine is called for a handled occurrence is about to be
224 procedure Notify_Unhandled_Exception
;
226 (C
, Notify_Unhandled_Exception
, "__gnat_notify_unhandled_exception");
227 -- This routine is called when an unhandled occurrence is about to be
230 procedure Unhandled_Exception_Terminate
;
231 pragma No_Return
(Unhandled_Exception_Terminate
);
232 -- This procedure is called to terminate execution following an
233 -- unhandled exception. The exception information, including
234 -- traceback if available is output, and execution is then
235 -- terminated. Note that at the point where this routine is
236 -- called, the stack has typically been destroyed.
238 end Exception_Traces
;
240 package Exception_Propagation
is
242 use Exception_Traces
;
243 -- Imports Notify_Unhandled_Exception and
244 -- Unhandled_Exception_Terminate
246 ------------------------------------
247 -- Exception propagation routines --
248 ------------------------------------
250 procedure Setup_Exception
253 Reraised
: Boolean := False);
254 -- Perform the necessary operations to prepare the propagation of Excep
255 -- in a task where Current is the current occurrence. Excep is assumed
256 -- to be a valid (non null) pointer.
258 -- This should be called before any (re-)setting of the current
259 -- occurrence. Any such (re-)setting shall take care *not* to clobber
260 -- the Private_Data component.
262 -- Having Current provided as an argument (instead of retrieving it via
263 -- Get_Current_Excep internally) is required to allow one task to setup
264 -- an exception for another task, which is used by Transfer_Occurrence.
266 procedure Propagate_Exception
(From_Signal_Handler
: Boolean);
267 pragma No_Return
(Propagate_Exception
);
268 -- This procedure propagates the exception represented by the occurrence
269 -- referenced by Current_Excep in the TSD for the current task.
271 end Exception_Propagation
;
273 package Stream_Attributes
is
275 --------------------------------
276 -- Stream attributes routines --
277 --------------------------------
279 function EId_To_String
(X
: Exception_Id
) return String;
280 function String_To_EId
(S
: String) return Exception_Id
;
281 -- Functions for implementing Exception_Id stream attributes
283 function EO_To_String
(X
: Exception_Occurrence
) return String;
284 function String_To_EO
(S
: String) return Exception_Occurrence
;
285 -- Functions for implementing Exception_Occurrence stream
288 end Stream_Attributes
;
290 procedure Raise_Current_Excep
(E
: Exception_Id
);
291 pragma No_Return
(Raise_Current_Excep
);
292 pragma Export
(C
, Raise_Current_Excep
, "__gnat_raise_nodefer_with_msg");
293 -- This is a simple wrapper to Process_Raise_Exception setting the
294 -- From_Signal_Handler argument to False.
296 -- This external name for Raise_Current_Excep is historical, and probably
297 -- should be changed but for now we keep it, because gdb and gigi know
300 procedure Raise_Exception_No_Defer
301 (E
: Exception_Id
; Message
: String := "");
303 (Ada
, Raise_Exception_No_Defer
,
304 "ada__exceptions__raise_exception_no_defer");
305 pragma No_Return
(Raise_Exception_No_Defer
);
306 -- Similar to Raise_Exception, but with no abort deferral
308 procedure Raise_With_Msg
(E
: Exception_Id
);
309 pragma No_Return
(Raise_With_Msg
);
310 pragma Export
(C
, Raise_With_Msg
, "__gnat_raise_with_msg");
311 -- Raises an exception with given exception id value. A message
312 -- is associated with the raise, and has already been stored in the
313 -- exception occurrence referenced by the Current_Excep in the TSD.
314 -- Abort is deferred before the raise call.
316 procedure Raise_With_Location_And_Msg
320 M
: System
.Address
:= System
.Null_Address
);
321 pragma No_Return
(Raise_With_Location_And_Msg
);
322 -- Raise an exception with given exception id value. A filename and line
323 -- number is associated with the raise and is stored in the exception
324 -- occurrence and in addition a string message M is appended to
325 -- this (if M is not null).
327 procedure Raise_Constraint_Error
328 (File
: System
.Address
;
330 pragma No_Return
(Raise_Constraint_Error
);
332 (C
, Raise_Constraint_Error
, "__gnat_raise_constraint_error");
333 -- Raise constraint error with file:line information
335 procedure Raise_Constraint_Error_Msg
336 (File
: System
.Address
;
338 Msg
: System
.Address
);
339 pragma No_Return
(Raise_Constraint_Error_Msg
);
341 (C
, Raise_Constraint_Error_Msg
, "__gnat_raise_constraint_error_msg");
342 -- Raise constraint error with file:line + msg information
344 procedure Raise_Program_Error
345 (File
: System
.Address
;
347 pragma No_Return
(Raise_Program_Error
);
349 (C
, Raise_Program_Error
, "__gnat_raise_program_error");
350 -- Raise program error with file:line information
352 procedure Raise_Program_Error_Msg
353 (File
: System
.Address
;
355 Msg
: System
.Address
);
356 pragma No_Return
(Raise_Program_Error_Msg
);
358 (C
, Raise_Program_Error_Msg
, "__gnat_raise_program_error_msg");
359 -- Raise program error with file:line + msg information
361 procedure Raise_Storage_Error
362 (File
: System
.Address
;
364 pragma No_Return
(Raise_Storage_Error
);
366 (C
, Raise_Storage_Error
, "__gnat_raise_storage_error");
367 -- Raise storage error with file:line information
369 procedure Raise_Storage_Error_Msg
370 (File
: System
.Address
;
372 Msg
: System
.Address
);
373 pragma No_Return
(Raise_Storage_Error_Msg
);
375 (C
, Raise_Storage_Error_Msg
, "__gnat_raise_storage_error_msg");
376 -- Raise storage error with file:line + reason msg information
378 -- The exception raising process and the automatic tracing mechanism rely
379 -- on some careful use of flags attached to the exception occurrence. The
380 -- graph below illustrates the relations between the Raise_ subprograms
381 -- and identifies the points where basic flags such as Exception_Raised
384 -- (i) signs indicate the flags initialization points. R stands for Raise,
385 -- W for With, and E for Exception.
387 -- R_No_Msg R_E R_Pe R_Ce R_Se
389 -- +--+ +--+ +---+ | +---+
391 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc
393 -- +------------+ | +-----------+ +--+
395 -- | | | Set_E_C_Msg(i)
397 -- Raise_Current_Excep
400 pragma No_Return
(Reraise
);
401 pragma Export
(C
, Reraise
, "__gnat_reraise");
402 -- Reraises the exception referenced by the Current_Excep field of
403 -- the TSD (all fields of this exception occurrence are set). Abort
404 -- is deferred before the reraise operation.
406 -- Save_Occurrence variations: As the management of the private data
407 -- attached to occurrences is delicate, wether or not pointers to such
408 -- data has to be copied in various situations is better made explicit.
409 -- The following procedures provide an internal interface to help making
412 procedure Save_Occurrence_And_Private
413 (Target
: out Exception_Occurrence
;
414 Source
: Exception_Occurrence
);
415 -- Copy all the components of Source to Target as well as the
416 -- Private_Data pointer.
418 procedure Save_Occurrence_No_Private
419 (Target
: out Exception_Occurrence
;
420 Source
: Exception_Occurrence
);
421 -- Copy all the components of Source to Target, except the
422 -- Private_Data pointer.
424 procedure Transfer_Occurrence
425 (Target
: Exception_Occurrence_Access
;
426 Source
: Exception_Occurrence
);
427 pragma Export
(C
, Transfer_Occurrence
, "__gnat_transfer_occurrence");
428 -- Called from System.Tasking.RendezVous.Exceptional_Complete_RendezVous
429 -- to setup Target from Source as an exception to be propagated in the
430 -- caller task. Target is expected to be a pointer to the fixed TSD
431 -- occurrence for this task.
433 -----------------------------
434 -- Run-Time Check Routines --
435 -----------------------------
437 -- These routines are called from the runtime to raise a specific
438 -- exception with a reason message attached. The parameters are
439 -- the file name and line number in each case. The names are keyed
440 -- to the codes defined in Types.ads and a-types.h (for example,
441 -- the name Rcheck_05 refers to the Reason whose Pos code is 5).
443 procedure Rcheck_00
(File
: System
.Address
; Line
: Integer);
444 procedure Rcheck_01
(File
: System
.Address
; Line
: Integer);
445 procedure Rcheck_02
(File
: System
.Address
; Line
: Integer);
446 procedure Rcheck_03
(File
: System
.Address
; Line
: Integer);
447 procedure Rcheck_04
(File
: System
.Address
; Line
: Integer);
448 procedure Rcheck_05
(File
: System
.Address
; Line
: Integer);
449 procedure Rcheck_06
(File
: System
.Address
; Line
: Integer);
450 procedure Rcheck_07
(File
: System
.Address
; Line
: Integer);
451 procedure Rcheck_08
(File
: System
.Address
; Line
: Integer);
452 procedure Rcheck_09
(File
: System
.Address
; Line
: Integer);
453 procedure Rcheck_10
(File
: System
.Address
; Line
: Integer);
454 procedure Rcheck_11
(File
: System
.Address
; Line
: Integer);
455 procedure Rcheck_12
(File
: System
.Address
; Line
: Integer);
456 procedure Rcheck_13
(File
: System
.Address
; Line
: Integer);
457 procedure Rcheck_14
(File
: System
.Address
; Line
: Integer);
458 procedure Rcheck_15
(File
: System
.Address
; Line
: Integer);
459 procedure Rcheck_16
(File
: System
.Address
; Line
: Integer);
460 procedure Rcheck_17
(File
: System
.Address
; Line
: Integer);
461 procedure Rcheck_18
(File
: System
.Address
; Line
: Integer);
462 procedure Rcheck_19
(File
: System
.Address
; Line
: Integer);
463 procedure Rcheck_20
(File
: System
.Address
; Line
: Integer);
464 procedure Rcheck_21
(File
: System
.Address
; Line
: Integer);
465 procedure Rcheck_22
(File
: System
.Address
; Line
: Integer);
466 procedure Rcheck_23
(File
: System
.Address
; Line
: Integer);
467 procedure Rcheck_24
(File
: System
.Address
; Line
: Integer);
468 procedure Rcheck_25
(File
: System
.Address
; Line
: Integer);
469 procedure Rcheck_26
(File
: System
.Address
; Line
: Integer);
470 procedure Rcheck_27
(File
: System
.Address
; Line
: Integer);
471 procedure Rcheck_28
(File
: System
.Address
; Line
: Integer);
472 procedure Rcheck_29
(File
: System
.Address
; Line
: Integer);
473 procedure Rcheck_30
(File
: System
.Address
; Line
: Integer);
475 pragma Export
(C
, Rcheck_00
, "__gnat_rcheck_00");
476 pragma Export
(C
, Rcheck_01
, "__gnat_rcheck_01");
477 pragma Export
(C
, Rcheck_02
, "__gnat_rcheck_02");
478 pragma Export
(C
, Rcheck_03
, "__gnat_rcheck_03");
479 pragma Export
(C
, Rcheck_04
, "__gnat_rcheck_04");
480 pragma Export
(C
, Rcheck_05
, "__gnat_rcheck_05");
481 pragma Export
(C
, Rcheck_06
, "__gnat_rcheck_06");
482 pragma Export
(C
, Rcheck_07
, "__gnat_rcheck_07");
483 pragma Export
(C
, Rcheck_08
, "__gnat_rcheck_08");
484 pragma Export
(C
, Rcheck_09
, "__gnat_rcheck_09");
485 pragma Export
(C
, Rcheck_10
, "__gnat_rcheck_10");
486 pragma Export
(C
, Rcheck_11
, "__gnat_rcheck_11");
487 pragma Export
(C
, Rcheck_12
, "__gnat_rcheck_12");
488 pragma Export
(C
, Rcheck_13
, "__gnat_rcheck_13");
489 pragma Export
(C
, Rcheck_14
, "__gnat_rcheck_14");
490 pragma Export
(C
, Rcheck_15
, "__gnat_rcheck_15");
491 pragma Export
(C
, Rcheck_16
, "__gnat_rcheck_16");
492 pragma Export
(C
, Rcheck_17
, "__gnat_rcheck_17");
493 pragma Export
(C
, Rcheck_18
, "__gnat_rcheck_18");
494 pragma Export
(C
, Rcheck_19
, "__gnat_rcheck_19");
495 pragma Export
(C
, Rcheck_20
, "__gnat_rcheck_20");
496 pragma Export
(C
, Rcheck_21
, "__gnat_rcheck_21");
497 pragma Export
(C
, Rcheck_22
, "__gnat_rcheck_22");
498 pragma Export
(C
, Rcheck_23
, "__gnat_rcheck_23");
499 pragma Export
(C
, Rcheck_24
, "__gnat_rcheck_24");
500 pragma Export
(C
, Rcheck_25
, "__gnat_rcheck_25");
501 pragma Export
(C
, Rcheck_26
, "__gnat_rcheck_26");
502 pragma Export
(C
, Rcheck_27
, "__gnat_rcheck_27");
503 pragma Export
(C
, Rcheck_28
, "__gnat_rcheck_28");
504 pragma Export
(C
, Rcheck_29
, "__gnat_rcheck_29");
505 pragma Export
(C
, Rcheck_30
, "__gnat_rcheck_30");
507 -- None of these procedures ever returns (they raise an exception!). By
508 -- using pragma No_Return, we ensure that any junk code after the call,
509 -- such as normal return epilog stuff, can be eliminated).
511 pragma No_Return
(Rcheck_00
);
512 pragma No_Return
(Rcheck_01
);
513 pragma No_Return
(Rcheck_02
);
514 pragma No_Return
(Rcheck_03
);
515 pragma No_Return
(Rcheck_04
);
516 pragma No_Return
(Rcheck_05
);
517 pragma No_Return
(Rcheck_06
);
518 pragma No_Return
(Rcheck_07
);
519 pragma No_Return
(Rcheck_08
);
520 pragma No_Return
(Rcheck_09
);
521 pragma No_Return
(Rcheck_10
);
522 pragma No_Return
(Rcheck_11
);
523 pragma No_Return
(Rcheck_12
);
524 pragma No_Return
(Rcheck_13
);
525 pragma No_Return
(Rcheck_14
);
526 pragma No_Return
(Rcheck_15
);
527 pragma No_Return
(Rcheck_16
);
528 pragma No_Return
(Rcheck_17
);
529 pragma No_Return
(Rcheck_18
);
530 pragma No_Return
(Rcheck_19
);
531 pragma No_Return
(Rcheck_20
);
532 pragma No_Return
(Rcheck_21
);
533 pragma No_Return
(Rcheck_22
);
534 pragma No_Return
(Rcheck_23
);
535 pragma No_Return
(Rcheck_24
);
536 pragma No_Return
(Rcheck_25
);
537 pragma No_Return
(Rcheck_26
);
538 pragma No_Return
(Rcheck_27
);
539 pragma No_Return
(Rcheck_28
);
540 pragma No_Return
(Rcheck_29
);
541 pragma No_Return
(Rcheck_30
);
543 ---------------------------------------------
544 -- Reason Strings for Run-Time Check Calls --
545 ---------------------------------------------
547 -- These strings are null-terminated and are used by Rcheck_nn. The
548 -- strings correspond to the definitions for Types.RT_Exception_Code.
552 Rmsg_00
: constant String := "access check failed" & NUL
;
553 Rmsg_01
: constant String := "access parameter is null" & NUL
;
554 Rmsg_02
: constant String := "discriminant check failed" & NUL
;
555 Rmsg_03
: constant String := "divide by zero" & NUL
;
556 Rmsg_04
: constant String := "explicit raise" & NUL
;
557 Rmsg_05
: constant String := "index check failed" & NUL
;
558 Rmsg_06
: constant String := "invalid data" & NUL
;
559 Rmsg_07
: constant String := "length check failed" & NUL
;
560 Rmsg_08
: constant String := "null-exclusion check failed" & NUL
;
561 Rmsg_09
: constant String := "overflow check failed" & NUL
;
562 Rmsg_10
: constant String := "partition check failed" & NUL
;
563 Rmsg_11
: constant String := "range check failed" & NUL
;
564 Rmsg_12
: constant String := "tag check failed" & NUL
;
565 Rmsg_13
: constant String := "access before elaboration" & NUL
;
566 Rmsg_14
: constant String := "accessibility check failed" & NUL
;
567 Rmsg_15
: constant String := "all guards closed" & NUL
;
568 Rmsg_16
: constant String := "duplicated entry address" & NUL
;
569 Rmsg_17
: constant String := "explicit raise" & NUL
;
570 Rmsg_18
: constant String := "finalize/adjust raised exception" & NUL
;
571 Rmsg_19
: constant String := "misaligned address value" & NUL
;
572 Rmsg_20
: constant String := "missing return" & NUL
;
573 Rmsg_21
: constant String := "overlaid controlled object" & NUL
;
574 Rmsg_22
: constant String := "potentially blocking operation" & NUL
;
575 Rmsg_23
: constant String := "stubbed subprogram called" & NUL
;
576 Rmsg_24
: constant String := "unchecked union restriction" & NUL
;
577 Rmsg_25
: constant String := "illegal use of"
578 & " remote access-to-class-wide type, see RM E.4(18)" & NUL
;
579 Rmsg_26
: constant String := "empty storage pool" & NUL
;
580 Rmsg_27
: constant String := "explicit raise" & NUL
;
581 Rmsg_28
: constant String := "infinite recursion" & NUL
;
582 Rmsg_29
: constant String := "object too large" & NUL
;
583 Rmsg_30
: constant String := "restriction violation" & NUL
;
585 -----------------------
586 -- Polling Interface --
587 -----------------------
589 type Unsigned
is mod 2 ** 32;
591 Counter
: Unsigned
:= 0;
592 pragma Warnings
(Off
, Counter
);
593 -- This counter is provided for convenience. It can be used in Poll to
594 -- perform periodic but not systematic operations.
596 procedure Poll
is separate;
597 -- The actual polling routine is separate, so that it can easily
598 -- be replaced with a target dependent version.
600 --------------------------
601 -- Code_Address_For_AAA --
602 --------------------------
604 -- This function gives us the start of the PC range for addresses
605 -- within the exception unit itself. We hope that gigi/gcc keep all the
606 -- procedures in their original order!
608 function Code_Address_For_AAA
return System
.Address
is
610 -- We are using a label instead of merely using
611 -- Code_Address_For_AAA'Address because on some platforms the latter
612 -- does not yield the address we want, but the address of a stub or of
613 -- a descriptor instead. This is the case at least on Alpha-VMS and
617 return Start_Of_AAA
'Address;
618 end Code_Address_For_AAA
;
624 procedure Call_Chain
(Excep
: EOA
) is separate;
625 -- The actual Call_Chain routine is separate, so that it can easily
626 -- be dummied out when no exception traceback information is needed.
628 ------------------------------
629 -- Current_Target_Exception --
630 ------------------------------
632 function Current_Target_Exception
return Exception_Occurrence
is
634 return Null_Occurrence
;
635 end Current_Target_Exception
;
641 function EId_To_String
(X
: Exception_Id
) return String
642 renames Stream_Attributes
.EId_To_String
;
648 -- We use the null string to represent the null occurrence, otherwise
649 -- we output the Exception_Information string for the occurrence.
651 function EO_To_String
(X
: Exception_Occurrence
) return String
652 renames Stream_Attributes
.EO_To_String
;
654 ------------------------
655 -- Exception_Identity --
656 ------------------------
658 function Exception_Identity
659 (X
: Exception_Occurrence
) return Exception_Id
662 -- Note that the following test used to be here for the original
663 -- Ada 95 semantics, but these were modified by AI-241 to require
664 -- returning Null_Id instead of raising Constraint_Error.
666 -- if X.Id = Null_Id then
667 -- raise Constraint_Error;
671 end Exception_Identity
;
673 ---------------------------
674 -- Exception_Information --
675 ---------------------------
677 function Exception_Information
(X
: Exception_Occurrence
) return String is
679 if X
.Id
= Null_Id
then
680 raise Constraint_Error
;
683 return Exception_Data
.Exception_Information
(X
);
684 end Exception_Information
;
686 -----------------------
687 -- Exception_Message --
688 -----------------------
690 function Exception_Message
(X
: Exception_Occurrence
) return String is
692 if X
.Id
= Null_Id
then
693 raise Constraint_Error
;
696 return X
.Msg
(1 .. X
.Msg_Length
);
697 end Exception_Message
;
703 function Exception_Name
(Id
: Exception_Id
) return String is
706 raise Constraint_Error
;
709 return To_Ptr
(Id
.Full_Name
) (1 .. Id
.Name_Length
- 1);
712 function Exception_Name
(X
: Exception_Occurrence
) return String is
714 return Exception_Name
(X
.Id
);
717 ---------------------------
718 -- Exception_Name_Simple --
719 ---------------------------
721 function Exception_Name_Simple
(X
: Exception_Occurrence
) return String is
722 Name
: constant String := Exception_Name
(X
);
728 exit when Name
(P
- 1) = '.';
732 -- Return result making sure lower bound is 1
735 subtype Rname
is String (1 .. Name
'Length - P
+ 1);
737 return Rname
(Name
(P
.. Name
'Length));
739 end Exception_Name_Simple
;
745 package body Exception_Data
is separate;
746 -- This package can be easily dummied out if we do not want the
747 -- basic support for exception messages (such as in Ada 83).
749 ---------------------------
750 -- Exception_Propagation --
751 ---------------------------
753 package body Exception_Propagation
is separate;
754 -- Depending on the actual exception mechanism used (front-end or
755 -- back-end based), the implementation will differ, which is why this
756 -- package is separated.
758 ----------------------
759 -- Exception_Traces --
760 ----------------------
762 package body Exception_Traces
is separate;
763 -- Depending on the underlying support for IO the implementation
764 -- will differ. Moreover we would like to dummy out this package
765 -- in case we do not want any exception tracing support. This is
766 -- why this package is separated.
768 -----------------------
769 -- Stream Attributes --
770 -----------------------
772 package body Stream_Attributes
is separate;
773 -- This package can be easily dummied out if we do not want the
774 -- support for streaming Exception_Ids and Exception_Occurrences.
776 -----------------------------
777 -- Process_Raise_Exception --
778 -----------------------------
780 procedure Process_Raise_Exception
782 From_Signal_Handler
: Boolean)
784 pragma Inspection_Point
(E
);
785 -- This is so the debugger can reliably inspect the parameter
787 Jumpbuf_Ptr
: constant Address
:= Get_Jmpbuf_Address
.all;
788 Excep
: constant EOA
:= Get_Current_Excep
.all;
791 -- WARNING : There should be no exception handler for this body
792 -- because this would cause gigi to prepend a setup for a new
793 -- jmpbuf to the sequence of statements. We would then always get
794 -- this new buf in Jumpbuf_Ptr instead of the one for the exception
795 -- we are handling, which would completely break the whole design
796 -- of this procedure.
798 -- Processing varies between zero cost and setjmp/lonjmp processing
800 if Zero_Cost_Exceptions
/= 0 then
802 -- Use the GCC back-end to propagate the exception. Backtrace
803 -- computation is performed, if required, by the underlying routine.
804 -- Notifications for the debugger are also not performed here,
805 -- because we do not yet know if the exception is handled.
807 Exception_Propagation
.Propagate_Exception
(From_Signal_Handler
);
810 -- Compute the backtrace for this occurrence if corresponding binder
811 -- option has been set. Call_Chain takes care of the reraise case.
815 -- Note on above call to Call_Chain:
817 -- We used to only do this if From_Signal_Handler was not set,
818 -- based on the assumption that backtracing from a signal handler
819 -- would not work due to stack layout oddities. However, since
821 -- 1. The flag is never set in tasking programs (Notify_Exception
822 -- performs regular raise statements), and
824 -- 2. No problem has shown up in tasking programs around here so
825 -- far, this turned out to be too strong an assumption.
827 -- As, in addition, the test was
829 -- 1. preventing the production of backtraces in non-tasking
832 -- 2. introducing a behavior inconsistency between
833 -- the tasking and non-tasking cases,
835 -- we have simply removed it
837 -- If the jump buffer pointer is non-null, transfer control using
838 -- it. Otherwise announce an unhandled exception (note that this
839 -- means that we have no finalizations to do other than at the outer
840 -- level). Perform the necessary notification tasks in both cases.
842 if Jumpbuf_Ptr
/= Null_Address
then
844 if not Excep
.Exception_Raised
then
845 Excep
.Exception_Raised
:= True;
846 Exception_Traces
.Notify_Handled_Exception
;
849 builtin_longjmp
(Jumpbuf_Ptr
, 1);
852 -- The pragma Inspection point here ensures that the debugger
853 -- can inspect the parameter.
855 pragma Inspection_Point
(E
);
857 Exception_Traces
.Notify_Unhandled_Exception
;
858 Exception_Traces
.Unhandled_Exception_Terminate
;
861 end Process_Raise_Exception
;
863 ----------------------------
864 -- Raise_Constraint_Error --
865 ----------------------------
867 procedure Raise_Constraint_Error
868 (File
: System
.Address
;
872 Raise_With_Location_And_Msg
873 (Constraint_Error_Def
'Access, File
, Line
);
874 end Raise_Constraint_Error
;
876 --------------------------------
877 -- Raise_Constraint_Error_Msg --
878 --------------------------------
880 procedure Raise_Constraint_Error_Msg
881 (File
: System
.Address
;
883 Msg
: System
.Address
)
886 Raise_With_Location_And_Msg
887 (Constraint_Error_Def
'Access, File
, Line
, Msg
);
888 end Raise_Constraint_Error_Msg
;
890 -------------------------
891 -- Raise_Current_Excep --
892 -------------------------
894 procedure Raise_Current_Excep
(E
: Exception_Id
) is
895 pragma Inspection_Point
(E
);
896 -- This is so the debugger can reliably inspect the parameter
898 Process_Raise_Exception
(E
=> E
, From_Signal_Handler
=> False);
899 end Raise_Current_Excep
;
901 ---------------------
902 -- Raise_Exception --
903 ---------------------
905 procedure Raise_Exception
907 Message
: String := "")
911 Exception_Data
.Set_Exception_Msg
(E
, Message
);
913 Raise_Current_Excep
(E
);
917 ----------------------------
918 -- Raise_Exception_Always --
919 ----------------------------
921 procedure Raise_Exception_Always
923 Message
: String := "")
926 Exception_Data
.Set_Exception_Msg
(E
, Message
);
928 Raise_Current_Excep
(E
);
929 end Raise_Exception_Always
;
931 -------------------------------
932 -- Raise_From_Signal_Handler --
933 -------------------------------
935 procedure Raise_From_Signal_Handler
940 Exception_Data
.Set_Exception_C_Msg
(E
, M
);
942 Process_Raise_Exception
(E
=> E
, From_Signal_Handler
=> True);
943 end Raise_From_Signal_Handler
;
945 -------------------------
946 -- Raise_Program_Error --
947 -------------------------
949 procedure Raise_Program_Error
950 (File
: System
.Address
;
954 Raise_With_Location_And_Msg
955 (Program_Error_Def
'Access, File
, Line
);
956 end Raise_Program_Error
;
958 -----------------------------
959 -- Raise_Program_Error_Msg --
960 -----------------------------
962 procedure Raise_Program_Error_Msg
963 (File
: System
.Address
;
965 Msg
: System
.Address
)
968 Raise_With_Location_And_Msg
969 (Program_Error_Def
'Access, File
, Line
, Msg
);
970 end Raise_Program_Error_Msg
;
972 -------------------------
973 -- Raise_Storage_Error --
974 -------------------------
976 procedure Raise_Storage_Error
977 (File
: System
.Address
;
981 Raise_With_Location_And_Msg
982 (Storage_Error_Def
'Access, File
, Line
);
983 end Raise_Storage_Error
;
985 -----------------------------
986 -- Raise_Storage_Error_Msg --
987 -----------------------------
989 procedure Raise_Storage_Error_Msg
990 (File
: System
.Address
;
992 Msg
: System
.Address
)
995 Raise_With_Location_And_Msg
996 (Storage_Error_Def
'Access, File
, Line
, Msg
);
997 end Raise_Storage_Error_Msg
;
999 ---------------------------------
1000 -- Raise_With_Location_And_Msg --
1001 ---------------------------------
1003 procedure Raise_With_Location_And_Msg
1007 M
: System
.Address
:= System
.Null_Address
)
1010 Exception_Data
.Set_Exception_C_Msg
(E
, F
, L
, M
);
1012 Raise_Current_Excep
(E
);
1013 end Raise_With_Location_And_Msg
;
1015 --------------------
1016 -- Raise_With_Msg --
1017 --------------------
1019 procedure Raise_With_Msg
(E
: Exception_Id
) is
1020 Excep
: constant EOA
:= Get_Current_Excep
.all;
1023 Exception_Propagation
.Setup_Exception
(Excep
, Excep
);
1025 Excep
.Exception_Raised
:= False;
1027 Excep
.Num_Tracebacks
:= 0;
1028 Excep
.Cleanup_Flag
:= False;
1029 Excep
.Pid
:= Local_Partition_ID
;
1031 Raise_Current_Excep
(E
);
1034 --------------------------------------
1035 -- Calls to Run-Time Check Routines --
1036 --------------------------------------
1038 procedure Rcheck_00
(File
: System
.Address
; Line
: Integer) is
1040 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_00
'Address);
1043 procedure Rcheck_01
(File
: System
.Address
; Line
: Integer) is
1045 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_01
'Address);
1048 procedure Rcheck_02
(File
: System
.Address
; Line
: Integer) is
1050 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_02
'Address);
1053 procedure Rcheck_03
(File
: System
.Address
; Line
: Integer) is
1055 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_03
'Address);
1058 procedure Rcheck_04
(File
: System
.Address
; Line
: Integer) is
1060 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_04
'Address);
1063 procedure Rcheck_05
(File
: System
.Address
; Line
: Integer) is
1065 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_05
'Address);
1068 procedure Rcheck_06
(File
: System
.Address
; Line
: Integer) is
1070 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_06
'Address);
1073 procedure Rcheck_07
(File
: System
.Address
; Line
: Integer) is
1075 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_07
'Address);
1078 procedure Rcheck_08
(File
: System
.Address
; Line
: Integer) is
1080 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_08
'Address);
1083 procedure Rcheck_09
(File
: System
.Address
; Line
: Integer) is
1085 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_09
'Address);
1088 procedure Rcheck_10
(File
: System
.Address
; Line
: Integer) is
1090 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_10
'Address);
1093 procedure Rcheck_11
(File
: System
.Address
; Line
: Integer) is
1095 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_11
'Address);
1098 procedure Rcheck_12
(File
: System
.Address
; Line
: Integer) is
1100 Raise_Constraint_Error_Msg
(File
, Line
, Rmsg_12
'Address);
1103 procedure Rcheck_13
(File
: System
.Address
; Line
: Integer) is
1105 Raise_Program_Error_Msg
(File
, Line
, Rmsg_13
'Address);
1108 procedure Rcheck_14
(File
: System
.Address
; Line
: Integer) is
1110 Raise_Program_Error_Msg
(File
, Line
, Rmsg_14
'Address);
1113 procedure Rcheck_15
(File
: System
.Address
; Line
: Integer) is
1115 Raise_Program_Error_Msg
(File
, Line
, Rmsg_15
'Address);
1118 procedure Rcheck_16
(File
: System
.Address
; Line
: Integer) is
1120 Raise_Program_Error_Msg
(File
, Line
, Rmsg_16
'Address);
1123 procedure Rcheck_17
(File
: System
.Address
; Line
: Integer) is
1125 Raise_Program_Error_Msg
(File
, Line
, Rmsg_17
'Address);
1128 procedure Rcheck_18
(File
: System
.Address
; Line
: Integer) is
1130 Raise_Program_Error_Msg
(File
, Line
, Rmsg_18
'Address);
1133 procedure Rcheck_19
(File
: System
.Address
; Line
: Integer) is
1135 Raise_Program_Error_Msg
(File
, Line
, Rmsg_19
'Address);
1138 procedure Rcheck_20
(File
: System
.Address
; Line
: Integer) is
1140 Raise_Program_Error_Msg
(File
, Line
, Rmsg_20
'Address);
1143 procedure Rcheck_21
(File
: System
.Address
; Line
: Integer) is
1145 Raise_Program_Error_Msg
(File
, Line
, Rmsg_21
'Address);
1148 procedure Rcheck_22
(File
: System
.Address
; Line
: Integer) is
1150 Raise_Program_Error_Msg
(File
, Line
, Rmsg_22
'Address);
1153 procedure Rcheck_23
(File
: System
.Address
; Line
: Integer) is
1155 Raise_Program_Error_Msg
(File
, Line
, Rmsg_23
'Address);
1158 procedure Rcheck_24
(File
: System
.Address
; Line
: Integer) is
1160 Raise_Program_Error_Msg
(File
, Line
, Rmsg_24
'Address);
1163 procedure Rcheck_25
(File
: System
.Address
; Line
: Integer) is
1165 Raise_Program_Error_Msg
(File
, Line
, Rmsg_25
'Address);
1168 procedure Rcheck_26
(File
: System
.Address
; Line
: Integer) is
1170 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_26
'Address);
1173 procedure Rcheck_27
(File
: System
.Address
; Line
: Integer) is
1175 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_27
'Address);
1178 procedure Rcheck_28
(File
: System
.Address
; Line
: Integer) is
1180 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_28
'Address);
1183 procedure Rcheck_29
(File
: System
.Address
; Line
: Integer) is
1185 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_29
'Address);
1188 procedure Rcheck_30
(File
: System
.Address
; Line
: Integer) is
1190 Raise_Storage_Error_Msg
(File
, Line
, Rmsg_30
'Address);
1197 procedure Reraise
is
1198 Excep
: constant EOA
:= Get_Current_Excep
.all;
1202 Exception_Propagation
.Setup_Exception
(Excep
, Excep
, Reraised
=> True);
1203 Raise_Current_Excep
(Excep
.Id
);
1206 ------------------------
1207 -- Reraise_Occurrence --
1208 ------------------------
1210 procedure Reraise_Occurrence
(X
: Exception_Occurrence
) is
1212 if X
.Id
/= null then
1214 Exception_Propagation
.Setup_Exception
1215 (X
'Unrestricted_Access, Get_Current_Excep
.all, Reraised
=> True);
1216 Save_Occurrence_No_Private
(Get_Current_Excep
.all.all, X
);
1217 Raise_Current_Excep
(X
.Id
);
1219 end Reraise_Occurrence
;
1221 -------------------------------
1222 -- Reraise_Occurrence_Always --
1223 -------------------------------
1225 procedure Reraise_Occurrence_Always
(X
: Exception_Occurrence
) is
1228 Exception_Propagation
.Setup_Exception
1229 (X
'Unrestricted_Access, Get_Current_Excep
.all, Reraised
=> True);
1230 Save_Occurrence_No_Private
(Get_Current_Excep
.all.all, X
);
1231 Raise_Current_Excep
(X
.Id
);
1232 end Reraise_Occurrence_Always
;
1234 ---------------------------------
1235 -- Reraise_Occurrence_No_Defer --
1236 ---------------------------------
1238 procedure Reraise_Occurrence_No_Defer
(X
: Exception_Occurrence
) is
1240 Exception_Propagation
.Setup_Exception
1241 (X
'Unrestricted_Access, Get_Current_Excep
.all, Reraised
=> True);
1242 Save_Occurrence_No_Private
(Get_Current_Excep
.all.all, X
);
1243 Raise_Current_Excep
(X
.Id
);
1244 end Reraise_Occurrence_No_Defer
;
1246 ---------------------
1247 -- Save_Occurrence --
1248 ---------------------
1250 procedure Save_Occurrence
1251 (Target
: out Exception_Occurrence
;
1252 Source
: Exception_Occurrence
)
1255 Save_Occurrence_No_Private
(Target
, Source
);
1256 end Save_Occurrence
;
1258 function Save_Occurrence
(Source
: Exception_Occurrence
) return EOA
is
1259 Target
: constant EOA
:= new Exception_Occurrence
;
1261 Save_Occurrence
(Target
.all, Source
);
1263 end Save_Occurrence
;
1265 --------------------------------
1266 -- Save_Occurrence_And_Private --
1267 --------------------------------
1269 procedure Save_Occurrence_And_Private
1270 (Target
: out Exception_Occurrence
;
1271 Source
: Exception_Occurrence
)
1274 Save_Occurrence_No_Private
(Target
, Source
);
1275 Target
.Private_Data
:= Source
.Private_Data
;
1276 end Save_Occurrence_And_Private
;
1278 --------------------------------
1279 -- Save_Occurrence_No_Private --
1280 --------------------------------
1282 procedure Save_Occurrence_No_Private
1283 (Target
: out Exception_Occurrence
;
1284 Source
: Exception_Occurrence
)
1287 Target
.Id
:= Source
.Id
;
1288 Target
.Msg_Length
:= Source
.Msg_Length
;
1289 Target
.Num_Tracebacks
:= Source
.Num_Tracebacks
;
1290 Target
.Pid
:= Source
.Pid
;
1291 Target
.Cleanup_Flag
:= Source
.Cleanup_Flag
;
1293 Target
.Msg
(1 .. Target
.Msg_Length
) :=
1294 Source
.Msg
(1 .. Target
.Msg_Length
);
1296 Target
.Tracebacks
(1 .. Target
.Num_Tracebacks
) :=
1297 Source
.Tracebacks
(1 .. Target
.Num_Tracebacks
);
1298 end Save_Occurrence_No_Private
;
1300 -------------------------
1301 -- Transfer_Occurrence --
1302 -------------------------
1304 procedure Transfer_Occurrence
1305 (Target
: Exception_Occurrence_Access
;
1306 Source
: Exception_Occurrence
)
1309 -- Setup Target as an exception to be propagated in the calling task
1310 -- (rendezvous-wise), taking care not to clobber the associated private
1311 -- data. Target is expected to be a pointer to the calling task's
1312 -- fixed TSD occurrence, which is very different from Get_Current_Excep
1313 -- here because this subprogram is called from the called task.
1315 Exception_Propagation
.Setup_Exception
(Target
, Target
);
1316 Save_Occurrence_No_Private
(Target
.all, Source
);
1317 end Transfer_Occurrence
;
1323 function String_To_EId
(S
: String) return Exception_Id
1324 renames Stream_Attributes
.String_To_EId
;
1330 function String_To_EO
(S
: String) return Exception_Occurrence
1331 renames Stream_Attributes
.String_To_EO
;
1333 ------------------------------
1334 -- Raise_Exception_No_Defer --
1335 ------------------------------
1337 procedure Raise_Exception_No_Defer
1339 Message
: String := "")
1342 Exception_Data
.Set_Exception_Msg
(E
, Message
);
1344 -- Do not call Abort_Defer.all, as specified by the spec
1346 Raise_Current_Excep
(E
);
1347 end Raise_Exception_No_Defer
;
1353 procedure To_Stderr
(C
: Character) is
1355 type int
is new Integer;
1357 procedure put_char_stderr
(C
: int
);
1358 pragma Import
(C
, put_char_stderr
, "put_char_stderr");
1361 put_char_stderr
(Character'Pos (C
));
1364 procedure To_Stderr
(S
: String) is
1366 for J
in S
'Range loop
1367 if S
(J
) /= ASCII
.CR
then
1373 --------------------------
1374 -- Code_Address_For_ZZZ --
1375 --------------------------
1377 -- This function gives us the end of the PC range for addresses
1378 -- within the exception unit itself. We hope that gigi/gcc keeps all the
1379 -- procedures in their original order!
1381 function Code_Address_For_ZZZ
return System
.Address
is
1384 return Start_Of_ZZZ
'Address;
1385 end Code_Address_For_ZZZ
;