Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Mitchell <mark@codesourcery.com>
To: gdb-patches@sources.redhat.com
Cc: nickc@redhat.com
Subject: PATCH: Fix ARM "open" simulation
Date: Mon, 29 Dec 2003 19:57:00 -0000	[thread overview]
Message-ID: <200312291956.hBTJuVbA026722@sirius.codesourcery.com> (raw)


This obvious patch fixes a bug in the ARM simulator.  The
translate_open_mode table mapped ARM SWI open modes into UNIX-style
open modes -- but for the *host* operating system rather than for the
*target* operating system.  The generic simulation code will translate
from the target system to the host system, so it is wrong to do that
in armos.c.  Without this patch, the wrong value was used for things
like O_TRUNC when building a GNU/Linux-hosted simulator targeting ARM,
resulting in some very weird failure modes.

Tested on i686-pc-linux-gnu by running the SIM testsuite and the
libstdc++-v3 testsuite.

I've applied this patch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-12-29  Mark Mitchell  <mark@codesourcery.com>

	* armos.c (fcntl.h): Do not include it.
	(O_RDONLY): Do not define.
	(O_WRONLY): Likewise.
	(O_RDWR): Likewise.
	(targ-vals.h): Include it.
	(translate_open_mode): Use TARGET_O_* instead of O_*.
	(SWIopen): Likewise.
	* Makefile.in (armos.o): Depend on targ-vals.h.

Index: sim/arm/Makefile.in
===================================================================
RCS file: /cvs/src/src/sim/arm/Makefile.in,v
retrieving revision 1.8
diff -c -5 -p -r1.8 Makefile.in
*** sim/arm/Makefile.in	30 Mar 2003 10:39:22 -0000	1.8
--- sim/arm/Makefile.in	29 Dec 2003 19:49:57 -0000
*************** SIM_OBJS = armemu26.o armemu32.o arminit
*** 26,36 ****
  	armvirt.o bag.o thumbemu.o wrapper.o sim-load.o $(COPRO) 
  
  ## COMMON_POST_CONFIG_FRAG
  
  
! armos.o: armos.c armdefs.h armos.h armfpe.h
  
  armcopro.o: armcopro.c armdefs.h
  maverick.o: maverick.c armdefs.h
  iwmmxt.o: iwmmxt.c iwmmxt.h armdefs.h
  
--- 26,36 ----
  	armvirt.o bag.o thumbemu.o wrapper.o sim-load.o $(COPRO) 
  
  ## COMMON_POST_CONFIG_FRAG
  
  
! armos.o: armos.c armdefs.h armos.h armfpe.h targ-vals.h
  
  armcopro.o: armcopro.c armdefs.h
  maverick.o: maverick.c armdefs.h
  iwmmxt.o: iwmmxt.c iwmmxt.h armdefs.h
  
Index: sim/arm/armos.c
===================================================================
RCS file: /cvs/src/src/sim/arm/armos.c,v
retrieving revision 1.20
diff -c -5 -p -r1.20 armos.c
*** sim/arm/armos.c	27 Mar 2003 17:13:33 -0000	1.20
--- sim/arm/armos.c	29 Dec 2003 19:49:57 -0000
***************
*** 26,48 ****
  #include "ansidecl.h"
  
  #include <time.h>
  #include <errno.h>
  #include <string.h>
! #include <fcntl.h>
  
! #ifndef O_RDONLY
! #define O_RDONLY 0
! #endif
! #ifndef O_WRONLY
! #define O_WRONLY 1
! #endif
! #ifndef O_RDWR
! #define O_RDWR   2
! #endif
! #ifndef O_BINARY
! #define O_BINARY 0
  #endif
  
  #ifdef __STDC__
  #define unlink(s) remove(s)
  #endif
--- 26,39 ----
  #include "ansidecl.h"
  
  #include <time.h>
  #include <errno.h>
  #include <string.h>
! #include "targ-vals.h"
  
! #ifndef TARGET_O_BINARY
! #define TARGET_O_BINARY 0
  #endif
  
  #ifdef __STDC__
  #define unlink(s) remove(s)
  #endif
