From patchwork Thu Feb 7 09:40:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31343 Received: (qmail 75112 invoked by alias); 7 Feb 2019 09:40:35 -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 75029 invoked by uid 89); 7 Feb 2019 09:40:34 -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_HELO_PASS autolearn=ham version=3.3.2 spammy=from_tty X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.163) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Feb 2019 09:40:33 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway22.websitewelcome.com (Postfix) with ESMTP id E2CCF141FE for ; Thu, 7 Feb 2019 03:40:31 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id rgAZgE2Nq2PzOrgAZgkLYi; Thu, 07 Feb 2019 03:40:31 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=QY7PjugiSVaLZsdiWbe8Beiqx6aUqGBTFxuonBlMuNs=; b=qoDFmV7EaCB+PHMXJ7h6Wa74cz VHSc9nW5unjAnhZPLHdkmrkCnHcufS31bsxTcDTbaNa9q4KP6mS+y3tm5wI3MDnemzSbqZjCIl+TL V15HtSlenZbSwauqrTZOcQP4Z; Received: from dhcp-guest.act-europe.fr ([194.98.77.127]:61727 helo=bapiya.act-europe.fr) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1grgAZ-003W3S-D2; Thu, 07 Feb 2019 03:40:31 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/8] Add push_target overload Date: Thu, 7 Feb 2019 02:40:14 -0700 Message-Id: <20190207094016.368-7-tom@tromey.com> In-Reply-To: <20190207094016.368-1-tom@tromey.com> References: <20190207094016.368-1-tom@tromey.com> From: Tom Tromey This adds a push_target overload that takes a "target_ops_up &&". This removes some calls to release a target_ops_up, and makes the intent here clearer. gdb/ChangeLog 2019-02-07 Tom Tromey * target.h (push_target): Declare new overload. * target.c (push_target): New overload, taking an rvalue reference. * remote.c (remote_target::open_1): Use push_target overload. * corelow.c (core_target_open): Use push_target overload. --- gdb/ChangeLog | 7 +++++++ gdb/corelow.c | 3 +-- gdb/remote.c | 4 +--- gdb/target.c | 9 +++++++++ gdb/target.h | 3 +++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index 52d6d95b3c0..6a29d6a2328 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -417,8 +417,7 @@ core_target_open (const char *arg, int from_tty) if (!exec_bfd) set_gdbarch_from_file (core_bfd); - push_target (target); - target_holder.release (); + push_target (std::move (target_holder)); inferior_ptid = null_ptid; diff --git a/gdb/remote.c b/gdb/remote.c index 18e678d07af..95201eeab5c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5547,9 +5547,7 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p) } /* Switch to using the remote target now. */ - push_target (remote); - /* The target stack owns the target now. */ - target_holder.release (); + push_target (std::move (target_holder)); /* Register extra event sources in the event loop. */ rs->remote_async_inferior_event_token diff --git a/gdb/target.c b/gdb/target.c index c1ab07f7608..116510e8cb8 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -585,6 +585,15 @@ push_target (struct target_ops *t) g_target_stack.push (t); } +/* See target.h */ + +void +push_target (target_ops_up &&t) +{ + g_target_stack.push (t.get ()); + t.release (); +} + /* See target.h. */ int diff --git a/gdb/target.h b/gdb/target.h index 96413aa6c3a..c95151a4044 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -2333,6 +2333,9 @@ extern void add_deprecated_target_alias (const target_info &info, extern void push_target (struct target_ops *); +/* An overload that deletes the target on failure. */ +extern void push_target (target_ops_up &&); + extern int unpush_target (struct target_ops *); extern void target_pre_inferior (int);