* arm.c (FL_WBUF): Define.
[official-gcc.git] / gcc / ada / a-exextr.adb
blob835c2cb526865f3d5a846814bb986d293f1204c4
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- ADA.EXCEPTIONS.EXCEPTION_TRACES --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 with Unchecked_Conversion;
36 pragma Warnings (Off);
37 with Ada.Exceptions.Last_Chance_Handler;
38 pragma Warnings (On);
39 -- Bring last chance handler into closure
41 separate (Ada.Exceptions)
42 package body Exception_Traces is
44 Nline : constant String := String'(1 => ASCII.LF);
45 -- Convenient shortcut
47 type Exception_Action is access procedure (E : Exception_Occurrence);
48 Global_Action : Exception_Action := null;
49 pragma Export
50 (Ada, Global_Action, "__gnat_exception_actions_global_action");
51 -- Global action, executed whenever an exception is raised. Changing the
52 -- export name must be coordinated with code in g-excact.adb.
54 Raise_Hook_Initialized : Boolean := False;
55 pragma Export
56 (Ada, Raise_Hook_Initialized, "__gnat_exception_actions_initialized");
58 procedure Last_Chance_Handler
59 (Except : Exception_Occurrence);
60 pragma Import (C, Last_Chance_Handler, "__gnat_last_chance_handler");
61 pragma No_Return (Last_Chance_Handler);
62 -- Users can replace the default version of this routine,
63 -- Ada.Exceptions.Last_Chance_Handler.
65 function To_Action is new Unchecked_Conversion
66 (Raise_Action, Exception_Action);
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Notify_Exception (Excep : EOA; Is_Unhandled : Boolean);
73 -- Factorizes the common processing for Notify_Handled_Exception and
74 -- Notify_Unhandled_Exception. Is_Unhandled is set to True only in the
75 -- latter case because Notify_Handled_Exception may be called for an
76 -- actually unhandled occurrence in the Front-End-SJLJ case.
78 ---------------------------------
79 -- Debugger Interface Routines --
80 ---------------------------------
82 -- The routines here are null routines that normally have no effect.
83 -- They are provided for the debugger to place breakpoints on their
84 -- entry points to get control on an exception.
86 procedure Unhandled_Exception;
87 pragma Export (C, Unhandled_Exception, "__gnat_unhandled_exception");
88 -- Hook for GDB to support "break exception unhandled".
90 -- For "break exception", GDB uses __gnat_raise_nodefer_with_msg, which
91 -- is not in this section because it fullfills other purposes than a mere
92 -- debugger interface.
94 --------------------------------
95 -- Import Run-Time C Routines --
96 --------------------------------
98 -- The purpose of the following pragma Import is to ensure that we
99 -- generate appropriate subprogram descriptors for all C routines in
100 -- the standard GNAT library that can raise exceptions. This ensures
101 -- that the exception propagation can properly find these routines
103 pragma Propagate_Exceptions;
105 ----------------------
106 -- Notify_Exception --
107 ----------------------
109 procedure Notify_Exception (Excep : EOA; Is_Unhandled : Boolean) is
110 begin
111 -- Output the exception information required by the Exception_Trace
112 -- configuration. Take care not to output information about internal
113 -- exceptions.
115 -- ??? In the Front-End ZCX case, the traceback entries we have at this
116 -- point only include the ones we stored while walking up the stack *up
117 -- to the handler*. All the frames above the subprogram in which the
118 -- handler is found are missing.
120 if not Excep.Id.Not_Handled_By_Others
121 and then
122 (Exception_Trace = Every_Raise
123 or else (Exception_Trace = Unhandled_Raise and then Is_Unhandled))
124 then
125 To_Stderr (Nline);
127 if Is_Unhandled then
128 To_Stderr ("Unhandled ");
129 end if;
131 To_Stderr ("Exception raised");
132 To_Stderr (Nline);
133 To_Stderr (Tailored_Exception_Information (Excep.all));
134 end if;
136 -- Call the user-specific actions
137 -- ??? We should presumably look at the reraise status here.
139 if Raise_Hook_Initialized
140 and then Exception_Data_Ptr (Excep.Id).Raise_Hook /= null
141 then
142 To_Action (Exception_Data_Ptr (Excep.Id).Raise_Hook) (Excep.all);
143 end if;
145 if Global_Action /= null then
146 Global_Action (Excep.all);
147 end if;
148 end Notify_Exception;
150 ------------------------------
151 -- Notify_Handled_Exception --
152 ------------------------------
154 procedure Notify_Handled_Exception is
155 begin
156 Notify_Exception (Get_Current_Excep.all, Is_Unhandled => False);
157 end Notify_Handled_Exception;
159 --------------------------------
160 -- Notify_Unhandled_Exception --
161 --------------------------------
163 procedure Notify_Unhandled_Exception is
164 begin
165 Notify_Exception (Get_Current_Excep.all, Is_Unhandled => True);
166 Unhandled_Exception;
167 end Notify_Unhandled_Exception;
169 -------------------------
170 -- Unhandled_Exception --
171 -------------------------
173 procedure Unhandled_Exception is
174 begin
175 null;
176 end Unhandled_Exception;
178 -----------------------------------
179 -- Unhandled_Exception_Terminate --
180 -----------------------------------
182 procedure Unhandled_Exception_Terminate is
183 Excep : constant EOA := Save_Occurrence (Get_Current_Excep.all.all);
184 -- This occurrence will be used to display a message after finalization.
185 -- It is necessary to save a copy here, or else the designated value
186 -- could be overwritten if an exception is raised during finalization
187 -- (even if that exception is caught).
189 begin
190 Last_Chance_Handler (Excep.all);
191 end Unhandled_Exception_Terminate;
194 ------------------------------------
195 -- Handling GNAT.Exception_Traces --
196 ------------------------------------
198 -- The bulk of exception traces output is centralized in Notify_Exception,
199 -- for both the Handled and Unhandled cases. Extra task specific output is
200 -- triggered in the task wrapper for unhandled occurrences in tasks. It is
201 -- not performed in this unit to avoid dragging dependencies against the
202 -- tasking units here.
204 -- We used to rely on the output performed by Unhanded_Exception_Terminate
205 -- for the case of an unhandled occurrence in the environment thread, and
206 -- the task wrapper was responsible for the whole output in the tasking
207 -- case.
209 -- This initial scheme had a drawback: the output from Terminate only
210 -- occurs after finalization is done, which means possibly never if some
211 -- tasks keep hanging around.
213 -- The first "presumably obvious" fix consists in moving the Terminate
214 -- output before the finalization. It has not been retained because it
215 -- introduces annoying changes in output orders when the finalization
216 -- itself issues outputs, this also in "regular" cases not resorting to
217 -- Exception_Traces.
219 -- Today's solution has the advantage of simplicity and better isolates
220 -- the Exception_Traces machinery.
222 -- It currently outputs the information about unhandled exceptions twice
223 -- in the environment thread, once in the notification routine and once in
224 -- the termination routine. Avoiding the second output is possible but so
225 -- far has been considered undesirable. It would mean changing the order
226 -- of outputs between the two runs with or without exception traces, while
227 -- it seems preferrable to only have additional outputs in the former
228 -- case.
230 end Exception_Traces;