OSDN Git Service

* gcc-interface/Make-lang.in: Fix typo.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-exexpr.adb
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-2009, 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 3,  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.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 --  This is the default version, using the __builtin_setjmp/longjmp EH
33 --  mechanism.
34
35 with System.Storage_Elements;  use System.Storage_Elements;
36
37 pragma Warnings (Off);
38 --  Since several constructs give warnings in 3.14a1, including unreferenced
39 --  variables and pragma Unreferenced itself.
40
41 separate (Ada.Exceptions)
42 package body Exception_Propagation is
43
44    ---------------------
45    -- Setup_Exception --
46    ---------------------
47
48    procedure Setup_Exception
49      (Excep    : EOA;
50       Current  : EOA;
51       Reraised : Boolean := False)
52    is
53       pragma Unreferenced (Excep, Current, Reraised);
54    begin
55       --  In the GNAT-SJLJ case this "stack" only exists implicitly, by way of
56       --  local occurrence declarations together with save/restore operations
57       --  generated by the front-end, and this routine has nothing to do.
58
59       null;
60    end Setup_Exception;
61
62    -------------------------
63    -- Propagate_Exception --
64    -------------------------
65
66    procedure Propagate_Exception
67      (E                   : Exception_Id;
68       From_Signal_Handler : Boolean)
69    is
70       pragma Inspection_Point (E);
71
72       Jumpbuf_Ptr : constant Address := Get_Jmpbuf_Address.all;
73       Excep       : constant EOA := Get_Current_Excep.all;
74    begin
75       --  Compute the backtrace for this occurrence if corresponding binder
76       --  option has been set. Call_Chain takes care of the reraise case.
77
78       Call_Chain (Excep);
79
80       --  Note on above call to Call_Chain:
81
82       --  We used to only do this if From_Signal_Handler was not set,
83       --  based on the assumption that backtracing from a signal handler
84       --  would not work due to stack layout oddities. However, since
85
86       --   1. The flag is never set in tasking programs (Notify_Exception
87       --      performs regular raise statements), and
88
89       --   2. No problem has shown up in tasking programs around here so
90       --      far, this turned out to be too strong an assumption.
91
92       --  As, in addition, the test was
93
94       --   1. preventing the production of backtraces in non-tasking
95       --      programs, and
96
97       --   2. introducing a behavior inconsistency between
98       --      the tasking and non-tasking cases,
99
100       --  we have simply removed it
101
102       --  If the jump buffer pointer is non-null, transfer control using
103       --  it. Otherwise announce an unhandled exception (note that this
104       --  means that we have no finalizations to do other than at the outer
105       --  level). Perform the necessary notification tasks in both cases.
106
107       if Jumpbuf_Ptr /= Null_Address then
108          if not Excep.Exception_Raised then
109             Excep.Exception_Raised := True;
110             Exception_Traces.Notify_Handled_Exception;
111          end if;
112
113          builtin_longjmp (To_Jmpbuf_Address (Jumpbuf_Ptr), 1);
114
115       else
116          Exception_Traces.Notify_Unhandled_Exception;
117          Exception_Traces.Unhandled_Exception_Terminate;
118       end if;
119    end Propagate_Exception;
120
121 end Exception_Propagation;