Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / comperr.adb
blob17258902df2e15562f22bb760cb81b528aff8703
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-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 -- 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, but there are specializations for
81 -- the GNATPRO and Public releases by Ada Core Technologies.
83 procedure End_Line;
84 -- Add blanks up to column 76, and then a final vertical bar
86 --------------
87 -- End_Line --
88 --------------
90 procedure End_Line is
91 begin
92 Repeat_Char (' ', 76, '|');
93 Write_Eol;
94 end End_Line;
96 Is_Public_Version : constant Boolean := Get_Gnat_Build_Type = Public;
97 Is_FSF_Version : constant Boolean := Get_Gnat_Build_Type = FSF;
98 Is_GAP_Version : constant Boolean := Get_Gnat_Build_Type = GAP;
100 -- Start of processing for Compiler_Abort
102 begin
103 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
105 if Abort_In_Progress then
106 Exit_Program (E_Abort);
107 end if;
109 Abort_In_Progress := True;
111 -- If any errors have already occurred, then we guess that the abort
112 -- may well be caused by previous errors, and we don't make too much
113 -- fuss about it, since we want to let programmer fix the errors first.
115 -- Debug flag K disables this behavior (useful for debugging)
117 if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then
118 Errout.Finalize;
120 Set_Standard_Error;
121 Write_Str ("compilation abandoned due to previous error");
122 Write_Eol;
124 Set_Standard_Output;
125 Source_Dump;
126 Tree_Dump;
127 Exit_Program (E_Errors);
129 -- Otherwise give message with details of the abort
131 else
132 Set_Standard_Error;
134 -- Generate header for bug box
136 Write_Char ('+');
137 Repeat_Char ('=', 29, 'G');
138 Write_Str ("NAT BUG DETECTED");
139 Repeat_Char ('=', 76, '+');
140 Write_Eol;
142 -- Output GNAT version identification
144 Write_Str ("| ");
145 Write_Str (Gnat_Version_String);
146 Write_Str (" (");
148 -- Output target name, deleting junk final reverse slash
150 if Target_Name.all (Target_Name.all'Last) = '\'
151 or else Target_Name.all (Target_Name.all'Last) = '/'
152 then
153 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
154 else
155 Write_Str (Target_Name.all);
156 end if;
158 -- Output identification of error
160 Write_Str (") ");
162 if X'Length + Column > 76 then
163 if Code < 0 then
164 Write_Str ("GCC error:");
165 end if;
167 End_Line;
169 Write_Str ("| ");
170 end if;
172 if X'Length > 70 then
173 declare
174 Last_Blank : Integer := 70;
176 begin
177 for P in 40 .. 69 loop
178 if X (P) = ' ' then
179 Last_Blank := P;
180 end if;
181 end loop;
183 Write_Str (X (1 .. Last_Blank));
184 End_Line;
185 Write_Str ("| ");
186 Write_Str (X (Last_Blank + 1 .. X'Length));
187 end;
188 else
189 Write_Str (X);
190 end if;
192 if Code > 0 then
193 Write_Str (", Code=");
194 Write_Int (Int (Code));
196 elsif Code = 0 then
198 -- For exception case, get exception message from the TSD. Note
199 -- that it would be neater and cleaner to pass the exception
200 -- message (obtained from Exception_Message) as a parameter to
201 -- Compiler_Abort, but we can't do this quite yet since it would
202 -- cause bootstrap path problems for 3.10 to 3.11.
204 Write_Char (' ');
205 Write_Str (Exception_Message (Get_Current_Excep.all.all));
206 end if;
208 End_Line;
210 -- Output source location information
212 if Sloc (Current_Error_Node) <= Standard_Location
213 or else Sloc (Current_Error_Node) = No_Location
214 then
215 Write_Str ("| No source file position information available");
216 End_Line;
217 else
218 Write_Str ("| Error detected at ");
219 Write_Location (Sloc (Current_Error_Node));
220 End_Line;
221 end if;
223 -- There are two cases now. If the file gnat_bug.box exists,
224 -- we use the contents of this file at this point.
226 declare
227 Lo : Source_Ptr;
228 Hi : Source_Ptr;
229 Src : Source_Buffer_Ptr;
231 begin
232 Namet.Unlock;
233 Name_Buffer (1 .. 12) := "gnat_bug.box";
234 Name_Len := 12;
235 Read_Source_File (Name_Enter, 0, Hi, Src);
237 -- If we get a Src file, we use it
239 if Src /= null then
240 Lo := 0;
242 Outer : while Lo < Hi loop
243 Write_Str ("| ");
245 Inner : loop
246 exit Inner when Src (Lo) = ASCII.CR
247 or else Src (Lo) = ASCII.LF;
248 Write_Char (Src (Lo));
249 Lo := Lo + 1;
250 end loop Inner;
252 End_Line;
254 while Lo <= Hi
255 and then (Src (Lo) = ASCII.CR
256 or else Src (Lo) = ASCII.LF)
257 loop
258 Lo := Lo + 1;
259 end loop;
260 end loop Outer;
262 -- Otherwise we use the standard fixed text
264 else
265 if Is_FSF_Version then
266 Write_Str
267 ("| Please submit a bug report; see" &
268 " http://gcc.gnu.org/bugs.html.");
269 End_Line;
271 else
272 Write_Str
273 ("| Please submit bug report by email " &
274 "to report@gnat.com.");
275 End_Line;
277 Write_Str
278 ("| Use a subject line meaningful to you" &
279 " and us to track the bug.");
280 End_Line;
281 end if;
283 if not (Is_Public_Version or Is_FSF_Version) then
284 Write_Str
285 ("| (include your customer number #nnn " &
286 "in the subject line).");
287 End_Line;
288 end if;
290 Write_Str
291 ("| Include the entire contents of this bug " &
292 "box in the report.");
293 End_Line;
295 Write_Str
296 ("| Include the exact gcc or gnatmake command " &
297 "that you entered.");
298 End_Line;
300 Write_Str
301 ("| Also include sources listed below in gnatchop format");
302 End_Line;
304 Write_Str
305 ("| (concatenated together with no headers between files).");
306 End_Line;
308 if Is_Public_Version then
309 Write_Str
310 ("| (use plain ASCII or MIME attachment).");
311 End_Line;
313 Write_Str
314 ("| See gnatinfo.txt for full info on procedure " &
315 "for submitting bugs.");
316 End_Line;
318 elsif Is_GAP_Version then
319 Write_Str
320 ("| (use plain ASCII or MIME attachment, or FTP "
321 & "to your GAP account.).");
322 End_Line;
324 Write_Str
325 ("| Please use your GAP account to report this.");
326 End_Line;
328 elsif not Is_FSF_Version then
329 Write_Str
330 ("| (use plain ASCII or MIME attachment, or FTP "
331 & "to your customer directory).");
332 End_Line;
334 Write_Str
335 ("| See README.GNATPRO for full info on procedure " &
336 "for submitting bugs.");
337 End_Line;
338 end if;
339 end if;
340 end;
342 -- Complete output of bug box
344 Write_Char ('+');
345 Repeat_Char ('=', 76, '+');
346 Write_Eol;
348 if Debug_Flag_3 then
349 Write_Eol;
350 Write_Eol;
351 Print_Tree_Node (Current_Error_Node);
352 Write_Eol;
353 end if;
355 Write_Eol;
357 Write_Line ("Please include these source files with error report");
358 Write_Line ("Note that list may not be accurate in some cases, ");
359 Write_Line ("so please double check that the problem can still ");
360 Write_Line ("be reproduced with the set of files listed.");
361 Write_Eol;
363 for U in Main_Unit .. Last_Unit loop
364 begin
365 if not Is_Internal_File_Name
366 (File_Name (Source_Index (U)))
367 then
368 Write_Name (Full_File_Name (Source_Index (U)));
369 Write_Eol;
370 end if;
372 -- No point in double bug box if we blow up trying to print
373 -- the list of file names! Output informative msg and quit.
375 exception
376 when others =>
377 Write_Str ("list may be incomplete");
378 exit;
379 end;
380 end loop;
382 Write_Eol;
383 Set_Standard_Output;
385 Tree_Dump;
386 Source_Dump;
387 raise Unrecoverable_Error;
388 end if;
390 end Compiler_Abort;
392 -----------------
393 -- Repeat_Char --
394 -----------------
396 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
397 begin
398 while Column < Col loop
399 Write_Char (Char);
400 end loop;
402 Write_Char (After);
403 end Repeat_Char;
405 end Comperr;