with Atree; use Atree;
with Debug; use Debug;
with Errout; use Errout;
with Fname; use Fname;
with Gnatvsn; use Gnatvsn;
with Lib; use Lib;
with Namet; use Namet;
with Osint; use Osint;
with Output; use Output;
with Sinput; use Sinput;
with Sprint; use Sprint;
with Sdefault; use Sdefault;
with Treepr; use Treepr;
with Types; use Types;
with Ada.Exceptions; use Ada.Exceptions;
with System.Soft_Links; use System.Soft_Links;
package body Comperr is
Abort_In_Progress : Boolean := False;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character);
procedure Compiler_Abort
(X : String;
Code : Integer := 0)
is
procedure End_Line;
procedure End_Line is
begin
Repeat_Char (' ', 76, '|');
Write_Eol;
end End_Line;
Is_Public_Version : constant Boolean := Get_Gnat_Build_Type = Public;
Is_FSF_Version : constant Boolean := Get_Gnat_Build_Type = FSF;
Is_GAP_Version : constant Boolean := Get_Gnat_Build_Type = GAP;
begin
if Abort_In_Progress then
Exit_Program (E_Abort);
end if;
Abort_In_Progress := True;
if Serious_Errors_Detected /= 0 and then not Debug_Flag_K then
Errout.Finalize;
Set_Standard_Error;
Write_Str ("compilation abandoned due to previous error");
Write_Eol;
Set_Standard_Output;
Source_Dump;
Tree_Dump;
Exit_Program (E_Errors);
else
Set_Standard_Error;
Write_Char ('+');
Repeat_Char ('=', 29, 'G');
Write_Str ("NAT BUG DETECTED");
Repeat_Char ('=', 76, '+');
Write_Eol;
Write_Str ("| ");
Write_Str (Gnat_Version_String);
Write_Str (" (");
if Target_Name.all (Target_Name.all'Last) = '\'
or else Target_Name.all (Target_Name.all'Last) = '/'
then
Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
else
Write_Str (Target_Name.all);
end if;
Write_Str (") ");
if X'Length + Column > 76 then
if Code < 0 then
Write_Str ("GCC error:");
end if;
End_Line;
Write_Str ("| ");
end if;
if X'Length > 70 then
declare
Last_Blank : Integer := 70;
begin
for P in 40 .. 69 loop
if X (P) = ' ' then
Last_Blank := P;
end if;
end loop;
Write_Str (X (1 .. Last_Blank));
End_Line;
Write_Str ("| ");
Write_Str (X (Last_Blank + 1 .. X'Length));
end;
else
Write_Str (X);
end if;
if Code > 0 then
Write_Str (", Code=");
Write_Int (Int (Code));
elsif Code = 0 then
Write_Char (' ');
Write_Str (Exception_Message (Get_Current_Excep.all.all));
end if;
End_Line;
if Sloc (Current_Error_Node) <= Standard_Location
or else Sloc (Current_Error_Node) = No_Location
then
Write_Str ("| No source file position information available");
End_Line;
else
Write_Str ("| Error detected at ");
Write_Location (Sloc (Current_Error_Node));
End_Line;
end if;
declare
Lo : Source_Ptr;
Hi : Source_Ptr;
Src : Source_Buffer_Ptr;
begin
Namet.Unlock;
Name_Buffer (1 .. 12) := "gnat_bug.box";
Name_Len := 12;
Read_Source_File (Name_Enter, 0, Hi, Src);
if Src /= null then
Lo := 0;
Outer : while Lo < Hi loop
Write_Str ("| ");
Inner : loop
exit Inner when Src (Lo) = ASCII.CR
or else Src (Lo) = ASCII.LF;
Write_Char (Src (Lo));
Lo := Lo + 1;
end loop Inner;
End_Line;
while Lo <= Hi
and then (Src (Lo) = ASCII.CR
or else Src (Lo) = ASCII.LF)
loop
Lo := Lo + 1;
end loop;
end loop Outer;
else
if Is_FSF_Version then
Write_Str
("| Please submit a bug report; see" &
" http://gcc.gnu.org/bugs.html.");
End_Line;
else
Write_Str
("| Please submit bug report by email " &
"to report@gnat.com.");
End_Line;
Write_Str
("| Use a subject line meaningful to you" &
" and us to track the bug.");
End_Line;
end if;
if not (Is_Public_Version or Is_FSF_Version) then
Write_Str
("| (include your customer number #nnn " &
"in the subject line).");
End_Line;
end if;
Write_Str
("| Include the entire contents of this bug " &
"box in the report.");
End_Line;
Write_Str
("| Include the exact gcc or gnatmake command " &
"that you entered.");
End_Line;
Write_Str
("| Also include sources listed below in gnatchop format");
End_Line;
Write_Str
("| (concatenated together with no headers between files).");
End_Line;
if Is_Public_Version then
Write_Str
("| (use plain ASCII or MIME attachment).");
End_Line;
Write_Str
("| See gnatinfo.txt for full info on procedure " &
"for submitting bugs.");
End_Line;
elsif Is_GAP_Version then
Write_Str
("| (use plain ASCII or MIME attachment, or FTP "
& "to your GAP account.).");
End_Line;
Write_Str
("| Please use your GAP account to report this.");
End_Line;
elsif not Is_FSF_Version then
Write_Str
("| (use plain ASCII or MIME attachment, or FTP "
& "to your customer directory).");
End_Line;
Write_Str
("| See README.GNATPRO for full info on procedure " &
"for submitting bugs.");
End_Line;
end if;
end if;
end;
Write_Char ('+');
Repeat_Char ('=', 76, '+');
Write_Eol;
if Debug_Flag_3 then
Write_Eol;
Write_Eol;
Print_Tree_Node (Current_Error_Node);
Write_Eol;
end if;
Write_Eol;
Write_Line ("Please include these source files with error report");
Write_Line ("Note that list may not be accurate in some cases, ");
Write_Line ("so please double check that the problem can still ");
Write_Line ("be reproduced with the set of files listed.");
Write_Eol;
for U in Main_Unit .. Last_Unit loop
begin
if not Is_Internal_File_Name
(File_Name (Source_Index (U)))
then
Write_Name (Full_File_Name (Source_Index (U)));
Write_Eol;
end if;
exception
when others =>
Write_Str ("list may be incomplete");
exit;
end;
end loop;
Write_Eol;
Set_Standard_Output;
Tree_Dump;
Source_Dump;
raise Unrecoverable_Error;
end if;
end Compiler_Abort;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
begin
while Column < Col loop
Write_Char (Char);
end loop;
Write_Char (After);
end Repeat_Char;
end Comperr;