Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / ada / comperr.adb
blobda6c8a688ed31f596f47411ee92caf1822f8a087
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C O M P E R R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by AdaCore. --
23 -- --
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;
35 with Opt; use Opt;
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
51 ----------------
52 -- Local Data --
53 ----------------
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).
68 --------------------
69 -- Compiler_Abort --
70 --------------------
72 procedure Compiler_Abort
73 (X : String;
74 Code : Integer := 0;
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
86 procedure End_Line;
87 -- Add blanks up to column 76, and then a final vertical bar
89 --------------
90 -- End_Line --
91 --------------
93 procedure End_Line is
94 begin
95 Repeat_Char (' ', 76, '|');
96 Write_Eol;
97 end End_Line;
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
104 begin
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);
111 end if;
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
137 then
138 if VM_Target = CLI_Target then
139 Error_Msg_N
140 ("unsupported construct in this context",
141 Current_Error_Node);
142 else
143 Error_Msg_N ("cannot generate 'S'C'I'L", Current_Error_Node);
144 end if;
145 end if;
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;
157 Set_Standard_Error;
158 Write_Str ("compilation abandoned due to previous error");
159 Write_Eol;
161 Set_Standard_Output;
162 Source_Dump;
163 Tree_Dump;
164 Exit_Program (E_Errors);
166 -- Otherwise give message with details of the abort
168 else
169 Set_Standard_Error;
171 -- Generate header for bug box
173 Write_Char ('+');
174 Repeat_Char ('=', 29, 'G');
175 Write_Str ("NAT BUG DETECTED");
176 Repeat_Char ('=', 76, '+');
177 Write_Eol;
179 -- Output GNAT version identification
181 Write_Str ("| ");
182 Write_Str (Gnat_Version_String);
183 Write_Str (" (");
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) = '/'
189 then
190 Write_Str (Target_Name.all (1 .. Target_Name.all'Last - 1));
191 else
192 Write_Str (Target_Name.all);
193 end if;
195 -- Output identification of error
197 Write_Str (") ");
199 if X'Length + Column > 76 then
200 if Code < 0 then
201 Write_Str ("GCC error:");
202 end if;
204 End_Line;
206 Write_Str ("| ");
207 end if;
209 if X'Length > 70 then
210 declare
211 Last_Blank : Integer := 70;
213 begin
214 for P in 39 .. 68 loop
215 if X (XF + P) = ' ' then
216 Last_Blank := P;
217 end if;
218 end loop;
220 Write_Str (X (XF .. XF - 1 + Last_Blank));
221 End_Line;
222 Write_Str ("| ");
223 Write_Str (X (XF + Last_Blank .. X'Last));
224 end;
225 else
226 Write_Str (X);
227 end if;
229 if Code > 0 then
230 Write_Str (", Code=");
231 Write_Int (Int (Code));
233 elsif Code = 0 then
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.
241 Write_Char (' ');
242 Write_Str (Exception_Message (Get_Current_Excep.all.all));
243 end if;
245 End_Line;
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);
253 else
254 Write_Str ("| No source file position information available");
255 end if;
257 End_Line;
258 else
259 Write_Str ("| Error detected at ");
260 Write_Location (Sloc (Current_Error_Node));
261 End_Line;
262 end if;
264 -- There are two cases now. If the file gnat_bug.box exists,
265 -- we use the contents of this file at this point.
267 declare
268 Lo : Source_Ptr;
269 Hi : Source_Ptr;
270 Src : Source_Buffer_Ptr;
272 begin
273 Namet.Unlock;
274 Name_Buffer (1 .. 12) := "gnat_bug.box";
275 Name_Len := 12;
276 Read_Source_File (Name_Enter, 0, Hi, Src);
278 -- If we get a Src file, we use it
280 if Src /= null then
281 Lo := 0;
283 Outer : while Lo < Hi loop
284 Write_Str ("| ");
286 Inner : loop
287 exit Inner when Src (Lo) = ASCII.CR
288 or else Src (Lo) = ASCII.LF;
289 Write_Char (Src (Lo));
290 Lo := Lo + 1;
291 end loop Inner;
293 End_Line;
295 while Lo <= Hi
296 and then (Src (Lo) = ASCII.CR
297 or else Src (Lo) = ASCII.LF)
298 loop
299 Lo := Lo + 1;
300 end loop;
301 end loop Outer;
303 -- Otherwise we use the standard fixed text
305 else
306 if Is_FSF_Version then
307 Write_Str
308 ("| Please submit a bug report; see" &
309 " http://gcc.gnu.org/bugs.html.");
310 End_Line;
312 elsif Is_GPL_Version then
314 Write_Str
315 ("| Please submit a bug report by email " &
316 "to report@adacore.com.");
317 End_Line;
319 Write_Str
320 ("| GAP members can alternatively use GNAT Tracker:");
321 End_Line;
323 Write_Str
324 ("| http://www.adacore.com/ " &
325 "section 'send a report'.");
326 End_Line;
328 Write_Str
329 ("| See gnatinfo.txt for full info on procedure " &
330 "for submitting bugs.");
331 End_Line;
333 else
334 Write_Str
335 ("| Please submit a bug report using GNAT Tracker:");
336 End_Line;
338 Write_Str
339 ("| http://www.adacore.com/gnattracker/ " &
340 "section 'send a report'.");
341 End_Line;
343 Write_Str
344 ("| alternatively submit a bug report by email " &
345 "to report@adacore.com,");
346 End_Line;
348 Write_Str
349 ("| including your customer number #nnn " &
350 "in the subject line.");
351 End_Line;
352 end if;
354 Write_Str
355 ("| Use a subject line meaningful to you" &
356 " and us to track the bug.");
357 End_Line;
359 Write_Str
360 ("| Include the entire contents of this bug " &
361 "box in the report.");
362 End_Line;
364 Write_Str
365 ("| Include the exact gcc or gnatmake command " &
366 "that you entered.");
367 End_Line;
369 Write_Str
370 ("| Also include sources listed below in gnatchop format");
371 End_Line;
373 Write_Str
374 ("| (concatenated together with no headers between files).");
375 End_Line;
377 if not Is_FSF_Version then
378 Write_Str
379 ("| Use plain ASCII or MIME attachment.");
380 End_Line;
381 end if;
382 end if;
383 end;
385 -- Complete output of bug box
387 Write_Char ('+');
388 Repeat_Char ('=', 76, '+');
389 Write_Eol;
391 if Debug_Flag_3 then
392 Write_Eol;
393 Write_Eol;
394 Print_Tree_Node (Current_Error_Node);
395 Write_Eol;
396 end if;
398 Write_Eol;
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).");
405 Write_Eol;
407 begin
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.
413 exception
414 when others =>
415 Write_Str ("list may be incomplete");
416 end;
418 Write_Eol;
419 Set_Standard_Output;
421 Tree_Dump;
422 Source_Dump;
423 raise Unrecoverable_Error;
424 end if;
426 end Compiler_Abort;
428 -----------------
429 -- Repeat_Char --
430 -----------------
432 procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
433 begin
434 while Column < Col loop
435 Write_Char (Char);
436 end loop;
438 Write_Char (After);
439 end Repeat_Char;
441 end Comperr;