1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This package contains routines called when a fatal internal compiler
30 -- error is detected. Calls to these routines cause termination of the
31 -- current compilation with appropriate error output.
33 with Atree; use Atree;
34 with Debug; use Debug;
35 with Errout; use Errout;
36 with Fname; use Fname;
37 with Gnatvsn; use Gnatvsn;
39 with Namet; use Namet;
40 with Osint; use Osint;
41 with Output; use Output;
42 with Sinput; use Sinput;
43 with Sprint; use Sprint;
44 with Sdefault; use Sdefault;
45 with Treepr; use Treepr;
46 with Types; use Types;
48 with Ada.Exceptions; use Ada.Exceptions;
50 with System.Soft_Links; use System.Soft_Links;
52 package body Comperr is
54 -----------------------
55 -- Local Subprograms --
56 -----------------------
58 procedure Repeat_Char (Char : Character; Col : Nat; After : Character);
59 -- Output Char until current column is at or past Col, and then output
60 -- the character given by After (if column is already past Col on entry,
61 -- then the effect is simply to output the After character).
67 procedure Compiler_Abort
72 -- Add blanks up to column 76, and then a final vertical bar
76 Repeat_Char (' ', 76, '|');
80 Public_Version : constant Boolean := (Gnat_Version_String (5) = 'p');
82 -- Start of processing for Compiler_Abort
85 -- If errors have already occured, then we guess that the abort may
86 -- well be caused by previous errors, and we don't make too much fuss
87 -- about it, since we want to let the programmer fix the errors first.
89 -- Debug flag K disables this behavior (useful for debugging)
91 if Errors_Detected /= 0 and then not Debug_Flag_K then
95 Write_Str ("compilation abandoned due to previous error");
101 Exit_Program (E_Errors);
103 -- Otherwise give message with details of the abort
108 -- Generate header for bug box
111 Repeat_Char ('=', 29, 'G');
112 Write_Str ("NAT BUG DETECTED");
113 Repeat_Char ('=', 76, '+');
116 -- Output GNAT version identification
119 Write_Str (Gnat_Version_String);
122 -- Output target name, deleting junk final reverse slash
124 if Target_Name.all (Target_Name.all'Last) = '\'
125 or else Target_Name.all (Target_Name.all'Last) = '/'
127 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
129 Write_Str (Target_Name.all);
132 -- Output identification of error
136 if X'Length + Column > 76 then
138 Write_Str ("GCC error:");
146 if X'Length > 70 then
148 Last_Blank : Integer := 70;
151 for P in 40 .. 69 loop
157 Write_Str (X (1 .. Last_Blank));
160 Write_Str (X (Last_Blank + 1 .. X'Length));
167 Write_Str (", Code=");
168 Write_Int (Int (Code));
172 -- For exception case, get exception message from the TSD. Note
173 -- that it would be neater and cleaner to pass the exception
174 -- message (obtained from Exception_Message) as a parameter to
175 -- Compiler_Abort, but we can't do this quite yet since it would
176 -- cause bootstrap path problems for 3.10 to 3.11.
179 Write_Str (Exception_Message (Get_Current_Excep.all.all));
184 -- Output source location information
186 if Sloc (Current_Error_Node) <= Standard_Location
187 or else Sloc (Current_Error_Node) = No_Location
189 Write_Str ("| No source file position information available");
192 Write_Str ("| Error detected at ");
193 Write_Location (Sloc (Current_Error_Node));
197 -- There are two cases now. If the file gnat_bug.box exists,
198 -- we use the contents of this file at this point.
203 Src : Source_Buffer_Ptr;
207 Name_Buffer (1 .. 12) := "gnat_bug.box";
209 Read_Source_File (Name_Enter, 0, Hi, Src);
211 -- If we get a Src file, we use it
216 Outer : while Lo < Hi loop
220 exit Inner when Src (Lo) = ASCII.CR
221 or else Src (Lo) = ASCII.LF;
222 Write_Char (Src (Lo));
229 and then (Src (Lo) = ASCII.CR
230 or else Src (Lo) = ASCII.LF)
236 -- Otherwise we use the standard fixed text
240 ("| Please submit bug report by email to report@gnat.com.");
243 if not Public_Version then
245 ("| Use a subject line meaningful to you" &
246 " and us to track the bug.");
250 ("| (include your customer number #nnn " &
251 "in the subject line).");
256 ("| Include the entire contents of this bug " &
257 "box in the report.");
261 ("| Include the exact gcc or gnatmake command " &
262 "that you entered.");
266 ("| Also include sources listed below in gnatchop format");
270 ("| (concatenated together with no headers between files).");
273 if Public_Version then
275 ("| (use plain ASCII or MIME attachment).");
279 ("| See gnatinfo.txt for full info on procedure " &
280 "for submitting bugs.");
285 ("| (use plain ASCII or MIME attachment, or FTP "
286 & "to your customer directory).");
290 ("| See README.GNATPRO for full info on procedure " &
291 "for submitting bugs.");
297 -- Complete output of bug box
300 Repeat_Char ('=', 76, '+');
306 Print_Tree_Node (Current_Error_Node);
312 Write_Line ("Please include these source files with error report");
315 for U in Main_Unit .. Last_Unit loop
317 if not Is_Internal_File_Name
318 (File_Name (Source_Index (U)))
320 Write_Name (Full_File_Name (Source_Index (U)));
324 -- No point in double bug box if we blow up trying to print
325 -- the list of file names! Output informative msg and quit.
329 Write_Str ("list may be incomplete");
339 raise Unrecoverable_Error;
348 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
350 while Column < Col loop