1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002 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 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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.
84 -- Add blanks up to column 76, and then a final vertical bar
92 Repeat_Char
(' ', 76, '|');
96 -- Start of processing for Compiler_Abort
99 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
101 if Abort_In_Progress
then
102 Exit_Program
(E_Abort
);
105 Abort_In_Progress
:= True;
107 -- If any errors have already occurred, then we guess that the abort
108 -- may well be caused by previous errors, and we don't make too much
109 -- fuss about it, since we want to let programmer fix the errors first.
111 -- Debug flag K disables this behavior (useful for debugging)
113 if Total_Errors_Detected
/= 0 and then not Debug_Flag_K
then
117 Write_Str
("compilation abandoned due to previous error");
123 Exit_Program
(E_Errors
);
125 -- Otherwise give message with details of the abort
130 -- Generate header for bug box
133 Repeat_Char
('=', 29, 'G');
134 Write_Str
("NAT BUG DETECTED");
135 Repeat_Char
('=', 76, '+');
138 -- Output GNAT version identification
141 Write_Str
(Gnat_Version_String
);
144 -- Output target name, deleting junk final reverse slash
146 if Target_Name
.all (Target_Name
.all'Last) = '\'
147 or else Target_Name
.all (Target_Name
.all'Last) = '/'
149 Write_Str
(Target_Name
.all (1 .. Target_Name
.all'Last - 1));
151 Write_Str
(Target_Name
.all);
154 -- Output identification of error
158 if X
'Length + Column
> 76 then
160 Write_Str
("GCC error:");
168 if X
'Length > 70 then
170 Last_Blank
: Integer := 70;
173 for P
in 40 .. 69 loop
179 Write_Str
(X
(1 .. Last_Blank
));
182 Write_Str
(X
(Last_Blank
+ 1 .. X
'Length));
189 Write_Str
(", Code=");
190 Write_Int
(Int
(Code
));
194 -- For exception case, get exception message from the TSD. Note
195 -- that it would be neater and cleaner to pass the exception
196 -- message (obtained from Exception_Message) as a parameter to
197 -- Compiler_Abort, but we can't do this quite yet since it would
198 -- cause bootstrap path problems for 3.10 to 3.11.
201 Write_Str
(Exception_Message
(Get_Current_Excep
.all.all));
206 -- Output source location information
208 if Sloc
(Current_Error_Node
) <= Standard_Location
209 or else Sloc
(Current_Error_Node
) = No_Location
211 Write_Str
("| No source file position information available");
214 Write_Str
("| Error detected at ");
215 Write_Location
(Sloc
(Current_Error_Node
));
219 -- There are two cases now. If the file gnat_bug.box exists,
220 -- we use the contents of this file at this point.
225 Src
: Source_Buffer_Ptr
;
229 Name_Buffer
(1 .. 12) := "gnat_bug.box";
231 Read_Source_File
(Name_Enter
, 0, Hi
, Src
);
233 -- If we get a Src file, we use it
238 Outer
: while Lo
< Hi
loop
242 exit Inner
when Src
(Lo
) = ASCII
.CR
243 or else Src
(Lo
) = ASCII
.LF
;
244 Write_Char
(Src
(Lo
));
251 and then (Src
(Lo
) = ASCII
.CR
252 or else Src
(Lo
) = ASCII
.LF
)
258 -- Otherwise we use the standard fixed text
262 ("| Please submit a bug report; see" &
263 " http://gcc.gnu.org/bugs.html.");
267 ("| Include the entire contents of this bug " &
268 "box in the report.");
272 ("| Include the exact gcc or gnatmake command " &
273 "that you entered.");
277 ("| Also include sources listed below in gnatchop format");
281 ("| concatenated together with no headers between files.");
287 -- Complete output of bug box
290 Repeat_Char
('=', 76, '+');
296 Print_Tree_Node
(Current_Error_Node
);
302 Write_Line
("Please include these source files with error report");
305 for U
in Main_Unit
.. Last_Unit
loop
307 if not Is_Internal_File_Name
308 (File_Name
(Source_Index
(U
)))
310 Write_Name
(Full_File_Name
(Source_Index
(U
)));
314 -- No point in double bug box if we blow up trying to print
315 -- the list of file names! Output informative msg and quit.
319 Write_Str
("list may be incomplete");
329 raise Unrecoverable_Error
;
338 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character) is
340 while Column
< Col
loop