1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 error
27 -- is detected. Calls to these routines cause termination of the current
28 -- 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
;
35 with Namet
; use Namet
;
37 with Osint
; use Osint
;
38 with Output
; use Output
;
39 with Sinfo
; use Sinfo
;
40 with Sinput
; use Sinput
;
41 with Sprint
; use Sprint
;
42 with Sdefault
; use Sdefault
;
43 with Treepr
; use Treepr
;
44 with Types
; use Types
;
46 with Ada
.Exceptions
; use Ada
.Exceptions
;
48 with System
.OS_Lib
; use System
.OS_Lib
;
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
76 Fallback_Loc
: String := "";
77 From_GCC
: Boolean := False)
79 -- The procedures below output a "bug box" with information about
80 -- the cause of the compiler abort and about the preferred method
81 -- of reporting bugs. The default is a bug box appropriate for
82 -- the FSF version of GNAT, but there are specializations for
83 -- the GNATPRO and Public releases by AdaCore.
85 XF
: constant Positive := X
'First;
86 -- Start index, usually 1, but we won't assume this
89 -- Add blanks up to column 76, and then a final vertical bar
97 Repeat_Char
(' ', 76, '|');
101 Is_GPL_Version
: constant Boolean := Gnatvsn
.Build_Type
= GPL
;
102 Is_FSF_Version
: constant Boolean := Gnatvsn
.Build_Type
= FSF
;
104 -- Start of processing for Compiler_Abort
107 Cancel_Special_Output
;
109 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV
111 if Abort_In_Progress
then
112 Exit_Program
(E_Abort
);
115 Abort_In_Progress
:= True;
117 -- Generate a "standard" error message instead of a bug box in case
118 -- of CodePeer rather than generating a bug box, friendlier.
120 -- Note that the call to Error_Msg_N below sets Serious_Errors_Detected
121 -- to 1, so we use the regular mechanism below in order to display a
122 -- "compilation abandoned" message and exit, so we still know we have
123 -- this case (and -gnatdk can still be used to get the bug box).
126 and then Serious_Errors_Detected
= 0
127 and then not Debug_Flag_K
128 and then Sloc
(Current_Error_Node
) > No_Location
130 Error_Msg_N
("cannot generate 'S'C'I'L", Current_Error_Node
);
133 -- If we are in CodePeer mode, we must also delete SCIL files
135 if CodePeer_Mode
then
139 -- If any errors have already occurred, then we guess that the abort
140 -- may well be caused by previous errors, and we don't make too much
141 -- fuss about it, since we want to let programmer fix the errors first.
143 -- Debug flag K disables this behavior (useful for debugging)
145 if Serious_Errors_Detected
/= 0 and then not Debug_Flag_K
then
146 Errout
.Finalize
(Last_Call
=> True);
147 Errout
.Output_Messages
;
150 Write_Str
("compilation abandoned due to previous error");
156 Exit_Program
(E_Errors
);
158 -- Otherwise give message with details of the abort
163 -- Generate header for bug box
166 Repeat_Char
('=', 29, 'G');
167 Write_Str
("NAT BUG DETECTED");
168 Repeat_Char
('=', 76, '+');
171 -- Output GNAT version identification
174 Write_Str
(Gnat_Version_String
);
177 -- Output target name, deleting junk final reverse slash
179 if Target_Name
.all (Target_Name
.all'Last) = '\'
180 or else Target_Name
.all (Target_Name
.all'Last) = '/'
182 Write_Str
(Target_Name
.all (1 .. Target_Name
.all'Last - 1));
184 Write_Str
(Target_Name
.all);
187 -- Output identification of error
191 if X
'Length + Column
> 76 then
193 Write_Str
("GCC error:");
201 if X
'Length > 70 then
203 Last_Blank
: Integer := 70;
206 for P
in 39 .. 68 loop
207 if X
(XF
+ P
) = ' ' then
212 Write_Str
(X
(XF
.. XF
- 1 + Last_Blank
));
215 Write_Str
(X
(XF
+ Last_Blank
.. X
'Last));
223 -- For exception case, get exception message from the TSD. Note
224 -- that it would be neater and cleaner to pass the exception
225 -- message (obtained from Exception_Message) as a parameter to
226 -- Compiler_Abort, but we can't do this quite yet since it would
227 -- cause bootstrap path problems for 3.10 to 3.11.
230 Write_Str
(Exception_Message
(Get_Current_Excep
.all.all));
235 -- Output source location information
237 if Sloc
(Current_Error_Node
) <= No_Location
then
238 if Fallback_Loc
'Length > 0 then
239 Write_Str
("| Error detected around ");
240 Write_Str
(Fallback_Loc
);
242 Write_Str
("| No source file position information available");
247 Write_Str
("| Error detected at ");
248 Write_Location
(Sloc
(Current_Error_Node
));
252 -- There are two cases now. If the file gnat_bug.box exists,
253 -- we use the contents of this file at this point.
256 FD
: File_Descriptor
;
259 Src
: Source_Buffer_Ptr
;
263 Name_Buffer
(1 .. 12) := "gnat_bug.box";
265 Read_Source_File
(Name_Enter
, 0, Hi
, Src
, FD
);
267 -- If we get a Src file, we use it
269 if not Null_Source_Buffer_Ptr
(Src
) then
272 Outer
: while Lo
< Hi
loop
276 exit Inner
when Src
(Lo
) = ASCII
.CR
277 or else Src
(Lo
) = ASCII
.LF
;
278 Write_Char
(Src
(Lo
));
285 and then (Src
(Lo
) = ASCII
.CR
286 or else Src
(Lo
) = ASCII
.LF
)
292 -- Otherwise we use the standard fixed text
295 if Is_FSF_Version
then
297 ("| Please submit a bug report; see" &
298 " https://gcc.gnu.org/bugs/ .");
301 elsif Is_GPL_Version
then
304 ("| Please submit a bug report by email " &
305 "to report@adacore.com.");
309 ("| GAP members can alternatively use GNAT Tracker:");
313 ("| http://www.adacore.com/ " &
314 "section 'send a report'.");
318 ("| See gnatinfo.txt for full info on procedure " &
319 "for submitting bugs.");
324 ("| Please submit a bug report using GNAT Tracker:");
328 ("| http://www.adacore.com/gnattracker/ " &
329 "section 'send a report'.");
333 ("| alternatively submit a bug report by email " &
334 "to report@adacore.com,");
338 ("| including your customer number #nnn " &
339 "in the subject line.");
344 ("| Use a subject line meaningful to you" &
345 " and us to track the bug.");
349 ("| Include the entire contents of this bug " &
350 "box in the report.");
354 ("| Include the exact command that you entered.");
358 ("| Also include sources listed below.");
361 if not Is_FSF_Version
then
363 ("| Use plain ASCII or MIME attachment(s).");
369 -- Complete output of bug box
372 Repeat_Char
('=', 76, '+');
378 Print_Tree_Node
(Current_Error_Node
);
384 Write_Line
("Please include these source files with error report");
385 Write_Line
("Note that list may not be accurate in some cases, ");
386 Write_Line
("so please double check that the problem can still ");
387 Write_Line
("be reproduced with the set of files listed.");
388 Write_Line
("Consider also -gnatd.n switch (see debug.adb).");
392 Dump_Source_File_Names
;
394 -- If we blow up trying to print the list of file names, just output
395 -- informative msg and continue.
399 Write_Str
("list may be incomplete");
407 raise Unrecoverable_Error
;
411 -----------------------
412 -- Delete_SCIL_Files --
413 -----------------------
415 procedure Delete_SCIL_Files
is
420 pragma Unreferenced
(Success
);
422 procedure Decode_Name_Buffer
;
423 -- Replace "__" by "." in Name_Buffer, and adjust Name_Len accordingly
425 ------------------------
426 -- Decode_Name_Buffer --
427 ------------------------
429 procedure Decode_Name_Buffer
is
436 while J
<= Name_Len
loop
440 and then Name_Buffer
(J
) = '_'
441 and then Name_Buffer
(J
+ 1) = '_'
443 Name_Buffer
(K
) := '.';
446 Name_Buffer
(K
) := Name_Buffer
(J
);
453 end Decode_Name_Buffer
;
455 -- Start of processing for Delete_SCIL_Files
458 -- If parsing was not successful, no Main_Unit is available, so return
461 if Main_Source_File
<= No_Source_File
then
465 -- Retrieve unit name, and remove old versions of SCIL/<unit>.scil and
466 -- SCIL/<unit>__body.scil, ditto for .scilx files.
468 Main
:= Unit
(Cunit
(Main_Unit
));
471 when N_Package_Declaration
473 | N_Subprogram_Declaration
475 Unit_Name
:= Defining_Unit_Name
(Specification
(Main
));
477 when N_Package_Body
=>
478 Unit_Name
:= Corresponding_Spec
(Main
);
480 when N_Package_Instantiation
481 | N_Package_Renaming_Declaration
483 Unit_Name
:= Defining_Unit_Name
(Main
);
485 -- No SCIL file generated for generic package declarations
487 when N_Generic_Package_Declaration
=>
490 -- Should never happen, but can be ignored in production
493 pragma Assert
(False);
497 case Nkind
(Unit_Name
) is
498 when N_Defining_Identifier
=>
499 Get_Name_String
(Chars
(Unit_Name
));
501 when N_Defining_Program_Unit_Name
=>
502 Get_Name_String
(Chars
(Defining_Identifier
(Unit_Name
)));
505 -- Should never happen, but can be ignored in production
508 pragma Assert
(False);
513 ("SCIL/" & Name_Buffer
(1 .. Name_Len
) & ".scil", Success
);
515 ("SCIL/" & Name_Buffer
(1 .. Name_Len
) & ".scilx", Success
);
517 ("SCIL/" & Name_Buffer
(1 .. Name_Len
) & "__body.scil", Success
);
519 ("SCIL/" & Name_Buffer
(1 .. Name_Len
) & "__body.scilx", Success
);
520 end Delete_SCIL_Files
;
526 procedure Repeat_Char
(Char
: Character; Col
: Nat
; After
: Character) is
528 while Column
< Col
loop