1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- A D A . E X C E P T I O N S . E X C E P T I O N _ P R O P A G A T I O N --
9 -- Copyright (C) 1992-2006 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the default version, using the __builtin_setjmp/longjmp EH
37 with System
.Storage_Elements
; use System
.Storage_Elements
;
39 pragma Warnings
(Off
);
40 -- Since several constructs give warnings in 3.14a1, including unreferenced
41 -- variables and pragma Unreferenced itself.
43 separate (Ada
.Exceptions
)
44 package body Exception_Propagation
is
46 procedure builtin_longjmp
(buffer
: Address
; Flag
: Integer);
47 pragma No_Return
(builtin_longjmp
);
48 pragma Import
(C
, builtin_longjmp
, "_gnat_builtin_longjmp");
54 procedure Setup_Exception
57 Reraised
: Boolean := False)
59 pragma Unreferenced
(Excep
, Current
, Reraised
);
61 -- In the GNAT-SJLJ case this "stack" only exists implicitely, by way of
62 -- local occurrence declarations together with save/restore operations
63 -- generated by the front-end, and this routine has nothing to do.
68 -------------------------
69 -- Propagate_Exception --
70 -------------------------
72 procedure Propagate_Exception
74 From_Signal_Handler
: Boolean)
76 pragma Inspection_Point
(E
);
78 Jumpbuf_Ptr
: constant Address
:= Get_Jmpbuf_Address
.all;
79 Excep
: constant EOA
:= Get_Current_Excep
.all;
81 -- Compute the backtrace for this occurrence if corresponding binder
82 -- option has been set. Call_Chain takes care of the reraise case.
86 -- Note on above call to Call_Chain:
88 -- We used to only do this if From_Signal_Handler was not set,
89 -- based on the assumption that backtracing from a signal handler
90 -- would not work due to stack layout oddities. However, since
92 -- 1. The flag is never set in tasking programs (Notify_Exception
93 -- performs regular raise statements), and
95 -- 2. No problem has shown up in tasking programs around here so
96 -- far, this turned out to be too strong an assumption.
98 -- As, in addition, the test was
100 -- 1. preventing the production of backtraces in non-tasking
103 -- 2. introducing a behavior inconsistency between
104 -- the tasking and non-tasking cases,
106 -- we have simply removed it
108 -- If the jump buffer pointer is non-null, transfer control using
109 -- it. Otherwise announce an unhandled exception (note that this
110 -- means that we have no finalizations to do other than at the outer
111 -- level). Perform the necessary notification tasks in both cases.
113 if Jumpbuf_Ptr
/= Null_Address
then
114 if not Excep
.Exception_Raised
then
115 Excep
.Exception_Raised
:= True;
116 Exception_Traces
.Notify_Handled_Exception
;
119 builtin_longjmp
(Jumpbuf_Ptr
, 1);
122 Exception_Traces
.Notify_Unhandled_Exception
;
123 Exception_Traces
.Unhandled_Exception_Terminate
;
125 end Propagate_Exception
;
127 end Exception_Propagation
;