1 /* messages.c - error reporter -
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
4 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 static void identify (char *);
25 static void as_show_where (void);
26 static void as_warn_internal (char *, unsigned int, char *);
27 static void as_bad_internal (char *, unsigned int, char *);
29 /* Despite the rest of the comments in this file, (FIXME-SOON),
30 here is the current scheme for error messages etc:
32 as_fatal() is used when gas is quite confused and
33 continuing the assembly is pointless. In this case we
34 exit immediately with error status.
36 as_bad() is used to mark errors that result in what we
37 presume to be a useless object file. Say, we ignored
38 something that might have been vital. If we see any of
39 these, assembly will continue to the end of the source,
40 no object file will be produced, and we will terminate
41 with error status. The new option, -Z, tells us to
42 produce an object file anyway but we still exit with
43 error status. The assumption here is that you don't want
44 this object file but we could be wrong.
46 as_warn() is used when we have an error from which we
47 have a plausible error recovery. eg, masking the top
48 bits of a constant that is longer than will fit in the
49 destination. In this case we will continue to assemble
50 the source, although we may have made a bad assumption,
51 and we will produce an object file and return normal exit
52 status (ie, no error). The new option -X tells us to
53 treat all as_warn() errors as as_bad() errors. That is,
54 no object file will be produced and we will exit with
55 error status. The idea here is that we don't kill an
56 entire make because of an error that we knew how to
57 correct. On the other hand, sometimes you might want to
58 stop the make at these points.
60 as_tsktsk() is used when we see a minor error for which
61 our error recovery action is almost certainly correct.
62 In this case, we print a message and then assembly
63 continues as though no error occurred. */
68 static int identified
;
81 fprintf (stderr
, "%s: ", file
);
82 fprintf (stderr
, _("Assembler messages:\n"));
85 /* The number of warnings issued. */
86 static int warning_count
;
94 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
95 and exit with a nonzero error code. */
97 static int error_count
;
105 /* Print the current location to stderr. */
113 as_where (&file
, &line
);
116 fprintf (stderr
, "%s:%u: ", file
, line
);
119 /* Like perror(3), but with more info. */
122 as_perror (const char *gripe
, /* Unpunctuated error theme. */
123 const char *filename
)
126 int saved_errno
= errno
;
129 fprintf (stderr
, gripe
, filename
);
131 errtxt
= bfd_errmsg (bfd_get_error ());
132 fprintf (stderr
, ": %s\n", errtxt
);
134 bfd_set_error (bfd_error_no_error
);
137 /* Send to stderr a string as a warning, and locate warning
139 Please only use this for when we have some recovery action.
140 Please explain in string (which may have '\n's) what recovery was
145 as_tsktsk (const char *format
, ...)
150 va_start (args
, format
);
151 vfprintf (stderr
, format
, args
);
153 (void) putc ('\n', stderr
);
157 as_tsktsk (format
, va_alist
)
165 vfprintf (stderr
, format
, args
);
167 (void) putc ('\n', stderr
);
169 #endif /* not NO_STDARG */
171 /* The common portion of as_warn and as_warn_where. */
174 as_warn_internal (char *file
, unsigned int line
, char *buffer
)
179 as_where (&file
, &line
);
183 fprintf (stderr
, "%s:%u: ", file
, line
);
184 fprintf (stderr
, _("Warning: "));
185 fputs (buffer
, stderr
);
186 (void) putc ('\n', stderr
);
188 listing_warning (buffer
);
192 /* Send to stderr a string as a warning, and locate warning
194 Please only use this for when we have some recovery action.
195 Please explain in string (which may have '\n's) what recovery was
200 as_warn (const char *format
, ...)
205 if (!flag_no_warnings
)
207 va_start (args
, format
);
208 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
210 as_warn_internal ((char *) NULL
, 0, buffer
);
215 as_warn (format
, va_alist
)
222 if (!flag_no_warnings
)
225 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
227 as_warn_internal ((char *) NULL
, 0, buffer
);
230 #endif /* not NO_STDARG */
232 /* Like as_bad but the file name and line number are passed in.
233 Unfortunately, we have to repeat the function in order to handle
234 the varargs correctly and portably. */
238 as_warn_where (char *file
, unsigned int line
, const char *format
, ...)
243 if (!flag_no_warnings
)
245 va_start (args
, format
);
246 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
248 as_warn_internal (file
, line
, buffer
);
253 as_warn_where (file
, line
, format
, va_alist
)
262 if (!flag_no_warnings
)
265 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
267 as_warn_internal (file
, line
, buffer
);
270 #endif /* not NO_STDARG */
272 /* The common portion of as_bad and as_bad_where. */
275 as_bad_internal (char *file
, unsigned int line
, char *buffer
)
280 as_where (&file
, &line
);
284 fprintf (stderr
, "%s:%u: ", file
, line
);
285 fprintf (stderr
, _("Error: "));
286 fputs (buffer
, stderr
);
287 (void) putc ('\n', stderr
);
289 listing_error (buffer
);
293 /* Send to stderr a string as a warning, and locate warning in input
294 file(s). Please us when there is no recovery, but we want to
295 continue processing but not produce an object file.
296 Please explain in string (which may have '\n's) what recovery was
301 as_bad (const char *format
, ...)
306 va_start (args
, format
);
307 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
310 as_bad_internal ((char *) NULL
, 0, buffer
);
315 as_bad (format
, va_alist
)
323 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
326 as_bad_internal ((char *) NULL
, 0, buffer
);
328 #endif /* not NO_STDARG */
330 /* Like as_bad but the file name and line number are passed in.
331 Unfortunately, we have to repeat the function in order to handle
332 the varargs correctly and portably. */
336 as_bad_where (char *file
, unsigned int line
, const char *format
, ...)
341 va_start (args
, format
);
342 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
345 as_bad_internal (file
, line
, buffer
);
350 as_bad_where (file
, line
, format
, va_alist
)
360 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
363 as_bad_internal (file
, line
, buffer
);
365 #endif /* not NO_STDARG */
367 /* Send to stderr a string as a fatal message, and print location of
368 error in input file(s).
369 Please only use this for when we DON'T have some recovery action.
370 It xexit()s with a warning status. */
374 as_fatal (const char *format
, ...)
379 va_start (args
, format
);
380 fprintf (stderr
, _("Fatal error: "));
381 vfprintf (stderr
, format
, args
);
382 (void) putc ('\n', stderr
);
384 /* Delete the output file, if it exists. This will prevent make from
385 thinking that a file was created and hence does not need rebuilding. */
386 if (out_file_name
!= NULL
)
387 unlink_if_ordinary (out_file_name
);
388 xexit (EXIT_FAILURE
);
392 as_fatal (format
, va_alist
)
400 fprintf (stderr
, _("Fatal error: "));
401 vfprintf (stderr
, format
, args
);
402 (void) putc ('\n', stderr
);
404 xexit (EXIT_FAILURE
);
406 #endif /* not NO_STDARG */
408 /* Indicate assertion failure.
409 Arguments: Filename, line number, optional function name. */
412 as_assert (const char *file
, int line
, const char *fn
)
415 fprintf (stderr
, _("Internal error!\n"));
417 fprintf (stderr
, _("Assertion failure in %s at %s line %d.\n"),
420 fprintf (stderr
, _("Assertion failure at %s line %d.\n"), file
, line
);
421 fprintf (stderr
, _("Please report this bug.\n"));
422 xexit (EXIT_FAILURE
);
425 /* as_abort: Print a friendly message saying how totally hosed we are,
426 and exit without producing a core file. */
429 as_abort (const char *file
, int line
, const char *fn
)
433 fprintf (stderr
, _("Internal error, aborting at %s line %d in %s\n"),
436 fprintf (stderr
, _("Internal error, aborting at %s line %d\n"),
438 fprintf (stderr
, _("Please report this bug.\n"));
439 xexit (EXIT_FAILURE
);
442 /* Support routines. */
445 sprint_value (char *buf
, valueT val
)
447 if (sizeof (val
) <= sizeof (long))
449 sprintf (buf
, "%ld", (long) val
);
452 if (sizeof (val
) <= sizeof (bfd_vma
))
454 sprintf_vma (buf
, val
);
460 #define HEX_MAX_THRESHOLD 1024
461 #define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD)
464 as_internal_value_out_of_range (char * prefix
,
477 if ( val
< HEX_MAX_THRESHOLD
478 && min
< HEX_MAX_THRESHOLD
479 && max
< HEX_MAX_THRESHOLD
480 && val
> HEX_MIN_THRESHOLD
481 && min
> HEX_MIN_THRESHOLD
482 && max
> HEX_MIN_THRESHOLD
)
484 /* xgettext:c-format */
485 err
= _("%s out of range (%d is not between %d and %d)");
488 as_bad_where (file
, line
, err
,
489 prefix
, (int) val
, (int) min
, (int) max
);
491 as_warn_where (file
, line
, err
,
492 prefix
, (int) val
, (int) min
, (int) max
);
496 char val_buf
[sizeof (val
) * 3 + 2];
497 char min_buf
[sizeof (val
) * 3 + 2];
498 char max_buf
[sizeof (val
) * 3 + 2];
500 if (sizeof (val
) > sizeof (bfd_vma
))
503 sprintf_vma (val_buf
, val
);
504 sprintf_vma (min_buf
, min
);
505 sprintf_vma (max_buf
, max
);
507 /* xgettext:c-format. */
508 err
= _("%s out of range (0x%s is not between 0x%s and 0x%s)");
511 as_bad_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
513 as_warn_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
518 as_warn_value_out_of_range (char * prefix
,
525 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 0);
529 as_bad_value_out_of_range (char * prefix
,
536 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 1);