diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2015-07-15 17:37:27 +0200 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2015-07-15 17:39:59 +0200 |
commit | f7af1fcd759fa126612018a5916cf808df7bb8bc (patch) | |
tree | 0d73528838655c2a32772211586bf2b33cb4750f /gdb/target.c | |
parent | 6e5b4429db0d66e2d0b27e1bcfe4709f3dae73ed (diff) | |
download | gdb-f7af1fcd759fa126612018a5916cf808df7bb8bc.zip gdb-f7af1fcd759fa126612018a5916cf808df7bb8bc.tar.gz gdb-f7af1fcd759fa126612018a5916cf808df7bb8bc.tar.bz2 |
Prepare linux_find_memory_regions_full & co. for move
Prepare code for move into gdb/common/.
gdb/ChangeLog
2015-07-15 Aleksandar Ristovski <aristovski@qnx.com
Jan Kratochvil <jan.kratochvil@redhat.com>
Prepare linux_find_memory_regions_full & co. for move.
* linux-tdep.c (linux_find_memory_region_ftype): Comment.
(linux_find_memory_regions_full): Change signature and prepare
for moving to linux-maps.
(linux_find_memory_regions_data): Rename field 'obfd' to 'data'.
(linux_find_memory_regions_thunk): New.
(linux_find_memory_regions_thunk): Use 'data' field instead of 'obfd'.
(linux_find_memory_regions_gdb): New.
(linux_find_memory_regions): Rename argument 'obfd' to 'func_data'.
(linux_make_mappings_corefile_notes): Use
linux_find_memory_regions_gdb.
* target.c (read_alloc_pread_ftype): New typedef.
(target_fileio_read_alloc_1_pread): New function.
(read_alloc): Refactor from target_fileio_read_alloc_1.
(read_stralloc_func_ftype): New typedef.
(target_fileio_read_alloc_1): New implementation. Use read_alloc.
(read_stralloc): Refactored from target_fileio_read_stralloc.
(target_fileio_read_stralloc): New implementation, use read_stralloc.
Diffstat (limited to 'gdb/target.c')
-rw-r--r-- | gdb/target.c | 96 |
1 files changed, 64 insertions, 32 deletions
diff --git a/gdb/target.c b/gdb/target.c index 4e2d005..2dd3116 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2973,6 +2973,20 @@ target_fileio_close_cleanup (void *opaque) target_fileio_close (fd, &target_errno); } +typedef int (read_alloc_pread_ftype) (int handle, gdb_byte *read_buf, int len, + ULONGEST offset, int *target_errno); + +/* Helper for target_fileio_read_alloc_1 to make it interruptible. */ + +static int +target_fileio_read_alloc_1_pread (int handle, gdb_byte *read_buf, int len, + ULONGEST offset, int *target_errno) +{ + QUIT; + + return target_fileio_pread (handle, read_buf, len, offset, target_errno); +} + /* Read target file FILENAME, in the filesystem as seen by INF. If INF is NULL, use the filesystem seen by the debugger (GDB or, for remote targets, the remote stub). Store the result in *BUF_P and @@ -2982,23 +2996,14 @@ target_fileio_close_cleanup (void *opaque) more information. */ static LONGEST -target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, - gdb_byte **buf_p, int padding) +read_alloc (gdb_byte **buf_p, int handle, read_alloc_pread_ftype *pread_func, + int padding) { - struct cleanup *close_cleanup; size_t buf_alloc, buf_pos; gdb_byte *buf; LONGEST n; - int fd; int target_errno; - fd = target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700, - &target_errno); - if (fd == -1) - return -1; - - close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd); - /* Start by reading up to 4K at a time. The target will throttle this number down if necessary. */ buf_alloc = 4096; @@ -3006,25 +3011,24 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, buf_pos = 0; while (1) { - n = target_fileio_pread (fd, &buf[buf_pos], - buf_alloc - buf_pos - padding, buf_pos, - &target_errno); - if (n < 0) + n = pread_func (handle, &buf[buf_pos], buf_alloc - buf_pos - padding, + buf_pos, &target_errno); + if (n <= 0) { - /* An error occurred. */ - do_cleanups (close_cleanup); - xfree (buf); - return -1; - } - else if (n == 0) - { - /* Read all there was. */ - do_cleanups (close_cleanup); - if (buf_pos == 0) + if (n < 0 || (n == 0 && buf_pos == 0)) xfree (buf); else *buf_p = buf; - return buf_pos; + if (n < 0) + { + /* An error occurred. */ + return -1; + } + else + { + /* Read all there was. */ + return buf_pos; + } } buf_pos += n; @@ -3035,11 +3039,31 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, buf_alloc *= 2; buf = xrealloc (buf, buf_alloc); } - - QUIT; } } +typedef LONGEST (read_stralloc_func_ftype) (struct inferior *inf, + const char *filename, + gdb_byte **buf_p, int padding); + +static LONGEST +target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, + gdb_byte **buf_p, int padding) +{ + struct cleanup *close_cleanup; + int fd, target_errno; + LONGEST retval; + + fd = target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700, &target_errno); + if (fd == -1) + return -1; + + close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd); + retval = read_alloc (buf_p, fd, target_fileio_read_alloc_1_pread, padding); + do_cleanups (close_cleanup); + return retval; +} + /* See target.h. */ LONGEST @@ -3049,16 +3073,17 @@ target_fileio_read_alloc (struct inferior *inf, const char *filename, return target_fileio_read_alloc_1 (inf, filename, buf_p, 0); } -/* See target.h. */ +/* Helper for target_fileio_read_stralloc. */ -char * -target_fileio_read_stralloc (struct inferior *inf, const char *filename) +static char * +read_stralloc (struct inferior *inf, const char *filename, + read_stralloc_func_ftype *func) { gdb_byte *buffer; char *bufstr; LONGEST i, transferred; - transferred = target_fileio_read_alloc_1 (inf, filename, &buffer, 1); + transferred = func (inf, filename, &buffer, 1); bufstr = (char *) buffer; if (transferred < 0) @@ -3082,6 +3107,13 @@ target_fileio_read_stralloc (struct inferior *inf, const char *filename) return bufstr; } +/* See target.h. */ + +char * +target_fileio_read_stralloc (struct inferior *inf, const char *filename) +{ + return read_stralloc (inf, filename, target_fileio_read_alloc_1); +} static int default_region_ok_for_hw_watchpoint (struct target_ops *self, |