From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5215 invoked by alias); 11 Mar 2011 22:05:05 -0000 Received: (qmail 5132 invoked by uid 22791); 11 Mar 2011 22:05:00 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_RG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Mar 2011 22:04:50 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2BM4nYK001622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Mar 2011 17:04:49 -0500 Received: from mesquite.lan (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2BM4mbS020154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Fri, 11 Mar 2011 17:04:48 -0500 Date: Fri, 11 Mar 2011 22:17:00 -0000 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [RFC] sim updates which fix some fileio.exp failures for v850-elf Message-ID: <20110311150447.68b4b30a@mesquite.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00683.txt.bz2 The patch below, in conjunction with a corresponding patch to libgloss and newlib, fixes several failures in the gdb.base/fileio.exp test. The patch to newlib can be found here: http://sourceware.org/ml/newlib/2011/msg00095.html Note that the newlib changes are needed for regenerating nltvals.def. I didn't post the regenerated file below as it's quite large. (There are some whitespace differences which make it look a lot bigger than it really is. A more meaningful patch can be obtained by use of diff's -w switch. I'd be willing to post that diff if anyone's interested.) This patch, in conjunction with a small patch that I committed for the sim a few weeks ago, fix the following failures: FAIL: gdb.base/fileio.exp: Creating already existing file returns EEXIST FAIL: gdb.base/fileio.exp: Open directory for writing returns EISDIR FAIL: gdb.base/fileio.exp: Opening nonexistant file returns ENOENT FAIL: gdb.base/fileio.exp: Open for write but no write permission returns EACCES FAIL: gdb.base/fileio.exp: Write using invalid file descriptor returns EBADF FAIL: gdb.base/fileio.exp: Writing to a read-only file returns EBADF FAIL: gdb.base/fileio.exp: Read using invalid file descriptor returns EBADF FAIL: gdb.base/fileio.exp: Closing an invalid file descriptor returns EBADF FAIL: gdb.base/fileio.exp: Stat a NULL pathname returns ENOENT or EFAULT FAIL: gdb.base/fileio.exp: Stat an empty pathname returns ENOENT FAIL: gdb.base/fileio.exp: Stat a nonexistant file returns ENOENT FAIL: gdb.base/fileio.exp: Fstat an open file FAIL: gdb.base/fileio.exp: Fstat an invalid file descriptor returns EBADF FAIL: gdb.base/fileio.exp: Rename a file FAIL: gdb.base/fileio.exp: Unlinking a nonexistant file returns ENOENT Comments? sim/common/ChangeLog: * gennltvals.sh: Search sys/_default_fcntl.h, in addition to fcntl.h and sys/fcntl.h, for constants. * nltvals.def: Regenerate. * sim-io.c (sim_io_stat, sim_io_fstat): New functions. * sim-io.h (sys/types.h, sys/stat.h): Include. (sim_io_stat, sim_io_fstat): Declare. sim/v850/ChangeLog: * simops (OP_10007E0): Update errno handling as most traps do not invoke the host's functionality directly. Invoke sim_io_stat() instead of stat() for implementing TARGET_SYS_stat. Implement TARGET_SYS_fstat, TARGET_SYS_rename, and TARGET_SYS_unlink. Index: sim/common/gennltvals.sh =================================================================== RCS file: /cvs/src/src/sim/common/gennltvals.sh,v retrieving revision 1.6 diff -u -p -r1.6 gennltvals.sh --- sim/common/gennltvals.sh 6 Mar 2011 00:20:21 -0000 1.6 +++ sim/common/gennltvals.sh 11 Mar 2011 21:20:47 -0000 @@ -20,7 +20,7 @@ $shell ${srccom}/gentvals.sh "" signal $ "signal.h sys/signal.h" 'SIG[A-Z0-9]*' "${cpp}" $shell ${srccom}/gentvals.sh "" open ${srcroot}/newlib/libc/include \ - "fcntl.h sys/fcntl.h" 'O_[A-Z0-9]*' "${cpp}" + "fcntl.h sys/fcntl.h sys/_default_fcntl.h" 'O_[A-Z0-9]*' "${cpp}" # Unfortunately, each newlib/libgloss port has seen fit to define their own # syscall.h file. This means that system call numbers can vary for each port. Index: sim/common/sim-io.c =================================================================== RCS file: /cvs/src/src/sim/common/sim-io.c,v retrieving revision 1.8 diff -u -p -r1.8 sim-io.c --- sim/common/sim-io.c 1 Jan 2011 15:33:56 -0000 1.8 +++ sim/common/sim-io.c 11 Mar 2011 21:20:47 -0000 @@ -387,3 +387,15 @@ sim_io_poll_read (SIM_DESC sd, return sim_io_read (sd, sim_io_fd, buf, sizeof_buf); #endif } + +int +sim_io_stat (SIM_DESC sd, const char *path, struct stat *buf) +{ + return STATE_CALLBACK (sd)->stat (STATE_CALLBACK (sd), path, buf); +} + +int +sim_io_fstat (SIM_DESC sd, int fd, struct stat *buf) +{ + return STATE_CALLBACK (sd)->fstat (STATE_CALLBACK (sd), fd, buf); +} Index: sim/common/sim-io.h =================================================================== RCS file: /cvs/src/src/sim/common/sim-io.h,v retrieving revision 1.9 diff -u -p -r1.9 sim-io.h --- sim/common/sim-io.h 1 Jan 2011 15:33:56 -0000 1.9 +++ sim/common/sim-io.h 11 Mar 2011 21:20:47 -0000 @@ -84,4 +84,10 @@ void sim_io_poll_quit (SIM_DESC sd); /* Returns -1 and sets (host) EAGAIN if not ready. */ int sim_io_poll_read (SIM_DESC sd, int, char *, int); +#include +#include + +int sim_io_stat (SIM_DESC sd, const char *path, struct stat *buf); + +int sim_io_fstat (SIM_DESC sd, int fd, struct stat *buf); #endif Index: sim/v850/simops.c =================================================================== RCS file: /cvs/src/src/sim/v850/simops.c,v retrieving revision 1.11 diff -u -p -r1.11 simops.c --- sim/v850/simops.c 14 Feb 2011 05:14:28 -0000 1.11 +++ sim/v850/simops.c 11 Mar 2011 21:20:47 -0000 @@ -1629,6 +1629,8 @@ OP_10007E0 () #define MEMPTR(x) (map (x)) + RETERR = 0; + switch (FUNC) { @@ -1636,6 +1638,7 @@ OP_10007E0 () #ifdef TARGET_SYS_fork case TARGET_SYS_fork: RETVAL = fork (); + RETERR = errno; break; #endif #endif @@ -1651,6 +1654,7 @@ OP_10007E0 () free (path); freeargv (argv); freeargv (envp); + RETERR = errno; break; } #endif @@ -1665,6 +1669,7 @@ OP_10007E0 () RETVAL = execv (path, argv); free (path); freeargv (argv); + RETERR = errno; break; } #endif @@ -1682,6 +1687,7 @@ OP_10007E0 () SW (buf, host_fd[0]); buf += sizeof(uint16); SW (buf, host_fd[1]); + RETERR = errno; } break; #endif @@ -1695,6 +1701,7 @@ OP_10007E0 () RETVAL = wait (&status); SW (PARM1, status); + RETERR = errno; } break; #endif @@ -1707,6 +1714,8 @@ OP_10007E0 () RETVAL = sim_io_read (simulator, PARM1, buf, PARM3); sim_write (simulator, PARM2, buf, PARM3); free (buf); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); break; } #endif @@ -1721,6 +1730,8 @@ OP_10007E0 () else RETVAL = sim_io_write (simulator, PARM1, buf, PARM3); free (buf); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); break; } #endif @@ -1728,12 +1739,16 @@ OP_10007E0 () #ifdef TARGET_SYS_lseek case TARGET_SYS_lseek: RETVAL = sim_io_lseek (simulator, PARM1, PARM2, PARM3); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); break; #endif #ifdef TARGET_SYS_close case TARGET_SYS_close: RETVAL = sim_io_close (simulator, PARM1); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); break; #endif @@ -1743,6 +1758,8 @@ OP_10007E0 () char *buf = fetch_str (simulator, PARM1); RETVAL = sim_io_open (simulator, buf, PARM2); free (buf); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); break; } #endif @@ -1764,7 +1781,6 @@ OP_10007E0 () break; #endif -#if !defined(__GO32__) && !defined(_WIN32) #ifdef TARGET_SYS_stat case TARGET_SYS_stat: /* added at hmsi */ /* stat system call */ @@ -1773,7 +1789,7 @@ OP_10007E0 () reg_t buf; char *path = fetch_str (simulator, PARM1); - RETVAL = stat (path, &host_stat); + RETVAL = sim_io_stat (simulator, path, &host_stat); free (path); buf = PARM2; @@ -1790,9 +1806,67 @@ OP_10007E0 () store_mem (buf + 20, 4, host_stat.st_atime); store_mem (buf + 28, 4, host_stat.st_mtime); store_mem (buf + 36, 4, host_stat.st_ctime); + + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); + } + break; +#endif + +#ifdef TARGET_SYS_fstat + case TARGET_SYS_fstat: + /* fstat system call */ + { + struct stat host_stat; + reg_t buf; + + RETVAL = sim_io_fstat (simulator, PARM1, &host_stat); + + buf = PARM2; + + /* Just wild-assed guesses. */ + store_mem (buf, 2, host_stat.st_dev); + store_mem (buf + 2, 2, host_stat.st_ino); + store_mem (buf + 4, 4, host_stat.st_mode); + store_mem (buf + 8, 2, host_stat.st_nlink); + store_mem (buf + 10, 2, host_stat.st_uid); + store_mem (buf + 12, 2, host_stat.st_gid); + store_mem (buf + 14, 2, host_stat.st_rdev); + store_mem (buf + 16, 4, host_stat.st_size); + store_mem (buf + 20, 4, host_stat.st_atime); + store_mem (buf + 28, 4, host_stat.st_mtime); + store_mem (buf + 36, 4, host_stat.st_ctime); + + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); } break; #endif + +#ifdef TARGET_SYS_rename + case TARGET_SYS_rename: + { + char *oldpath = fetch_str (simulator, PARM1); + char *newpath = fetch_str (simulator, PARM2); + RETVAL = sim_io_rename (simulator, oldpath, newpath); + free (oldpath); + free (newpath); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); + } + break; +#endif + +#ifdef TARGET_SYS_unlink + case TARGET_SYS_unlink: + { + char *path = fetch_str (simulator, PARM1); + RETVAL = sim_io_unlink (simulator, path); + free (path); + if ((int) RETVAL < 0) + RETERR = sim_io_get_errno (simulator); + } + break; #endif #ifdef HAVE_CHOWN @@ -1802,6 +1876,7 @@ OP_10007E0 () char *path = fetch_str (simulator, PARM1); RETVAL = chown (path, PARM2, PARM3); free (path); + RETERR = errno; } break; #endif @@ -1814,6 +1889,7 @@ OP_10007E0 () char *path = fetch_str (simulator, PARM1); RETVAL = chmod (path, PARM2); free (path); + RETERR = errno; } break; #endif @@ -1826,6 +1902,7 @@ OP_10007E0 () time_t now; RETVAL = time (&now); store_mem (PARM1, 4, now); + RETERR = errno; } break; #endif @@ -1841,6 +1918,7 @@ OP_10007E0 () store_mem (PARM1 + 4, 4, tms.tms_stime); store_mem (PARM1 + 8, 4, tms.tms_cutime); store_mem (PARM1 + 12, 4, tms.tms_cstime); + reterr = errno; break; } #endif @@ -1857,6 +1935,7 @@ OP_10007E0 () store_mem (PARM1 + 4, 4, t.tv_usec); store_mem (PARM2, 4, tz.tz_minuteswest); store_mem (PARM2 + 4, 4, tz.tz_dsttime); + RETERR = errno; break; } #endif @@ -1878,7 +1957,6 @@ OP_10007E0 () default: abort (); } - RETERR = errno; errno = save_errno; return 4;