From patchwork Wed Jul 11 14:15:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28313 Received: (qmail 23079 invoked by alias); 11 Jul 2018 14:15:59 -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 23003 invoked by uid 89); 11 Jul 2018 14:15:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 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=UD:infrun.c, infrun.c, infrunc, our X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 14:15:56 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 918E817A45A for ; Wed, 11 Jul 2018 09:15:55 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id dFuNfWFK5RPojdFuNf5Wai; Wed, 11 Jul 2018 09:15:55 -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=jW4AOIAefnrvFY2FOuAP3BohrcS5looPtlyUCqPYl3U=; b=JzuCI9QfgsGDaHL1oOryxddVUs fy+2o5DA+8Wh+CVsSgmg42nsXHr7lNrH2tuqAi7QJwv0pkpgKsi/TDGEEss+P9qMPrsvTUq3l/qdf gAkMz1lcKgg/gWWK2pn0Ln4tj; 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 1fdFuN-000rOq-BV; Wed, 11 Jul 2018 09:15:55 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/5] Remove two infrun cleanups Date: Wed, 11 Jul 2018 08:15:51 -0600 Message-Id: <20180711141552.10136-5-tom@tromey.com> In-Reply-To: <20180711141552.10136-1-tom@tromey.com> References: <20180711141552.10136-1-tom@tromey.com> This removes a couple of cleanups from infrun by introducing a couple of unique_ptr specializations. gdb/ChangeLog 2018-07-11 Tom Tromey * inferior.h (struct infcall_suspend_state_deleter): New. (infcall_suspend_state_up): New typedef. (struct infcall_control_state_deleter): New. (infcall_control_state_up): New typedef. (make_cleanup_restore_infcall_suspend_state) (make_cleanup_restore_infcall_control_state): Don't declare. * infcall.c (call_function_by_hand_dummy): Update. * infrun.c (do_restore_infcall_suspend_state_cleanup) (make_cleanup_restore_infcall_suspend_state): Remove. (do_restore_infcall_control_state_cleanup) (make_cleanup_restore_infcall_control_state): Remove. --- gdb/ChangeLog | 14 ++++++++++++++ gdb/infcall.c | 39 ++++++++++++++------------------------- gdb/inferior.h | 31 +++++++++++++++++++++++++++---- gdb/infrun.c | 26 -------------------------- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 95d4f51f62c..12e27000151 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2018-07-11 Tom Tromey + + * inferior.h (struct infcall_suspend_state_deleter): New. + (infcall_suspend_state_up): New typedef. + (struct infcall_control_state_deleter): New. + (infcall_control_state_up): New typedef. + (make_cleanup_restore_infcall_suspend_state) + (make_cleanup_restore_infcall_control_state): Don't declare. + * infcall.c (call_function_by_hand_dummy): Update. + * infrun.c (do_restore_infcall_suspend_state_cleanup) + (make_cleanup_restore_infcall_suspend_state): Remove. + (do_restore_infcall_control_state_cleanup) + (make_cleanup_restore_infcall_control_state): Remove. + 2018-07-11 Tom Tromey * infrun.c (struct infcall_control_state): Add initializers. diff --git a/gdb/infcall.c b/gdb/infcall.c index 172c26ac820..b7071a722f1 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -724,9 +724,6 @@ call_function_by_hand_dummy (struct value *function, struct type *target_values_type; unsigned char struct_return = 0, hidden_first_param_p = 0; CORE_ADDR struct_addr = 0; - struct infcall_control_state *inf_status; - struct cleanup *inf_status_cleanup; - struct infcall_suspend_state *caller_state; CORE_ADDR real_pc; CORE_ADDR bp_addr; struct frame_id dummy_id; @@ -760,19 +757,16 @@ call_function_by_hand_dummy (struct value *function, if (!gdbarch_push_dummy_call_p (gdbarch)) error (_("This target does not support function calls.")); - /* A cleanup for the inferior status. + /* A holder for the inferior status. This is only needed while we're preparing the inferior function call. */ - inf_status = save_infcall_control_state (); - inf_status_cleanup - = make_cleanup_restore_infcall_control_state (inf_status); + infcall_control_state_up inf_status (save_infcall_control_state ()); /* Save the caller's registers and other state associated with the inferior itself so that they can be restored once the callee returns. To allow nested calls the registers are (further - down) pushed onto a dummy frame stack. Include a cleanup (which - is tossed once the regcache has been pushed). */ - caller_state = save_infcall_suspend_state (); - make_cleanup_restore_infcall_suspend_state (caller_state); + down) pushed onto a dummy frame stack. This unique pointer + is released once the regcache has been pushed). */ + infcall_suspend_state_up caller_state (save_infcall_suspend_state ()); /* Ensure that the initial SP is correctly aligned. */ { @@ -1133,15 +1127,10 @@ call_function_by_hand_dummy (struct value *function, if (unwind_on_terminating_exception_p) set_std_terminate_breakpoint (); - /* Discard both inf_status and caller_state cleanups. - From this point on we explicitly restore the associated state - or discard it. */ - discard_cleanups (inf_status_cleanup); - /* Everything's ready, push all the info needed to restore the caller (and identify the dummy-frame) onto the dummy-frame stack. */ - dummy_frame_push (caller_state, &dummy_id, call_thread.get ()); + dummy_frame_push (caller_state.release (), &dummy_id, call_thread.get ()); if (dummy_dtor != NULL) register_dummy_frame_dtor (dummy_id, call_thread.get (), dummy_dtor, dummy_dtor_data); @@ -1196,7 +1185,7 @@ call_function_by_hand_dummy (struct value *function, suspend state, and restore the inferior control state. */ dummy_frame_pop (dummy_id, call_thread.get ()); - restore_infcall_control_state (inf_status); + restore_infcall_control_state (inf_status.release ()); /* Get the return value. */ retval = sm->return_value; @@ -1227,7 +1216,7 @@ call_function_by_hand_dummy (struct value *function, const char *name = get_function_name (funaddr, name_buf, sizeof (name_buf)); - discard_infcall_control_state (inf_status); + discard_infcall_control_state (inf_status.release ()); /* We could discard the dummy frame here if the program exited, but it will get garbage collected the next time the program is @@ -1258,7 +1247,7 @@ When the function is done executing, GDB will silently stop."), /* If we try to restore the inferior status, we'll crash as the inferior is no longer running. */ - discard_infcall_control_state (inf_status); + discard_infcall_control_state (inf_status.release ()); /* We could discard the dummy frame here given that the program exited, but it will get garbage collected the next time the program is @@ -1280,7 +1269,7 @@ When the function is done executing, GDB will silently stop."), signal or breakpoint while our thread was running. There's no point in restoring the inferior status, we're in a different thread. */ - discard_infcall_control_state (inf_status); + discard_infcall_control_state (inf_status.release ()); /* Keep the dummy frame record, if the user switches back to the thread with the hand-call, we'll need it. */ if (stopped_by_random_signal) @@ -1321,7 +1310,7 @@ When the function is done executing, GDB will silently stop."), /* We also need to restore inferior status to that before the dummy call. */ - restore_infcall_control_state (inf_status); + restore_infcall_control_state (inf_status.release ()); /* FIXME: Insert a bunch of wrap_here; name can be very long if it's a C++ name with arguments and stuff. */ @@ -1339,7 +1328,7 @@ Evaluation of the expression containing the function\n\ (default). Discard inferior status, we're not at the same point we started at. */ - discard_infcall_control_state (inf_status); + discard_infcall_control_state (inf_status.release ()); /* FIXME: Insert a bunch of wrap_here; name can be very long if it's a C++ name with arguments and stuff. */ @@ -1362,7 +1351,7 @@ When the function is done executing, GDB will silently stop."), /* We also need to restore inferior status to that before the dummy call. */ - restore_infcall_control_state (inf_status); + restore_infcall_control_state (inf_status.release ()); error (_("\ The program being debugged entered a std::terminate call, most likely\n\ @@ -1381,7 +1370,7 @@ will be abandoned."), Keep the dummy frame, the user may want to examine its state. Discard inferior status, we're not at the same point we started at. */ - discard_infcall_control_state (inf_status); + discard_infcall_control_state (inf_status.release ()); /* The following error message used to say "The expression which contained the function call has been discarded." diff --git a/gdb/inferior.h b/gdb/inferior.h index c5dc324fa39..5591382079f 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -63,10 +63,33 @@ extern struct infcall_control_state *save_infcall_control_state (void); extern void restore_infcall_suspend_state (struct infcall_suspend_state *); extern void restore_infcall_control_state (struct infcall_control_state *); -extern struct cleanup *make_cleanup_restore_infcall_suspend_state - (struct infcall_suspend_state *); -extern struct cleanup *make_cleanup_restore_infcall_control_state - (struct infcall_control_state *); +/* A deleter for infcall_suspend_state that calls + restore_infcall_suspend_state. */ +struct infcall_suspend_state_deleter +{ + void operator() (struct infcall_suspend_state *state) const + { + restore_infcall_suspend_state (state); + } +}; + +/* A unique_ptr specialization for infcall_suspend_state. */ +typedef std::unique_ptr + infcall_suspend_state_up; + +/* A deleter for infcall_control_state that calls + restore_infcall_control_state. */ +struct infcall_control_state_deleter +{ + void operator() (struct infcall_control_state *state) const + { + restore_infcall_control_state (state); + } +}; + +/* A unique_ptr specialization for infcall_control_state. */ +typedef std::unique_ptr + infcall_control_state_up; extern void discard_infcall_suspend_state (struct infcall_suspend_state *); extern void discard_infcall_control_state (struct infcall_control_state *); diff --git a/gdb/infrun.c b/gdb/infrun.c index 3bc8dc03830..98b79e8c5ae 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8896,19 +8896,6 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) discard_infcall_suspend_state (inf_state); } -static void -do_restore_infcall_suspend_state_cleanup (void *state) -{ - restore_infcall_suspend_state ((struct infcall_suspend_state *) state); -} - -struct cleanup * -make_cleanup_restore_infcall_suspend_state - (struct infcall_suspend_state *inf_state) -{ - return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state); -} - void discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) { @@ -9033,19 +9020,6 @@ restore_infcall_control_state (struct infcall_control_state *inf_status) delete inf_status; } -static void -do_restore_infcall_control_state_cleanup (void *sts) -{ - restore_infcall_control_state ((struct infcall_control_state *) sts); -} - -struct cleanup * -make_cleanup_restore_infcall_control_state - (struct infcall_control_state *inf_status) -{ - return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status); -} - void discard_infcall_control_state (struct infcall_control_state *inf_status) {