1 /* messages.c - error reporter -
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 96, 97, 1998
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 *));
51 * Despite the rest of the comments in this file, (FIXME-SOON),
52 * here is the current scheme for error messages etc:
54 * as_fatal() is used when gas is quite confused and
55 * continuing the assembly is pointless. In this case we
56 * exit immediately with error status.
58 * as_bad() is used to mark errors that result in what we
59 * presume to be a useless object file. Say, we ignored
60 * something that might have been vital. If we see any of
61 * these, assembly will continue to the end of the source,
62 * no object file will be produced, and we will terminate
63 * with error status. The new option, -Z, tells us to
64 * produce an object file anyway but we still exit with
65 * error status. The assumption here is that you don't want
66 * this object file but we could be wrong.
68 * as_warn() is used when we have an error from which we
69 * have a plausible error recovery. eg, masking the top
70 * bits of a constant that is longer than will fit in the
71 * destination. In this case we will continue to assemble
72 * the source, although we may have made a bad assumption,
73 * and we will produce an object file and return normal exit
74 * status (ie, no error). The new option -X tells us to
75 * treat all as_warn() errors as as_bad() errors. That is,
76 * no object file will be produced and we will exit with
77 * error status. The idea here is that we don't kill an
78 * entire make because of an error that we knew how to
79 * correct. On the other hand, sometimes you might want to
80 * stop the make at these points.
82 * as_tsktsk() is used when we see a minor error for which
83 * our error recovery action is almost certainly correct.
84 * In this case, we print a message and then assembly
85 * continues as though no error occurred.
92 static int identified;
100 as_where (&file, &x);
104 fprintf (stderr, "%s: ", file);
105 fprintf (stderr, _("Assembler messages:\n"));
108 static int warning_count; /* Count of number of warnings issued */
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);
144 * Like perror(3), but with more info.
148 as_perror (gripe, filename)
149 const char *gripe; /* Unpunctuated error theme. */
150 const char *filename;
155 fprintf (stderr, gripe, filename);
157 errtxt = bfd_errmsg (bfd_get_error ());
159 errtxt = xstrerror (errno);
161 fprintf (stderr, ": %s\n", errtxt);
164 bfd_set_error (bfd_error_no_error);
169 * a s _ t s k t s k ()
171 * Send to stderr a string as a warning, and locate warning
173 * Please only use this for when we have some recovery action.
174 * Please explain in string (which may have '\n's) what recovery was done.
179 as_tsktsk (const char *format,...)
184 va_start (args, format);
185 vfprintf (stderr, format, args);
187 (void) putc ('\n', stderr);
191 as_tsktsk (format, va_alist)
199 vfprintf (stderr, format, args);
201 (void) putc ('\n', stderr);
203 #endif /* not NO_STDARG */
205 /* The common portion of as_warn and as_warn_where. */
208 as_warn_internal (file, line, buffer)
216 as_where (&file, &line);
220 fprintf (stderr, "%s:%u: ", file, line);
221 fprintf (stderr, _("Warning: "));
222 fputs (buffer, stderr);
223 (void) putc ('\n', stderr);
225 listing_warning (buffer);
232 * Send to stderr a string as a warning, and locate warning
234 * Please only use this for when we have some recovery action.
235 * Please explain in string (which may have '\n's) what recovery was done.
240 as_warn (const char *format,...)
245 if (!flag_no_warnings)
247 va_start (args, format);
248 vsprintf (buffer, format, args);
250 as_warn_internal ((char *) NULL, 0, buffer);
256 as_warn (format, va_alist)
263 if (!flag_no_warnings)
266 vsprintf (buffer, format, args);
268 as_warn_internal ((char *) NULL, 0, buffer);
271 #endif /* not NO_STDARG */
273 /* as_warn_where, like as_bad but the file name and line number are
274 passed in. Unfortunately, we have to repeat the function in order
275 to handle the varargs correctly and portably. */
279 as_warn_where (char *file, unsigned int line, const char *format,...)
284 if (!flag_no_warnings)
286 va_start (args, format);
287 vsprintf (buffer, format, args);
289 as_warn_internal (file, line, buffer);
295 as_warn_where (file, line, format, va_alist)
304 if (!flag_no_warnings)
307 vsprintf (buffer, format, args);
309 as_warn_internal (file, line, buffer);
312 #endif /* not NO_STDARG */
314 /* The common portion of as_bad and as_bad_where. */
317 as_bad_internal (file, line, buffer)
325 as_where (&file, &line);
329 fprintf (stderr, "%s:%u: ", file, line);
330 fprintf (stderr, _("Error: "));
331 fputs (buffer, stderr);
332 (void) putc ('\n', stderr);
334 listing_error (buffer);
341 * Send to stderr a string as a warning, and locate warning in input file(s).
342 * Please us when there is no recovery, but we want to continue processing
343 * but not produce an object file.
344 * Please explain in string (which may have '\n's) what recovery was done.
349 as_bad (const char *format,...)
354 va_start (args, format);
355 vsprintf (buffer, format, args);
358 as_bad_internal ((char *) NULL, 0, buffer);
364 as_bad (format, va_alist)
372 vsprintf (buffer, format, args);
375 as_bad_internal ((char *) NULL, 0, buffer);
377 #endif /* not NO_STDARG */
379 /* as_bad_where, like as_bad but the file name and line number are
380 passed in. Unfortunately, we have to repeat the function in order
381 to handle the varargs correctly and portably. */
385 as_bad_where (char *file, unsigned int line, const char *format,...)
390 va_start (args, format);
391 vsprintf (buffer, format, args);
394 as_bad_internal (file, line, buffer);
400 as_bad_where (file, line, format, va_alist)
410 vsprintf (buffer, format, args);
413 as_bad_internal (file, line, buffer);
415 #endif /* not NO_STDARG */
420 * Send to stderr a string as a fatal message, and print location of error in
422 * Please only use this for when we DON'T have some recovery action.
423 * It xexit()s with a warning status.
428 as_fatal (const char *format,...)
433 va_start (args, format);
434 fprintf (stderr, _("Fatal error: "));
435 vfprintf (stderr, format, args);
436 (void) putc ('\n', stderr);
438 xexit (EXIT_FAILURE);
443 as_fatal (format, va_alist)
451 fprintf (stderr, _("Fatal error: "));
452 vfprintf (stderr, format, args);
453 (void) putc ('\n', stderr);
455 xexit (EXIT_FAILURE);
457 #endif /* not NO_STDARG */
460 * as_assert: Indicate assertion failure.
461 * Arguments: Filename, line number, optional function name.
465 as_assert (file, line, fn)
466 const char *file, *fn;
470 fprintf (stderr, _("Internal error!\n"));
472 fprintf (stderr, _("Assertion failure in %s at %s line %d.\n"),
475 fprintf (stderr, _("Assertion failure at %s line %d.\n"), file, line);
476 fprintf (stderr, _("Please report this bug.\n"));
477 xexit (EXIT_FAILURE);
480 /* as_abort: Print a friendly message saying how totally hosed we are,
481 and exit without producing a core file. */
483 as_abort (file, line, fn)
484 const char *file, *fn;
489 fprintf (stderr, _("Internal error, aborting at %s line %d in %s\n"),
492 fprintf (stderr, _("Internal error, aborting at %s line %d\n"),
494 fprintf (stderr, _("Please report this bug.\n"));
495 xexit (EXIT_FAILURE);
498 /* Support routines. */
501 fprint_value (file, val)
505 if (sizeof (val) <= sizeof (long))
507 fprintf (file, "%ld", (long) val);
511 if (sizeof (val) <= sizeof (bfd_vma))
513 fprintf_vma (file, val);
521 sprint_value (buf, val)
525 if (sizeof (val) <= sizeof (long))
527 sprintf (buf, "%ld", (long) val);
531 if (sizeof (val) <= sizeof (bfd_vma))
533 sprintf_vma (buf, val);
540 /* end of messages.c */