1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
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
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).
73 procedure Compiler_Abort
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.
84 -- Add blanks up to column 76, and then a final vertical bar
92 Repeat_Char (' ', 76, '|');
96 Is_Public_Version : constant Boolean := Get_Gnat_Build_Type = Public;
97 Is_FSF_Version : constant Boolean := Get_Gnat_Build_Type = FSF;
99 -- Start of processing for Compiler_Abort
102 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
104 if Abort_In_Progress then
105 Exit_Program (E_Abort);
108 Abort_In_Progress := True;
110 -- If any errors have already occurred, then we guess that the abort
111 -- may well be caused by previous errors, and we don't make too much
112 -- fuss about it, since we want to let programmer fix the errors first.
114 -- Debug flag K disables this behavior (useful for debugging)
116 if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then
120 Write_Str ("compilation abandoned due to previous error");
126 Exit_Program (E_Errors);
128 -- Otherwise give message with details of the abort
133 -- Generate header for bug box
136 Repeat_Char ('=', 29, 'G');
137 Write_Str ("NAT BUG DETECTED");
138 Repeat_Char ('=', 76, '+');
141 -- Output GNAT version identification
144 Write_Str (Gnat_Version_String);
147 -- Output target name, deleting junk final reverse slash
149 if Target_Name.all (Target_Name.all'Last) = '\'
150 or else Target_Name.all (Target_Name.all'Last) = '/'
152 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
154 Write_Str (Target_Name.all);
157 -- Output identification of error
161 if X'Length + Column > 76 then
163 Write_Str ("GCC error:");
171 if X'Length > 70 then
173 Last_Blank : Integer := 70;
176 for P in 40 .. 69 loop
182 Write_Str (X (1 .. Last_Blank));
185 Write_Str (X (Last_Blank + 1 .. X'Length));
192 Write_Str (", Code=");
193 Write_Int (Int (Code));
197 -- For exception case, get exception message from the TSD. Note
198 -- that it would be neater and cleaner to pass the exception
199 -- message (obtained from Exception_Message) as a parameter to
200 -- Compiler_Abort, but we can't do this quite yet since it would
201 -- cause bootstrap path problems for 3.10 to 3.11.
204 Write_Str (Exception_Message (Get_Current_Excep.all.all));
209 -- Output source location information
211 if Sloc (Current_Error_Node) <= Standard_Location
212 or else Sloc (Current_Error_Node) = No_Location
214 Write_Str ("| No source file position information available");
217 Write_Str ("| Error detected at ");
218 Write_Location (Sloc (Current_Error_Node));
222 -- There are two cases now. If the file gnat_bug.box exists,
223 -- we use the contents of this file at this point.
228 Src : Source_Buffer_Ptr;
232 Name_Buffer (1 .. 12) := "gnat_bug.box";
234 Read_Source_File (Name_Enter, 0, Hi, Src);
236 -- If we get a Src file, we use it
241 Outer : while Lo < Hi loop
245 exit Inner when Src (Lo) = ASCII.CR
246 or else Src (Lo) = ASCII.LF;
247 Write_Char (Src (Lo));
254 and then (Src (Lo) = ASCII.CR
255 or else Src (Lo) = ASCII.LF)
261 -- Otherwise we use the standard fixed text
264 if Is_FSF_Version then
266 ("| Please submit a bug report; see" &
267 " http://gcc.gnu.org/bugs.html.");
272 ("| Please submit bug report by email " &
273 "to report@gnat.com.");
277 ("| Use a subject line meaningful to you" &
278 " and us to track the bug.");
282 if not (Is_Public_Version and Is_FSF_Version) then
284 ("| (include your customer number #nnn " &
285 "in the subject line).");
290 ("| Include the entire contents of this bug " &
291 "box in the report.");
295 ("| Include the exact gcc or gnatmake command " &
296 "that you entered.");
300 ("| Also include sources listed below in gnatchop format");
304 ("| (concatenated together with no headers between files).");
307 if Is_Public_Version then
309 ("| (use plain ASCII or MIME attachment).");
313 ("| See gnatinfo.txt for full info on procedure " &
314 "for submitting bugs.");
317 elsif not Is_FSF_Version then
319 ("| (use plain ASCII or MIME attachment, or FTP "
320 & "to your customer directory).");
324 ("| See README.GNATPRO for full info on procedure " &
325 "for submitting bugs.");
331 -- Complete output of bug box
334 Repeat_Char ('=', 76, '+');
340 Print_Tree_Node (Current_Error_Node);
346 Write_Line ("Please include these source files with error report");
347 Write_Line ("Note that list may not be accurate in some cases, ");
348 Write_Line ("so please double check that the problem can still ");
349 Write_Line ("be reproduced with the set of files listed.");
352 for U in Main_Unit .. Last_Unit loop
354 if not Is_Internal_File_Name
355 (File_Name (Source_Index (U)))
357 Write_Name (Full_File_Name (Source_Index (U)));
361 -- No point in double bug box if we blow up trying to print
362 -- the list of file names! Output informative msg and quit.
366 Write_Str ("list may be incomplete");
376 raise Unrecoverable_Error;
385 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
387 while Column < Col loop