From patchwork Wed Jul 18 14:09:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28456 Received: (qmail 54315 invoked by alias); 18 Jul 2018 14:09:54 -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 54300 invoked by uid 89); 18 Jul 2018 14:09:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.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_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4332, 83067 X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.55.25) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Jul 2018 14:09:51 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 34877400E6749 for ; Wed, 18 Jul 2018 09:09:50 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id fn8gfaomyPvAdfn93fft1U; Wed, 18 Jul 2018 09:09:49 -0500 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=5NxG7AoewmSz+HFzRehmoueYqkLyGAl64kkjmAAQtcI=; b=UZ4lxj7jcc9lds5DkEqm2PuM3+ HntnP9yp6s1Ww+nFxCluSRBmf2J5FbpXguZZKp4Qag1vYBF1EogyZ0bUTCMw3D2TOJVnGImL22Rg3 MPttYQSSsyEP5T4Ac+7F1SwDp; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:57494 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1ffn8f-000r59-W5; Wed, 18 Jul 2018 09:09:10 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 5/6] Remove release_stop_context_cleanup Date: Wed, 18 Jul 2018 08:09:03 -0600 Message-Id: <20180718140904.16811-6-tom@tromey.com> In-Reply-To: <20180718140904.16811-1-tom@tromey.com> References: <20180718140904.16811-1-tom@tromey.com> This removes release_stop_context_cleanup, replacing it with a stop_context destructor. It also mildly c++-ifies this struct. gdb/ChangeLog 2018-07-18 Tom Tromey * infrun.c (struct stop_context): Declare constructor, destructor, "changed" method. (stop_context::stop_context): Rename from save_stop_context. (stop_context::~stop_context): Rename from release_stop_context_cleanup. (normal_stop): Update. (stop_context::changed): Rename from stop_context_changed. Return bool. --- gdb/ChangeLog | 11 ++++++++ gdb/infrun.c | 74 +++++++++++++++++++++++---------------------------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e0dd2988f72..d786f1f3838 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2018-07-18 Tom Tromey + + * infrun.c (struct stop_context): Declare constructor, + destructor, "changed" method. + (stop_context::stop_context): Rename from save_stop_context. + (stop_context::~stop_context): Rename from + release_stop_context_cleanup. + (normal_stop): Update. + (stop_context::changed): Rename from stop_context_changed. Return + bool. + 2018-07-18 Tom Tromey * inferior.h (struct infcall_suspend_state_deleter): New. diff --git a/gdb/infrun.c b/gdb/infrun.c index 9dbea4a58ac..15bdf004b1a 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8098,6 +8098,13 @@ maybe_remove_breakpoints (void) struct stop_context { + stop_context (); + ~stop_context (); + + DISABLE_COPY_AND_ASSIGN (stop_context); + + bool changed () const; + /* The stop ID. */ ULONGEST stop_id; @@ -8113,59 +8120,50 @@ struct stop_context int inf_num; }; -/* Returns a new stop context. If stopped for a thread event, this +/* Initializes a new stop context. If stopped for a thread event, this takes a strong reference to the thread. */ -static struct stop_context * -save_stop_context (void) +stop_context::stop_context () { - struct stop_context *sc = XNEW (struct stop_context); - - sc->stop_id = get_stop_id (); - sc->ptid = inferior_ptid; - sc->inf_num = current_inferior ()->num; + stop_id = get_stop_id (); + ptid = inferior_ptid; + inf_num = current_inferior ()->num; if (inferior_ptid != null_ptid) { /* Take a strong reference so that the thread can't be deleted yet. */ - sc->thread = inferior_thread (); - sc->thread->incref (); + thread = inferior_thread (); + thread->incref (); } else - sc->thread = NULL; - - return sc; + thread = NULL; } /* Release a stop context previously created with save_stop_context. Releases the strong reference to the thread as well. */ -static void -release_stop_context_cleanup (void *arg) +stop_context::~stop_context () { - struct stop_context *sc = (struct stop_context *) arg; - - if (sc->thread != NULL) - sc->thread->decref (); - xfree (sc); + if (thread != NULL) + thread->decref (); } /* Return true if the current context no longer matches the saved stop context. */ -static int -stop_context_changed (struct stop_context *prev) -{ - if (prev->ptid != inferior_ptid) - return 1; - if (prev->inf_num != current_inferior ()->num) - return 1; - if (prev->thread != NULL && prev->thread->state != THREAD_STOPPED) - return 1; - if (get_stop_id () != prev->stop_id) - return 1; - return 0; +bool +stop_context::changed () const +{ + if (ptid != inferior_ptid) + return true; + if (inf_num != current_inferior ()->num) + return true; + if (thread != NULL && thread->state != THREAD_STOPPED) + return true; + if (get_stop_id () != stop_id) + return true; + return false; } /* See infrun.h. */ @@ -8308,9 +8306,7 @@ normal_stop (void) of stop_command's pre-hook not existing). */ if (stop_command != NULL) { - struct stop_context *saved_context = save_stop_context (); - struct cleanup *old_chain - = make_cleanup (release_stop_context_cleanup, saved_context); + stop_context saved_context; TRY { @@ -8328,12 +8324,8 @@ normal_stop (void) gone. Likewise if the command switches thread or inferior -- the observers would print a stop for the wrong thread/inferior. */ - if (stop_context_changed (saved_context)) - { - do_cleanups (old_chain); - return 1; - } - do_cleanups (old_chain); + if (saved_context.changed ()) + return 1; } /* Notify observers about the stop. This is where the interpreters