1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
28 -- This package contains routines called when a fatal internal compiler
29 -- error is detected. Calls to these routines cause termination of the
30 -- current compilation with appropriate error output.
32 with Atree
; use Atree
;
33 with Debug
; use Debug
;
34 with Errout
; use Errout
;
35 with Fname
; use Fname
;
36 with Gnatvsn
; use Gnatvsn
;
38 with Namet
; use Namet
;
39 with Osint
; use Osint
;
40 with Output
; use Output
;
41 with Sinput
; use Sinput
;
42 with Sprint
; use Sprint
;
43 with Sdefault
; use Sdefault
;
44 with Treepr
; use Treepr
;
45 with Types
; use Types
;
47 with Ada
.Exceptions
; use Ada
.Exceptions
;
49 with System
.Soft_Links
; use System
.Soft_Links
;
51 package body Comperr
is
57 Abort_In_Progress
: Boolean := False;
58 -- Used to prevent runaway recursion if something segfaults
59 -- while processing a previous abort.
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character);
66 -- Output Char until current column is at or past Col, and then output
67 -- the character given by After (if column is already past Col on entry,
68 -- then the effect is simply to output the After character).
74 procedure Compiler_Abort
78 -- The procedures below output a "bug box" with information about
79 -- the cause of the compiler abort and about the preferred method
80 -- of reporting bugs. The default is a bug box appropriate for
81 -- the FSF version of GNAT, but there are specializations for
82 -- the GNATPRO and Public releases by Ada Core Technologies.
84 Public_Version
: constant Boolean := Gnat_Version_Type
= "PUBLIC ";
85 -- Set True for the public version of GNAT
87 GNATPRO_Version
: constant Boolean := Gnat_Version_Type
= "GNATPRO";
88 -- Set True for the GNATPRO version of GNAT
91 -- Add blanks up to column 76, and then a final vertical bar
99 Repeat_Char
(' ', 76, '|');
103 -- Start of processing for Compiler_Abort
106 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
108 if Abort_In_Progress
then
109 Exit_Program
(E_Abort
);
112 Abort_In_Progress
:= True;
114 -- If any errors have already occurred, then we guess that the abort
115 -- may well be caused by previous errors, and we don't make too much
116 -- fuss about it, since we want to let programmer fix the errors first.
118 -- Debug flag K disables this behavior (useful for debugging)
120 if Total_Errors_Detected
/= 0 and then not Debug_Flag_K
then
124 Write_Str
("compilation abandoned due to previous error");
130 Exit_Program
(E_Errors
);
132 -- Otherwise give message with details of the abort
137 -- Generate header for bug box
140 Repeat_Char
('=', 29, 'G');
141 Write_Str
("NAT BUG DETECTED");
142 Repeat_Char
('=', 76, '+');
145 -- Output GNAT version identification
148 Write_Str
(Gnat_Version_String
);
151 -- Output target name, deleting junk final reverse slash
153 if Target_Name
.all (Target_Name
.all'Last) = '\'
154 or else Target_Name
.all (Target_Name
.all'Last) = '/'
156 Write_Str
(Target_Name
.all (1 .. Target_Name
.all'Last - 1));
158 Write_Str
(Target_Name
.all);
161 -- Output identification of error
165 if X
'Length + Column
> 76 then
167 Write_Str
("GCC error:");
175 if X
'Length > 70 then
177 Last_Blank
: Integer := 70;
180 for P
in 40 .. 69 loop
186 Write_Str
(X
(1 .. Last_Blank
));
189 Write_Str
(X
(Last_Blank
+ 1 .. X
'Length));
196 Write_Str
(", Code=");
197 Write_Int
(Int
(Code
));
201 -- For exception case, get exception message from the TSD. Note
202 -- that it would be neater and cleaner to pass the exception
203 -- message (obtained from Exception_Message) as a parameter to
204 -- Compiler_Abort, but we can't do this quite yet since it would
205 -- cause bootstrap path problems for 3.10 to 3.11.
208 Write_Str
(Exception_Message
(Get_Current_Excep
.all.all));
213 -- Output source location information
215 if Sloc
(Current_Error_Node
) <= Standard_Location
216 or else Sloc
(Current_Error_Node
) = No_Location
218 Write_Str
("| No source file position information available");
221 Write_Str
("| Error detected at ");
222 Write_Location
(Sloc
(Current_Error_Node
));
226 -- There are two cases now. If the file gnat_bug.box exists,
227 -- we use the contents of this file at this point.
232 Src
: Source_Buffer_Ptr
;
236 Name_Buffer
(1 .. 12) := "gnat_bug.box";
238 Read_Source_File
(Name_Enter
, 0, Hi
, Src
);
240 -- If we get a Src file, we use it
245 Outer
: while Lo
< Hi
loop
249 exit Inner
when Src
(Lo
) = ASCII
.CR
250 or else Src
(Lo
) = ASCII
.LF
;
251 Write_Char
(Src
(Lo
));
258 and then (Src
(Lo
) = ASCII
.CR
259 or else Src
(Lo
) = ASCII
.LF
)
265 -- Otherwise we use the standard fixed text
268 if Public_Version
or GNATPRO_Version
then
270 ("| Please submit bug report by email " &
271 "to report@gnat.com.");
276 ("| Please submit bug report by email " &
277 "to gcc-bugs@gcc.gnu.org.");
282 ("| Use a subject line meaningful to you" &
283 " and us to track the bug.");
286 if GNATPRO_Version
then
288 ("| (include your customer number #nnn " &
289 "in the subject line).");
294 ("| Include the entire contents of this bug " &
295 "box in the report.");
299 ("| Include the exact gcc or gnatmake command " &
300 "that you entered.");
304 ("| Also include sources listed below in gnatchop format");
308 ("| (concatenated together with no headers between files).");
311 if not GNATPRO_Version
then
313 ("| (use plain ASCII or MIME attachment).");
317 ("| See gnatinfo.txt for full info on procedure " &
318 "for submitting bugs.");
323 ("| (use plain ASCII or MIME attachment, or FTP "
324 & "to your customer directory).");
328 ("| See README.GNATPRO for full info on procedure " &
329 "for submitting bugs.");
335 -- Complete output of bug box
338 Repeat_Char
('=', 76, '+');
344 Print_Tree_Node
(Current_Error_Node
);
350 Write_Line
("Please include these source files with error report");
353 for U
in Main_Unit
.. Last_Unit
loop
355 if not Is_Internal_File_Name
356 (File_Name
(Source_Index
(U
)))
358 Write_Name
(Full_File_Name
(Source_Index
(U
)));
362 -- No point in double bug box if we blow up trying to print
363 -- the list of file names! Output informative msg and quit.
367 Write_Str
("list may be incomplete");
377 raise Unrecoverable_Error
;
386 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character) is
388 while Column
< Col
loop