From patchwork Tue Jan 1 22:45:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30932 Received: (qmail 123738 invoked by alias); 1 Jan 2019 22:45:34 -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 123318 invoked by uid 89); 1 Jan 2019 22:45:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=holding, stupid X-HELO: mail-wr1-f68.google.com Received: from mail-wr1-f68.google.com (HELO mail-wr1-f68.google.com) (209.85.221.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Jan 2019 22:45:25 +0000 Received: by mail-wr1-f68.google.com with SMTP id s12so28920489wrt.4 for ; Tue, 01 Jan 2019 14:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8dYcS5pNYUZMNdjpgD4yBseYZOPDEqvtGiKwOKIhil8=; b=OZ1/AJ7jweMjhe6JpUU4ZLAo0q7802tWE62OKJBxA+OV0u/S0cSmzau42xzlSueG4q V9sIX+/ECFDi3x9ufqh3pL8/j/ocat66QcwX4Pg1AVRaMxuvf1BARRMh2llFL0C9zPFa 9sWzhYb/KwnbDnoAuqxlhjJbKp9W4PmsZjKA9Ewp2N8qj9k6y4slopIaU69yMcWxw+UK XPEmSwjJ+YEQxwaHG/FfDDwKmKXJGIPYlZRRkYa5P3WWziEGD99R3sHoQYtpUrOoFUL/ ar0oyGrtEp+cQ4WA5WMQc7vCLq1Tp7ymSh39mbl407d2KnB8DmhgaTwRgmHAhwk0uY01 lvmQ== Return-Path: Received: from localhost (host86-172-198-47.range86-172.btcentralplus.com. [86.172.198.47]) by smtp.gmail.com with ESMTPSA id 143sm48936967wml.14.2019.01.01.14.45.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Jan 2019 14:45:22 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 6/6] gdb: Remove cleanup from linux_nat_target::follow_fork Date: Tue, 1 Jan 2019 22:45:06 +0000 Message-Id: <97a0b30452b34e2859f345b0afeab1fbb586b087.1546382416.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Remove cleanup from linux_nat_target::follow_fork, instead add a new unique_ptr specialisation for holding lwp_info pointers and use this to ensure the pointer is cleaned up when needed. gdb/ChangeLog: * linux-nat.c (delete_lwp_cleanup): Delete. (struct lwp_deleter): New struct. (lwp_info_up): New typedef. (linux_nat_target::follow_fork): Delete cleanup, and make use of lwp_info_up. --- gdb/ChangeLog | 8 ++++++++ gdb/linux-nat.c | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 7286207dd49..73d4fd193ae 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -425,15 +425,19 @@ num_lwps (int pid) return count; } -/* Call delete_lwp with prototype compatible for make_cleanup. */ +/* Deleter for lwp_info unique_ptr specialisation. */ -static void -delete_lwp_cleanup (void *lp_voidp) +struct lwp_deleter { - struct lwp_info *lp = (struct lwp_info *) lp_voidp; + void operator() (struct lwp_info *lwp) const + { + delete_lwp (lwp->ptid); + } +}; - delete_lwp (lp->ptid); -} +/* A unique_ptr specialisation for lwp_info. */ + +typedef std::unique_ptr lwp_info_up; /* Target hook for follow_fork. On entry inferior_ptid must be the ptid of the followed inferior. At return, inferior_ptid will be @@ -466,10 +470,13 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork) { int child_stop_signal = 0; bool detach_child = true; - struct cleanup *old_chain = make_cleanup (delete_lwp_cleanup, - child_lp); - linux_target->low_prepare_to_resume (child_lp); + /* Move CHILD_LP into a unique_ptr and clear the source pointer + to prevent us doing anything stupid with it. */ + lwp_info_up child_lp_ptr (child_lp); + child_lp = nullptr; + + linux_target->low_prepare_to_resume (child_lp_ptr.get ()); /* When debugging an inferior in an architecture that supports hardware single stepping on a kernel without commit @@ -508,8 +515,6 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork) signo = 0; ptrace (PTRACE_DETACH, child_pid, 0, signo); } - - do_cleanups (old_chain); } else {