1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by AdaCore. --
24 ------------------------------------------------------------------------------
26 -- This package contains routines called when a fatal internal compiler
27 -- error is detected. Calls to these routines cause termination of the
28 -- current compilation with appropriate error output.
30 with Atree
; use Atree
;
31 with Debug
; use Debug
;
32 with Errout
; use Errout
;
33 with Gnatvsn
; use Gnatvsn
;
34 with Namet
; use Namet
;
36 with Osint
; use Osint
;
37 with Output
; use Output
;
38 with Sinput
; use Sinput
;
39 with Sprint
; use Sprint
;
40 with Sdefault
; use Sdefault
;
41 with Targparm
; use Targparm
;
42 with Treepr
; use Treepr
;
43 with Types
; use Types
;
45 with Ada
.Exceptions
; use Ada
.Exceptions
;
47 with System
.Soft_Links
; use System
.Soft_Links
;
49 package body Comperr
is
55 Abort_In_Progress
: Boolean := False;
56 -- Used to prevent runaway recursion if something segfaults
57 -- while processing a previous abort.
59 -----------------------
60 -- Local Subprograms --
61 -----------------------
63 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character);
64 -- Output Char until current column is at or past Col, and then output
65 -- the character given by After (if column is already past Col on entry,
66 -- then the effect is simply to output the After character).
72 procedure Compiler_Abort
75 Fallback_Loc
: String := "")
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 AdaCore.
83 XF
: constant Positive := X
'First;
84 -- Start index, usually 1, but we won't assume this
87 -- Add blanks up to column 76, and then a final vertical bar
95 Repeat_Char
(' ', 76, '|');
99 Is_GPL_Version
: constant Boolean := Gnatvsn
.Build_Type
= GPL
;
100 Is_FSF_Version
: constant Boolean := Gnatvsn
.Build_Type
= FSF
;
102 -- Start of processing for Compiler_Abort
105 Cancel_Special_Output
;
107 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV
109 if Abort_In_Progress
then
110 Exit_Program
(E_Abort
);
113 Abort_In_Progress
:= True;
115 -- Generate a "standard" error message instead of a bug box in case of
116 -- .NET compiler, since we do not support all constructs of the
117 -- language. Of course ideally, we should detect this before bombing
118 -- on e.g. an assertion error, but in practice most of these bombs
119 -- are due to a legitimate case of a construct not being supported (in
120 -- a sense they all are, since for sure we are not supporting something
121 -- if we bomb!) By giving this message, we provide a more reasonable
122 -- practical interface, since giving scary bug boxes on unsupported
123 -- features is definitely not helpful.
125 -- Similarly if we are generating SCIL, an error message is sufficient
126 -- instead of generating a bug box.
128 -- Note that the call to Error_Msg_N below sets Serious_Errors_Detected
129 -- to 1, so we use the regular mechanism below in order to display a
130 -- "compilation abandoned" message and exit, so we still know we have
131 -- this case (and -gnatdk can still be used to get the bug box).
133 if (VM_Target
= CLI_Target
or else CodePeer_Mode
)
134 and then Serious_Errors_Detected
= 0
135 and then not Debug_Flag_K
136 and then Sloc
(Current_Error_Node
) > No_Location
138 if VM_Target
= CLI_Target
then
140 ("unsupported construct in this context",
143 Error_Msg_N
("cannot generate 'S'C'I'L", Current_Error_Node
);
147 -- If any errors have already occurred, then we guess that the abort
148 -- may well be caused by previous errors, and we don't make too much
149 -- fuss about it, since we want to let programmer fix the errors first.
151 -- Debug flag K disables this behavior (useful for debugging)
153 if Serious_Errors_Detected
/= 0 and then not Debug_Flag_K
then
154 Errout
.Finalize
(Last_Call
=> True);
155 Errout
.Output_Messages
;
158 Write_Str
("compilation abandoned due to previous error");
164 Exit_Program
(E_Errors
);
166 -- Otherwise give message with details of the abort
171 -- Generate header for bug box
174 Repeat_Char
('=', 29, 'G');
175 Write_Str
("NAT BUG DETECTED");
176 Repeat_Char
('=', 76, '+');
179 -- Output GNAT version identification
182 Write_Str
(Gnat_Version_String
);
185 -- Output target name, deleting junk final reverse slash
187 if Target_Name
.all (Target_Name
.all'Last) = '\'
188 or else Target_Name
.all (Target_Name
.all'Last) = '/'
190 Write_Str
(Target_Name
.all (1 .. Target_Name
.all'Last - 1));
192 Write_Str
(Target_Name
.all);
195 -- Output identification of error
199 if X
'Length + Column
> 76 then
201 Write_Str
("GCC error:");
209 if X
'Length > 70 then
211 Last_Blank
: Integer := 70;
214 for P
in 39 .. 68 loop
215 if X
(XF
+ P
) = ' ' then
220 Write_Str
(X
(XF
.. XF
- 1 + Last_Blank
));
223 Write_Str
(X
(XF
+ Last_Blank
.. X
'Last));
230 Write_Str
(", Code=");
231 Write_Int
(Int
(Code
));
235 -- For exception case, get exception message from the TSD. Note
236 -- that it would be neater and cleaner to pass the exception
237 -- message (obtained from Exception_Message) as a parameter to
238 -- Compiler_Abort, but we can't do this quite yet since it would
239 -- cause bootstrap path problems for 3.10 to 3.11.
242 Write_Str
(Exception_Message
(Get_Current_Excep
.all.all));
247 -- Output source location information
249 if Sloc
(Current_Error_Node
) <= No_Location
then
250 if Fallback_Loc
'Length > 0 then
251 Write_Str
("| Error detected around ");
252 Write_Str
(Fallback_Loc
);
254 Write_Str
("| No source file position information available");
259 Write_Str
("| Error detected at ");
260 Write_Location
(Sloc
(Current_Error_Node
));
264 -- There are two cases now. If the file gnat_bug.box exists,
265 -- we use the contents of this file at this point.
270 Src
: Source_Buffer_Ptr
;
274 Name_Buffer
(1 .. 12) := "gnat_bug.box";
276 Read_Source_File
(Name_Enter
, 0, Hi
, Src
);
278 -- If we get a Src file, we use it
283 Outer
: while Lo
< Hi
loop
287 exit Inner
when Src
(Lo
) = ASCII
.CR
288 or else Src
(Lo
) = ASCII
.LF
;
289 Write_Char
(Src
(Lo
));
296 and then (Src
(Lo
) = ASCII
.CR
297 or else Src
(Lo
) = ASCII
.LF
)
303 -- Otherwise we use the standard fixed text
306 if Is_FSF_Version
then
308 ("| Please submit a bug report; see" &
309 " http://gcc.gnu.org/bugs.html.");
312 elsif Is_GPL_Version
then
315 ("| Please submit a bug report by email " &
316 "to report@adacore.com.");
320 ("| GAP members can alternatively use GNAT Tracker:");
324 ("| http://www.adacore.com/ " &
325 "section 'send a report'.");
329 ("| See gnatinfo.txt for full info on procedure " &
330 "for submitting bugs.");
335 ("| Please submit a bug report using GNAT Tracker:");
339 ("| http://www.adacore.com/gnattracker/ " &
340 "section 'send a report'.");
344 ("| alternatively submit a bug report by email " &
345 "to report@adacore.com,");
349 ("| including your customer number #nnn " &
350 "in the subject line.");
355 ("| Use a subject line meaningful to you" &
356 " and us to track the bug.");
360 ("| Include the entire contents of this bug " &
361 "box in the report.");
365 ("| Include the exact gcc or gnatmake command " &
366 "that you entered.");
370 ("| Also include sources listed below in gnatchop format");
374 ("| (concatenated together with no headers between files).");
377 if not Is_FSF_Version
then
379 ("| Use plain ASCII or MIME attachment.");
385 -- Complete output of bug box
388 Repeat_Char
('=', 76, '+');
394 Print_Tree_Node
(Current_Error_Node
);
400 Write_Line
("Please include these source files with error report");
401 Write_Line
("Note that list may not be accurate in some cases, ");
402 Write_Line
("so please double check that the problem can still ");
403 Write_Line
("be reproduced with the set of files listed.");
404 Write_Line
("Consider also -gnatd.n switch (see debug.adb).");
408 Dump_Source_File_Names
;
410 -- If we blow up trying to print the list of file names, just output
411 -- informative msg and continue.
415 Write_Str
("list may be incomplete");
423 raise Unrecoverable_Error
;
432 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character) is
434 while Column
< Col
loop