gcc:
[official-gcc.git] / gcc / ada / comperr.adb
blob648c4b1e059b7ac6d10b63f68006ea16d2de0259
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-2006, 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 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by AdaCore. --
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, but there are specializations for
81 -- the GNATPRO and Public releases by AdaCore.
83 XF : constant Positive := X'First;
84 -- Start index, usually 1, but we won't assume this
86 procedure End_Line;
87 -- Add blanks up to column 76, and then a final vertical bar
89 --------------
90 -- End_Line --
91 --------------
93 procedure End_Line is
94 begin
95 Repeat_Char (' ', 76, '|');
96 Write_Eol;
97 end End_Line;
99 Is_GPL_Version : constant Boolean := Get_Gnat_Build_Type = GPL;
100 Is_FSF_Version : constant Boolean := Get_Gnat_Build_Type = FSF;
102 -- Start of processing for Compiler_Abort
104 begin
105 Cancel_Special_Output;
107 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV
109 if Abort_In_Progress then
110 Exit_Program (E_Abort);
111 end if;
113 Abort_In_Progress := True;
115 -- If any errors have already occurred, then we guess that the abort
116 -- may well be caused by previous errors, and we don't make too much
117 -- fuss about it, since we want to let programmer fix the errors first.
119 -- Debug flag K disables this behavior (useful for debugging)
121 if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then
122 Errout.Finalize;
124 Set_Standard_Error;
125 Write_Str ("compilation abandoned due to previous error");
126 Write_Eol;
128 Set_Standard_Output;
129 Source_Dump;
130 Tree_Dump;
131 Exit_Program (E_Errors);
133 -- Otherwise give message with details of the abort
135 else
136 Set_Standard_Error;
138 -- Generate header for bug box
140 Write_Char ('+');
141 Repeat_Char ('=', 29, 'G');
142 Write_Str ("NAT BUG DETECTED");
143 Repeat_Char ('=', 76, '+');
144 Write_Eol;
146 -- Output GNAT version identification
148 Write_Str ("| ");
149 Write_Str (Gnat_Version_String);
150 Write_Str (" (");
152 -- Output target name, deleting junk final reverse slash
154 if Target_Name.all (Target_Name.all'Last) = '\'
155 or else Target_Name.all (Target_Name.all'Last) = '/'
156 then
157 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
158 else
159 Write_Str (Target_Name.all);
160 end if;
162 -- Output identification of error
164 Write_Str (") ");
166 if X'Length + Column > 76 then
167 if Code < 0 then
168 Write_Str ("GCC error:");
169 end if;
171 End_Line;
173 Write_Str ("| ");
174 end if;
176 if X'Length > 70 then
177 declare
178 Last_Blank : Integer := 70;
180 begin
181 for P in 39 .. 68 loop
182 if X (XF + P) = ' ' then
183 Last_Blank := P;
184 end if;
185 end loop;
187 Write_Str (X (XF .. XF - 1 + Last_Blank));
188 End_Line;
189 Write_Str ("| ");
190 Write_Str (X (XF + Last_Blank .. X'Last));
191 end;
192 else
193 Write_Str (X);
194 end if;
196 if Code > 0 then
197 Write_Str (", Code=");
198 Write_Int (Int (Code));
200 elsif Code = 0 then
202 -- For exception case, get exception message from the TSD. Note
203 -- that it would be neater and cleaner to pass the exception
204 -- message (obtained from Exception_Message) as a parameter to
205 -- Compiler_Abort, but we can't do this quite yet since it would
206 -- cause bootstrap path problems for 3.10 to 3.11.
208 Write_Char (' ');
209 Write_Str (Exception_Message (Get_Current_Excep.all.all));
210 end if;
212 End_Line;
214 -- Output source location information
216 if Sloc (Current_Error_Node) <= Standard_Location
217 or else Sloc (Current_Error_Node) = No_Location
218 then
219 Write_Str ("| No source file position information available");
220 End_Line;
221 else
222 Write_Str ("| Error detected at ");
223 Write_Location (Sloc (Current_Error_Node));
224 End_Line;
225 end if;
227 -- There are two cases now. If the file gnat_bug.box exists,
228 -- we use the contents of this file at this point.
230 declare
231 Lo : Source_Ptr;
232 Hi : Source_Ptr;
233 Src : Source_Buffer_Ptr;
235 begin
236 Namet.Unlock;
237 Name_Buffer (1 .. 12) := "gnat_bug.box";
238 Name_Len := 12;
239 Read_Source_File (Name_Enter, 0, Hi, Src);
241 -- If we get a Src file, we use it
243 if Src /= null then
244 Lo := 0;
246 Outer : while Lo < Hi loop
247 Write_Str ("| ");
249 Inner : loop
250 exit Inner when Src (Lo) = ASCII.CR
251 or else Src (Lo) = ASCII.LF;
252 Write_Char (Src (Lo));
253 Lo := Lo + 1;
254 end loop Inner;
256 End_Line;
258 while Lo <= Hi
259 and then (Src (Lo) = ASCII.CR
260 or else Src (Lo) = ASCII.LF)
261 loop
262 Lo := Lo + 1;
263 end loop;
264 end loop Outer;
266 -- Otherwise we use the standard fixed text
268 else
269 if Is_FSF_Version then
270 Write_Str
271 ("| Please submit a bug report; see" &
272 " http://gcc.gnu.org/bugs.html.");
273 End_Line;
275 elsif Is_GPL_Version then
277 Write_Str
278 ("| Please submit a bug report by email " &
279 "to report@adacore.com.");
280 End_Line;
282 Write_Str
283 ("| GAP members can alternatively use GNAT Tracker:");
284 End_Line;
286 Write_Str
287 ("| http://www.adacore.com/ " &
288 "section 'send a report'.");
289 End_Line;
291 Write_Str
292 ("| See gnatinfo.txt for full info on procedure " &
293 "for submitting bugs.");
294 End_Line;
296 else
297 Write_Str
298 ("| Please submit a bug report using GNAT Tracker:");
299 End_Line;
301 Write_Str
302 ("| http://www.adacore.com/gnattracker/ " &
303 "section 'send a report'.");
304 End_Line;
306 Write_Str
307 ("| alternatively submit a bug report by email " &
308 "to report@adacore.com,");
309 End_Line;
311 Write_Str
312 ("| including your customer number #nnn " &
313 "in the subject line.");
314 End_Line;
315 end if;
317 Write_Str
318 ("| Use a subject line meaningful to you" &
319 " and us to track the bug.");
320 End_Line;
322 Write_Str
323 ("| Include the entire contents of this bug " &
324 "box in the report.");
325 End_Line;
327 Write_Str
328 ("| Include the exact gcc or gnatmake command " &
329 "that you entered.");
330 End_Line;
332 Write_Str
333 ("| Also include sources listed below in gnatchop format");
334 End_Line;
336 Write_Str
337 ("| (concatenated together with no headers between files).");
338 End_Line;
340 if not Is_FSF_Version then
341 Write_Str
342 ("| Use plain ASCII or MIME attachment.");
343 End_Line;
344 end if;
345 end if;
346 end;
348 -- Complete output of bug box
350 Write_Char ('+');
351 Repeat_Char ('=', 76, '+');
352 Write_Eol;
354 if Debug_Flag_3 then
355 Write_Eol;
356 Write_Eol;
357 Print_Tree_Node (Current_Error_Node);
358 Write_Eol;
359 end if;
361 Write_Eol;
363 Write_Line ("Please include these source files with error report");
364 Write_Line ("Note that list may not be accurate in some cases, ");
365 Write_Line ("so please double check that the problem can still ");
366 Write_Line ("be reproduced with the set of files listed.");
367 Write_Eol;
369 for U in Main_Unit .. Last_Unit loop
370 begin
371 if not Is_Internal_File_Name
372 (File_Name (Source_Index (U)))
373 then
374 Write_Name (Full_File_Name (Source_Index (U)));
375 Write_Eol;
376 end if;
378 -- No point in double bug box if we blow up trying to print
379 -- the list of file names! Output informative msg and quit.
381 exception
382 when others =>
383 Write_Str ("list may be incomplete");
384 exit;
385 end;
386 end loop;
388 Write_Eol;
389 Set_Standard_Output;
391 Tree_Dump;
392 Source_Dump;
393 raise Unrecoverable_Error;
394 end if;
396 end Compiler_Abort;
398 -----------------
399 -- Repeat_Char --
400 -----------------
402 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
403 begin
404 while Column < Col loop
405 Write_Char (Char);
406 end loop;
408 Write_Char (After);
409 end Repeat_Char;
411 end Comperr;