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
58 Abort_In_Progress
: Boolean := False;
59 -- Used to prevent runaway recursion if something segfaults
60 -- while processing a previous abort.
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character);
67 -- Output Char until current column is at or past Col, and then output
68 -- the character given by After (if column is already past Col on entry,
69 -- then the effect is simply to output the After character).
75 procedure Compiler_Abort
80 -- Add blanks up to column 76, and then a final vertical bar
84 Repeat_Char
(' ', 76, '|');
88 Public_Version
: constant Boolean := (Gnat_Version_String
(5) = 'p');
90 -- Start of processing for Compiler_Abort
93 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
95 if Abort_In_Progress
then
96 Exit_Program
(E_Abort
);
99 Abort_In_Progress
:= True;
101 -- If errors have already occured, then we guess that the abort may
102 -- well be caused by previous errors, and we don't make too much fuss
103 -- about it, since we want to let the programmer fix the errors first.
105 -- Debug flag K disables this behavior (useful for debugging)
107 if Errors_Detected
/= 0 and then not Debug_Flag_K
then
111 Write_Str
("compilation abandoned due to previous error");
117 Exit_Program
(E_Errors
);
119 -- Otherwise give message with details of the abort
124 -- Generate header for bug box
127 Repeat_Char
('=', 29, 'G');
128 Write_Str
("NAT BUG DETECTED");
129 Repeat_Char
('=', 76, '+');
132 -- Output GNAT version identification
135 Write_Str
(Gnat_Version_String
);
138 -- Output target name, deleting junk final reverse slash
140 if Target_Name
.all (Target_Name
.all'Last) = '\'
141 or else Target_Name
.all (Target_Name
.all'Last) = '/'
143 Write_Str
(Target_Name
.all (1 .. Target_Name
.all'Last - 1));
145 Write_Str
(Target_Name
.all);
148 -- Output identification of error
152 if X
'Length + Column
> 76 then
154 Write_Str
("GCC error:");
162 if X
'Length > 70 then
164 Last_Blank
: Integer := 70;
167 for P
in 40 .. 69 loop
173 Write_Str
(X
(1 .. Last_Blank
));
176 Write_Str
(X
(Last_Blank
+ 1 .. X
'Length));
183 Write_Str
(", Code=");
184 Write_Int
(Int
(Code
));
188 -- For exception case, get exception message from the TSD. Note
189 -- that it would be neater and cleaner to pass the exception
190 -- message (obtained from Exception_Message) as a parameter to
191 -- Compiler_Abort, but we can't do this quite yet since it would
192 -- cause bootstrap path problems for 3.10 to 3.11.
195 Write_Str
(Exception_Message
(Get_Current_Excep
.all.all));
200 -- Output source location information
202 if Sloc
(Current_Error_Node
) <= Standard_Location
203 or else Sloc
(Current_Error_Node
) = No_Location
205 Write_Str
("| No source file position information available");
208 Write_Str
("| Error detected at ");
209 Write_Location
(Sloc
(Current_Error_Node
));
213 -- There are two cases now. If the file gnat_bug.box exists,
214 -- we use the contents of this file at this point.
219 Src
: Source_Buffer_Ptr
;
223 Name_Buffer
(1 .. 12) := "gnat_bug.box";
225 Read_Source_File
(Name_Enter
, 0, Hi
, Src
);
227 -- If we get a Src file, we use it
232 Outer
: while Lo
< Hi
loop
236 exit Inner
when Src
(Lo
) = ASCII
.CR
237 or else Src
(Lo
) = ASCII
.LF
;
238 Write_Char
(Src
(Lo
));
245 and then (Src
(Lo
) = ASCII
.CR
246 or else Src
(Lo
) = ASCII
.LF
)
252 -- Otherwise we use the standard fixed text
256 ("| Please submit bug report by email to report@gnat.com.");
259 if not Public_Version
then
261 ("| Use a subject line meaningful to you" &
262 " and us to track the bug.");
266 ("| (include your customer number #nnn " &
267 "in the subject line).");
272 ("| Include the entire contents of this bug " &
273 "box in the report.");
277 ("| Include the exact gcc or gnatmake command " &
278 "that you entered.");
282 ("| Also include sources listed below in gnatchop format");
286 ("| (concatenated together with no headers between files).");
289 if Public_Version
then
291 ("| (use plain ASCII or MIME attachment).");
295 ("| See gnatinfo.txt for full info on procedure " &
296 "for submitting bugs.");
301 ("| (use plain ASCII or MIME attachment, or FTP "
302 & "to your customer directory).");
306 ("| See README.GNATPRO for full info on procedure " &
307 "for submitting bugs.");
313 -- Complete output of bug box
316 Repeat_Char
('=', 76, '+');
322 Print_Tree_Node
(Current_Error_Node
);
328 Write_Line
("Please include these source files with error report");
331 for U
in Main_Unit
.. Last_Unit
loop
333 if not Is_Internal_File_Name
334 (File_Name
(Source_Index
(U
)))
336 Write_Name
(Full_File_Name
(Source_Index
(U
)));
340 -- No point in double bug box if we blow up trying to print
341 -- the list of file names! Output informative msg and quit.
345 Write_Str
("list may be incomplete");
355 raise Unrecoverable_Error
;
364 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character) is
366 while Column
< Col
loop