Add hppa-openbsd target
[official-gcc.git] / gcc / ada / comperr.adb
blob2f96b44b4f4794aa05df05929cfc37f816da8c4d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C O M P E R R --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
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). --
25 -- --
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;
37 with Lib; use Lib;
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
53 ----------------
54 -- Local Data --
55 ----------------
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).
70 --------------------
71 -- Compiler_Abort --
72 --------------------
74 procedure Compiler_Abort
75 (X : String;
76 Code : Integer := 0)
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
90 procedure End_Line;
91 -- Add blanks up to column 76, and then a final vertical bar
93 --------------
94 -- End_Line --
95 --------------
97 procedure End_Line is
98 begin
99 Repeat_Char (' ', 76, '|');
100 Write_Eol;
101 end End_Line;
103 -- Start of processing for Compiler_Abort
105 begin
106 -- Prevent recursion through Compiler_Abort, e.g. via SIGSEGV.
108 if Abort_In_Progress then
109 Exit_Program (E_Abort);
110 end if;
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
121 Errout.Finalize;
123 Set_Standard_Error;
124 Write_Str ("compilation abandoned due to previous error");
125 Write_Eol;
127 Set_Standard_Output;
128 Source_Dump;
129 Tree_Dump;
130 Exit_Program (E_Errors);
132 -- Otherwise give message with details of the abort
134 else
135 Set_Standard_Error;
137 -- Generate header for bug box
139 Write_Char ('+');
140 Repeat_Char ('=', 29, 'G');
141 Write_Str ("NAT BUG DETECTED");
142 Repeat_Char ('=', 76, '+');
143 Write_Eol;
145 -- Output GNAT version identification
147 Write_Str ("| ");
148 Write_Str (Gnat_Version_String);
149 Write_Str (" (");
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) = '/'
155 then
156 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
157 else
158 Write_Str (Target_Name.all);
159 end if;
161 -- Output identification of error
163 Write_Str (") ");
165 if X'Length + Column > 76 then
166 if Code < 0 then
167 Write_Str ("GCC error:");
168 end if;
170 End_Line;
172 Write_Str ("| ");
173 end if;
175 if X'Length > 70 then
176 declare
177 Last_Blank : Integer := 70;
179 begin
180 for P in 40 .. 69 loop
181 if X (P) = ' ' then
182 Last_Blank := P;
183 end if;
184 end loop;
186 Write_Str (X (1 .. Last_Blank));
187 End_Line;
188 Write_Str ("| ");
189 Write_Str (X (Last_Blank + 1 .. X'Length));
190 end;
191 else
192 Write_Str (X);
193 end if;
195 if Code > 0 then
196 Write_Str (", Code=");
197 Write_Int (Int (Code));
199 elsif Code = 0 then
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.
207 Write_Char (' ');
208 Write_Str (Exception_Message (Get_Current_Excep.all.all));
209 end if;
211 End_Line;
213 -- Output source location information
215 if Sloc (Current_Error_Node) <= Standard_Location
216 or else Sloc (Current_Error_Node) = No_Location
217 then
218 Write_Str ("| No source file position information available");
219 End_Line;
220 else
221 Write_Str ("| Error detected at ");
222 Write_Location (Sloc (Current_Error_Node));
223 End_Line;
224 end if;
226 -- There are two cases now. If the file gnat_bug.box exists,
227 -- we use the contents of this file at this point.
229 declare
230 Lo : Source_Ptr;
231 Hi : Source_Ptr;
232 Src : Source_Buffer_Ptr;
234 begin
235 Namet.Unlock;
236 Name_Buffer (1 .. 12) := "gnat_bug.box";
237 Name_Len := 12;
238 Read_Source_File (Name_Enter, 0, Hi, Src);
240 -- If we get a Src file, we use it
242 if Src /= null then
243 Lo := 0;
245 Outer : while Lo < Hi loop
246 Write_Str ("| ");
248 Inner : loop
249 exit Inner when Src (Lo) = ASCII.CR
250 or else Src (Lo) = ASCII.LF;
251 Write_Char (Src (Lo));
252 Lo := Lo + 1;
253 end loop Inner;
255 End_Line;
257 while Lo <= Hi
258 and then (Src (Lo) = ASCII.CR
259 or else Src (Lo) = ASCII.LF)
260 loop
261 Lo := Lo + 1;
262 end loop;
263 end loop Outer;
265 -- Otherwise we use the standard fixed text
267 else
268 if Public_Version or GNATPRO_Version then
269 Write_Str
270 ("| Please submit bug report by email " &
271 "to report@gnat.com.");
272 End_Line;
274 else
275 Write_Str
276 ("| Please submit bug report by email " &
277 "to gcc-bugs@gcc.gnu.org.");
278 End_Line;
279 end if;
281 Write_Str
282 ("| Use a subject line meaningful to you" &
283 " and us to track the bug.");
284 End_Line;
286 if GNATPRO_Version then
287 Write_Str
288 ("| (include your customer number #nnn " &
289 "in the subject line).");
290 End_Line;
291 end if;
293 Write_Str
294 ("| Include the entire contents of this bug " &
295 "box in the report.");
296 End_Line;
298 Write_Str
299 ("| Include the exact gcc or gnatmake command " &
300 "that you entered.");
301 End_Line;
303 Write_Str
304 ("| Also include sources listed below in gnatchop format");
305 End_Line;
307 Write_Str
308 ("| (concatenated together with no headers between files).");
309 End_Line;
311 if not GNATPRO_Version then
312 Write_Str
313 ("| (use plain ASCII or MIME attachment).");
314 End_Line;
316 Write_Str
317 ("| See gnatinfo.txt for full info on procedure " &
318 "for submitting bugs.");
319 End_Line;
321 else
322 Write_Str
323 ("| (use plain ASCII or MIME attachment, or FTP "
324 & "to your customer directory).");
325 End_Line;
327 Write_Str
328 ("| See README.GNATPRO for full info on procedure " &
329 "for submitting bugs.");
330 End_Line;
331 end if;
332 end if;
333 end;
335 -- Complete output of bug box
337 Write_Char ('+');
338 Repeat_Char ('=', 76, '+');
339 Write_Eol;
341 if Debug_Flag_3 then
342 Write_Eol;
343 Write_Eol;
344 Print_Tree_Node (Current_Error_Node);
345 Write_Eol;
346 end if;
348 Write_Eol;
350 Write_Line ("Please include these source files with error report");
351 Write_Eol;
353 for U in Main_Unit .. Last_Unit loop
354 begin
355 if not Is_Internal_File_Name
356 (File_Name (Source_Index (U)))
357 then
358 Write_Name (Full_File_Name (Source_Index (U)));
359 Write_Eol;
360 end if;
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.
365 exception
366 when others =>
367 Write_Str ("list may be incomplete");
368 exit;
369 end;
370 end loop;
372 Write_Eol;
373 Set_Standard_Output;
375 Tree_Dump;
376 Source_Dump;
377 raise Unrecoverable_Error;
378 end if;
380 end Compiler_Abort;
382 -----------------
383 -- Repeat_Char --
384 -----------------
386 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
387 begin
388 while Column < Col loop
389 Write_Char (Char);
390 end loop;
392 Write_Char (After);
393 end Repeat_Char;
395 end Comperr;