1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S --
10 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
36 -- We must turn polling off for this unit, because otherwise we get
37 -- elaboration circularities with System.Exception_Tables.
39 with Ada
.Unchecked_Deallocation
;
41 with GNAT
.Heap_Sort_A
; use GNAT
.Heap_Sort_A
;
43 with System
; use System
;
44 with System
.Exception_Table
; use System
.Exception_Table
;
45 with System
.Exceptions
; use System
.Exceptions
;
46 with System
.Standard_Library
; use System
.Standard_Library
;
47 with System
.Storage_Elements
; use System
.Storage_Elements
;
48 with System
.Soft_Links
; use System
.Soft_Links
;
49 with System
.Machine_State_Operations
; use System
.Machine_State_Operations
;
50 with System
.Traceback
;
52 with Unchecked_Conversion
;
54 package body Ada
.Exceptions
is
56 procedure builtin_longjmp
(buffer
: Address
; Flag
: Integer);
57 pragma No_Return
(builtin_longjmp
);
58 pragma Import
(C
, builtin_longjmp
, "_gnat_builtin_longjmp");
60 pragma Suppress
(All_Checks
);
61 -- We definitely do not want exceptions occurring within this unit, or
62 -- we are in big trouble. If an exceptional situation does occur, better
63 -- that it not be raised, since raising it can cause confusing chaos.
65 type Subprogram_Descriptor_List_Ptr
is
66 access all Subprogram_Descriptor_List
;
68 Subprogram_Descriptors
: Subprogram_Descriptor_List_Ptr
;
69 -- This location is initialized by Register_Exceptions to point to a
70 -- list of pointers to procedure descriptors, sorted into ascending
71 -- order of PC addresses.
73 -- Note that SDP_Table_Build is called *before* this unit (or any
74 -- other unit) is elaborated. That's important, because exceptions can
75 -- and do occur during elaboration of units, and must be handled during
76 -- elaboration. This means that we are counting on the fact that the
77 -- initialization of Subprogram_Descriptors to null is done by the
78 -- load process and NOT by an explicit assignment during elaboration.
80 Num_Subprogram_Descriptors
: Natural;
81 -- Number of subprogram descriptors, the useful descriptors are stored
82 -- in Subprogram_Descriptors (1 .. Num_Subprogram_Descriptors). There
83 -- can be unused entries at the end of the array due to elimination of
84 -- duplicated entries (which can arise from use of pragma Import).
86 Exception_Tracebacks
: Integer;
87 pragma Import
(C
, Exception_Tracebacks
, "__gl_exception_tracebacks");
88 -- Boolean indicating whether tracebacks should be stored in exception
91 Zero_Cost_Exceptions
: Integer;
92 pragma Import
(C
, Zero_Cost_Exceptions
, "__gl_zero_cost_exceptions");
93 -- Boolean indicating if we are handling exceptions using a zero cost
96 -- ??? We currently have two alternatives for this scheme : one using
97 -- front-end tables and one using back-end tables. The former is known to
98 -- only work for GNAT3 and the latter is known to only work for GNAT5.
99 -- Both are present in this implementation and it would be good to have
100 -- separate bodies at some point.
102 -- Note that although we currently do not support it, the GCC3 back-end
103 -- tables are also potentially useable for setjmp/longjmp processing.
105 Nline
: constant String := String' (1 => ASCII.LF);
106 -- Convenient shortcut
108 ------------------------------------------------
109 -- Entities to interface with the GCC runtime --
110 ------------------------------------------------
112 -- These come from "C++ ABI for Itanium : Exception handling", which is
113 -- the reference for GCC. They are used only when we are relying on
114 -- back-end tables for exception propagation, which in turn is currenly
115 -- only the case for Zero_Cost_Exceptions in GNAT5.
117 -- Return codes from the GCC runtime functions used to propagate
120 type Unwind_Reason_Code is
122 URC_FOREIGN_EXCEPTION_CAUGHT,
129 URC_CONTINUE_UNWIND);
131 -- ??? pragma Unreferenced is unknown until 3.15, so we need to disable
132 -- warnings around it to fix the bootstrap path.
134 pragma Warnings (Off);
137 URC_FOREIGN_EXCEPTION_CAUGHT,
144 URC_CONTINUE_UNWIND);
145 pragma Warnings (On);
147 pragma Convention (C, Unwind_Reason_Code);
149 -- Mandatory common header for any exception object handled by the
150 -- GCC unwinding runtime.
152 subtype Exception_Class is String (1 .. 8);
154 GNAT_Exception_Class : constant Exception_Class
155 := "GNU" & ASCII.NUL & "Ada" & ASCII.NUL;
157 type Unwind_Exception is record
158 Class : Exception_Class := GNAT_Exception_Class;
159 Cleanup : System.Address := System.Null_Address;
164 pragma Convention (C, Unwind_Exception);
166 for Unwind_Exception'Alignment use Standard'Maximum_Alignment;
168 -- A GNAT exception object to be dealt with by the personality routine
169 -- called by the GCC unwinding runtime. This structure shall match the
170 -- one in raise.c and is currently experimental as it might be merged
171 -- with the GNAT runtime definition some day.
173 type GNAT_GCC_Exception is record
174 Header : Unwind_Exception;
175 -- Exception header first, as required by the ABI.
178 -- Usual Exception identifier
180 Handled_By_Others : Boolean;
181 -- Is this exception handled by "when others" ?
183 Has_Cleanup : Boolean;
184 -- Did we see any at-end handler while walking up the stack
185 -- searching for a handler ? This is used to determine if we
186 -- start the propagation again after having tried once without
187 -- finding a true handler for the exception.
189 Select_Cleanups : Boolean;
190 -- Do we consider at-end handlers as legitimate handlers for the
191 -- exception ? This is used to control the propagation process
192 -- as described in Raise_Current_Excep.
195 pragma Convention (C, GNAT_GCC_Exception);
197 -- GCC runtime functions used
199 function Unwind_RaiseException
200 (E : access GNAT_GCC_Exception)
201 return Unwind_Reason_Code;
202 pragma Import (C, Unwind_RaiseException, "__gnat_Unwind_RaiseException");
204 -----------------------
205 -- Local Subprograms --
206 -----------------------
208 -- Note: the exported subprograms in this package body are called directly
209 -- from C clients using the given external name, even though they are not
210 -- technically visible in the Ada sense.
213 -- Mark start of procedures in this unit
216 -- Mark end of procedures in this package
218 function Address_Image (A : System.Address) return String;
219 -- Returns at string of the form 0xhhhhhhhhh for 32-bit addresses
220 -- or 0xhhhhhhhhhhhhhhhh for 64-bit addresses. Hex characters are
223 procedure Call_Chain (Excep : EOA);
224 -- Store up to Max_Tracebacks in Excep, corresponding to the current
228 is new Ada.Unchecked_Deallocation
229 (Subprogram_Descriptor_List, Subprogram_Descriptor_List_Ptr);
231 procedure Process_Raise_Exception
233 From_Signal_Handler : Boolean);
234 pragma Inline (Process_Raise_Exception);
235 pragma No_Return (Process_Raise_Exception);
236 -- This is the lowest level raise routine. It raises the exception
237 -- referenced by Current_Excep.all in the TSD, without deferring abort
238 -- (the caller must ensure that abort is deferred on entry).
240 -- This is actually the common implementation for Raise_Current_Excep and
241 -- Raise_From_Signal_Handler, with a couple of operations inhibited when
242 -- called from the latter. The origin of the call is indicated by the
243 -- From_Signal_Handler argument.
245 -- The Inline pragma is there for efficiency reasons.
247 procedure Propagate_Exception_With_FE_Support (Mstate : Machine_State);
248 pragma No_Return (Propagate_Exception_With_FE_Support);
249 -- This procedure propagates the exception represented by the occurrence
250 -- referenced by Current_Excep in the TSD for the current task. M is the
251 -- initial machine state, representing the site of the exception raise
254 -- The procedure searches the front end exception tables for an applicable
255 -- handler, calling Pop_Frame as needed. If and when it locates an
256 -- applicable handler, Enter_Handler is called to actually enter this
257 -- handler. If the search is unable to locate an applicable handler,
258 -- execution is terminated by calling Unhandled_Exception_Terminate.
260 procedure Propagate_Exception_With_GCC_Support (Mstate : Machine_State);
261 pragma No_Return (Propagate_Exception_With_GCC_Support);
262 -- This procedure propagates the exception represented by the occurrence
263 -- referenced by Current_Excep in the TSD for the current task. M is the
264 -- initial machine state, representing the site of the exception raise
265 -- operation. It is currently not used and is there for the purpose of
266 -- interface consistency against Propagate_Exception_With_FE_Support.
268 -- The procedure builds an object suitable for the libgcc processing and
269 -- calls Unwind_RaiseException to actually throw, taking care of handling
270 -- the two phase scheme it implements.
272 procedure Raise_Current_Excep (E : Exception_Id);
273 pragma No_Return (Raise_Current_Excep);
274 pragma Export (C, Raise_Current_Excep, "__gnat_raise_nodefer_with_msg");
275 -- This is a simple wrapper to Process_Raise_Exception setting the
276 -- From_Signal_Handler argument to False.
278 -- This external name for Raise_Current_Excep is historical, and probably
279 -- should be changed but for now we keep it, because gdb and gigi know
282 procedure Raise_Exception_No_Defer
283 (E : Exception_Id; Message : String := "");
284 pragma Export (Ada, Raise_Exception_No_Defer,
285 "ada__exceptions__raise_exception_no_defer");
286 pragma No_Return (Raise_Exception_No_Defer);
287 -- Similar to Raise_Exception, but with no abort deferral
289 procedure Raise_With_Msg (E : Exception_Id);
290 pragma No_Return (Raise_With_Msg);
291 pragma Export (C, Raise_With_Msg, "__gnat_raise_with_msg");
292 -- Raises an exception with given exception id value. A message
293 -- is associated with the raise, and has already been stored in the
294 -- exception occurrence referenced by the Current_Excep in the TSD.
295 -- Abort is deferred before the raise call.
297 procedure Raise_With_Location
301 pragma No_Return (Raise_With_Location);
302 -- Raise an exception with given exception id value. A filename and line
303 -- number is associated with the raise and is stored in the exception
306 procedure Raise_With_Location_And_Msg
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 this.
316 procedure Raise_Constraint_Error
317 (File : Big_String_Ptr;
319 pragma No_Return (Raise_Constraint_Error);
321 (C, Raise_Constraint_Error, "__gnat_raise_constraint_error");
322 -- Raise constraint error with file:line information
324 procedure Raise_Constraint_Error_Msg
325 (File : Big_String_Ptr;
327 Msg : Big_String_Ptr);
328 pragma No_Return (Raise_Constraint_Error_Msg);
330 (C, Raise_Constraint_Error_Msg, "__gnat_raise_constraint_error_msg");
331 -- Raise constraint error with file:line + msg information
333 procedure Raise_Program_Error
334 (File : Big_String_Ptr;
336 pragma No_Return (Raise_Program_Error);
338 (C, Raise_Program_Error, "__gnat_raise_program_error");
339 -- Raise program error with file:line information
341 procedure Raise_Program_Error_Msg
342 (File : Big_String_Ptr;
344 Msg : Big_String_Ptr);
345 pragma No_Return (Raise_Program_Error_Msg);
347 (C, Raise_Program_Error_Msg, "__gnat_raise_program_error_msg");
348 -- Raise program error with file:line + msg information
350 procedure Raise_Storage_Error
351 (File : Big_String_Ptr;
353 pragma No_Return (Raise_Storage_Error);
355 (C, Raise_Storage_Error, "__gnat_raise_storage_error");
356 -- Raise storage error with file:line information
358 procedure Raise_Storage_Error_Msg
359 (File : Big_String_Ptr;
361 Msg : Big_String_Ptr);
362 pragma No_Return (Raise_Storage_Error_Msg);
364 (C, Raise_Storage_Error_Msg, "__gnat_raise_storage_error_msg");
365 -- Raise storage error with file:line + reason msg information
367 -- The exception raising process and the automatic tracing mechanism rely
368 -- on some careful use of flags attached to the exception occurrence. The
369 -- graph below illustrates the relations between the Raise_ subprograms
370 -- and identifies the points where basic flags such as Exception_Raised
373 -- (i) signs indicate the flags initialization points. R stands for Raise,
374 -- W for With, and E for Exception.
376 -- R_No_Msg R_E R_Pe R_Ce R_Se
378 -- +--+ +--+ +---+ | +---+
380 -- R_E_No_Defer(i) R_W_Msg(i) R_W_Loc R_W_C_Msg
382 -- +------------+ | +-----------+ +--+ +--+ |
384 -- | | | Set_E_C_Msg(i) |
386 -- | | | +--------------------------+
388 -- Raise_Current_Excep
391 pragma No_Return (Reraise);
392 pragma Export (C, Reraise, "__gnat_reraise");
393 -- Reraises the exception referenced by the Current_Excep field of
394 -- the TSD (all fields of this exception occurrence are set). Abort
395 -- is deferred before the reraise operation.
397 function SDP_Table_Sort_Lt (Op1, Op2 : Natural) return Boolean;
398 -- Used in call to sort SDP table (SDP_Table_Build), compares two elements
400 procedure SDP_Table_Sort_Move (From : Natural; To : Natural);
401 -- Used in call to sort SDP table (SDP_Table_Build), moves one element
403 procedure Set_Exception_C_Msg
405 Msg1 : Big_String_Ptr;
407 Msg2 : Big_String_Ptr := null);
408 -- This routine is called to setup the exception referenced by the
409 -- Current_Excep field in the TSD to contain the indicated Id value
410 -- and message. Msg1 is a null terminated string which is generated
411 -- as the exception message. If line is non-zero, then a colon and
412 -- the decimal representation of this integer is appended to the
413 -- message. When Msg2 is non-null, a space and this additional null
414 -- terminated string is added to the message.
416 procedure To_Stderr (S : String);
417 pragma Export (Ada, To_Stderr, "__gnat_to_stderr");
418 -- Little routine to output string to stderr that is also used
419 -- in the tasking run time.
421 procedure Unhandled_Exception_Terminate;
422 pragma No_Return (Unhandled_Exception_Terminate);
423 -- This procedure is called to terminate execution following an unhandled
424 -- exception. The exception information, including traceback if available
425 -- is output, and execution is then terminated. Note that at the point
426 -- where this routine is called, the stack has typically been destroyed
428 ---------------------------------
429 -- Debugger Interface Routines --
430 ---------------------------------
432 -- The routines here are null routines that normally have no effect.
433 -- they are provided for the debugger to place breakpoints on their
434 -- entry points to get control on an exception.
436 procedure Notify_Exception
439 Is_Others : Boolean);
440 pragma Export (C, Notify_Exception, "__gnat_notify_exception");
441 -- This routine is called whenever an exception is signalled. The Id
442 -- parameter is the Exception_Id of the exception being raised. The
443 -- second parameter Handler is Null_Loc if the exception is unhandled,
444 -- and is otherwise the entry point of the handler that will handle
445 -- the exception. Is_Others is True if the handler is an others handler
446 -- and False otherwise. In the unhandled exception case, if possible
447 -- (and certainly if zero cost exception handling is active), the
448 -- stack is still intact when this procedure is called. Note that this
449 -- routine is entered before any finalization handlers are entered if
450 -- the exception is unhandled by a "real" exception handler.
452 procedure Unhandled_Exception;
453 pragma Export (C, Unhandled_Exception, "__gnat_unhandled_exception");
454 -- This routine is called in addition to Notify_Exception in the
455 -- unhandled exception case. The fact that there are two routines
456 -- which are somewhat redundant is historical. Notify_Exception
457 -- certainly is complete enough, but GDB still uses this routine.
459 -----------------------------
460 -- Run-Time Check Routines --
461 -----------------------------
463 -- These routines are called from the runtime to raise a specific
464 -- exception with a reason message attached. The parameters are
465 -- the file name and line number in each case. The names are keyed
466 -- to the codes defined in Types.ads and a-types.h (for example,
467 -- the name Rcheck_05 refers to the Reason whose Pos code is 5).
469 procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer);
470 procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer);
471 procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer);
472 procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer);
473 procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer);
474 procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer);
475 procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer);
476 procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer);
477 procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer);
478 procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer);
479 procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer);
480 procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer);
481 procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer);
482 procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer);
483 procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer);
484 procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer);
485 procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer);
486 procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer);
487 procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer);
488 procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer);
489 procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer);
490 procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer);
491 procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer);
492 procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer);
493 procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer);
494 procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer);
495 procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer);
496 procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer);
497 procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer);
499 pragma Export (C, Rcheck_00, "__gnat_rcheck_00");
500 pragma Export (C, Rcheck_01, "__gnat_rcheck_01");
501 pragma Export (C, Rcheck_02, "__gnat_rcheck_02");
502 pragma Export (C, Rcheck_03, "__gnat_rcheck_03");
503 pragma Export (C, Rcheck_04, "__gnat_rcheck_04");
504 pragma Export (C, Rcheck_05, "__gnat_rcheck_05");
505 pragma Export (C, Rcheck_06, "__gnat_rcheck_06");
506 pragma Export (C, Rcheck_07, "__gnat_rcheck_07");
507 pragma Export (C, Rcheck_08, "__gnat_rcheck_08");
508 pragma Export (C, Rcheck_09, "__gnat_rcheck_09");
509 pragma Export (C, Rcheck_10, "__gnat_rcheck_10");
510 pragma Export (C, Rcheck_11, "__gnat_rcheck_11");
511 pragma Export (C, Rcheck_12, "__gnat_rcheck_12");
512 pragma Export (C, Rcheck_13, "__gnat_rcheck_13");
513 pragma Export (C, Rcheck_14, "__gnat_rcheck_14");
514 pragma Export (C, Rcheck_15, "__gnat_rcheck_15");
515 pragma Export (C, Rcheck_16, "__gnat_rcheck_16");
516 pragma Export (C, Rcheck_17, "__gnat_rcheck_17");
517 pragma Export (C, Rcheck_18, "__gnat_rcheck_18");
518 pragma Export (C, Rcheck_19, "__gnat_rcheck_19");
519 pragma Export (C, Rcheck_20, "__gnat_rcheck_20");
520 pragma Export (C, Rcheck_21, "__gnat_rcheck_21");
521 pragma Export (C, Rcheck_22, "__gnat_rcheck_22");
522 pragma Export (C, Rcheck_23, "__gnat_rcheck_23");
523 pragma Export (C, Rcheck_24, "__gnat_rcheck_24");
524 pragma Export (C, Rcheck_25, "__gnat_rcheck_25");
525 pragma Export (C, Rcheck_26, "__gnat_rcheck_26");
526 pragma Export (C, Rcheck_27, "__gnat_rcheck_27");
527 pragma Export (C, Rcheck_28, "__gnat_rcheck_28");
529 ---------------------------------------------
530 -- Reason Strings for Run-Time Check Calls --
531 ---------------------------------------------
533 -- These strings are null-terminated and are used by Rcheck_nn. The
534 -- strings correspond to the definitions for Types.RT_Exception_Code.
538 Rmsg_00 : constant String := "access check failed" & NUL;
539 Rmsg_01 : constant String := "access parameter is null" & NUL;
540 Rmsg_02 : constant String := "discriminant check failed" & NUL;
541 Rmsg_03 : constant String := "divide by zero" & NUL;
542 Rmsg_04 : constant String := "explicit raise" & NUL;
543 Rmsg_05 : constant String := "index check failed" & NUL;
544 Rmsg_06 : constant String := "invalid data" & NUL;
545 Rmsg_07 : constant String := "length check failed" & NUL;
546 Rmsg_08 : constant String := "overflow check failed" & NUL;
547 Rmsg_09 : constant String := "partition check failed" & NUL;
548 Rmsg_10 : constant String := "range check failed" & NUL;
549 Rmsg_11 : constant String := "tag check failed" & NUL;
550 Rmsg_12 : constant String := "access before elaboration" & NUL;
551 Rmsg_13 : constant String := "accessibility check failed" & NUL;
552 Rmsg_14 : constant String := "all guards closed" & NUL;
553 Rmsg_15 : constant String := "duplicated entry address" & NUL;
554 Rmsg_16 : constant String := "explicit raise" & NUL;
555 Rmsg_17 : constant String := "finalize raised exception" & NUL;
556 Rmsg_18 : constant String := "invalid data" & NUL;
557 Rmsg_19 : constant String := "misaligned address value" & NUL;
558 Rmsg_20 : constant String := "missing return" & NUL;
559 Rmsg_21 : constant String := "potentially blocking operation" & NUL;
560 Rmsg_22 : constant String := "stubbed subprogram called" & NUL;
561 Rmsg_23 : constant String := "unchecked union restriction" & NUL;
562 Rmsg_24 : constant String := "empty storage pool" & NUL;
563 Rmsg_25 : constant String := "explicit raise" & NUL;
564 Rmsg_26 : constant String := "infinite recursion" & NUL;
565 Rmsg_27 : constant String := "object too large" & NUL;
566 Rmsg_28 : constant String := "restriction violation" & NUL;
568 --------------------------------------
569 -- Calls to Run-Time Check Routines --
570 --------------------------------------
572 procedure Rcheck_00 (File : Big_String_Ptr; Line : Integer) is
574 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_00'Address));
577 procedure Rcheck_01 (File : Big_String_Ptr; Line : Integer) is
579 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_01'Address));
582 procedure Rcheck_02 (File : Big_String_Ptr; Line : Integer) is
584 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_02'Address));
587 procedure Rcheck_03 (File : Big_String_Ptr; Line : Integer) is
589 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_03'Address));
592 procedure Rcheck_04 (File : Big_String_Ptr; Line : Integer) is
594 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_04'Address));
597 procedure Rcheck_05 (File : Big_String_Ptr; Line : Integer) is
599 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_05'Address));
602 procedure Rcheck_06 (File : Big_String_Ptr; Line : Integer) is
604 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_06'Address));
607 procedure Rcheck_07 (File : Big_String_Ptr; Line : Integer) is
609 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_07'Address));
612 procedure Rcheck_08 (File : Big_String_Ptr; Line : Integer) is
614 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_08'Address));
617 procedure Rcheck_09 (File : Big_String_Ptr; Line : Integer) is
619 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_09'Address));
622 procedure Rcheck_10 (File : Big_String_Ptr; Line : Integer) is
624 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_10'Address));
627 procedure Rcheck_11 (File : Big_String_Ptr; Line : Integer) is
629 Raise_Constraint_Error_Msg (File, Line, To_Ptr (Rmsg_11'Address));
632 procedure Rcheck_12 (File : Big_String_Ptr; Line : Integer) is
634 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_12'Address));
637 procedure Rcheck_13 (File : Big_String_Ptr; Line : Integer) is
639 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_13'Address));
642 procedure Rcheck_14 (File : Big_String_Ptr; Line : Integer) is
644 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_14'Address));
647 procedure Rcheck_15 (File : Big_String_Ptr; Line : Integer) is
649 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_15'Address));
652 procedure Rcheck_16 (File : Big_String_Ptr; Line : Integer) is
654 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_16'Address));
657 procedure Rcheck_17 (File : Big_String_Ptr; Line : Integer) is
659 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_17'Address));
662 procedure Rcheck_18 (File : Big_String_Ptr; Line : Integer) is
664 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_18'Address));
667 procedure Rcheck_19 (File : Big_String_Ptr; Line : Integer) is
669 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_19'Address));
672 procedure Rcheck_20 (File : Big_String_Ptr; Line : Integer) is
674 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_20'Address));
677 procedure Rcheck_21 (File : Big_String_Ptr; Line : Integer) is
679 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_21'Address));
682 procedure Rcheck_22 (File : Big_String_Ptr; Line : Integer) is
684 Raise_Program_Error_Msg (File, Line, To_Ptr (Rmsg_22'Address));
687 procedure Rcheck_23 (File : Big_String_Ptr; Line : Integer) is
689 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_23'Address));
692 procedure Rcheck_24 (File : Big_String_Ptr; Line : Integer) is
694 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_24'Address));
697 procedure Rcheck_25 (File : Big_String_Ptr; Line : Integer) is
699 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_25'Address));
702 procedure Rcheck_26 (File : Big_String_Ptr; Line : Integer) is
704 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_26'Address));
707 procedure Rcheck_27 (File : Big_String_Ptr; Line : Integer) is
709 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_27'Address));
712 procedure Rcheck_28 (File : Big_String_Ptr; Line : Integer) is
714 Raise_Storage_Error_Msg (File, Line, To_Ptr (Rmsg_28'Address));
717 ---------------------------------------
718 -- Exception backtracing subprograms --
719 ---------------------------------------
721 -- What is automatically output when exception tracing is on basically
722 -- corresponds to the usual exception information, but with the call
723 -- chain backtrace possibly tailored by a backtrace decorator. Modifying
724 -- Exception_Information itself is not a good idea because the decorated
725 -- output is completely out of control and would break all our code
726 -- related to the streaming of exceptions.
728 -- We then provide an alternative function to Exception_Information to
729 -- compute the possibly tailored output, which is equivalent if no
730 -- decorator is currently set :
732 function Tailored_Exception_Information
733 (X : Exception_Occurrence)
735 -- Exception information to be output in the case of automatic tracing
736 -- requested through GNAT.Exception_Traces.
738 -- This is the same as Exception_Information if no backtrace decorator
739 -- is currently in place. Otherwise, this is Exception_Information with
740 -- the call chain raw addresses replaced by the result of a call to the
741 -- current decorator provided with the call chain addresses.
744 (Ada, Tailored_Exception_Information,
745 "__gnat_tailored_exception_information");
746 -- This function is used within this package but also from within
747 -- System.Tasking.Stages.
749 -- The output of Exception_Information and Tailored_Exception_Information
750 -- share a common part which was formerly built using local procedures
751 -- within Exception_Information. These procedures have been extracted from
752 -- their original place to be available to Tailored_Exception_Information
755 -- Each of these procedures appends some input to an information string
756 -- currently being built. The Ptr argument represents the last position
757 -- in this string at which a character has been written.
759 procedure Append_Info_Nat
761 Info : in out String;
762 Ptr : in out Natural);
763 -- Append the image of N at the end of the provided information string
765 procedure Append_Info_NL
766 (Info : in out String;
767 Ptr : in out Natural);
768 -- Append a LF at the end of the provided information string
770 procedure Append_Info_String
772 Info : in out String;
773 Ptr : in out Natural);
774 -- Append a string at the end of the provided information string
776 -- To build Exception_Information and Tailored_Exception_Information,
777 -- we then use three intermediate functions :
779 function Basic_Exception_Information
780 (X : Exception_Occurrence)
782 -- Returns the basic exception information string associated with a
783 -- given exception occurrence. This is the common part shared by both
784 -- Exception_Information and Tailored_Exception_Infomation.
786 function Basic_Exception_Traceback
787 (X : Exception_Occurrence)
789 -- Returns an image of the complete call chain associated with an
790 -- exception occurrence in its most basic form, that is as a raw sequence
791 -- of hexadecimal binary addresses.
793 function Tailored_Exception_Traceback
794 (X : Exception_Occurrence)
796 -- Returns an image of the complete call chain associated with an
797 -- exception occurrence, either in its basic form if no decorator is
798 -- in place, or as formatted by the decorator otherwise.
800 -- The overall organization of the exception information related code
801 -- is summarized below :
803 -- Exception_Information
805 -- +-------+--------+
807 -- Basic_Exc_Info & Basic_Exc_Tback
810 -- Tailored_Exception_Information
812 -- +----------+----------+
814 -- Basic_Exc_Info & Tailored_Exc_Tback
816 -- +-----------+------------+
818 -- Basic_Exc_Tback Or Tback_Decorator
819 -- if no decorator set otherwise
821 ----------------------------------------------
822 -- Run-Time Exception Notification Routines --
823 ----------------------------------------------
825 -- The notification routines described above are low level "handles" for
826 -- the debugger but what needs to be done at the notification points
827 -- always involves more than just calling one of these routines. The
828 -- routines below provide a common run-time interface for this purpose,
829 -- with variations depending on the handled/not handled status of the
830 -- occurrence. They are exported to be usable by the Ada exception
831 -- handling personality routine when the GCC 3 mechanism is used.
833 procedure Notify_Handled_Exception
836 Low_Notify : Boolean);
837 pragma Export (C, Notify_Handled_Exception,
838 "__gnat_notify_handled_exception");
839 -- Routine to call when a handled occurrence is about to be propagated.
840 -- Low_Notify might be set to false to skip the low level debugger
841 -- notification, which is useful when the information it requires is
842 -- not available, like in the SJLJ case.
844 procedure Notify_Unhandled_Exception (Id : Exception_Id);
845 pragma Export (C, Notify_Unhandled_Exception,
846 "__gnat_notify_unhandled_exception");
847 -- Routine to call when an unhandled occurrence is about to be propagated.
849 --------------------------------
850 -- Import Run-Time C Routines --
851 --------------------------------
853 -- The purpose of the following pragma Imports is to ensure that we
854 -- generate appropriate subprogram descriptors for all C routines in
855 -- the standard GNAT library that can raise exceptions. This ensures
856 -- that the exception propagation can properly find these routines
858 pragma Warnings (Off); -- so old compiler does not complain
859 pragma Propagate_Exceptions;
861 procedure Unhandled_Terminate;
862 pragma Import (C, Unhandled_Terminate, "__gnat_unhandled_terminate");
864 -----------------------
865 -- Polling Interface --
866 -----------------------
868 type Unsigned is mod 2 ** 32;
870 Counter : Unsigned := 0;
871 -- This counter is provided for convenience. It can be used in Poll to
872 -- perform periodic but not systematic operations.
874 procedure Poll is separate;
875 -- The actual polling routine is separate, so that it can easily
876 -- be replaced with a target dependent version.
882 -- This dummy procedure gives us the start of the PC range for addresses
883 -- within the exception unit itself. We hope that gigi/gcc keep all the
884 -- procedures in their original order!
895 function Address_Image (A : Address) return String is
896 S : String (1 .. 18);
900 H : constant array (Integer range 0 .. 15) of Character :=
906 S (P) := H (Integer (N mod 16));
913 return S (P - 1 .. S'Last);
916 ---------------------
917 -- Append_Info_Nat --
918 ---------------------
920 procedure Append_Info_Nat
922 Info : in out String;
923 Ptr : in out Natural)
927 Append_Info_Nat (N / 10, Info, Ptr);
931 Info (Ptr) := Character'Val (Character'Pos ('0') + N mod 10);
938 procedure Append_Info_NL
939 (Info : in out String;
940 Ptr : in out Natural)
944 Info (Ptr) := ASCII.LF;
947 ------------------------
948 -- Append_Info_String --
949 ------------------------
951 procedure Append_Info_String
953 Info : in out String;
954 Ptr : in out Natural)
957 Info (Ptr + 1 .. Ptr + S'Length) := S;
958 Ptr := Ptr + S'Length;
959 end Append_Info_String;
961 ---------------------------------
962 -- Basic_Exception_Information --
963 ---------------------------------
965 function Basic_Exception_Information
966 (X : Exception_Occurrence)
969 Name : constant String := Exception_Name (X);
970 Msg : constant String := Exception_Message (X);
971 -- Exception name and message that are going to be included in the
972 -- information to return, if not empty.
974 Name_Len : constant Natural := Name'Length;
975 Msg_Len : constant Natural := Msg'Length;
976 -- Length of these strings, useful to compute the size of the string
977 -- we have to allocate for the complete result as well as in the body
978 -- of this procedure.
980 Info_Maxlen : constant Natural := 50 + Name_Len + Msg_Len;
981 -- Maximum length of the information string we will build, with :
983 -- 50 = 16 + 2 for the text associated with the name
984 -- + 9 + 2 for the text associated with the message
985 -- + 5 + 2 for the text associated with the pid
986 -- + 14 for the text image of the pid itself and a margin.
988 -- This is indeed a maximum since some data may not appear at all if
989 -- not relevant. For example, nothing related to the exception message
990 -- will be there if this message is empty.
992 -- WARNING : Do not forget to update these numbers if anything
993 -- involved in the computation changes.
995 Info : String (1 .. Info_Maxlen);
996 -- Information string we are going to build, containing the common
997 -- part shared by Exc_Info and Tailored_Exc_Info.
1002 -- Output exception name and message except for _ABORT_SIGNAL, where
1003 -- these two lines are omitted (see discussion above).
1005 if Name (1) /= '_
' then
1006 Append_Info_String ("Exception name: ", Info, Ptr);
1007 Append_Info_String (Name, Info, Ptr);
1008 Append_Info_NL (Info, Ptr);
1010 if Msg_Len /= 0 then
1011 Append_Info_String ("Message: ", Info, Ptr);
1012 Append_Info_String (Msg, Info, Ptr);
1013 Append_Info_NL (Info, Ptr);
1017 -- Output PID line if non-zero
1020 Append_Info_String ("PID: ", Info, Ptr);
1021 Append_Info_Nat (X.Pid, Info, Ptr);
1022 Append_Info_NL (Info, Ptr);
1025 return Info (1 .. Ptr);
1026 end Basic_Exception_Information;
1028 -------------------------------
1029 -- Basic_Exception_Traceback --
1030 -------------------------------
1032 function Basic_Exception_Traceback
1033 (X : Exception_Occurrence)
1036 Info_Maxlen : constant Natural := 35 + X.Num_Tracebacks * 19;
1037 -- Maximum length of the information string we are building, with :
1038 -- 33 = 31 + 4 for the text before and after the traceback, and
1039 -- 19 = 2 + 16 + 1 for each address ("0x" + HHHH + " ")
1041 -- WARNING : Do not forget to update these numbers if anything
1042 -- involved in the computation changes.
1044 Info : String (1 .. Info_Maxlen);
1045 -- Information string we are going to build, containing an image
1046 -- of the call chain associated with the exception occurrence in its
1047 -- most basic form, that is as a sequence of binary addresses.
1052 if X.Num_Tracebacks > 0 then
1053 Append_Info_String ("Call stack traceback locations:", Info, Ptr);
1054 Append_Info_NL (Info, Ptr);
1056 for J in 1 .. X.Num_Tracebacks loop
1057 Append_Info_String (Address_Image (X.Tracebacks (J)), Info, Ptr);
1058 exit when J = X.Num_Tracebacks;
1059 Append_Info_String (" ", Info, Ptr);
1062 Append_Info_NL (Info, Ptr);
1065 return Info (1 .. Ptr);
1066 end Basic_Exception_Traceback;
1072 procedure Break_Start is
1081 procedure Call_Chain (Excep : EOA) is
1083 if Excep.Num_Tracebacks /= 0 then
1084 -- This is a reraise, no need to store a new (wrong) chain.
1088 System.Traceback.Call_Chain
1089 (Excep.Tracebacks'Address,
1091 Excep.Num_Tracebacks,
1096 ------------------------------
1097 -- Current_Target_Exception --
1098 ------------------------------
1100 function Current_Target_Exception return Exception_Occurrence is
1102 return Null_Occurrence;
1103 end Current_Target_Exception;
1109 function EId_To_String (X : Exception_Id) return String is
1114 return Exception_Name (X);
1122 -- We use the null string to represent the null occurrence, otherwise
1123 -- we output the Exception_Information string for the occurrence.
1125 function EO_To_String (X : Exception_Occurrence) return String is
1127 if X.Id = Null_Id then
1130 return Exception_Information (X);
1134 ------------------------
1135 -- Exception_Identity --
1136 ------------------------
1138 function Exception_Identity
1139 (X : Exception_Occurrence)
1143 if X.Id = Null_Id then
1144 raise Constraint_Error;
1148 end Exception_Identity;
1150 ---------------------------
1151 -- Exception_Information --
1152 ---------------------------
1154 -- The format of the string is:
1156 -- Exception_Name: nnnnn
1159 -- Call stack traceback locations:
1160 -- 0xhhhh 0xhhhh 0xhhhh ... 0xhhh
1164 -- nnnn is the fully qualified name of the exception in all upper
1165 -- case letters. This line is always present.
1167 -- mmmm is the message (this line present only if message is non-null)
1169 -- ppp is the Process Id value as a decimal integer (this line is
1170 -- present only if the Process Id is non-zero). Currently we are
1171 -- not making use of this field.
1173 -- The Call stack traceback locations line and the following values
1174 -- are present only if at least one traceback location was recorded.
1175 -- the values are given in C style format, with lower case letters
1176 -- for a-f, and only as many digits present as are necessary.
1178 -- The line terminator sequence at the end of each line, including the
1179 -- last line is a CR-LF sequence (16#0D# followed by 16#0A#).
1181 -- The Exception_Name and Message lines are omitted in the abort
1182 -- signal case, since this is not really an exception, and the only
1183 -- use of this routine is internal for printing termination output.
1185 -- WARNING: if the format of the generated string is changed, please note
1186 -- that an equivalent modification to the routine String_To_EO must be
1187 -- made to preserve proper functioning of the stream attributes.
1189 function Exception_Information (X : Exception_Occurrence) return String is
1191 -- This information is now built using the circuitry introduced in
1192 -- association with the support of traceback decorators, as the
1193 -- catenation of the exception basic information and the call chain
1194 -- backtrace in its basic form.
1196 Basic_Info : constant String := Basic_Exception_Information (X);
1197 Tback_Info : constant String := Basic_Exception_Traceback (X);
1199 Basic_Len : constant Natural := Basic_Info'Length;
1200 Tback_Len : constant Natural := Tback_Info'Length;
1202 Info : String (1 .. Basic_Len + Tback_Len);
1206 Append_Info_String (Basic_Info, Info, Ptr);
1207 Append_Info_String (Tback_Info, Info, Ptr);
1210 end Exception_Information;
1212 -----------------------
1213 -- Exception_Message --
1214 -----------------------
1216 function Exception_Message (X : Exception_Occurrence) return String is
1218 if X.Id = Null_Id then
1219 raise Constraint_Error;
1222 return X.Msg (1 .. X.Msg_Length);
1223 end Exception_Message;
1225 --------------------
1226 -- Exception_Name --
1227 --------------------
1229 function Exception_Name (Id : Exception_Id) return String is
1232 raise Constraint_Error;
1235 return Id.Full_Name.all (1 .. Id.Name_Length - 1);
1238 function Exception_Name (X : Exception_Occurrence) return String is
1240 return Exception_Name (X.Id);
1243 ---------------------------
1244 -- Exception_Name_Simple --
1245 ---------------------------
1247 function Exception_Name_Simple (X : Exception_Occurrence) return String is
1248 Name : constant String := Exception_Name (X);
1254 exit when Name (P - 1) = '.';
1258 return Name (P .. Name'Length);
1259 end Exception_Name_Simple;
1261 -----------------------------
1262 -- Process_Raise_Exception --
1263 -----------------------------
1265 procedure Process_Raise_Exception
1267 From_Signal_Handler : Boolean)
1269 pragma Inspection_Point (E);
1270 -- This is so the debugger can reliably inspect the parameter
1272 Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
1273 Mstate_Ptr : constant Machine_State :=
1274 Machine_State (Get_Machine_State_Addr.all);
1275 Excep : EOA := Get_Current_Excep.all;
1278 -- WARNING : There should be no exception handler for this body
1279 -- because this would cause gigi to prepend a setup for a new
1280 -- jmpbuf to the sequence of statements. We would then always get
1281 -- this new buf in Jumpbuf_Ptr instead of the one for the exception
1282 -- we are handling, which would completely break the whole design
1283 -- of this procedure.
1285 -- Processing varies between zero cost and setjmp/lonjmp processing.
1287 if Zero_Cost_Exceptions /= 0 then
1289 -- Use the front-end tables to propagate if we have them, otherwise
1290 -- resort to the GCC back-end alternative. The backtrace for the
1291 -- occurrence is stored while walking up the stack, and thus stops
1292 -- in the handler's frame if there is one. Notifications are also
1293 -- not performed here since it is not yet known if the exception is
1296 -- Set the machine state unless we are raising from a signal handler
1297 -- since it has already been set properly in that case.
1299 if not From_Signal_Handler then
1300 Set_Machine_State (Mstate_Ptr);
1303 if Subprogram_Descriptors /= null then
1304 Propagate_Exception_With_FE_Support (Mstate_Ptr);
1306 Propagate_Exception_With_GCC_Support (Mstate_Ptr);
1311 -- Compute the backtrace for this occurrence if the corresponding
1312 -- binder option has been set and we are not raising from a signal
1313 -- handler. Call_Chain takes care of the reraise case.
1315 if not From_Signal_Handler
1316 and then Exception_Tracebacks /= 0
1321 -- If the jump buffer pointer is non-null, transfer control using
1322 -- it. Otherwise announce an unhandled exception (note that this
1323 -- means that we have no finalizations to do other than at the outer
1324 -- level). Perform the necessary notification tasks in both cases.
1326 if Jumpbuf_Ptr /= Null_Address then
1328 if not Excep.Exception_Raised then
1329 Excep.Exception_Raised := True;
1330 Notify_Handled_Exception (Null_Loc, False, False);
1332 -- The low level debugger notification is skipped from the
1333 -- call above because we do not have the necessary information
1334 -- to "feed" it properly.
1338 builtin_longjmp (Jumpbuf_Ptr, 1);
1341 Notify_Unhandled_Exception (E);
1342 Unhandled_Exception_Terminate;
1346 end Process_Raise_Exception;
1348 -----------------------------------------
1349 -- Propagate_Exception_With_FE_Support --
1350 -----------------------------------------
1352 procedure Propagate_Exception_With_FE_Support (Mstate : Machine_State) is
1353 Excep : constant EOA := Get_Current_Excep.all;
1357 Hrec : Handler_Record_Ptr;
1358 Info : Subprogram_Info_Type;
1360 type Machine_State_Record is
1361 new Storage_Array (1 .. Machine_State_Length);
1362 for Machine_State_Record'Alignment use Standard'Maximum_Alignment;
1364 procedure Duplicate_Machine_State (Dest, Src : Machine_State);
1365 -- Copy Src into Dest, assuming that a Machine_State is pointing to
1366 -- an area of Machine_State_Length bytes.
1368 procedure Duplicate_Machine_State (Dest, Src : Machine_State) is
1369 type Machine_State_Record_Access is access Machine_State_Record;
1370 function To_MSR is new Unchecked_Conversion
1371 (Machine_State, Machine_State_Record_Access);
1374 To_MSR (Dest).all := To_MSR (Src).all;
1375 end Duplicate_Machine_State;
1377 -- Data for handling the finalization handler case. A simple approach
1378 -- in this routine would simply to unwind stack frames till we find a
1379 -- handler and then enter it. But this is undesirable in the case where
1380 -- we have only finalization handlers, and no "real" handler, i.e. a
1381 -- case where we have an unhandled exception.
1383 -- In this case we prefer to signal unhandled exception with the stack
1384 -- intact, and entering finalization handlers would destroy the stack
1385 -- state. To deal with this, as we unwind the stack, we note the first
1386 -- finalization handler, and remember it in the following variables.
1387 -- We then continue to unwind. If and when we find a "real", i.e. non-
1388 -- finalization handler, then we use these variables to pass control to
1389 -- the finalization handler.
1391 FH_Found : Boolean := False;
1392 -- Set when a finalization handler is found
1394 FH_Mstate : aliased Machine_State_Record;
1395 -- Records the machine state for the finalization handler
1397 FH_Handler : Code_Loc := Null_Address;
1398 -- Record handler address for finalization handler
1400 FH_Num_Trb : Natural := 0;
1401 -- Save number of tracebacks for finalization handler
1404 -- Loop through stack frames as exception propagates
1407 Loc := Get_Code_Loc (Mstate);
1408 exit Main_Loop when Loc = Null_Loc;
1410 -- Record location unless it is inside this unit. Note: this
1411 -- test should really say Code_Address, but Address is the same
1412 -- as Code_Address for unnested subprograms, and Code_Address
1413 -- would cause a bootstrap problem
1415 if Loc < AAA'Address or else Loc > ZZZ'Address then
1417 -- Record location unless we already recorded max tracebacks
1419 if Excep.Num_Tracebacks /= Max_Tracebacks then
1421 -- Do not record location if it is the return point from
1422 -- a reraise call from within a cleanup handler
1424 if not Excep.Cleanup_Flag then
1425 Excep.Num_Tracebacks := Excep.Num_Tracebacks + 1;
1426 Excep.Tracebacks (Excep.Num_Tracebacks) := Loc;
1428 -- For reraise call from cleanup handler, skip entry and
1429 -- clear the flag so that we will start to record again
1432 Excep.Cleanup_Flag := False;
1437 -- Do binary search on procedure table
1440 Hi := Num_Subprogram_Descriptors;
1442 -- Binary search loop
1445 Pdesc := (Lo + Hi) / 2;
1447 -- Note that Loc is expected to be the procedure's call point
1448 -- and not the return point.
1450 if Loc < Subprogram_Descriptors (Pdesc).Code then
1453 elsif Pdesc < Num_Subprogram_Descriptors
1454 and then Loc > Subprogram_Descriptors (Pdesc + 1).Code
1462 -- This happens when the current Loc is completely outside of
1463 -- the range of the program, which usually means that we reached
1464 -- the top level frame (e.g __start). In this case we have an
1465 -- unhandled exception.
1467 exit Main_Loop when Hi < Lo;
1470 -- Come here with Subprogram_Descriptors (Pdesc) referencing the
1471 -- procedure descriptor that applies to this PC value. Now do a
1472 -- serial search to see if any handler is applicable to this PC
1473 -- value, and to the exception that we are propagating
1475 for J in 1 .. Subprogram_Descriptors (Pdesc).Num_Handlers loop
1476 Hrec := Subprogram_Descriptors (Pdesc).Handler_Records (J);
1478 if Loc >= Hrec.Lo and then Loc < Hrec.Hi then
1480 -- PC range is applicable, see if handler is for this exception
1482 -- First test for case of "all others" (finalization) handler.
1483 -- We do not enter such a handler until we are sure there is
1484 -- a real handler further up the stack.
1486 if Hrec.Id = All_Others_Id then
1488 -- If this is the first finalization handler, then
1489 -- save the machine state so we can enter it later
1490 -- without having to repeat the search.
1492 if not FH_Found then
1494 Duplicate_Machine_State
1495 (Machine_State (FH_Mstate'Address), Mstate);
1496 FH_Handler := Hrec.Handler;
1497 FH_Num_Trb := Excep.Num_Tracebacks;
1500 -- Normal (non-finalization exception with matching Id)
1502 elsif Excep.Id = Hrec.Id
1503 or else (Hrec.Id = Others_Id
1504 and not Excep.Id.Not_Handled_By_Others)
1506 -- Perform the necessary notification tasks.
1508 Notify_Handled_Exception
1509 (Hrec.Handler, Hrec.Id = Others_Id, True);
1511 -- If we already encountered a finalization handler, then
1512 -- reset the context to that handler, and enter it.
1515 Excep.Num_Tracebacks := FH_Num_Trb;
1516 Excep.Cleanup_Flag := True;
1519 (Machine_State (FH_Mstate'Address), FH_Handler);
1521 -- If we have not encountered a finalization handler,
1522 -- then enter the current handler.
1525 Enter_Handler (Mstate, Hrec.Handler);
1531 Info := Subprogram_Descriptors (Pdesc).Subprogram_Info;
1532 exit Main_Loop when Info = No_Info;
1533 Pop_Frame (Mstate, Info);
1536 -- Fall through if no "real" exception handler found. First thing is to
1537 -- perform the necessary notification tasks with the stack intact.
1539 Notify_Unhandled_Exception (Excep.Id);
1541 -- If there were finalization handlers, then enter the top one.
1542 -- Just because there is no handler does not mean we don't have
1543 -- to still execute all finalizations and cleanups before
1544 -- terminating. Note that the process of calling cleanups
1545 -- does not disturb the back trace stack, since he same
1546 -- exception occurrence gets reraised, and new traceback
1547 -- entries added as we go along.
1550 Excep.Num_Tracebacks := FH_Num_Trb;
1551 Excep.Cleanup_Flag := True;
1552 Enter_Handler (Machine_State (FH_Mstate'Address), FH_Handler);
1555 -- If no cleanups, then this is the real unhandled termination
1557 Unhandled_Exception_Terminate;
1559 end Propagate_Exception_With_FE_Support;
1561 ------------------------------------------
1562 -- Propagate_Exception_With_GCC_Support --
1563 ------------------------------------------
1565 procedure Propagate_Exception_With_GCC_Support (Mstate : Machine_State) is
1566 Excep : EOA := Get_Current_Excep.all;
1567 This_Exception : aliased GNAT_GCC_Exception;
1568 Status : Unwind_Reason_Code;
1571 -- ??? Nothing is currently done for backtracing purposes. We could
1572 -- have used the personality routine to record the addresses while
1573 -- walking up the stack, but this method has two drawbacks : 1/ the
1574 -- trace is incomplete if the exception is handled since we don't walk
1575 -- up the frame with the handler, and 2/ we will miss frames if the
1576 -- exception propagates through frames for which our personality
1577 -- routine is not called (e.g. if C or C++ frames are on the way).
1579 -- Fill in the useful flags for the personality routine called for each
1580 -- frame via the call to Unwind_RaiseException below.
1582 This_Exception.Id := Excep.Id;
1583 This_Exception.Handled_By_Others := not Excep.Id.Not_Handled_By_Others;
1584 This_Exception.Has_Cleanup := False;
1586 -- We are looking for a regular handler first. If there is one, either
1587 -- it or the first at-end handler before it will be entered. If there
1588 -- is none, control will normally get back to after the call, with
1589 -- Has_Cleanup set to true if at least one at-end handler has been
1590 -- found while walking up the stack.
1592 This_Exception.Select_Cleanups := False;
1594 Status := Unwind_RaiseException (This_Exception'Access);
1596 -- If we get here we know the exception is not handled, as otherwise
1597 -- Unwind_RaiseException arranges for a handler to be entered. We might
1598 -- have met cleanups handlers, though, requiring to start again with
1599 -- the Select_Cleanups flag set to True.
1601 -- Before restarting for cleanups, take the necessary steps to enable
1602 -- the debugger to gain control while the stack is still intact. Flag
1603 -- the occurrence as raised to avoid notifying again in case cleanup
1604 -- handlers are entered later.
1606 if not Excep.Exception_Raised then
1607 Excep.Exception_Raised := True;
1608 Notify_Unhandled_Exception (Excep.Id);
1611 -- Now raise again selecting cleanups as true handlers. Only do this if
1612 -- we know at least one such handler exists since otherwise we would
1613 -- perform a complete stack upwalk for nothing.
1615 if This_Exception.Has_Cleanup then
1616 This_Exception.Select_Cleanups := True;
1617 Status := Unwind_RaiseException (This_Exception'Access);
1619 -- The first cleanup found is entered. It performs its job, raises
1620 -- the initial exception again, and the flow goes back to the first
1621 -- step above with the stack in a different state.
1624 -- We get here when there is no handler to be run at all. The debugger
1625 -- has been notified before the second step above.
1627 Unhandled_Exception_Terminate;
1629 end Propagate_Exception_With_GCC_Support;
1631 ----------------------------
1632 -- Raise_Constraint_Error --
1633 ----------------------------
1635 procedure Raise_Constraint_Error
1636 (File : Big_String_Ptr;
1640 Raise_With_Location (Constraint_Error_Def'Access, File, Line);
1641 end Raise_Constraint_Error;
1643 --------------------------------
1644 -- Raise_Constraint_Error_Msg --
1645 --------------------------------
1647 procedure Raise_Constraint_Error_Msg
1648 (File : Big_String_Ptr;
1650 Msg : Big_String_Ptr)
1653 Raise_With_Location_And_Msg
1654 (Constraint_Error_Def'Access, File, Line, Msg);
1655 end Raise_Constraint_Error_Msg;
1657 -------------------------
1658 -- Raise_Current_Excep --
1659 -------------------------
1661 procedure Raise_Current_Excep (E : Exception_Id) is
1663 Process_Raise_Exception (E => E, From_Signal_Handler => False);
1664 end Raise_Current_Excep;
1666 ---------------------
1667 -- Raise_Exception --
1668 ---------------------
1670 procedure Raise_Exception
1672 Message : String := "")
1674 Len : constant Natural :=
1675 Natural'Min (Message'Length, Exception_Msg_Max_Length);
1676 Excep : constant EOA := Get_Current_Excep.all;
1680 Excep.Msg_Length := Len;
1681 Excep.Msg (1 .. Len) := Message (1 .. Len);
1684 end Raise_Exception;
1686 ----------------------------
1687 -- Raise_Exception_Always --
1688 ----------------------------
1690 procedure Raise_Exception_Always
1692 Message : String := "")
1694 Len : constant Natural :=
1695 Natural'Min (Message'Length, Exception_Msg_Max_Length);
1697 Excep : constant EOA := Get_Current_Excep.all;
1700 Excep.Msg_Length := Len;
1701 Excep.Msg (1 .. Len) := Message (1 .. Len);
1703 end Raise_Exception_Always;
1705 -------------------------------
1706 -- Raise_From_Signal_Handler --
1707 -------------------------------
1709 procedure Raise_From_Signal_Handler
1714 Set_Exception_C_Msg (E, M);
1716 Process_Raise_Exception (E => E, From_Signal_Handler => True);
1717 end Raise_From_Signal_Handler;
1723 procedure Raise_No_Msg (E : Exception_Id) is
1724 Excep : constant EOA := Get_Current_Excep.all;
1727 Excep.Msg_Length := 0;
1731 -------------------------
1732 -- Raise_Program_Error --
1733 -------------------------
1735 procedure Raise_Program_Error
1736 (File : Big_String_Ptr;
1740 Raise_With_Location (Program_Error_Def'Access, File, Line);
1741 end Raise_Program_Error;
1743 -----------------------------
1744 -- Raise_Program_Error_Msg --
1745 -----------------------------
1747 procedure Raise_Program_Error_Msg
1748 (File : Big_String_Ptr;
1750 Msg : Big_String_Ptr)
1753 Raise_With_Location_And_Msg
1754 (Program_Error_Def'Access, File, Line, Msg);
1755 end Raise_Program_Error_Msg;
1757 -------------------------
1758 -- Raise_Storage_Error --
1759 -------------------------
1761 procedure Raise_Storage_Error
1762 (File : Big_String_Ptr;
1766 Raise_With_Location (Storage_Error_Def'Access, File, Line);
1767 end Raise_Storage_Error;
1769 -----------------------------
1770 -- Raise_Storage_Error_Msg --
1771 -----------------------------
1773 procedure Raise_Storage_Error_Msg
1774 (File : Big_String_Ptr;
1776 Msg : Big_String_Ptr)
1779 Raise_With_Location_And_Msg
1780 (Storage_Error_Def'Access, File, Line, Msg);
1781 end Raise_Storage_Error_Msg;
1783 ----------------------
1784 -- Raise_With_C_Msg --
1785 ----------------------
1787 procedure Raise_With_C_Msg
1792 Set_Exception_C_Msg (E, M);
1794 Raise_Current_Excep (E);
1795 end Raise_With_C_Msg;
1797 -------------------------
1798 -- Raise_With_Location --
1799 -------------------------
1801 procedure Raise_With_Location
1807 Set_Exception_C_Msg (E, F, L);
1809 Raise_Current_Excep (E);
1810 end Raise_With_Location;
1812 ---------------------------------
1813 -- Raise_With_Location_And_Msg --
1814 ---------------------------------
1816 procedure Raise_With_Location_And_Msg
1823 Set_Exception_C_Msg (E, F, L, M);
1825 Raise_Current_Excep (E);
1826 end Raise_With_Location_And_Msg;
1828 --------------------
1829 -- Raise_With_Msg --
1830 --------------------
1832 procedure Raise_With_Msg (E : Exception_Id) is
1833 Excep : constant EOA := Get_Current_Excep.all;
1836 Excep.Exception_Raised := False;
1838 Excep.Num_Tracebacks := 0;
1839 Excep.Cleanup_Flag := False;
1840 Excep.Pid := Local_Partition_ID;
1842 Raise_Current_Excep (E);
1849 procedure Reraise is
1850 Excep : constant EOA := Get_Current_Excep.all;
1854 Raise_Current_Excep (Excep.Id);
1857 ------------------------
1858 -- Reraise_Occurrence --
1859 ------------------------
1861 procedure Reraise_Occurrence (X : Exception_Occurrence) is
1863 if X.Id /= null then
1865 Save_Occurrence (Get_Current_Excep.all.all, X);
1866 Raise_Current_Excep (X.Id);
1868 end Reraise_Occurrence;
1870 -------------------------------
1871 -- Reraise_Occurrence_Always --
1872 -------------------------------
1874 procedure Reraise_Occurrence_Always (X : Exception_Occurrence) is
1877 Save_Occurrence (Get_Current_Excep.all.all, X);
1878 Raise_Current_Excep (X.Id);
1879 end Reraise_Occurrence_Always;
1881 ---------------------------------
1882 -- Reraise_Occurrence_No_Defer --
1883 ---------------------------------
1885 procedure Reraise_Occurrence_No_Defer (X : Exception_Occurrence) is
1887 Save_Occurrence (Get_Current_Excep.all.all, X);
1888 Raise_Current_Excep (X.Id);
1889 end Reraise_Occurrence_No_Defer;
1891 ---------------------
1892 -- Save_Occurrence --
1893 ---------------------
1895 procedure Save_Occurrence
1896 (Target : out Exception_Occurrence;
1897 Source : Exception_Occurrence)
1900 Target.Id := Source.Id;
1901 Target.Msg_Length := Source.Msg_Length;
1902 Target.Num_Tracebacks := Source.Num_Tracebacks;
1903 Target.Pid := Source.Pid;
1904 Target.Cleanup_Flag := Source.Cleanup_Flag;
1906 Target.Msg (1 .. Target.Msg_Length) :=
1907 Source.Msg (1 .. Target.Msg_Length);
1909 Target.Tracebacks (1 .. Target.Num_Tracebacks) :=
1910 Source.Tracebacks (1 .. Target.Num_Tracebacks);
1911 end Save_Occurrence;
1913 function Save_Occurrence
1914 (Source : Exception_Occurrence)
1917 Target : EOA := new Exception_Occurrence;
1920 Save_Occurrence (Target.all, Source);
1922 end Save_Occurrence;
1924 ---------------------
1925 -- SDP_Table_Build --
1926 ---------------------
1928 procedure SDP_Table_Build
1929 (SDP_Addresses : System.Address;
1930 SDP_Count : Natural;
1931 Elab_Addresses : System.Address;
1932 Elab_Addr_Count : Natural)
1934 type SDLP_Array is array (1 .. SDP_Count) of Subprogram_Descriptors_Ptr;
1935 type SDLP_Array_Ptr is access all SDLP_Array;
1937 function To_SDLP_Array_Ptr is new Unchecked_Conversion
1938 (System.Address, SDLP_Array_Ptr);
1940 T : constant SDLP_Array_Ptr := To_SDLP_Array_Ptr (SDP_Addresses);
1942 type Elab_Array is array (1 .. Elab_Addr_Count) of Code_Loc;
1943 type Elab_Array_Ptr is access all Elab_Array;
1945 function To_Elab_Array_Ptr is new Unchecked_Conversion
1946 (System.Address, Elab_Array_Ptr);
1948 EA : constant Elab_Array_Ptr := To_Elab_Array_Ptr (Elab_Addresses);
1951 Previous_Subprogram_Descriptors : Subprogram_Descriptor_List_Ptr;
1954 -- If first call, then initialize count of subprogram descriptors
1956 if Subprogram_Descriptors = null then
1957 Num_Subprogram_Descriptors := 0;
1960 -- First count number of subprogram descriptors. This count includes
1961 -- entries with duplicated code addresses (resulting from Import).
1963 Ndes := Num_Subprogram_Descriptors + Elab_Addr_Count;
1964 for J in T'Range loop
1965 Ndes := Ndes + T (J).Count;
1968 -- Now, allocate the new table (extra zero'th element is for sort call)
1969 -- after having saved the previous one
1971 Previous_Subprogram_Descriptors := Subprogram_Descriptors;
1972 Subprogram_Descriptors := new Subprogram_Descriptor_List (0 .. Ndes);
1974 -- If there was a previous Subprogram_Descriptors table, copy it back
1975 -- into the new one being built. Then free the memory used for the
1978 for J in 1 .. Num_Subprogram_Descriptors loop
1979 Subprogram_Descriptors (J) := Previous_Subprogram_Descriptors (J);
1982 Free (Previous_Subprogram_Descriptors);
1984 -- Next, append the elaboration routine addresses, building dummy
1985 -- SDP's for them as we go through the list.
1987 Ndes := Num_Subprogram_Descriptors;
1988 for J in EA'Range loop
1990 Subprogram_Descriptors (Ndes) := new Subprogram_Descriptor_0;
1992 Subprogram_Descriptors (Ndes).all :=
1993 Subprogram_Descriptor'
1995 Code
=> Fetch_Code
(EA
(J
)),
1996 Subprogram_Info
=> EA
(J
),
1997 Handler_Records
=> (1 .. 0 => null));
2000 -- Now copy in pointers to SDP addresses of application subprograms
2002 for J
in T
'Range loop
2003 for K
in 1 .. T
(J
).Count
loop
2005 Subprogram_Descriptors
(Ndes
) := T
(J
).SDesc
(K
);
2006 Subprogram_Descriptors
(Ndes
).Code
:=
2007 Fetch_Code
(T
(J
).SDesc
(K
).Code
);
2011 -- Now we need to sort the table into ascending PC order
2013 Sort
(Ndes
, SDP_Table_Sort_Move
'Access, SDP_Table_Sort_Lt
'Access);
2015 -- Now eliminate duplicate entries. Note that in the case where
2016 -- entries have duplicate code addresses, the code for the Lt
2017 -- routine ensures that the interesting one (i.e. the one with
2018 -- handler entries if there are any) comes first.
2020 Num_Subprogram_Descriptors
:= 1;
2022 for J
in 2 .. Ndes
loop
2023 if Subprogram_Descriptors
(J
).Code
/=
2024 Subprogram_Descriptors
(Num_Subprogram_Descriptors
).Code
2026 Num_Subprogram_Descriptors
:= Num_Subprogram_Descriptors
+ 1;
2027 Subprogram_Descriptors
(Num_Subprogram_Descriptors
) :=
2028 Subprogram_Descriptors
(J
);
2032 end SDP_Table_Build
;
2034 -----------------------
2035 -- SDP_Table_Sort_Lt --
2036 -----------------------
2038 function SDP_Table_Sort_Lt
(Op1
, Op2
: Natural) return Boolean is
2039 SDC1
: constant Code_Loc
:= Subprogram_Descriptors
(Op1
).Code
;
2040 SDC2
: constant Code_Loc
:= Subprogram_Descriptors
(Op2
).Code
;
2046 elsif SDC1
> SDC2
then
2049 -- For two descriptors for the same procedure, we want the more
2050 -- interesting one first. A descriptor with an exception handler
2051 -- is more interesting than one without. This happens if the less
2052 -- interesting one came from a pragma Import.
2055 return Subprogram_Descriptors
(Op1
).Num_Handlers
/= 0
2056 and then Subprogram_Descriptors
(Op2
).Num_Handlers
= 0;
2058 end SDP_Table_Sort_Lt
;
2060 --------------------------
2061 -- SDP_Table_Sort_Move --
2062 --------------------------
2064 procedure SDP_Table_Sort_Move
(From
: Natural; To
: Natural) is
2066 Subprogram_Descriptors
(To
) := Subprogram_Descriptors
(From
);
2067 end SDP_Table_Sort_Move
;
2069 -------------------------
2070 -- Set_Exception_C_Msg --
2071 -------------------------
2073 procedure Set_Exception_C_Msg
2075 Msg1
: Big_String_Ptr
;
2076 Line
: Integer := 0;
2077 Msg2
: Big_String_Ptr
:= null)
2079 Excep
: constant EOA
:= Get_Current_Excep
.all;
2080 Val
: Integer := Line
;
2082 Size
: Integer := 1;
2086 Excep
.Exception_Raised
:= False;
2088 Excep
.Num_Tracebacks
:= 0;
2089 Excep
.Pid
:= Local_Partition_ID
;
2090 Excep
.Msg_Length
:= 0;
2091 Excep
.Cleanup_Flag
:= False;
2093 while Msg1
(Excep
.Msg_Length
+ 1) /= ASCII
.NUL
2094 and then Excep
.Msg_Length
< Exception_Msg_Max_Length
2096 Excep
.Msg_Length
:= Excep
.Msg_Length
+ 1;
2097 Excep
.Msg
(Excep
.Msg_Length
) := Msg1
(Excep
.Msg_Length
);
2100 -- Append line number if present
2104 -- Compute the number of needed characters
2111 -- If enough characters are available, put the line number
2113 if Excep
.Msg_Length
<= Exception_Msg_Max_Length
- Size
then
2114 Excep
.Msg
(Excep
.Msg_Length
+ 1) := ':';
2115 Excep
.Msg_Length
:= Excep
.Msg_Length
+ Size
;
2120 Remind
:= Val
rem 10;
2122 Excep
.Msg
(Excep
.Msg_Length
- Size
) :=
2123 Character'Val (Remind
+ Character'Pos ('0'));
2129 -- Append second message if present
2132 and then Excep
.Msg_Length
+ 1 < Exception_Msg_Max_Length
2134 Excep
.Msg_Length
:= Excep
.Msg_Length
+ 1;
2135 Excep
.Msg
(Excep
.Msg_Length
) := ' ';
2138 while Msg2
(Ptr
) /= ASCII
.NUL
2139 and then Excep
.Msg_Length
< Exception_Msg_Max_Length
2141 Excep
.Msg_Length
:= Excep
.Msg_Length
+ 1;
2142 Excep
.Msg
(Excep
.Msg_Length
) := Msg2
(Ptr
);
2146 end Set_Exception_C_Msg
;
2152 function String_To_EId
(S
: String) return Exception_Id
is
2157 return Exception_Id
(Internal_Exception
(S
));
2165 function String_To_EO
(S
: String) return Exception_Occurrence
is
2169 X
: Exception_Occurrence
;
2170 -- This is the exception occurrence we will create
2173 pragma No_Return
(Bad_EO
);
2174 -- Signal bad exception occurrence string
2176 procedure Next_String
;
2177 -- On entry, To points to last character of previous line of the
2178 -- message, terminated by LF. On return, From .. To are set to
2179 -- specify the next string, or From > To if there are no more lines.
2184 (Program_Error
'Identity,
2185 "bad exception occurrence in stream input");
2188 procedure Next_String
is
2192 if From
< S
'Last then
2195 while To
< S
'Last - 1 loop
2196 if To
>= S
'Last then
2198 elsif S
(To
+ 1) = ASCII
.LF
then
2207 -- Start of processing for String_To_EO
2211 return Null_Occurrence
;
2214 X
.Cleanup_Flag
:= False;
2219 if S
(From
.. From
+ 15) /= "Exception name: " then
2223 X
.Id
:= Exception_Id
(Internal_Exception
(S
(From
+ 16 .. To
)));
2227 if From
<= To
and then S
(From
) = 'M' then
2228 if S
(From
.. From
+ 8) /= "Message: " then
2232 X
.Msg_Length
:= To
- From
- 8;
2233 X
.Msg
(1 .. X
.Msg_Length
) := S
(From
+ 9 .. To
);
2242 if From
<= To
and then S
(From
) = 'P' then
2243 if S
(From
.. From
+ 3) /= "PID:" then
2247 From
:= From
+ 5; -- skip past PID: space
2249 while From
<= To
loop
2250 X
.Pid
:= X
.Pid
* 10 +
2251 (Character'Pos (S
(From
)) - Character'Pos ('0'));
2258 X
.Num_Tracebacks
:= 0;
2261 if S
(From
.. To
) /= "Call stack traceback locations:" then
2267 exit when From
> To
;
2271 C
: Integer_Address
;
2272 N
: Integer_Address
;
2276 or else S
(From
+ 1) /= 'x'
2284 while From
<= To
loop
2287 if Ch
in '0' .. '9' then
2289 Character'Pos (S
(From
)) - Character'Pos ('0');
2291 elsif Ch
in 'a' .. 'f' then
2293 Character'Pos (S
(From
)) - Character'Pos ('a') + 10;
2308 if X
.Num_Tracebacks
= Max_Tracebacks
then
2312 X
.Num_Tracebacks
:= X
.Num_Tracebacks
+ 1;
2313 X
.Tracebacks
(X
.Num_Tracebacks
) := To_Address
(C
);
2318 -- If an exception was converted to a string, it must have
2319 -- already been raised, so flag it accordingly and we are done.
2321 X
.Exception_Raised
:= True;
2326 ----------------------------------
2327 -- Tailored_Exception_Traceback --
2328 ----------------------------------
2330 function Tailored_Exception_Traceback
2331 (X
: Exception_Occurrence
)
2334 -- We indeed reference the decorator *wrapper* from here and not the
2335 -- decorator itself. The purpose of the local variable Wrapper is to
2336 -- prevent a potential crash by race condition in the code below. The
2337 -- atomicity of this assignment is enforced by pragma Atomic in
2338 -- System.Soft_Links.
2340 -- The potential race condition here, if no local variable was used,
2341 -- relates to the test upon the wrapper's value and the call, which
2342 -- are not performed atomically. With the local variable, potential
2343 -- changes of the wrapper's global value between the test and the
2344 -- call become inoffensive.
2346 Wrapper
: constant Traceback_Decorator_Wrapper_Call
:=
2347 Traceback_Decorator_Wrapper
;
2350 if Wrapper
= null then
2351 return Basic_Exception_Traceback
(X
);
2353 return Wrapper
.all (X
.Tracebacks
'Address, X
.Num_Tracebacks
);
2355 end Tailored_Exception_Traceback
;
2357 ------------------------------------
2358 -- Tailored_Exception_Information --
2359 ------------------------------------
2361 function Tailored_Exception_Information
2362 (X
: Exception_Occurrence
)
2365 -- The tailored exception information is simply the basic information
2366 -- associated with the tailored call chain backtrace.
2368 Basic_Info
: constant String := Basic_Exception_Information
(X
);
2369 Tback_Info
: constant String := Tailored_Exception_Traceback
(X
);
2371 Basic_Len
: constant Natural := Basic_Info
'Length;
2372 Tback_Len
: constant Natural := Tback_Info
'Length;
2374 Info
: String (1 .. Basic_Len
+ Tback_Len
);
2378 Append_Info_String
(Basic_Info
, Info
, Ptr
);
2379 Append_Info_String
(Tback_Info
, Info
, Ptr
);
2382 end Tailored_Exception_Information
;
2384 -------------------------
2385 -- Unhandled_Exception --
2386 -------------------------
2388 procedure Unhandled_Exception
is
2391 end Unhandled_Exception
;
2393 ----------------------
2394 -- Notify_Exception --
2395 ----------------------
2397 procedure Notify_Exception
2400 Is_Others
: Boolean)
2404 end Notify_Exception
;
2406 ------------------------------
2407 -- Notify_Handled_Exception --
2408 ------------------------------
2410 procedure Notify_Handled_Exception
2411 (Handler
: Code_Loc
;
2412 Is_Others
: Boolean;
2413 Low_Notify
: Boolean)
2415 Excep
: constant EOA
:= Get_Current_Excep
.all;
2418 -- Notify the debugger that we have found a handler and are about to
2419 -- propagate an exception, but only if specifically told to do so.
2422 Notify_Exception
(Excep
.Id
, Handler
, Is_Others
);
2425 -- Output some exception information if necessary, as specified by
2426 -- GNAT.Exception_Traces. Take care not to output information about
2427 -- internal exceptions.
2429 -- ??? In the ZCX case, the traceback entries we have at this point
2430 -- only include the ones we stored while walking up the stack *up to
2431 -- the handler*. All the frames above the subprogram in which the
2432 -- handler is found are missing.
2434 if Exception_Trace
= Every_Raise
2435 and then not Excep
.Id
.Not_Handled_By_Others
2438 To_Stderr
("Exception raised");
2440 To_Stderr
(Tailored_Exception_Information
(Excep
.all));
2443 end Notify_Handled_Exception
;
2445 ------------------------------
2446 -- Notify_Handled_Exception --
2447 ------------------------------
2449 procedure Notify_Unhandled_Exception
(Id
: Exception_Id
) is
2451 -- Simply perform the two necessary low level notification calls.
2453 Unhandled_Exception
;
2454 Notify_Exception
(Id
, Null_Loc
, False);
2456 end Notify_Unhandled_Exception
;
2458 -----------------------------------
2459 -- Unhandled_Exception_Terminate --
2460 -----------------------------------
2462 adafinal_Called
: Boolean := False;
2463 -- Used to prevent recursive call to adafinal in the event that
2464 -- adafinal processing itself raises an unhandled exception.
2466 type FILEs
is new System
.Address
;
2467 type int
is new Integer;
2469 procedure Unhandled_Exception_Terminate
is
2471 Excep
: constant EOA
:= Save_Occurrence
(Get_Current_Excep
.all.all);
2472 -- This occurrence will be used to display a message after finalization.
2473 -- It is necessary to save a copy here, or else the designated value
2474 -- could be overwritten if an exception is raised during finalization
2475 -- (even if that exception is caught).
2477 Msg
: constant String := Exception_Message
(Excep
.all);
2479 -- Start of processing for Unhandled_Exception_Terminate
2482 -- First call adafinal
2484 if not adafinal_Called
then
2485 adafinal_Called
:= True;
2486 System
.Soft_Links
.Adafinal
.all;
2489 -- Check for special case of raising _ABORT_SIGNAL, which is not
2490 -- really an exception at all. We recognize this by the fact that
2491 -- it is the only exception whose name starts with underscore.
2493 if Exception_Name
(Excep
.all) (1) = '_' then
2495 To_Stderr
("Execution terminated by abort of environment task");
2498 -- If no tracebacks, we print the unhandled exception in the old style
2499 -- (i.e. the style used before ZCX was implemented). We do this to
2500 -- retain compatibility, especially with the nightly scripts, but
2501 -- this can be removed at some point ???
2503 elsif Excep
.Num_Tracebacks
= 0 then
2505 To_Stderr
("raised ");
2506 To_Stderr
(Exception_Name
(Excep
.all));
2508 if Msg
'Length /= 0 then
2515 -- New style, zero cost exception case
2518 -- Tailored_Exception_Information is also called here so that the
2519 -- backtrace decorator gets called if it has been set. This is
2520 -- currently required because some paths in Raise_Current_Excep
2521 -- do not go through the calls that display this information.
2523 -- Note also that with the current scheme in Raise_Current_Excep
2524 -- we can have this whole information output twice, typically when
2525 -- some handler is found on the call chain but none deals with the
2526 -- occurrence or if this occurrence gets reraised up to here.
2529 To_Stderr
("Execution terminated by unhandled exception");
2531 To_Stderr
(Tailored_Exception_Information
(Excep
.all));
2534 -- Perform system dependent shutdown code
2537 procedure Unhandled_Terminate
;
2538 pragma No_Return
(Unhandled_Terminate
);
2540 (C
, Unhandled_Terminate
, "__gnat_unhandled_terminate");
2543 Unhandled_Terminate
;
2546 end Unhandled_Exception_Terminate
;
2548 ------------------------------
2549 -- Raise_Exception_No_Defer --
2550 ------------------------------
2552 procedure Raise_Exception_No_Defer
2554 Message
: String := "")
2556 Len
: constant Natural :=
2557 Natural'Min (Message
'Length, Exception_Msg_Max_Length
);
2559 Excep
: constant EOA
:= Get_Current_Excep
.all;
2562 Excep
.Exception_Raised
:= False;
2563 Excep
.Msg_Length
:= Len
;
2564 Excep
.Msg
(1 .. Len
) := Message
(1 .. Len
);
2566 Excep
.Num_Tracebacks
:= 0;
2567 Excep
.Cleanup_Flag
:= False;
2568 Excep
.Pid
:= Local_Partition_ID
;
2570 -- DO NOT CALL Abort_Defer.all; !!!!
2572 Raise_Current_Excep
(E
);
2573 end Raise_Exception_No_Defer
;
2579 procedure To_Stderr
(S
: String) is
2580 procedure put_char_stderr
(C
: int
);
2581 pragma Import
(C
, put_char_stderr
, "put_char_stderr");
2584 for J
in 1 .. S
'Length loop
2585 if S
(J
) /= ASCII
.CR
then
2586 put_char_stderr
(Character'Pos (S
(J
)));
2595 -- This dummy procedure gives us the end of the PC range for addresses
2596 -- within the exception unit itself. We hope that gigi/gcc keeps all the
2597 -- procedures in their original order!
2605 -- Allocate the Non-Tasking Machine_State
2607 Set_Machine_State_Addr_NT
(System
.Address
(Allocate_Machine_State
));