*************** ARMword ARMul_OSLastErrorP (ARMul_State 
*** 258,279 ****
    return ((struct OSblock *) state->OSptr)->ErrorP;
  }
  
  static int translate_open_mode[] =
  {
!   O_RDONLY,			/* "r"   */
!   O_RDONLY + O_BINARY,		/* "rb"  */
!   O_RDWR,			/* "r+"  */
!   O_RDWR + O_BINARY,		/* "r+b" */
!   O_WRONLY + O_CREAT + O_TRUNC,	/* "w"   */
!   O_WRONLY + O_BINARY + O_CREAT + O_TRUNC,	/* "wb"  */
!   O_RDWR + O_CREAT + O_TRUNC,	/* "w+"  */
!   O_RDWR + O_BINARY + O_CREAT + O_TRUNC,	/* "w+b" */
!   O_WRONLY + O_APPEND + O_CREAT,	/* "a"   */
!   O_WRONLY + O_BINARY + O_APPEND + O_CREAT,	/* "ab"  */
!   O_RDWR + O_APPEND + O_CREAT,	/* "a+"  */
!   O_RDWR + O_BINARY + O_APPEND + O_CREAT	/* "a+b" */
  };
  
  static void
  SWIWrite0 (ARMul_State * state, ARMword addr)
  {
--- 249,270 ----
    return ((struct OSblock *) state->OSptr)->ErrorP;
  }
  
  static int translate_open_mode[] =
  {
!   TARGET_O_RDONLY,		/* "r"   */
!   TARGET_O_RDONLY + TARGET_O_BINARY,	/* "rb"  */
!   TARGET_O_RDWR,		/* "r+"  */
!   TARGET_O_RDWR + TARGET_O_BINARY,		/* "r+b" */
!   TARGET_O_WRONLY + TARGET_O_CREAT + TARGET_O_TRUNC,	/* "w"   */
!   TARGET_O_WRONLY + TARGET_O_BINARY + TARGET_O_CREAT + TARGET_O_TRUNC,	/* "wb"  */
!   TARGET_O_RDWR + TARGET_O_CREAT + TARGET_O_TRUNC,	/* "w+"  */
!   TARGET_O_RDWR + TARGET_O_BINARY + TARGET_O_CREAT + TARGET_O_TRUNC,	/* "w+b" */
!   TARGET_O_WRONLY + TARGET_O_APPEND + TARGET_O_CREAT,	/* "a"   */
!   TARGET_O_WRONLY + TARGET_O_BINARY + TARGET_O_APPEND + TARGET_O_CREAT,	/* "ab"  */
!   TARGET_O_RDWR + TARGET_O_APPEND + TARGET_O_CREAT,	/* "a+"  */
!   TARGET_O_RDWR + TARGET_O_BINARY + TARGET_O_APPEND + TARGET_O_CREAT	/* "a+b" */
  };
  
  static void
  SWIWrite0 (ARMul_State * state, ARMword addr)
  {
*************** SWIopen (ARMul_State * state, ARMword na
*** 323,333 ****
    flags = translate_open_mode[SWIflags];
  
    /* Filename ":tt" is special: it denotes stdin/out.  */
    if (strcmp (dummy, ":tt") == 0)
      {
!       if (flags == O_RDONLY)	/* opening tty "r" */
  	state->Reg[0] = 0;	/* stdin */
        else
  	state->Reg[0] = 1;	/* stdout */
      }
    else
--- 314,324 ----
    flags = translate_open_mode[SWIflags];
  
    /* Filename ":tt" is special: it denotes stdin/out.  */
    if (strcmp (dummy, ":tt") == 0)
      {
!       if (flags == TARGET_O_RDONLY) /* opening tty "r" */
  	state->Reg[0] = 0;	/* stdin */
        else
  	state->Reg[0] = 1;	/* stdout */
      }
    else


             reply	other threads:[~2003-12-29 19:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-29 19:57 Mark Mitchell [this message]
2004-01-02 17:08 ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200312291956.hBTJuVbA026722@sirius.codesourcery.com \
    --to=mark@codesourcery.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=nickc@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox