/* Remote File-I/O communications
- Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 2003-2015 Free Software Foundation, Inc.
This file is part of GDB.
/* See the GDB User Guide for details of the GDB remote protocol. */
#include "defs.h"
-#include "gdb_string.h"
#include "gdbcmd.h"
#include "remote.h"
-#include "gdb/fileio.h"
#include "gdb_wait.h"
-#include "gdb_stat.h"
-#include "exceptions.h"
+#include <sys/stat.h>
#include "remote-fileio.h"
#include "event-loop.h"
#include "target.h"
#include "filenames.h"
+#include "filestuff.h"
#include <fcntl.h>
#include <sys/time.h>
return hmode;
}
-static LONGEST
-remote_fileio_mode_to_target (mode_t mode)
-{
- mode_t tmode = 0;
-
- if (S_ISREG(mode))
- tmode |= FILEIO_S_IFREG;
- if (S_ISDIR(mode))
- tmode |= FILEIO_S_IFDIR;
- if (S_ISCHR(mode))
- tmode |= FILEIO_S_IFCHR;
- if (mode & S_IRUSR)
- tmode |= FILEIO_S_IRUSR;
- if (mode & S_IWUSR)
- tmode |= FILEIO_S_IWUSR;
- if (mode & S_IXUSR)
- tmode |= FILEIO_S_IXUSR;
-#ifdef S_IRGRP
- if (mode & S_IRGRP)
- tmode |= FILEIO_S_IRGRP;
-#endif
-#ifdef S_IWRGRP
- if (mode & S_IWGRP)
- tmode |= FILEIO_S_IWGRP;
-#endif
-#ifdef S_IXGRP
- if (mode & S_IXGRP)
- tmode |= FILEIO_S_IXGRP;
-#endif
- if (mode & S_IROTH)
- tmode |= FILEIO_S_IROTH;
-#ifdef S_IWOTH
- if (mode & S_IWOTH)
- tmode |= FILEIO_S_IWOTH;
-#endif
-#ifdef S_IXOTH
- if (mode & S_IXOTH)
- tmode |= FILEIO_S_IXOTH;
-#endif
- return tmode;
-}
-
static int
remote_fileio_errno_to_target (int error)
{
return 0;
}
-/* Convert to big endian. */
-static void
-remote_fileio_to_be (LONGEST num, char *buf, int bytes)
-{
- int i;
-
- for (i = 0; i < bytes; ++i)
- buf[i] = (num >> (8 * (bytes - i - 1))) & 0xff;
-}
-
-static void
-remote_fileio_to_fio_uint (long num, fio_uint_t fnum)
-{
- remote_fileio_to_be ((LONGEST) num, (char *) fnum, 4);
-}
-
-static void
-remote_fileio_to_fio_mode (mode_t num, fio_mode_t fnum)
-{
- remote_fileio_to_be (remote_fileio_mode_to_target(num), (char *) fnum, 4);
-}
-
-static void
-remote_fileio_to_fio_time (time_t num, fio_time_t fnum)
-{
- remote_fileio_to_be ((LONGEST) num, (char *) fnum, 4);
-}
-
static void
remote_fileio_to_fio_long (LONGEST num, fio_long_t fnum)
{
remote_fileio_to_be (num, (char *) fnum, 8);
}
-static void
-remote_fileio_to_fio_ulong (LONGEST num, fio_ulong_t fnum)
-{
- remote_fileio_to_be (num, (char *) fnum, 8);
-}
-
-static void
-remote_fileio_to_fio_stat (struct stat *st, struct fio_stat *fst)
-{
- LONGEST blksize;
-
- /* `st_dev' is set in the calling function. */
- remote_fileio_to_fio_uint ((long) st->st_ino, fst->fst_ino);
- remote_fileio_to_fio_mode (st->st_mode, fst->fst_mode);
- remote_fileio_to_fio_uint ((long) st->st_nlink, fst->fst_nlink);
- remote_fileio_to_fio_uint ((long) st->st_uid, fst->fst_uid);
- remote_fileio_to_fio_uint ((long) st->st_gid, fst->fst_gid);
- remote_fileio_to_fio_uint ((long) st->st_rdev, fst->fst_rdev);
- remote_fileio_to_fio_ulong ((LONGEST) st->st_size, fst->fst_size);
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
- blksize = st->st_blksize;
-#else
- blksize = 512;
-#endif
- remote_fileio_to_fio_ulong (blksize, fst->fst_blksize);
-#if HAVE_STRUCT_STAT_ST_BLOCKS
- remote_fileio_to_fio_ulong ((LONGEST) st->st_blocks, fst->fst_blocks);
-#else
- /* FIXME: This is correct for DJGPP, but other systems that don't
- have st_blocks, if any, might prefer 512 instead of st_blksize.
- (eliz, 30-12-2003) */
- remote_fileio_to_fio_ulong (((LONGEST) st->st_size + blksize - 1)
- / blksize,
- fst->fst_blocks);
-#endif
- remote_fileio_to_fio_time (st->st_atime, fst->fst_atime);
- remote_fileio_to_fio_time (st->st_mtime, fst->fst_mtime);
- remote_fileio_to_fio_time (st->st_ctime, fst->fst_ctime);
-}
-
static void
remote_fileio_to_fio_timeval (struct timeval *tv, struct fio_timeval *ftv)
{
static void
async_remote_fileio_interrupt (gdb_client_data arg)
{
- deprecated_throw_reason (RETURN_QUIT);
+ quit ();
}
static void
}
remote_fio_no_longjmp = 1;
- fd = open (pathname, flags, mode);
+ fd = gdb_open_cloexec (pathname, flags, mode);
if (fd < 0)
{
remote_fileio_return_errno (-1);
long target_fd, num;
LONGEST lnum;
CORE_ADDR ptrval;
- int fd, ret, retlength;
+ int fd, ret;
gdb_byte *buffer;
size_t length;
off_t old_offset, new_offset;
remote_fileio_func_fstat (char *buf)
{
CORE_ADDR ptrval;
- int fd, ret, retlength;
+ int fd, ret;
long target_fd;
LONGEST lnum;
struct stat st;
{
LONGEST lnum;
CORE_ADDR ptrval;
- int ret, retlength;
+ int ret;
struct timeval tv;
struct fio_timeval ftv;
remote_fileio_func_system (char *buf)
{
CORE_ADDR ptrval;
- int ret, length, retlength;
+ int ret, length;
char *cmdline = NULL;
/* Parameter: Ptr to commandline / length incl. trailing zero */
remote_fio_ctrl_c_flag = 0;
remote_fio_no_longjmp = 0;
- ex = catch_exceptions (uiout, do_remote_fileio_request, (void *)buf,
+ ex = catch_exceptions (current_uiout,
+ do_remote_fileio_request, (void *)buf,
RETURN_MASK_ALL);
switch (ex)
{
remote_fileio_sig_exit ();
}
+\f
+
+/* Unpack an fio_uint_t. */
+
+static unsigned int
+remote_fileio_to_host_uint (fio_uint_t fnum)
+{
+ return extract_unsigned_integer ((gdb_byte *) fnum, 4,
+ BFD_ENDIAN_BIG);
+}
+
+/* Unpack an fio_ulong_t. */
+
+static ULONGEST
+remote_fileio_to_host_ulong (fio_ulong_t fnum)
+{
+ return extract_unsigned_integer ((gdb_byte *) fnum, 8,
+ BFD_ENDIAN_BIG);
+}
+
+/* Unpack an fio_mode_t. */
+
+static mode_t
+remote_fileio_to_host_mode (fio_mode_t fnum)
+{
+ return remote_fileio_mode_to_host (remote_fileio_to_host_uint (fnum),
+ 0);
+}
+
+/* Unpack an fio_time_t. */
+
+static time_t
+remote_fileio_to_host_time (fio_time_t fnum)
+{
+ return remote_fileio_to_host_uint (fnum);
+}
+
+
+/* See remote-fileio.h. */
+
+void
+remote_fileio_to_host_stat (struct fio_stat *fst, struct stat *st)
+{
+ memset (st, 0, sizeof (struct stat));
+
+ st->st_dev = remote_fileio_to_host_uint (fst->fst_dev);
+ st->st_ino = remote_fileio_to_host_uint (fst->fst_ino);
+ st->st_mode = remote_fileio_to_host_mode (fst->fst_mode);
+ st->st_nlink = remote_fileio_to_host_uint (fst->fst_nlink);
+ st->st_uid = remote_fileio_to_host_uint (fst->fst_uid);
+ st->st_gid = remote_fileio_to_host_uint (fst->fst_gid);
+ st->st_rdev = remote_fileio_to_host_uint (fst->fst_rdev);
+ st->st_size = remote_fileio_to_host_ulong (fst->fst_size);
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
+ st->st_blksize = remote_fileio_to_host_ulong (fst->fst_blksize);
+#endif
+#if HAVE_STRUCT_STAT_ST_BLOCKS
+ st->st_blocks = remote_fileio_to_host_ulong (fst->fst_blocks);
+#endif
+ st->st_atime = remote_fileio_to_host_time (fst->fst_atime);
+ st->st_mtime = remote_fileio_to_host_time (fst->fst_mtime);
+ st->st_ctime = remote_fileio_to_host_time (fst->fst_ctime);
+}
+\f
static void
set_system_call_allowed (char *args, int from_tty)