1 /* messages.c - error reporter -
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 97, 98, 2000
3 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
36 #if !defined (USE_STDARG) && !defined (USE_VARARGS)
40 typedef int * va_list;
41 #define va_start(ARGS) ARGS = &REST
45 static void identify
PARAMS ((char *));
46 static void as_show_where
PARAMS ((void));
47 static void as_warn_internal
PARAMS ((char *, unsigned int, char *));
48 static void as_bad_internal
PARAMS ((char *, unsigned int, char *));
50 /* Despite the rest of the comments in this file, (FIXME-SOON),
51 * here is the current scheme for error messages etc:
53 * as_fatal() is used when gas is quite confused and
54 * continuing the assembly is pointless. In this case we
55 * exit immediately with error status.
57 * as_bad() is used to mark errors that result in what we
58 * presume to be a useless object file. Say, we ignored
59 * something that might have been vital. If we see any of
60 * these, assembly will continue to the end of the source,
61 * no object file will be produced, and we will terminate
62 * with error status. The new option, -Z, tells us to
63 * produce an object file anyway but we still exit with
64 * error status. The assumption here is that you don't want
65 * this object file but we could be wrong.
67 * as_warn() is used when we have an error from which we
68 * have a plausible error recovery. eg, masking the top
69 * bits of a constant that is longer than will fit in the
70 * destination. In this case we will continue to assemble
71 * the source, although we may have made a bad assumption,
72 * and we will produce an object file and return normal exit
73 * status (ie, no error). The new option -X tells us to
74 * treat all as_warn() errors as as_bad() errors. That is,
75 * no object file will be produced and we will exit with
76 * error status. The idea here is that we don't kill an
77 * entire make because of an error that we knew how to
78 * correct. On the other hand, sometimes you might want to
79 * stop the make at these points.
81 * as_tsktsk() is used when we see a minor error for which
82 * our error recovery action is almost certainly correct.
83 * In this case, we print a message and then assembly
84 * continues as though no error occurred.
91 static int identified
;
103 fprintf (stderr
, "%s: ", file
);
104 fprintf (stderr
, _("Assembler messages:\n"));
107 /* The number of warnings issued. */
108 static int warning_count
;
113 return (warning_count
);
116 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
117 and exit with a nonzero error code. */
119 static int error_count
;
124 return (error_count
);
127 /* Print the current location to stderr. */
135 as_where (&file
, &line
);
138 fprintf (stderr
, "%s:%u: ", file
, line
);
141 /* Like perror(3), but with more info. */
144 as_perror (gripe
, filename
)
145 const char *gripe
; /* Unpunctuated error theme. */
146 const char *filename
;
151 fprintf (stderr
, gripe
, filename
);
153 errtxt
= bfd_errmsg (bfd_get_error ());
155 errtxt
= xstrerror (errno
);
157 fprintf (stderr
, ": %s\n", errtxt
);
160 bfd_set_error (bfd_error_no_error
);
164 /* Send to stderr a string as a warning, and locate warning
166 Please only use this for when we have some recovery action.
167 Please explain in string (which may have '\n's) what recovery was
172 as_tsktsk (const char *format
, ...)
177 va_start (args
, format
);
178 vfprintf (stderr
, format
, args
);
180 (void) putc ('\n', stderr
);
184 as_tsktsk (format
, va_alist
)
192 vfprintf (stderr
, format
, args
);
194 (void) putc ('\n', stderr
);
196 #endif /* not NO_STDARG */
198 /* The common portion of as_warn and as_warn_where. */
201 as_warn_internal (file
, line
, buffer
)
209 as_where (&file
, &line
);
213 fprintf (stderr
, "%s:%u: ", file
, line
);
214 fprintf (stderr
, _("Warning: "));
215 fputs (buffer
, stderr
);
216 (void) putc ('\n', stderr
);
218 listing_warning (buffer
);
222 /* Send to stderr a string as a warning, and locate warning
224 Please only use this for when we have some recovery action.
225 Please explain in string (which may have '\n's) what recovery was
230 as_warn (const char *format
, ...)
235 if (!flag_no_warnings
)
237 va_start (args
, format
);
238 vsprintf (buffer
, format
, args
);
240 as_warn_internal ((char *) NULL
, 0, buffer
);
245 as_warn (format
, va_alist
)
252 if (!flag_no_warnings
)
255 vsprintf (buffer
, format
, args
);
257 as_warn_internal ((char *) NULL
, 0, buffer
);
260 #endif /* not NO_STDARG */
262 /* Like as_bad but the file name and line number are passed in.
263 Unfortunately, we have to repeat the function in order to handle
264 the varargs correctly and portably. */
268 as_warn_where (char *file
, unsigned int line
, const char *format
, ...)
273 if (!flag_no_warnings
)
275 va_start (args
, format
);
276 vsprintf (buffer
, format
, args
);
278 as_warn_internal (file
, line
, buffer
);
283 as_warn_where (file
, line
, format
, va_alist
)
292 if (!flag_no_warnings
)
295 vsprintf (buffer
, format
, args
);
297 as_warn_internal (file
, line
, buffer
);
300 #endif /* not NO_STDARG */
302 /* The common portion of as_bad and as_bad_where. */
305 as_bad_internal (file
, line
, buffer
)
313 as_where (&file
, &line
);
317 fprintf (stderr
, "%s:%u: ", file
, line
);
318 fprintf (stderr
, _("Error: "));
319 fputs (buffer
, stderr
);
320 (void) putc ('\n', stderr
);
322 listing_error (buffer
);
326 /* Send to stderr a string as a warning, and locate warning in input
327 file(s). Please us when there is no recovery, but we want to
328 continue processing but not produce an object file.
329 Please explain in string (which may have '\n's) what recovery was
334 as_bad (const char *format
, ...)
339 va_start (args
, format
);
340 vsprintf (buffer
, format
, args
);
343 as_bad_internal ((char *) NULL
, 0, buffer
);
348 as_bad (format
, va_alist
)
356 vsprintf (buffer
, format
, args
);
359 as_bad_internal ((char *) NULL
, 0, buffer
);
361 #endif /* not NO_STDARG */
363 /* Like as_bad but the file name and line number are passed in.
364 Unfortunately, we have to repeat the function in order to handle
365 the varargs correctly and portably. */
369 as_bad_where (char *file
, unsigned int line
, const char *format
, ...)
374 va_start (args
, format
);
375 vsprintf (buffer
, format
, args
);
378 as_bad_internal (file
, line
, buffer
);
383 as_bad_where (file
, line
, format
, va_alist
)
393 vsprintf (buffer
, format
, args
);
396 as_bad_internal (file
, line
, buffer
);
398 #endif /* not NO_STDARG */
400 /* Send to stderr a string as a fatal message, and print location of
401 error in input file(s).
402 Please only use this for when we DON'T have some recovery action.
403 It xexit()s with a warning status. */
407 as_fatal (const char *format
, ...)
412 va_start (args
, format
);
413 fprintf (stderr
, _("Fatal error: "));
414 vfprintf (stderr
, format
, args
);
415 (void) putc ('\n', stderr
);
417 xexit (EXIT_FAILURE
);
421 as_fatal (format
, va_alist
)
429 fprintf (stderr
, _("Fatal error: "));
430 vfprintf (stderr
, format
, args
);
431 (void) putc ('\n', stderr
);
433 xexit (EXIT_FAILURE
);
435 #endif /* not NO_STDARG */
437 /* Indicate assertion failure.
438 Arguments: Filename, line number, optional function name. */
441 as_assert (file
, line
, fn
)
442 const char *file
, *fn
;
446 fprintf (stderr
, _("Internal error!\n"));
448 fprintf (stderr
, _("Assertion failure in %s at %s line %d.\n"),
451 fprintf (stderr
, _("Assertion failure at %s line %d.\n"), file
, line
);
452 fprintf (stderr
, _("Please report this bug.\n"));
453 xexit (EXIT_FAILURE
);
456 /* as_abort: Print a friendly message saying how totally hosed we are,
457 and exit without producing a core file. */
460 as_abort (file
, line
, fn
)
461 const char *file
, *fn
;
466 fprintf (stderr
, _("Internal error, aborting at %s line %d in %s\n"),
469 fprintf (stderr
, _("Internal error, aborting at %s line %d\n"),
471 fprintf (stderr
, _("Please report this bug.\n"));
472 xexit (EXIT_FAILURE
);
475 /* Support routines. */
478 fprint_value (file
, val
)
482 if (sizeof (val
) <= sizeof (long))
484 fprintf (file
, "%ld", (long) val
);
488 if (sizeof (val
) <= sizeof (bfd_vma
))
490 fprintf_vma (file
, val
);
498 sprint_value (buf
, val
)
502 if (sizeof (val
) <= sizeof (long))
504 sprintf (buf
, "%ld", (long) val
);
508 if (sizeof (val
) <= sizeof (bfd_vma
))
510 sprintf_vma (buf
, val
);