From patchwork Wed Mar 22 03:02:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 19693 Received: (qmail 92319 invoked by alias); 22 Mar 2017 03:03:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 91528 invoked by uid 89); 22 Mar 2017 03:02:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=safer, teaches X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Mar 2017 03:02:22 +0000 X-ASG-Debug-ID: 1490151741-0c856e65d51987d90001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id a23OAhmOuIuRoHp4 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 21 Mar 2017 23:02:21 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id E8BFD440E7C; Tue, 21 Mar 2017 23:02:20 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: palves@redhat.com, Simon Marchi Subject: [PATCH v2] Remove lwp -> pid conversion in linux_nat_xfer_partial Date: Tue, 21 Mar 2017 23:02:15 -0400 X-ASG-Orig-Subj: [PATCH v2] Remove lwp -> pid conversion in linux_nat_xfer_partial Message-Id: <20170322030215.27737-1-simon.marchi@polymtl.ca> In-Reply-To: <15f668b8e6bfe802bad5671738f7ef3b@polymtl.ca> References: <15f668b8e6bfe802bad5671738f7ef3b@polymtl.ca> MIME-Version: 1.0 X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1490151741 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4128 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.37402 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-IsSubscribed: yes New in v2: - Use lwp in linux_proc_xfer_partial and linux_proc_xfer_spu. - Updated commit message (stole some of Pedro's text) The linux_nat_xfer_partial does a conversion of inferior_ptid: if it's an LWP (ptid::lwp != 0), it builds a new ptid with the lwp as the pid and assigns that temporarily to inferior_ptid. For example, if inferior_ptid is: { .pid = 1234, .lwp = 1235 } it will assign this to inferior_ptid for the duration of the call: { .pid = 1235, .lwp = 0 } Instead of doing this, this patch teaches the inf-ptrace implementation of xfer_partial to deal with ptids representing lwps by using get_ptrace_pid. Also, in linux_proc_xfer_spu and linux_proc_xfer_partial, we use ptid_get_lwp instead of ptid_get_pid. While not strictly necessary, since the content of /proc/ and /proc/ should be the same, it's a bit safer, because: - some files under /proc// may not work if the thread is running, just like ptrace requires a stopped thread. The current thread's lwp id is more likely to be in the necessary state (stopped). - if the leader exits, and goes zombie, then several files under "/proc/" won't work, though using "/proc//task/" would. The latter path form is also generally better for being robust in the case TID exits and is reused in another process, much like tkill vs tgkill. 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. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use lwp of inferior_ptid instead of pid. --- gdb/inf-ptrace.c | 2 +- gdb/linux-nat.c | 13 +++---------- 2 files changed, 4 insertions(+), 11 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..dff0da568a 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; } @@ -4001,8 +3994,8 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object, /* We could keep this file open and cache it - possibly one per thread. That requires some juggling, but is even faster. */ - xsnprintf (filename, sizeof filename, "/proc/%d/mem", - ptid_get_pid (inferior_ptid)); + xsnprintf (filename, sizeof filename, "/proc/%ld/mem", + ptid_get_lwp (inferior_ptid)); fd = gdb_open_cloexec (filename, ((readbuf ? O_RDONLY : O_WRONLY) | O_LARGEFILE), 0); if (fd == -1) @@ -4095,7 +4088,7 @@ linux_proc_xfer_spu (struct target_ops *ops, enum target_object object, char buf[128]; int fd = 0; int ret = -1; - int pid = ptid_get_pid (inferior_ptid); + int pid = ptid_get_lwp (inferior_ptid); if (!annex) {