Expose the fileio methods through the target vector. From: Pedro Alves --- gdb/remote.c | 6 ++++++ gdb/target.c | 25 +++++++++++++++++++++++++ gdb/target.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 60d7ecd..7542882 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10684,6 +10684,12 @@ Specify the serial device it is connected to\n\ remote_ops.to_static_tracepoint_markers_by_strid = remote_static_tracepoint_markers_by_strid; remote_ops.to_traceframe_info = remote_traceframe_info; + + remote_ops.to_file_open = remote_hostio_open; + remote_ops.to_file_pwrite = remote_hostio_pwrite; + remote_ops.to_file_pread = remote_hostio_pread; + remote_ops.to_file_close = remote_hostio_close; + remote_ops.to_file_unlink = remote_hostio_unlink; } /* Set up the extended remote vector by making a copy of the standard diff --git a/gdb/target.c b/gdb/target.c index 9aaa0ea..74238a5 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -697,6 +697,13 @@ update_current_target (void) INHERIT (to_static_tracepoint_marker_at, t); INHERIT (to_static_tracepoint_markers_by_strid, t); INHERIT (to_traceframe_info, t); + + INHERIT (to_file_open, t); + INHERIT (to_file_pwrite, t); + INHERIT (to_file_pread, t); + INHERIT (to_file_close, t); + INHERIT (to_file_unlink, t); + INHERIT (to_magic, t); /* Do not inherit to_memory_map. */ /* Do not inherit to_flash_erase. */ @@ -926,6 +933,24 @@ update_current_target (void) tcomplain); de_fault (to_execution_direction, default_execution_direction); + de_fault (to_file_open, + (int (*) (const char *, int, int, int *)) + tcomplain); + de_fault (to_file_pwrite, + (int (*) (int, const gdb_byte *, int, + ULONGEST, int *)) + tcomplain); + de_fault (to_file_pread, + (int (*) (int, gdb_byte *, int, + ULONGEST, int *)) + tcomplain); + de_fault (to_file_close, + (int (*) (int, int *)) + tcomplain); + de_fault (to_file_unlink, + (int (*) (const char *, int *)) + tcomplain); + #undef de_fault /* Finally, position the target-stack beneath the squashed diff --git a/gdb/target.h b/gdb/target.h index 7d0bed1..96176a5 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -795,6 +795,32 @@ struct target_ops re-fetching when necessary. */ struct traceframe_info *(*to_traceframe_info) (void); + /* Open FILENAME on the target, using FLAGS and MODE. Return a + target file descriptor, or -1 if an error occurs (and set + *TARGET_ERRNO). */ + int (*to_file_open) (const char *filename, int flags, int mode, + int *target_errno); + + /* Write up to LEN bytes from WRITE_BUF to FD on the target. + Return the number of bytes written, or -1 if an error occurs + (and set *TARGET_ERRNO). */ + int (*to_file_pwrite) (int fd, const gdb_byte *write_buf, int len, + ULONGEST offset, int *target_errno); + + /* Read up to LEN bytes FD on the target into READ_BUF. Return + the number of bytes read, or -1 if an error occurs (and set + *TARGET_ERRNO). */ + int (*to_file_pread) (int fd, gdb_byte *read_buf, int len, + ULONGEST offset, int *target_errno); + + /* Close FD on the target. Return 0, or -1 if an error occurs + (and set *TARGET_ERRNO). */ + int (*to_file_close) (int fd, int *target_errno); + + /* Unlink FILENAME on the target. Return 0, or -1 if an error + occurs (and set *TARGET_ERRNO). */ + int (*to_file_unlink) (const char *filename, int *target_errno); + int to_magic; /* Need sub-structure for target machine related rather than comm related? */ @@ -1493,7 +1519,6 @@ extern int target_search_memory (CORE_ADDR start_addr, #define target_trace_init() \ (*current_target.to_trace_init) () - #define target_download_tracepoint(t) \ (*current_target.to_download_tracepoint) (t) @@ -1744,6 +1769,26 @@ extern int may_stop; extern void update_target_permissions (void); +/* See to_file_open for description. */ +#define target_file_open(filename, flags, mode, target_errno) \ + (*current_target.to_file_open) (filename, flags, mode, target_errno) + +/* See to_file_pwrite for description. */ +#define target_file_pwrite(fd, write_buf, len, offset, target_errno) \ + (*current_target.to_file_pwrite) (fd, write_buf, len, offset, target_errno) + +/* See to_file_pread for description. */ +#define target_file_pread(fd, read_buf, len, offset, target_errno) \ + (*current_target.to_file_pread) (fd, read_buf, len, offset, target_errno) + +/* See to_file_close for description. */ +#define target_file_close(fd, target_errno) \ + (*current_target.to_file_close) (fd, target_errno) + +/* See to_file_unlink for description. */ +#define target_file_unlink(filename, target_errno) \ + (*current_target.to_file_close) (filename, target_errno) + /* Imported from machine dependent code. */