2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / a-exexpr.adb
blob165b5cef3d812121f40e69eae3b129d6fea561d2
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
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 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This is the default version, using the __builtin_setjmp/longjmp EH
35 -- mechanism.
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");
50 ---------------------
51 -- Setup_Exception --
52 ---------------------
54 procedure Setup_Exception
55 (Excep : EOA;
56 Current : EOA;
57 Reraised : Boolean := False)
59 pragma Unreferenced (Excep, Current, Reraised);
60 begin
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.
65 null;
66 end Setup_Exception;
68 -------------------------
69 -- Propagate_Exception --
70 -------------------------
72 procedure Propagate_Exception (From_Signal_Handler : Boolean) is
73 Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
74 Excep : constant EOA := Get_Current_Excep.all;
75 begin
76 -- Compute the backtrace for this occurrence if corresponding binder
77 -- option has been set. Call_Chain takes care of the reraise case.
79 Call_Chain (Excep);
81 -- Note on above call to Call_Chain:
83 -- We used to only do this if From_Signal_Handler was not set,
84 -- based on the assumption that backtracing from a signal handler
85 -- would not work due to stack layout oddities. However, since
87 -- 1. The flag is never set in tasking programs (Notify_Exception
88 -- performs regular raise statements), and
90 -- 2. No problem has shown up in tasking programs around here so
91 -- far, this turned out to be too strong an assumption.
93 -- As, in addition, the test was
95 -- 1. preventing the production of backtraces in non-tasking
96 -- programs, and
98 -- 2. introducing a behavior inconsistency between
99 -- the tasking and non-tasking cases,
101 -- we have simply removed it
103 -- If the jump buffer pointer is non-null, transfer control using
104 -- it. Otherwise announce an unhandled exception (note that this
105 -- means that we have no finalizations to do other than at the outer
106 -- level). Perform the necessary notification tasks in both cases.
108 if Jumpbuf_Ptr /= Null_Address then
109 if not Excep.Exception_Raised then
110 Excep.Exception_Raised := True;
111 Exception_Traces.Notify_Handled_Exception;
112 end if;
114 builtin_longjmp (Jumpbuf_Ptr, 1);
116 else
117 Exception_Traces.Notify_Unhandled_Exception;
118 Exception_Traces.Unhandled_Exception_Terminate;
119 end if;
120 end Propagate_Exception;
122 end Exception_Propagation;