aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
authorYao Qi <yao@codesourcery.com>2014-01-27 20:35:33 +0800
committerYao Qi <yao@codesourcery.com>2014-02-11 14:20:33 +0800
commit9b409511d07fe375284701af34909fb539029caf (patch)
tree963bd8ab614e83e16bac7caa81c3081f69c505ef /gdb/linux-nat.c
parenta8e6308380e7c76bff431ed8477b85b4fd3b3542 (diff)
downloadgdb-9b409511d07fe375284701af34909fb539029caf.zip
gdb-9b409511d07fe375284701af34909fb539029caf.tar.gz
gdb-9b409511d07fe375284701af34909fb539029caf.tar.bz2
Return target_xfer_status in to_xfer_partial
This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r--gdb/linux-nat.c99
1 files changed, 68 insertions, 31 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index ebf4055..1dac44d 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3862,10 +3862,11 @@ siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
}
}
-static LONGEST
+static enum target_xfer_status
linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, ULONGEST len)
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
{
int pid;
siginfo_t siginfo;
@@ -3912,27 +3913,28 @@ linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
return TARGET_XFER_E_IO;
}
- return len;
+ *xfered_len = len;
+ return TARGET_XFER_OK;
}
-static LONGEST
+static enum target_xfer_status
linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len)
+ ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
struct cleanup *old_chain;
- LONGEST xfer;
+ enum target_xfer_status xfer;
if (object == TARGET_OBJECT_SIGNAL_INFO)
return linux_xfer_siginfo (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
/* The target is connected but no live inferior is selected. Pass
this request down to a lower stratum (e.g., the executable
file). */
if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid))
- return 0;
+ return TARGET_XFER_EOF;
old_chain = save_inferior_ptid ();
@@ -3940,7 +3942,7 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
inferior_ptid = pid_to_ptid (ptid_get_lwp (inferior_ptid));
xfer = linux_ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
do_cleanups (old_chain);
return xfer;
@@ -4110,11 +4112,11 @@ linux_nat_make_corefile_notes (bfd *obfd, int *note_size)
can be much more efficient than banging away at PTRACE_PEEKTEXT,
but it doesn't support writes. */
-static LONGEST
+static enum target_xfer_status
linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
- ULONGEST offset, LONGEST len)
+ ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
{
LONGEST ret;
int fd;
@@ -4125,7 +4127,7 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
/* Don't bother for one word. */
if (len < 3 * sizeof (long))
- return 0;
+ return TARGET_XFER_EOF;
/* We could keep this file open and cache it - possibly one per
thread. That requires some juggling, but is even faster. */
@@ -4133,7 +4135,7 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
ptid_get_pid (inferior_ptid));
fd = gdb_open_cloexec (filename, O_RDONLY | O_LARGEFILE, 0);
if (fd == -1)
- return 0;
+ return TARGET_XFER_EOF;
/* If pread64 is available, use it. It's faster if the kernel
supports it (only one syscall), and it's 64-bit safe even on
@@ -4149,7 +4151,14 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
ret = len;
close (fd);
- return ret;
+
+ if (ret == 0)
+ return TARGET_XFER_EOF;
+ else
+ {
+ *xfered_len = ret;
+ return TARGET_XFER_OK;
+ }
}
@@ -4205,11 +4214,12 @@ spu_enumerate_spu_ids (int pid, gdb_byte *buf, ULONGEST offset, ULONGEST len)
/* Implement the to_xfer_partial interface for the TARGET_OBJECT_SPU
object type, using the /proc file system. */
-static LONGEST
+
+static enum target_xfer_status
linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
- ULONGEST offset, ULONGEST len)
+ ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
char buf[128];
int fd = 0;
@@ -4221,7 +4231,19 @@ linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
if (!readbuf)
return TARGET_XFER_E_IO;
else
- return spu_enumerate_spu_ids (pid, readbuf, offset, len);
+ {
+ LONGEST l = spu_enumerate_spu_ids (pid, readbuf, offset, len);
+
+ if (l < 0)
+ return TARGET_XFER_E_IO;
+ else if (l == 0)
+ return TARGET_XFER_EOF;
+ else
+ {
+ *xfered_len = (ULONGEST) l;
+ return TARGET_XFER_OK;
+ }
+ }
}
xsnprintf (buf, sizeof buf, "/proc/%d/fd/%s", pid, annex);
@@ -4233,7 +4255,7 @@ linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
&& lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
{
close (fd);
- return 0;
+ return TARGET_XFER_EOF;
}
if (writebuf)
@@ -4242,7 +4264,16 @@ linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
ret = read (fd, readbuf, (size_t) len);
close (fd);
- return ret;
+
+ if (ret < 0)
+ return TARGET_XFER_E_IO;
+ else if (ret == 0)
+ return TARGET_XFER_EOF;
+ else
+ {
+ *xfered_len = (ULONGEST) ret;
+ return TARGET_XFER_OK;
+ }
}
@@ -4329,34 +4360,40 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
do_cleanups (cleanup);
}
-static LONGEST
+static enum target_xfer_status
linux_nat_xfer_osdata (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, ULONGEST len)
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
{
gdb_assert (object == TARGET_OBJECT_OSDATA);
- return linux_common_xfer_osdata (annex, readbuf, offset, len);
+ *xfered_len = linux_common_xfer_osdata (annex, readbuf, offset, len);
+ if (*xfered_len == 0)
+ return TARGET_XFER_EOF;
+ else
+ return TARGET_XFER_OK;
}
-static LONGEST
+static enum target_xfer_status
linux_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, ULONGEST len)
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
{
- LONGEST xfer;
+ enum target_xfer_status xfer;
if (object == TARGET_OBJECT_AUXV)
return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
if (object == TARGET_OBJECT_OSDATA)
return linux_nat_xfer_osdata (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
if (object == TARGET_OBJECT_SPU)
return linux_proc_xfer_spu (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
/* GDB calculates all the addresses in possibly larget width of the address.
Address width needs to be masked before its final use - either by
@@ -4373,12 +4410,12 @@ linux_xfer_partial (struct target_ops *ops, enum target_object object,
}
xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf,
- offset, len);
- if (xfer != 0)
+ offset, len, xfered_len);
+ if (xfer != TARGET_XFER_EOF)
return xfer;
return super_xfer_partial (ops, object, annex, readbuf, writebuf,
- offset, len);
+ offset, len, xfered_len);
}
static void