This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Remove lwp -> pid conversion in linux_nat_xfer_partial
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>
- Date: Tue, 21 Mar 2017 18:17:44 -0400
- Subject: [PATCH] Remove lwp -> pid conversion in linux_nat_xfer_partial
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=ericsson.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
From: Simon Marchi <simon.marchi@polymtl.ca>
When inferior_ptid represents a lwp, linux_nat_xfer_partial converts it
to a ptid with only the pid field set. For example, if
inferior_ptid is:
{ .pid = 1234, .lwp = 1235 }
it will change it to:
{ .pid = 1235, .lwp = 0 }
This is presumably because not all implementations of to_xfer_partial
that might be called down the line know how to handle a ptid with a lwp.
>From what I found, it's been like this for a long long time, I traced
the original implementation at least to this commit (1999)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/lin-thread.c;h=2f255c0e54a0387f1b7994c0bf808f4320b9b054;hb=ed9a39e#l1241
It looks like a hack to me, I think it's simpler if we just make all
implementations handle ptids correctly. The only place I found that
needed fixing is inf_ptrace_xfer_partial.
There is also linux_proc_xfer_partial and linux_proc_xfer_spu, which
both only use the pid field of inferior_ptid and ignore lwp. However,
since they use "/proc/<pid>", using the id of any thread in the process
will give the same result (AFAIK).
The testsuite found no regression on native amd64 linux.
gdb/ChangeLog:
* inf-ptrace.c (inf_ptrace_xfer_partial): Get pid from ptid
using get_ptrace_pid.
* linux-nat.c (linux_nat_xfer_partial): Don't set/restore
inferior_ptid.
---
gdb/inf-ptrace.c | 2 +-
gdb/linux-nat.c | 7 -------
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index 61d24269a8..f912d28088 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -520,7 +520,7 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object,
const gdb_byte *writebuf,
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
- pid_t pid = ptid_get_pid (inferior_ptid);
+ pid_t pid = get_ptrace_pid (inferior_ptid);
switch (object)
{
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 73ef2d4947..0827f546a8 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3890,7 +3890,6 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
const gdb_byte *writebuf,
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
- struct cleanup *old_chain;
enum target_xfer_status xfer;
if (object == TARGET_OBJECT_SIGNAL_INFO)
@@ -3903,15 +3902,9 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid))
return TARGET_XFER_EOF;
- old_chain = save_inferior_ptid ();
-
- if (ptid_lwp_p (inferior_ptid))
- inferior_ptid = pid_to_ptid (ptid_get_lwp (inferior_ptid));
-
xfer = linux_ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
offset, len, xfered_len);
- do_cleanups (old_chain);
return xfer;
}
--
2.11.0