25#include "gdbsupport/gdb_wait.h"
28#include "gdbsupport/event-loop.h"
31#include "gdbsupport/filestuff.h"
34#include "gdbsupport/gdb_sys_time.h"
36#include <sys/cygwin.h>
45#define FIO_FD_INVALID -1
46#define FIO_FD_CONSOLE_IN -2
47#define FIO_FD_CONSOLE_OUT -3
63 for (i = 3; i < 10; ++i)
127 if (
flags & FILEIO_O_CREAT)
129 if (
flags & FILEIO_O_EXCL)
131 if (
flags & FILEIO_O_TRUNC)
133 if (
flags & FILEIO_O_APPEND)
135 if (
flags & FILEIO_O_RDONLY)
137 if (
flags & FILEIO_O_WRONLY)
139 if (
flags & FILEIO_O_RDWR)
156 if (mode & FILEIO_S_IFREG)
158 if (mode & FILEIO_S_IFDIR)
160 if (mode & FILEIO_S_IFCHR)
163 if (mode & FILEIO_S_IRUSR)
165 if (mode & FILEIO_S_IWUSR)
167 if (mode & FILEIO_S_IXUSR)
170 if (mode & FILEIO_S_IRGRP)
174 if (mode & FILEIO_S_IWGRP)
178 if (mode & FILEIO_S_IXGRP)
181 if (mode & FILEIO_S_IROTH)
184 if (mode & FILEIO_S_IWOTH)
188 if (mode & FILEIO_S_IXOTH)
201 case FILEIO_SEEK_SET:
204 case FILEIO_SEEK_CUR:
207 case FILEIO_SEEK_END:
222 if (!buf || !*buf || !**buf || !retlong)
224 c = strchr (*buf,
',');
228 c = strchr (*buf,
'\0');
229 while (strchr (
"+-", **buf))
235 for (*retlong = 0; **buf; ++*buf)
238 if (**buf >=
'0' && **buf <=
'9')
239 *retlong += **buf -
'0';
240 else if (**buf >=
'a' && **buf <=
'f')
241 *retlong += **buf -
'a' + 10;
242 else if (**buf >=
'A' && **buf <=
'F')
243 *retlong += **buf -
'A' + 10;
262 *retint = (long) retlong;
272 if (!buf || !*buf || !**buf || !ptrval || !length)
274 c = strchr (*buf,
'/');
280 *ptrval = (CORE_ADDR) retlong;
284 *length = (int) retlong;
291 host_to_bigendian (num, (
char *) fnum, 8);
297 host_to_fileio_time (tv->tv_sec, ftv->ftv_sec);
327 sprintf (buf + strlen (buf),
"%x", retcode);
331 error = FILEIO_EINTR;
337 sprintf (buf + strlen (buf),
",%x", error);
361 ? host_to_fileio_error (errno) : 0);
403 pathname = (
char *) alloca (length);
413 if (!stat (pathname, &st))
415 if (!S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
420 if (S_ISDIR (st.st_mode)
421 && ((
flags & O_WRONLY) == O_WRONLY || (
flags & O_RDWR) == O_RDWR))
428 fd = gdb_open_cloexec (pathname,
flags, mode).release ();
473 off_t old_offset, new_offset;
493 ptrval = (CORE_ADDR) lnum;
500 length = (size_t) num;
509 static char *remaining_buf = NULL;
510 static int remaining_length = 0;
512 buffer = (gdb_byte *)
xmalloc (16384);
515 if (remaining_length > length)
517 memcpy (buffer, remaining_buf, length);
518 memmove (remaining_buf, remaining_buf + length,
519 remaining_length - length);
520 remaining_length -= length;
525 memcpy (buffer, remaining_buf, remaining_length);
526 xfree (remaining_buf);
527 remaining_buf = NULL;
528 ret = remaining_length;
545 if (ret > 0 && (
size_t)ret > length)
547 remaining_buf = (
char *)
xmalloc (ret - length);
548 remaining_length = ret - length;
549 memcpy (remaining_buf, buffer + length, remaining_length);
556 buffer = (gdb_byte *)
xmalloc (length);
562 old_offset = lseek (fd, 0,
SEEK_CUR);
563 ret =
read (fd, buffer, length);
564 if (ret < 0 && errno == EINTR)
566 new_offset = lseek (fd, 0,
SEEK_CUR);
569 if (old_offset != new_offset)
570 ret = new_offset - old_offset;
618 ptrval = (CORE_ADDR) lnum;
625 length = (size_t) num;
627 buffer = (gdb_byte *)
xmalloc (length);
644 file->write ((
char *) buffer, length);
650 ret = write (fd, buffer, length);
651 if (ret < 0 && errno == EACCES)
697 offset = (off_t) lnum;
710 ret = lseek (fd, offset, flag);
712 if (ret == (off_t) -1)
721 CORE_ADDR old_ptr, new_ptr;
722 int old_len, new_len;
723 char *oldpath, *newpath;
725 struct stat ost, nst;
742 oldpath = (
char *) alloca (old_len);
750 newpath = (
char *) alloca (new_len);
758 of = stat (oldpath, &ost);
759 nf = stat (newpath, &nst);
760 if ((!of && !S_ISREG (ost.st_mode) && !S_ISDIR (ost.st_mode))
761 || (!nf && !S_ISREG (nst.st_mode) && !S_ISDIR (nst.st_mode)))
767 ret = rename (oldpath, newpath);
774 if (errno == ENOTEMPTY)
780 if (!of && !nf && S_ISDIR (nst.st_mode))
782 if (S_ISREG (ost.st_mode))
786 char oldfullpath[PATH_MAX];
787 char newfullpath[PATH_MAX];
790 cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath, oldfullpath,
792 cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, newfullpath,
794 len = strlen (oldfullpath);
795 if (IS_DIR_SEPARATOR (newfullpath[len])
796 && !filename_ncmp (oldfullpath, newfullpath, len))
827 pathname = (
char *) alloca (length);
836 if (!stat (pathname, &st) && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
842 ret = unlink (pathname);
853 CORE_ADDR statptr, nameptr;
873 statptr = (CORE_ADDR) lnum;
876 pathname = (
char *) alloca (namelength);
883 ret = stat (pathname, &st);
891 if (!ret && !S_ISREG (st.st_mode) && !S_ISDIR (st.st_mode))
898 host_to_fileio_stat (&st, &fst);
899 host_to_fileio_uint (0, fst.fst_dev);
940 ptrval = (CORE_ADDR) lnum;
944 host_to_fileio_uint (1, fst.fst_dev);
945 memset (&st, 0,
sizeof (st));
949 st.st_uid = getuid ();
952 st.st_gid = getgid ();
954#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
957#if HAVE_STRUCT_STAT_ST_BLOCKS
960 if (!gettimeofday (&tv, NULL))
961 st.st_atime = st.st_mtime = st.st_ctime = tv.tv_sec;
963 st.st_atime = st.st_mtime = st.st_ctime = (time_t) 0;
967 ret = fstat (fd, &st);
976 host_to_fileio_stat (&st, &fst);
995 struct fio_timeval ftv;
1003 ptrval = (CORE_ADDR) lnum;
1017 ret = gettimeofday (&tv, NULL);
1061 char *cmdline = NULL;
1073 cmdline = (
char *) alloca (length);
1094 ret = system (cmdline);
1131 c = strchr (++buf,
',');
1135 c = strchr (buf,
'\0');
1180 if (ctrlc_pending_p)
1194 catch (
const gdb_exception_forced_quit &ex)
1198 catch (
const gdb_exception_quit &ex)
1202 catch (
const gdb_exception &ex)
1253 memset (st, 0,
sizeof (
struct stat));
1263#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1266#if HAVE_STRUCT_STAT_ST_BLOCKS
1281 int val = strtoul (args, &arg_end, 10);
1283 if (*args && *arg_end ==
'\0')
1289 error (_(
"Illegal argument for \"set remote system-call-allowed\" command"));
1296 error (_(
"Garbage after \"show remote "
1297 "system-call-allowed\" command: `%s'"), args);
1298 gdb_printf (
"Calling host system(3) call from target is %sallowed\n",
1308 _(
"Set if the host system(3) call is allowed for the target."),
1312 _(
"Show if the host system(3) call is allowed for the target."),
void * xrealloc(void *ptr, size_t size)
virtual long read(char *buf, long length_buf)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
int check_quit_flag(void)
quit_handler_ftype * quit_handler
void quit_handler_ftype(void)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
ssize_t read(int fd, void *buf, size_t count)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
struct ui_file * gdb_stdtarg
struct ui_file * gdb_stdtargerr
struct ui_file * gdb_stdtargin
static int remote_fio_system_call_allowed
static mode_t remote_fileio_to_host_mode(fio_mode_t fnum)
static time_t remote_fileio_to_host_time(fio_time_t fnum)
static int remote_fileio_fd_to_targetfd(int fd)
static void remote_fileio_func_close(remote_target *remote, char *buf)
static quit_handler_ftype * remote_fileio_o_quit_handler
#define FIO_FD_CONSOLE_IN
static void remote_fileio_close_target_fd(int target_fd)
static void remote_fileio_quit_handler(void)
static void remote_fileio_to_fio_long(LONGEST num, fio_long_t fnum)
static mode_t remote_fileio_mode_to_host(long mode, int open_call)
static struct @161 remote_fio_data
void(* func)(remote_target *remote, char *)
void remote_fileio_request(remote_target *remote, char *buf, int ctrlc_pending_p)
static int remote_fileio_oflags_to_host(long flags)
static void do_remote_fileio_request(remote_target *remote, char *buf)
static void remote_fileio_func_gettimeofday(remote_target *remote, char *buf)
static void set_system_call_allowed(const char *args, int from_tty)
static void remote_fileio_func_unlink(remote_target *remote, char *buf)
static int remote_fileio_resize_fd_map(void)
void remote_fileio_to_host_stat(struct fio_stat *fst, struct stat *st)
static void remote_fileio_to_fio_timeval(struct timeval *tv, struct fio_timeval *ftv)
static void show_system_call_allowed(const char *args, int from_tty)
static unsigned int remote_fileio_to_host_uint(fio_uint_t fnum)
#define FIO_FD_CONSOLE_OUT
static int remote_fileio_extract_ptr_w_len(char **buf, CORE_ADDR *ptrval, int *length)
static void remote_fileio_func_lseek(remote_target *remote, char *buf)
void initialize_remote_fileio(struct cmd_list_element **remote_set_cmdlist, struct cmd_list_element **remote_show_cmdlist)
static int remote_fileio_map_fd(int target_fd)
static int remote_fileio_init_fd_map(void)
static struct @162 remote_fio_func_map[]
static void remote_fileio_func_stat(remote_target *remote, char *buf)
static void remote_fileio_return_errno(remote_target *remote, int retcode)
static void remote_fileio_return_success(remote_target *remote, int retcode)
static void remote_fileio_reply(remote_target *remote, int retcode, int error)
static void remote_fileio_func_system(remote_target *remote, char *buf)
static int remote_fileio_extract_long(char **buf, LONGEST *retlong)
static void remote_fileio_func_isatty(remote_target *remote, char *buf)
void remote_fileio_reset(void)
static int remote_fileio_next_free_fd(void)
static ULONGEST remote_fileio_to_host_ulong(fio_ulong_t fnum)
static void remote_fileio_func_rename(remote_target *remote, char *buf)
static void remote_fileio_func_read(remote_target *remote, char *buf)
static int remote_fileio_extract_int(char **buf, long *retint)
static void remote_fileio_func_fstat(remote_target *remote, char *buf)
static int remote_fileio_seek_flag_to_host(long num, int *flag)
static void remote_fileio_ioerror(remote_target *remote)
static void remote_fileio_func_open(remote_target *remote, char *buf)
static void remote_fileio_badfd(remote_target *remote)
static void remote_fileio_func_write(remote_target *remote, char *buf)
static struct cmd_list_element * remote_show_cmdlist
static struct cmd_list_element * remote_set_cmdlist
int putpkt(remote_target *remote, const char *buf)
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
void gdb_printf(struct ui_file *stream, const char *format,...)