aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2003-12-19 15:23:41 +0000
committerNick Clifton <nickc@redhat.com>2003-12-19 15:23:41 +0000
commit5a1964ecbd3d7a66c626e2bb5edd7780b99f5aa9 (patch)
treed74dd9613386288ff8eb98abd1c5b449c20b30de
parent10ecffb9b24b79b6a9f373d0c9df0f4c447864a5 (diff)
downloadgdb-5a1964ecbd3d7a66c626e2bb5edd7780b99f5aa9.zip
gdb-5a1964ecbd3d7a66c626e2bb5edd7780b99f5aa9.tar.gz
gdb-5a1964ecbd3d7a66c626e2bb5edd7780b99f5aa9.tar.bz2
Fix calls to as_perror() so that the errno system message will be printed.
Fix as_perror() so that errno is not corrupted.
-rw-r--r--gas/ChangeLog14
-rw-r--r--gas/input-file.c29
-rw-r--r--gas/listing.c149
-rw-r--r--gas/messages.c78
-rw-r--r--gas/output-file.c30
5 files changed, 152 insertions, 148 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index bfb7343..512b58c 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,17 @@
+2003-12-19 Nick Clifton <nickc@redhat.com>
+ Andreas Schwab <schwab@suse.de>
+
+ * messages.c (as_perror): Save errno around library calls.
+ * input-file.c [BFD_ASSEMBLER]: Set the BFD error to
+ bfd_error_system_call before each call to as_perror.
+ (input_file_open): Simplify the error reporting code to just use
+ as_perror().
+ * output-file.c (output_file_create) [BFD_ASSEMBLER]: Set the BFD
+ error to bfd_error_system_call before calling as_perror.
+ (output_file_close) [BFD_ASSEMBLER]: Likewise.
+ (output_file_append) [BFD_ASSEMBLER]: Likewise.
+ * listing.c (listing_print) [BFD_ASSEMBLER]: Likewise.
+
2003-12-19 Kazuhiro Inaoka <inaoka.kazuhiro@renesas.com>
Add m32r-linux and PIC support. Add new ABI that uses RELA.
diff --git a/gas/input-file.c b/gas/input-file.c
index bf36d5b..01cc669 100644
--- a/gas/input-file.c
+++ b/gas/input-file.c
@@ -151,18 +151,10 @@ input_file_open (char *filename, /* "" means use stdin. Must not be 0. */
if (f_in == NULL || ferror (f_in))
{
- switch (errno)
- {
- case ENOENT:
- as_bad (_("%s: no such file"), filename);
- break;
- case EISDIR:
- as_bad (_("%s: is a directory"), filename);
- break;
- default:
- as_bad (_("can't open %s for reading"), file_name);
- as_perror ("%s", file_name);
- }
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("Can't open %s for reading"), file_name);
if (f_in)
{
@@ -227,6 +219,9 @@ input_file_get (char *buf, int buflen)
size = fread (buf, sizeof (char), buflen, f_in);
if (size < 0)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Can't read from %s"), file_name);
size = 0;
}
@@ -253,6 +248,9 @@ input_file_give_next_buffer (char *where /* Where to place 1st character of new
size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
if (size < 0)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Can't read from %s"), file_name);
size = 0;
}
@@ -261,7 +259,12 @@ input_file_give_next_buffer (char *where /* Where to place 1st character of new
else
{
if (fclose (f_in))
- as_perror (_("Can't close %s"), file_name);
+ {
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("Can't close %s"), file_name);
+ }
f_in = (FILE *) 0;
return_value = 0;
}
diff --git a/gas/listing.c b/gas/listing.c
index 635cb3a..aa22c5e 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -1,27 +1,26 @@
/* listing.c - maintain assembly listings
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002
+ 2001, 2002, 2003
Free Software Foundation, Inc.
-This file is part of GAS, the GNU Assembler.
+ This file is part of GAS, the GNU Assembler.
-GAS is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+ GAS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
-GAS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ GAS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with GAS; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with GAS; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
-/*
- Contributed by Steve Chamberlain <sac@cygnus.com>
+/* Contributed by Steve Chamberlain <sac@cygnus.com>
A listing page looks like:
@@ -88,8 +87,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
LISTING_LHS_CONT_LINES Max number of lines to use up for a continuation
LISTING_RHS_WIDTH Number of chars from the input file to print
- on a line
-*/
+ on a line. */
#include "as.h"
#include "obstack.h"
@@ -119,7 +117,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#endif
/* This structure remembers which .s were used. */
-typedef struct file_info_struct {
+typedef struct file_info_struct
+{
struct file_info_struct * next;
char * filename;
long pos;
@@ -129,12 +128,14 @@ typedef struct file_info_struct {
/* This structure remembers which line from which file goes into which
frag. */
-struct list_info_struct {
+struct list_info_struct
+{
/* Frag which this line of source is nearest to. */
fragS *frag;
/* The actual line in the source file. */
unsigned int line;
+
/* Pointer to the file info struct for the file which this line
belongs to. */
file_info_type *file;
@@ -148,21 +149,23 @@ struct list_info_struct {
/* Pointer to the file info struct for the high level language
source line that belongs here. */
file_info_type *hll_file;
+
/* High level language source line. */
unsigned int hll_line;
/* Pointer to any error message associated with this line. */
char *message;
- enum {
- EDICT_NONE,
- EDICT_SBTTL,
- EDICT_TITLE,
- EDICT_NOLIST,
- EDICT_LIST,
- EDICT_NOLIST_NEXT,
- EDICT_EJECT
- } edict;
+ enum
+ {
+ EDICT_NONE,
+ EDICT_SBTTL,
+ EDICT_TITLE,
+ EDICT_NOLIST,
+ EDICT_LIST,
+ EDICT_NOLIST_NEXT,
+ EDICT_EJECT
+ } edict;
char *edict_arg;
/* Nonzero if this line is to be omitted because it contains
@@ -204,19 +207,17 @@ static FILE *list_file;
static char *data_buffer;
/* Prototypes. */
-static void listing_message (const char *name, const char *message);
-static file_info_type *file_info (const char *file_name);
+static void listing_message (const char *, const char *);
+static file_info_type *file_info (const char *);
static void new_frag (void);
-static char *buffer_line (file_info_type *file, char *line, unsigned int size);
-static void listing_page (list_info_type *list);
-static unsigned int calc_hex (list_info_type *list);
-static void print_lines (list_info_type *, unsigned int,
- char *, unsigned int);
+static char *buffer_line (file_info_type *, char *, unsigned int);
+static void listing_page (list_info_type *);
+static unsigned int calc_hex (list_info_type *);
+static void print_lines (list_info_type *, unsigned int, char *, unsigned int);
static void list_symbol_table (void);
-static void print_source (file_info_type *current_file, list_info_type *list,
- char *buffer, unsigned int width);
+static void print_source (file_info_type *, list_info_type *, char *, unsigned int);
static int debugging_pseudo (list_info_type *, const char *);
-static void listing_listing (char *name);
+static void listing_listing (char *);
static void
listing_message (const char *name, const char *message)
@@ -257,8 +258,7 @@ file_info (const char *file_name)
}
/* Make new entry. */
-
- p = (file_info_type *) xmalloc (sizeof (file_info_type));
+ p = xmalloc (sizeof (file_info_type));
p->next = file_info_head;
file_info_head = p;
p->filename = xstrdup (file_name);
@@ -272,10 +272,8 @@ file_info (const char *file_name)
static void
new_frag (void)
{
-
frag_wane (frag_now);
frag_new (0);
-
}
void
@@ -373,7 +371,7 @@ listing_newline (char *ps)
}
else
{
- new = (list_info_type *) xmalloc (sizeof (list_info_type));
+ new = xmalloc (sizeof (list_info_type));
new->line_contents = ps;
}
@@ -591,9 +589,7 @@ calc_hex (list_info_type *list)
&& data_buffer_size < MAX_BYTES - 3)
{
if (address == ~(unsigned int) 0)
- {
- address = frag_ptr->fr_address / OCTETS_PER_BYTE;
- }
+ address = frag_ptr->fr_address / OCTETS_PER_BYTE;
sprintf (data_buffer + data_buffer_size,
"%02X",
@@ -612,9 +608,8 @@ calc_hex (list_info_type *list)
&& data_buffer_size < MAX_BYTES - 3)
{
if (address == ~(unsigned int) 0)
- {
- address = frag_ptr->fr_address / OCTETS_PER_BYTE;
- }
+ address = frag_ptr->fr_address / OCTETS_PER_BYTE;
+
sprintf (data_buffer + data_buffer_size,
"%02X",
(frag_ptr->fr_literal[var_rep_idx]) & 0xff);
@@ -861,6 +856,7 @@ print_source (file_info_type *current_file, list_info_type *list,
&& !current_file->at_end)
{
char *p = buffer_line (current_file, buffer, width);
+
fprintf (list_file, "%4u:%-13s **** %s\n", current_file->linenum,
current_file->filename, p);
on_page++;
@@ -933,7 +929,6 @@ debugging_pseudo (list_info_type *list, const char *line)
return 1;
if (strncmp (line, "tag", 3) == 0)
return 1;
-
if (strncmp (line, "stabs", 5) == 0)
return 1;
if (strncmp (line, "stabn", 5) == 0)
@@ -963,7 +958,6 @@ listing_listing (char *name ATTRIBUTE_UNUSED)
if (list->next)
list->frag = list->next->frag;
list = list->next;
-
}
list = head->next;
@@ -1025,24 +1019,19 @@ listing_listing (char *name ATTRIBUTE_UNUSED)
message = 0;
if (list->hll_file)
- {
- current_hll_file = list->hll_file;
- }
+ current_hll_file = list->hll_file;
if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
- {
- print_source (current_hll_file, list, buffer, width);
- }
+ print_source (current_hll_file, list, buffer, width);
if (list->line_contents)
{
if (!((listing & LISTING_NODEBUG)
&& debugging_pseudo (list, list->line_contents)))
- {
- print_lines (list,
- list->file->linenum == 0 ? list->line : list->file->linenum,
- list->line_contents, calc_hex (list));
- }
+ print_lines (list,
+ list->file->linenum == 0 ? list->line : list->file->linenum,
+ list->line_contents, calc_hex (list));
+
free (list->line_contents);
list->line_contents = NULL;
}
@@ -1067,9 +1056,7 @@ listing_listing (char *name ATTRIBUTE_UNUSED)
}
if (list->edict == EDICT_EJECT)
- {
- eject = 1;
- }
+ eject = 1;
}
if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
@@ -1103,6 +1090,9 @@ listing_print (char *name)
using_stdout = 0;
else
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("can't open list file: %s"), name);
list_file = stdout;
using_stdout = 1;
@@ -1110,30 +1100,27 @@ listing_print (char *name)
}
if (listing & LISTING_NOFORM)
- {
- paper_height = 0;
- }
+ paper_height = 0;
if (listing & LISTING_LISTING)
- {
- listing_listing (name);
- }
+ listing_listing (name);
if (listing & LISTING_SYMBOLS)
- {
- list_symbol_table ();
- }
+ list_symbol_table ();
if (! using_stdout)
{
if (fclose (list_file) == EOF)
- as_perror (_("error closing list file: %s"), name);
+ {
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("error closing list file: %s"), name);
+ }
}
if (last_open_file)
- {
- fclose (last_open_file);
- }
+ fclose (last_open_file);
}
void
@@ -1337,25 +1324,21 @@ listing_title (int depth)
void
listing_file (const char *name)
{
-
}
void
listing_newline (char *name)
{
-
}
void
listing_source_line (unsigned int n)
{
-
}
void
listing_source_file (const char *n)
{
-
}
#endif
diff --git a/gas/messages.c b/gas/messages.c
index 18d22da..005cd22 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -1,5 +1,5 @@
/* messages.c - error reporter -
- Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001
+ Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2003
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -48,46 +48,46 @@ static void as_warn_internal (char *, unsigned int, char *);
static void as_bad_internal (char *, unsigned int, char *);
/* Despite the rest of the comments in this file, (FIXME-SOON),
- * here is the current scheme for error messages etc:
- *
- * as_fatal() is used when gas is quite confused and
- * continuing the assembly is pointless. In this case we
- * exit immediately with error status.
- *
- * as_bad() is used to mark errors that result in what we
- * presume to be a useless object file. Say, we ignored
- * something that might have been vital. If we see any of
- * these, assembly will continue to the end of the source,
- * no object file will be produced, and we will terminate
- * with error status. The new option, -Z, tells us to
- * produce an object file anyway but we still exit with
- * error status. The assumption here is that you don't want
- * this object file but we could be wrong.
- *
- * as_warn() is used when we have an error from which we
- * have a plausible error recovery. eg, masking the top
- * bits of a constant that is longer than will fit in the
- * destination. In this case we will continue to assemble
- * the source, although we may have made a bad assumption,
- * and we will produce an object file and return normal exit
- * status (ie, no error). The new option -X tells us to
- * treat all as_warn() errors as as_bad() errors. That is,
- * no object file will be produced and we will exit with
- * error status. The idea here is that we don't kill an
- * entire make because of an error that we knew how to
- * correct. On the other hand, sometimes you might want to
- * stop the make at these points.
- *
- * as_tsktsk() is used when we see a minor error for which
- * our error recovery action is almost certainly correct.
- * In this case, we print a message and then assembly
- * continues as though no error occurred.
- */
+ here is the current scheme for error messages etc:
+
+ as_fatal() is used when gas is quite confused and
+ continuing the assembly is pointless. In this case we
+ exit immediately with error status.
+
+ as_bad() is used to mark errors that result in what we
+ presume to be a useless object file. Say, we ignored
+ something that might have been vital. If we see any of
+ these, assembly will continue to the end of the source,
+ no object file will be produced, and we will terminate
+ with error status. The new option, -Z, tells us to
+ produce an object file anyway but we still exit with
+ error status. The assumption here is that you don't want
+ this object file but we could be wrong.
+
+ as_warn() is used when we have an error from which we
+ have a plausible error recovery. eg, masking the top
+ bits of a constant that is longer than will fit in the
+ destination. In this case we will continue to assemble
+ the source, although we may have made a bad assumption,
+ and we will produce an object file and return normal exit
+ status (ie, no error). The new option -X tells us to
+ treat all as_warn() errors as as_bad() errors. That is,
+ no object file will be produced and we will exit with
+ error status. The idea here is that we don't kill an
+ entire make because of an error that we knew how to
+ correct. On the other hand, sometimes you might want to
+ stop the make at these points.
+
+ as_tsktsk() is used when we see a minor error for which
+ our error recovery action is almost certainly correct.
+ In this case, we print a message and then assembly
+ continues as though no error occurred. */
static void
identify (char *file)
{
static int identified;
+
if (identified)
return;
identified++;
@@ -109,7 +109,7 @@ static int warning_count;
int
had_warnings (void)
{
- return (warning_count);
+ return warning_count;
}
/* Nonzero if we've hit a 'bad error', and should not write an obj file,
@@ -120,7 +120,7 @@ static int error_count;
int
had_errors (void)
{
- return (error_count);
+ return error_count;
}
/* Print the current location to stderr. */
@@ -144,9 +144,11 @@ as_perror (const char *gripe, /* Unpunctuated error theme. */
const char *filename)
{
const char *errtxt;
+ int saved_errno = errno;
as_show_where ();
fprintf (stderr, gripe, filename);
+ errno = saved_errno;
#ifdef BFD_ASSEMBLER
errtxt = bfd_errmsg (bfd_get_error ());
#else
diff --git a/gas/output-file.c b/gas/output-file.c
index 304e904..4c376b4 100644
--- a/gas/output-file.c
+++ b/gas/output-file.c
@@ -1,5 +1,5 @@
/* output-file.c - Deal with the output file
- Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001
+ Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001, 2003
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -84,10 +84,9 @@ output_file_close (char *filename)
#ifndef BFD_ASSEMBLER
void
-output_file_append (where, length, filename)
- char *where ATTRIBUTE_UNUSED;
- long length ATTRIBUTE_UNUSED;
- char *filename ATTRIBUTE_UNUSED;
+output_file_append (char *where ATTRIBUTE_UNUSED,
+ long length ATTRIBUTE_UNUSED,
+ char *filename ATTRIBUTE_UNUSED)
{
abort ();
}
@@ -98,8 +97,7 @@ output_file_append (where, length, filename)
static FILE *stdoutput;
void
-output_file_create (name)
- char *name;
+output_file_create (char *name)
{
if (name[0] == '-' && name[1] == '\0')
{
@@ -110,17 +108,22 @@ output_file_create (name)
stdoutput = fopen (name, FOPEN_WB);
if (stdoutput == NULL)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("FATAL: can't create %s"), name);
exit (EXIT_FAILURE);
}
}
void
-output_file_close (filename)
- char *filename;
+output_file_close (char *filename)
{
if (EOF == fclose (stdoutput))
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("FATAL: can't close %s"), filename);
exit (EXIT_FAILURE);
}
@@ -130,18 +133,17 @@ output_file_close (filename)
}
void
-output_file_append (where, length, filename)
- char * where;
- long length;
- char * filename;
+output_file_append (char * where, long length, char * filename)
{
for (; length; length--, where++)
{
(void) putc (*where, stdoutput);
if (ferror (stdoutput))
- /* if ( EOF == (putc( *where, stdoutput )) ) */
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Failed to emit an object byte"), filename);
as_fatal (_("can't continue"));
}