From patchwork Fri Jan 19 16:16:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 25455 Received: (qmail 58926 invoked by alias); 19 Jan 2018 16:16:48 -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 58889 invoked by uid 89); 19 Jan 2018 16:16:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=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=opportunity 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; Fri, 19 Jan 2018 16:16:44 +0000 X-ASG-Debug-ID: 1516378595-0c856e65d44696ae0001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id G74aSS05tRIvDdal (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 19 Jan 2018 11:16:35 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) by smtp.ebox.ca (Postfix) with ESMTP id 7BE84441D65; Fri, 19 Jan 2018 11:16:35 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-251-162.qc.cable.ebox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter Date: Fri, 19 Jan 2018 11:16:28 -0500 X-ASG-Orig-Subj: [PATCH v2 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter Message-Id: <20180119161628.21611-3-simon.marchi@polymtl.ca> In-Reply-To: <20180119161628.21611-1-simon.marchi@polymtl.ca> References: <20180119161628.21611-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1516378595 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: 5689 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.47050 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes From: Simon Marchi No changes in v2. This patch makes these two functions actually use the inferior parameter added by the previous patch, instead of reading inferior_ptid. I chose these two, because they are the one actually used when I detach on my GNU/Linux system, so they were easy to test. I took the opportunity to pass the inferior being detached to inf_ptrace_detach_success, so it could use it too. From there, it made sense to add an overload of detach_inferior that takes the inferior directly rather than the pid, to avoid having to pass inf->pid only for the callee to look up the inferior structure by pid. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_detach): Adjust call to inf_ptrace_detach_success. (inf_ptrace_detach_success): Add inferior parameter, use it instead of inferior_ptid, pass it to detach_inferior. * inf-ptrace.h (inf_ptrace_detach_success): Add inferior parameter. * inferior.c (detach_inferior): Add overload that takes an inferior object. * inferior.h (detach_inferior): Likewise. * linux-nat.c (linux_nat_detach): Use the inf parameter, don't use inferior_ptid, adjust call to inf_ptrace_detach_success. * linux-thread-db.c (thread_db_detach): Use inf parameter. --- gdb/inf-ptrace.c | 8 +++----- gdb/inf-ptrace.h | 2 +- gdb/inferior.c | 15 +++++++++++++-- gdb/inferior.h | 3 +++ gdb/linux-nat.c | 8 +++----- gdb/linux-thread-db.c | 2 +- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index aa8b17f41a..72aa33480f 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -263,18 +263,16 @@ inf_ptrace_detach (struct target_ops *ops, inferior *inf, int from_tty) error (_("This system does not support detaching from a process")); #endif - inf_ptrace_detach_success (ops); + inf_ptrace_detach_success (ops, inf); } /* See inf-ptrace.h. */ void -inf_ptrace_detach_success (struct target_ops *ops) +inf_ptrace_detach_success (struct target_ops *ops, inferior *inf) { - pid_t pid = ptid_get_pid (inferior_ptid); - inferior_ptid = null_ptid; - detach_inferior (pid); + detach_inferior (inf); inf_child_maybe_unpush_target (ops); } diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h index c5bd757360..d10f64ae56 100644 --- a/gdb/inf-ptrace.h +++ b/gdb/inf-ptrace.h @@ -40,6 +40,6 @@ extern pid_t get_ptrace_pid (ptid_t); /* Cleanup the inferior after a successful ptrace detach. */ -extern void inf_ptrace_detach_success (struct target_ops *ops); +extern void inf_ptrace_detach_success (struct target_ops *ops, inferior *inf); #endif diff --git a/gdb/inferior.c b/gdb/inferior.c index 0b8f340b63..38b7369275 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -253,10 +253,13 @@ exit_inferior_num_silent (int num) exit_inferior_1 (inf, 1); } +/* See inferior.h. */ + void -detach_inferior (int pid) +detach_inferior (inferior *inf) { - struct inferior *inf = find_inferior_pid (pid); + /* Save the pid, since exit_inferior_1 will reset it. */ + int pid = inf->pid; exit_inferior_1 (inf, 0); @@ -264,6 +267,14 @@ detach_inferior (int pid) printf_unfiltered (_("[Inferior %d detached]\n"), pid); } +/* See inferior.h. */ + +void +detach_inferior (int pid) +{ + detach_inferior (find_inferior_pid (pid)); +} + void inferior_appeared (struct inferior *inf, int pid) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 01a12f2290..a87ffe0054 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -458,6 +458,9 @@ extern struct inferior *add_inferior_silent (int pid); extern void delete_inferior (struct inferior *todel); /* Delete an existing inferior list entry, due to inferior detaching. */ +extern void detach_inferior (inferior *inf); + +/* Same as the above, but with the inferior specified by PID. */ extern void detach_inferior (int pid); extern void exit_inferior (int pid); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 70f4c084dc..b83066cb04 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1499,10 +1499,8 @@ detach_callback (struct lwp_info *lp, void *data) static void linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) { - int pid; struct lwp_info *main_lwp; - - pid = ptid_get_pid (inferior_ptid); + int pid = inf->pid; /* Don't unregister from the event loop, as there may be other inferiors running. */ @@ -1517,7 +1515,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) iterate_over_lwps (pid_to_ptid (pid), detach_callback, NULL); /* Only the initial process should be left right now. */ - gdb_assert (num_lwps (ptid_get_pid (inferior_ptid)) == 1); + gdb_assert (num_lwps (pid) == 1); main_lwp = find_lwp_pid (pid_to_ptid (pid)); @@ -1538,7 +1536,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) detach_one_lwp (main_lwp, &signo); - inf_ptrace_detach_success (ops); + inf_ptrace_detach_success (ops, inf); } } diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 873f929144..794c97b48a 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1094,7 +1094,7 @@ thread_db_detach (struct target_ops *ops, inferior *inf, int from_tty) { struct target_ops *target_beneath = find_target_beneath (ops); - delete_thread_db_info (ptid_get_pid (inferior_ptid)); + delete_thread_db_info (inf->pid); target_beneath->to_detach (target_beneath, inf, from_tty);