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
);
128 /* Print the current location to stderr. */
136 as_where (&file
, &line
);
139 fprintf (stderr
, "%s:%u: ", file
, line
);
145 * Like perror(3), but with more info.
149 as_perror (gripe
, filename
)
150 const char *gripe
; /* Unpunctuated error theme. */
151 const char *filename
;
156 fprintf (stderr
, gripe
, filename
);
158 errtxt
= bfd_errmsg (bfd_get_error ());
160 errtxt
= xstrerror (errno
);
162 fprintf (stderr
, ": %s\n", errtxt
);
165 bfd_set_error (bfd_error_no_error
);
170 * a s _ t s k t s k ()
172 * Send to stderr a string as a warning, and locate warning
174 * Please only use this for when we have some recovery action.
175 * Please explain in string (which may have '\n's) what recovery was done.
180 as_tsktsk (const char *format
,...)
185 va_start (args
, format
);
186 vfprintf (stderr
, format
, args
);
188 (void) putc ('\n', stderr
);
192 as_tsktsk (format
, va_alist
)
200 vfprintf (stderr
, format
, args
);
202 (void) putc ('\n', stderr
);
204 #endif /* not NO_STDARG */
206 /* The common portion of as_warn and as_warn_where. */
209 as_warn_internal (file
, line
, buffer
)
217 as_where (&file
, &line
);
221 fprintf (stderr
, "%s:%u: ", file
, line
);
222 fprintf (stderr
, _("Warning: "));
223 fputs (buffer
, stderr
);
224 (void) putc ('\n', stderr
);
226 listing_warning (buffer
);
233 * Send to stderr a string as a warning, and locate warning
235 * Please only use this for when we have some recovery action.
236 * Please explain in string (which may have '\n's) what recovery was done.
241 as_warn (const char *format
,...)
246 if (!flag_no_warnings
)
248 va_start (args
, format
);
249 vsprintf (buffer
, format
, args
);
251 as_warn_internal ((char *) NULL
, 0, buffer
);
257 as_warn (format
, va_alist
)
264 if (!flag_no_warnings
)
267 vsprintf (buffer
, format
, args
);
269 as_warn_internal ((char *) NULL
, 0, buffer
);
272 #endif /* not NO_STDARG */
274 /* as_warn_where, like as_bad but the file name and line number are
275 passed in. Unfortunately, we have to repeat the function in order
276 to handle the varargs correctly and portably. */
280 as_warn_where (char *file
, unsigned int line
, const char *format
,...)
285 if (!flag_no_warnings
)
287 va_start (args
, format
);
288 vsprintf (buffer
, format
, args
);
290 as_warn_internal (file
, line
, buffer
);
296 as_warn_where (file
, line
, format
, va_alist
)
305 if (!flag_no_warnings
)
308 vsprintf (buffer
, format
, args
);
310 as_warn_internal (file
, line
, buffer
);
313 #endif /* not NO_STDARG */
315 /* The common portion of as_bad and as_bad_where. */
318 as_bad_internal (file
, line
, buffer
)
326 as_where (&file
, &line
);
330 fprintf (stderr
, "%s:%u: ", file
, line
);
331 fprintf (stderr
, _("Error: "));
332 fputs (buffer
, stderr
);
333 (void) putc ('\n', stderr
);
335 listing_error (buffer
);
342 * Send to stderr a string as a warning, and locate warning in input file(s).
343 * Please us when there is no recovery, but we want to continue processing
344 * but not produce an object file.
345 * Please explain in string (which may have '\n's) what recovery was done.
350 as_bad (const char *format
,...)
355 va_start (args
, format
);
356 vsprintf (buffer
, format
, args
);
359 as_bad_internal ((char *) NULL
, 0, buffer
);
365 as_bad (format
, va_alist
)
373 vsprintf (buffer
, format
, args
);
376 as_bad_internal ((char *) NULL
, 0, buffer
);
378 #endif /* not NO_STDARG */
380 /* as_bad_where, like as_bad but the file name and line number are
381 passed in. Unfortunately, we have to repeat the function in order
382 to handle the varargs correctly and portably. */
386 as_bad_where (char *file
, unsigned int line
, const char *format
,...)
391 va_start (args
, format
);
392 vsprintf (buffer
, format
, args
);
395 as_bad_internal (file
, line
, buffer
);
401 as_bad_where (file
, line
, format
, va_alist
)
411 vsprintf (buffer
, format
, args
);
414 as_bad_internal (file
, line
, buffer
);
416 #endif /* not NO_STDARG */
421 * Send to stderr a string as a fatal message, and print location of error in
423 * Please only use this for when we DON'T have some recovery action.
424 * It xexit()s with a warning status.
429 as_fatal (const char *format
,...)
434 va_start (args
, format
);
435 fprintf (stderr
, _("Fatal error: "));
436 vfprintf (stderr
, format
, args
);
437 (void) putc ('\n', stderr
);
439 xexit (EXIT_FAILURE
);
444 as_fatal (format
, va_alist
)
452 fprintf (stderr
, _("Fatal error: "));
453 vfprintf (stderr
, format
, args
);
454 (void) putc ('\n', stderr
);
456 xexit (EXIT_FAILURE
);
458 #endif /* not NO_STDARG */
461 * as_assert: Indicate assertion failure.
462 * Arguments: Filename, line number, optional function name.
466 as_assert (file
, line
, fn
)
467 const char *file
, *fn
;
471 fprintf (stderr
, _("Internal error!\n"));
473 fprintf (stderr
, _("Assertion failure in %s at %s line %d.\n"),
476 fprintf (stderr
, _("Assertion failure at %s line %d.\n"), file
, line
);
477 fprintf (stderr
, _("Please report this bug.\n"));
478 xexit (EXIT_FAILURE
);
481 /* as_abort: Print a friendly message saying how totally hosed we are,
482 and exit without producing a core file. */
484 as_abort (file
, line
, fn
)
485 const char *file
, *fn
;
490 fprintf (stderr
, _("Internal error, aborting at %s line %d in %s\n"),
493 fprintf (stderr
, _("Internal error, aborting at %s line %d\n"),
495 fprintf (stderr
, _("Please report this bug.\n"));
496 xexit (EXIT_FAILURE
);
499 /* Support routines. */
502 fprint_value (file
, val
)
506 if (sizeof (val
) <= sizeof (long))
508 fprintf (file
, "%ld", (long) val
);
512 if (sizeof (val
) <= sizeof (bfd_vma
))
514 fprintf_vma (file
, val
);
522 sprint_value (buf
, val
)
526 if (sizeof (val
) <= sizeof (long))
528 sprintf (buf
, "%ld", (long) val
);
532 if (sizeof (val
) <= sizeof (bfd_vma
))
534 sprintf_vma (buf
, val
);
541 /* end of messages.c */
This page took 0.04068 seconds and 4 git commands to generate.