From patchwork Wed Jul 11 14:15:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28315 Received: (qmail 25146 invoked by alias); 11 Jul 2018 14:16: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 24910 invoked by uid 89); 11 Jul 2018 14:16:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 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= X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.47.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 14:16:22 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 46ADC31356 for ; Wed, 11 Jul 2018 09:16:21 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id dFuNfGGK4kBj6dFubfdFLr; Wed, 11 Jul 2018 09:16:20 -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=zU3mWv3TtpGTFfoazmZNkEQX2k4R/SbDQ+bnuYmecoA=; b=f79sZL9mWQaYGf0G0m2ucyA4Cg KgpIOB/Y34U/o7l9vnrqgAhgYYG/hg8/z8dAuDMCI0jId7Zyp00rl2fHHaq8taxxbPmDwAKlSOluk NTFT+OysIcGGB7HzUnpi1bC+d; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:49352 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fdFuM-000rOq-RP; Wed, 11 Jul 2018 09:15:54 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/5] Remove cleanup from infrun.c Date: Wed, 11 Jul 2018 08:15:49 -0600 Message-Id: <20180711141552.10136-3-tom@tromey.com> In-Reply-To: <20180711141552.10136-1-tom@tromey.com> References: <20180711141552.10136-1-tom@tromey.com> This removes a cleanup from infrun.c by taking advantage of the previous patch to introduce a use of unique_xmalloc_ptr. gdb/ChangeLog 2018-07-11 Tom Tromey * infrun.c (struct infcall_suspend_state) : Now a unique_ptr. : Now a unique_xmalloc_ptr. (save_infcall_suspend_state, restore_infcall_suspend_state) (discard_infcall_suspend_state) (get_infcall_suspend_state_regcache): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/infrun.c | 29 +++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8c0d7b5f6a9..d46ccf53999 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2018-07-11 Tom Tromey + + * infrun.c (struct infcall_suspend_state) : Now a + unique_ptr. + : Now a unique_xmalloc_ptr. + (save_infcall_suspend_state, restore_infcall_suspend_state) + (discard_infcall_suspend_state) + (get_infcall_suspend_state_regcache): Update. + 2018-07-11 Tom Tromey * infrun.c (struct infcall_suspend_state): Add initializers. diff --git a/gdb/infrun.c b/gdb/infrun.c index da71f3132a0..1157b266b1a 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8813,7 +8813,7 @@ struct infcall_suspend_state struct thread_suspend_state thread_suspend {}; /* Other fields: */ - readonly_detached_regcache *registers = nullptr; + std::unique_ptr registers; /* Format of SIGINFO_DATA or NULL if it is not present. */ struct gdbarch *siginfo_gdbarch = nullptr; @@ -8821,7 +8821,7 @@ struct infcall_suspend_state /* The inferior format depends on SIGINFO_GDBARCH and it has a length of TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the content would be invalid. */ - gdb_byte *siginfo_data = nullptr; + gdb::unique_xmalloc_ptr siginfo_data; }; struct infcall_suspend_state * @@ -8831,25 +8831,20 @@ save_infcall_suspend_state (void) struct thread_info *tp = inferior_thread (); struct regcache *regcache = get_current_regcache (); struct gdbarch *gdbarch = regcache->arch (); - gdb_byte *siginfo_data = NULL; + gdb::unique_xmalloc_ptr siginfo_data; if (gdbarch_get_siginfo_type_p (gdbarch)) { struct type *type = gdbarch_get_siginfo_type (gdbarch); size_t len = TYPE_LENGTH (type); - struct cleanup *back_to; - siginfo_data = (gdb_byte *) xmalloc (len); - back_to = make_cleanup (xfree, siginfo_data); + siginfo_data.reset ((gdb_byte *) xmalloc (len)); if (target_read (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL, - siginfo_data, 0, len) == len) - discard_cleanups (back_to); - else + siginfo_data.get (), 0, len) != len) { /* Errors ignored. */ - do_cleanups (back_to); - siginfo_data = NULL; + siginfo_data.reset (nullptr); } } @@ -8858,7 +8853,7 @@ save_infcall_suspend_state (void) if (siginfo_data) { inf_state->siginfo_gdbarch = gdbarch; - inf_state->siginfo_data = siginfo_data; + inf_state->siginfo_data = std::move (siginfo_data); } inf_state->thread_suspend = tp->suspend; @@ -8867,7 +8862,7 @@ save_infcall_suspend_state (void) GDB_SIGNAL_0 anyway. */ tp->suspend.stop_signal = GDB_SIGNAL_0; - inf_state->registers = new readonly_detached_regcache (*regcache); + inf_state->registers.reset (new readonly_detached_regcache (*regcache)); return inf_state; } @@ -8889,14 +8884,14 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) /* Errors ignored. */ target_write (current_top_target (), TARGET_OBJECT_SIGNAL_INFO, NULL, - inf_state->siginfo_data, 0, TYPE_LENGTH (type)); + inf_state->siginfo_data.get (), 0, TYPE_LENGTH (type)); } /* The inferior can be gone if the user types "print exit(0)" (and perhaps other times). */ if (target_has_execution) /* NB: The register write goes through to the target. */ - regcache->restore (inf_state->registers); + regcache->restore (inf_state->registers.get ()); discard_infcall_suspend_state (inf_state); } @@ -8917,15 +8912,13 @@ make_cleanup_restore_infcall_suspend_state void discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) { - delete inf_state->registers; - xfree (inf_state->siginfo_data); delete inf_state; } readonly_detached_regcache * get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) { - return inf_state->registers; + return inf_state->registers.get (); } /* infcall_control_state contains state regarding gdb's control of the