* config/arm/elf.h (ASM_OUTPUT_ALIGNED_COMMON): Remove definition.
[official-gcc.git] / gcc / ada / comperr.adb
blob284ed47d9c95ac497b2d20582f0bbddfc3e05167
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C O M P E R R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2003 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 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- This package contains routines called when a fatal internal compiler
28 -- error is detected. Calls to these routines cause termination of the
29 -- current compilation with appropriate error output.
31 with Atree; use Atree;
32 with Debug; use Debug;
33 with Errout; use Errout;
34 with Fname; use Fname;
35 with Gnatvsn; use Gnatvsn;
36 with Lib; use Lib;
37 with Namet; use Namet;
38 with Osint; use Osint;
39 with Output; use Output;
40 with Sinput; use Sinput;
41 with Sprint; use Sprint;
42 with Sdefault; use Sdefault;
43 with Treepr; use Treepr;
44 with Types; use Types;
46 with Ada.Exceptions; use Ada.Exceptions;
48 with System.Soft_Links; use System.Soft_Links;
50 package body Comperr is
52 ----------------
53 -- Local Data --
54 ----------------
56 Abort_In_Progress : Boolean := False;
57 -- Used to prevent runaway recursion if something segfaults
58 -- while processing a previous abort.
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Repeat_Char (Char : Character; Col : Nat; After : Character);
65 -- Output Char until current column is at or past Col, and then output
66 -- the character given by After (if column is already past Col on entry,
67 -- then the effect is simply to output the After character).
69 --------------------
70 -- Compiler_Abort --
71 --------------------
73 procedure Compiler_Abort
74 (X : String;
75 Code : Integer := 0)
77 -- The procedures below output a "bug box" with information about
78 -- the cause of the compiler abort and about the preferred method
79 -- of reporting bugs. The default is a bug box appropriate for
80 -- the FSF version of GNAT.
82 procedure End_Line;
83 -- Add blanks up to column 76, and then a final vertical bar
85 --------------
86 -- End_Line --
87 --------------
89 procedure End_Line is
90 begin
91 Repeat_Char (' ', 76, '|');
92 Write_Eol;
93 end End_Line;
95 -- Start of processing for Compiler_Abort
97 begin
98 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
100 if Abort_In_Progress then
101 Exit_Program (E_Abort);
102 end if;
104 Abort_In_Progress := True;
106 -- If any errors have already occurred, then we guess that the abort
107 -- may well be caused by previous errors, and we don't make too much
108 -- fuss about it, since we want to let programmer fix the errors first.
110 -- Debug flag K disables this behavior (useful for debugging)
112 if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then
113 Errout.Finalize;
115 Set_Standard_Error;
116 Write_Str ("compilation abandoned due to previous error");
117 Write_Eol;
119 Set_Standard_Output;
120 Source_Dump;
121 Tree_Dump;
122 Exit_Program (E_Errors);
124 -- Otherwise give message with details of the abort
126 else
127 Set_Standard_Error;
129 -- Generate header for bug box
131 Write_Char ('+');
132 Repeat_Char ('=', 29, 'G');
133 Write_Str ("NAT BUG DETECTED");
134 Repeat_Char ('=', 76, '+');
135 Write_Eol;
137 -- Output GNAT version identification
139 Write_Str ("| ");
140 Write_Str (Gnat_Version_String);
141 Write_Str (" (");
143 -- Output target name, deleting junk final reverse slash
145 if Target_Name.all (Target_Name.all'Last) = '\'
146 or else Target_Name.all (Target_Name.all'Last) = '/'
147 then
148 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
149 else
150 Write_Str (Target_Name.all);
151 end if;
153 -- Output identification of error
155 Write_Str (") ");
157 if X'Length + Column > 76 then
158 if Code < 0 then
159 Write_Str ("GCC error:");
160 end if;
162 End_Line;
164 Write_Str ("| ");
165 end if;
167 if X'Length > 70 then
168 declare
169 Last_Blank : Integer := 70;
171 begin
172 for P in 40 .. 69 loop
173 if X (P) = ' ' then
174 Last_Blank := P;
175 end if;
176 end loop;
178 Write_Str (X (1 .. Last_Blank));
179 End_Line;
180 Write_Str ("| ");
181 Write_Str (X (Last_Blank + 1 .. X'Length));
182 end;
183 else
184 Write_Str (X);
185 end if;
187 if Code > 0 then
188 Write_Str (", Code=");
189 Write_Int (Int (Code));
191 elsif Code = 0 then
193 -- For exception case, get exception message from the TSD. Note
194 -- that it would be neater and cleaner to pass the exception
195 -- message (obtained from Exception_Message) as a parameter to
196 -- Compiler_Abort, but we can't do this quite yet since it would
197 -- cause bootstrap path problems for 3.10 to 3.11.
199 Write_Char (' ');
200 Write_Str (Exception_Message (Get_Current_Excep.all.all));
201 end if;
203 End_Line;
205 -- Output source location information
207 if Sloc (Current_Error_Node) <= Standard_Location
208 or else Sloc (Current_Error_Node) = No_Location
209 then
210 Write_Str ("| No source file position information available");
211 End_Line;
212 else
213 Write_Str ("| Error detected at ");
214 Write_Location (Sloc (Current_Error_Node));
215 End_Line;
216 end if;
218 -- There are two cases now. If the file gnat_bug.box exists,
219 -- we use the contents of this file at this point.
221 declare
222 Lo : Source_Ptr;
223 Hi : Source_Ptr;
224 Src : Source_Buffer_Ptr;
226 begin
227 Namet.Unlock;
228 Name_Buffer (1 .. 12) := "gnat_bug.box";
229 Name_Len := 12;
230 Read_Source_File (Name_Enter, 0, Hi, Src);
232 -- If we get a Src file, we use it
234 if Src /= null then
235 Lo := 0;
237 Outer : while Lo < Hi loop
238 Write_Str ("| ");
240 Inner : loop
241 exit Inner when Src (Lo) = ASCII.CR
242 or else Src (Lo) = ASCII.LF;
243 Write_Char (Src (Lo));
244 Lo := Lo + 1;
245 end loop Inner;
247 End_Line;
249 while Lo <= Hi
250 and then (Src (Lo) = ASCII.CR
251 or else Src (Lo) = ASCII.LF)
252 loop
253 Lo := Lo + 1;
254 end loop;
255 end loop Outer;
257 -- Otherwise we use the standard fixed text
259 else
260 Write_Str
261 ("| Please submit a bug report; see" &
262 " http://gcc.gnu.org/bugs.html.");
263 End_Line;
265 Write_Str
266 ("| Include the entire contents of this bug " &
267 "box in the report.");
268 End_Line;
270 Write_Str
271 ("| Include the exact gcc or gnatmake command " &
272 "that you entered.");
273 End_Line;
275 Write_Str
276 ("| Also include sources listed below in gnatchop format");
277 End_Line;
279 Write_Str
280 ("| (concatenated together with no headers between files).");
281 End_Line;
283 end if;
284 end;
286 -- Complete output of bug box
288 Write_Char ('+');
289 Repeat_Char ('=', 76, '+');
290 Write_Eol;
292 if Debug_Flag_3 then
293 Write_Eol;
294 Write_Eol;
295 Print_Tree_Node (Current_Error_Node);
296 Write_Eol;
297 end if;
299 Write_Eol;
301 Write_Line ("Please include these source files with error report");
302 Write_Line ("Note that list may not be accurate in some cases, ");
303 Write_Line ("so please double check that the problem can still ");
304 Write_Line ("be reproduced with the set of files listed.");
305 Write_Eol;
307 for U in Main_Unit .. Last_Unit loop
308 begin
309 if not Is_Internal_File_Name
310 (File_Name (Source_Index (U)))
311 then
312 Write_Name (Full_File_Name (Source_Index (U)));
313 Write_Eol;
314 end if;
316 -- No point in double bug box if we blow up trying to print
317 -- the list of file names! Output informative msg and quit.
319 exception
320 when others =>
321 Write_Str ("list may be incomplete");
322 exit;
323 end;
324 end loop;
326 Write_Eol;
327 Set_Standard_Output;
329 Tree_Dump;
330 Source_Dump;
331 raise Unrecoverable_Error;
332 end if;
334 end Compiler_Abort;
336 -----------------
337 -- Repeat_Char --
338 -----------------
340 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
341 begin
342 while Column < Col loop
343 Write_Char (Char);
344 end loop;
346 Write_Char (After);
347 end Repeat_Char;
349 end Comperr;