1 /* messages.c - error reporter -
2 Copyright (C) 1987, 1991, 1992 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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
36 #endif /* NO_VARARGS */
37 #endif /* NO_STDARG */
39 extern char *strerror ();
41 static void as_show_where PARAMS ((void));
42 static void as_warn_internal PARAMS ((char *, unsigned int, char *));
43 static void as_bad_internal PARAMS ((char *, unsigned int, char *));
46 * Despite the rest of the comments in this file, (FIXME-SOON),
47 * here is the current scheme for error messages etc:
49 * as_fatal() is used when gas is quite confused and
50 * continuing the assembly is pointless. In this case we
51 * exit immediately with error status.
53 * as_bad() is used to mark errors that result in what we
54 * presume to be a useless object file. Say, we ignored
55 * something that might have been vital. If we see any of
56 * these, assembly will continue to the end of the source,
57 * no object file will be produced, and we will terminate
58 * with error status. The new option, -Z, tells us to
59 * produce an object file anyway but we still exit with
60 * error status. The assumption here is that you don't want
61 * this object file but we could be wrong.
63 * as_warn() is used when we have an error from which we
64 * have a plausible error recovery. eg, masking the top
65 * bits of a constant that is longer than will fit in the
66 * destination. In this case we will continue to assemble
67 * the source, although we may have made a bad assumption,
68 * and we will produce an object file and return normal exit
69 * status (ie, no error). The new option -X tells us to
70 * treat all as_warn() errors as as_bad() errors. That is,
71 * no object file will be produced and we will exit with
72 * error status. The idea here is that we don't kill an
73 * entire make because of an error that we knew how to
74 * correct. On the other hand, sometimes you might want to
75 * stop the make at these points.
77 * as_tsktsk() is used when we see a minor error for which
78 * our error recovery action is almost certainly correct.
79 * In this case, we print a message and then assembly
80 * continues as though no error occurred.
87 static int identified;
98 fprintf (stderr, "%s: Assembler messages:\n", file);
101 static int warning_count; /* Count of number of warnings issued */
106 return (warning_count);
109 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
110 and exit with a nonzero error code */
112 static int error_count;
117 return (error_count);
121 /* Print the current location to stderr. */
129 as_where (&file, &line);
131 fprintf (stderr, "%s:%u: ", file, line);
137 * Like perror(3), but with more info.
141 as_perror (gripe, filename)
142 const char *gripe; /* Unpunctuated error theme. */
143 const char *filename;
148 fprintf (stderr, gripe, filename);
150 errtxt = bfd_errmsg (bfd_get_error ());
152 errtxt = strerror (errno);
154 fprintf (stderr, ": %s\n", errtxt);
157 bfd_set_error (bfd_error_no_error);
162 * a s _ t s k t s k ()
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 done.
172 as_tsktsk (const char *format,...)
177 va_start (args, format);
178 vfprintf (stderr, format, args);
180 (void) putc ('\n', stderr);
186 as_tsktsk (format, va_alist)
194 vfprintf (stderr, format, args);
196 (void) putc ('\n', stderr);
201 as_tsktsk (format, args)
205 _doprnt (format, &args, stderr);
206 (void) putc ('\n', stderr);
209 #endif /* not NO_VARARGS */
210 #endif /* not NO_STDARG */
212 /* The common portion of as_warn and as_warn_where. */
215 as_warn_internal (file, line, buffer)
223 as_where (&file, &line);
226 fprintf (stderr, "%s:%u: Warning: ", file, line);
227 fputs (buffer, stderr);
228 (void) putc ('\n', stderr);
230 listing_warning (buffer);
237 * Send to stderr a string as a warning, and locate warning
239 * Please only use this for when we have some recovery action.
240 * Please explain in string (which may have '\n's) what recovery was done.
245 as_warn (const char *format,...)
252 va_start (args, format);
253 vsprintf (buffer, format, args);
255 as_warn_internal ((char *) NULL, 0, buffer);
262 as_warn (format, va_alist)
272 vsprintf (buffer, format, args);
274 as_warn_internal ((char *) NULL, 0, buffer);
280 as_warn (format, args)
287 fprintf (stderr, "Warning: ");
288 _doprnt (format, &args, stderr);
289 (void) putc ('\n', stderr);
293 #endif /* not NO_VARARGS */
294 #endif /* not NO_STDARG */
296 /* as_warn_where, like as_bad but the file name and line number are
297 passed in. Unfortunately, we have to repeat the function in order
298 to handle the varargs correctly and portably. */
302 as_warn_where (char *file, unsigned int line, const char *format,...)
309 va_start (args, format);
310 vsprintf (buffer, format, args);
312 as_warn_internal (file, line, buffer);
319 as_warn_where (file, line, format, va_alist)
331 vsprintf (buffer, format, args);
333 as_warn_internal (file, line, buffer);
339 as_warn_where (file, line, format, args)
348 fprintf (stderr, "%s:%u: Warning: ", file, line);
349 _doprnt (format, &args, stderr);
350 (void) putc ('\n', stderr);
354 #endif /* not NO_VARARGS */
355 #endif /* not NO_STDARG */
357 /* The common portion of as_bad and as_bad_where. */
360 as_bad_internal (file, line, buffer)
368 as_where (&file, &line);
371 fprintf (stderr, "%s:%u: Error: ", file, line);
372 fputs (buffer, stderr);
373 (void) putc ('\n', stderr);
375 listing_error (buffer);
382 * Send to stderr a string as a warning, and locate warning in input file(s).
383 * Please us when there is no recovery, but we want to continue processing
384 * but not produce an object file.
385 * Please explain in string (which may have '\n's) what recovery was done.
390 as_bad (const char *format,...)
395 va_start (args, format);
396 vsprintf (buffer, format, args);
399 as_bad_internal ((char *) NULL, 0, buffer);
405 as_bad (format, va_alist)
413 vsprintf (buffer, format, args);
416 as_bad_internal ((char *) NULL, 0, buffer);
421 as_bad (format, args)
427 fprintf (stderr, "Error: ");
428 _doprnt (format, &args, stderr);
429 (void) putc ('\n', stderr);
432 #endif /* not NO_VARARGS */
433 #endif /* not NO_STDARG */
435 /* as_bad_where, like as_bad but the file name and line number are
436 passed in. Unfortunately, we have to repeat the function in order
437 to handle the varargs correctly and portably. */
441 as_bad_where (char *file, unsigned int line, const char *format,...)
446 va_start (args, format);
447 vsprintf (buffer, format, args);
450 as_bad_internal (file, line, buffer);
456 as_bad_where (file, line, format, va_alist)
466 vsprintf (buffer, format, args);
469 as_bad_internal (file, line, buffer);
474 as_bad_where (file, line, format, args)
482 fprintf (stderr, "%s:%u: Error: ", file, line);
483 _doprnt (format, &args, stderr);
484 (void) putc ('\n', stderr);
487 #endif /* not NO_VARARGS */
488 #endif /* not NO_STDARG */
493 * Send to stderr a string as a fatal message, and print location of error in
495 * Please only use this for when we DON'T have some recovery action.
496 * It exit()s with a warning status.
501 as_fatal (const char *format,...)
506 va_start (args, format);
507 fprintf (stderr, "Fatal error:");
508 vfprintf (stderr, format, args);
509 (void) putc ('\n', stderr);
517 as_fatal (format, va_alist)
525 fprintf (stderr, "Fatal error:");
526 vfprintf (stderr, format, args);
527 (void) putc ('\n', stderr);
534 as_fatal (format, args)
538 fprintf (stderr, "Fatal error:");
539 _doprnt (format, &args, stderr);
540 (void) putc ('\n', stderr);
541 exit (33); /* What is a good exit status? */
544 #endif /* not NO_VARARGS */
545 #endif /* not NO_STDARG */
548 fprint_value (file, val)
552 if (sizeof (val) <= sizeof (long))
554 fprintf (file, "%ld", val);
558 if (sizeof (val) <= sizeof (bfd_vma))
560 fprintf_vma (file, val);
568 sprint_value (buf, val)
572 if (sizeof (val) <= sizeof (long))
574 sprintf (buf, "%ld", val);
578 if (sizeof (val) <= sizeof (bfd_vma))
580 sprintf_vma (buf, val);
587 /* end of messages.c */