From patchwork Wed Jan 9 03:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31003 Received: (qmail 36934 invoked by alias); 9 Jan 2019 03:34:36 -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 36595 invoked by uid 89); 9 Jan 2019 03:34:33 -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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1988, breakpoint.c, breakpointc, 1986 X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.200) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Jan 2019 03:34:30 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 109B2FAF7C0 for ; Tue, 8 Jan 2019 21:34:29 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id h4dQg1gJo2PzOh4dRggF08; Tue, 08 Jan 2019 21:34:29 -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=1P7NNix4PzTDWlOsoQZkty1dCbN6uyZfhD6Ip8t6RwQ=; b=rGt7IYFLgol2cehEwhD/6gnodc q63ZaM9j8fmj4lkLQQbAfAiQQx6IA/WUp0ccSGKERnqjVj7KRLX0IYOZ7iIxqtfTMYbH9sYCD5Vse YqKSaeTH65x35ltLaJ92LWq4A; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:47026 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gh4dQ-000HG2-QG; Tue, 08 Jan 2019 21:34:28 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 01/12] Remove delete_longjmp_breakpoint_cleanup Date: Tue, 8 Jan 2019 20:34:15 -0700 Message-Id: <20190109033426.16062-2-tom@tromey.com> In-Reply-To: <20190109033426.16062-1-tom@tromey.com> References: <20190109033426.16062-1-tom@tromey.com> This removes delete_longjmp_breakpoint_cleanup in favor of a new cleanup function type. This new type is somewhat generic, and will be reused in subsequent patches. Note that cleanup_function::cancel was purposely not named "reset". An earlier version did this, but it was too easy to mistake cleanup_function::reset and gdb::optional::reset, as pointed out by Andrew Burgess when reviewing an earlier version of this series. gdb/ChangeLog 2019-01-08 Tom Tromey * common/cleanup-function.h: New file. * breakpoint.c (until_break_command): Use cleanup_function. * infcmd.c (delete_longjmp_breakpoint_cleanup): Remove. (until_next_command): Use cleanup_function. * inferior.h (delete_longjmp_breakpoint_cleanup): Don't declare. --- gdb/ChangeLog | 9 +++++ gdb/breakpoint.c | 16 ++++++--- gdb/common/cleanup-function.h | 62 +++++++++++++++++++++++++++++++++++ gdb/infcmd.c | 18 +++++----- gdb/inferior.h | 2 -- 5 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 gdb/common/cleanup-function.h diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d54d496972..24ba4071ff 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -83,6 +83,7 @@ #include "progspace-and-thread.h" #include "common/array-view.h" #include "common/gdb_optional.h" +#include "common/cleanup-function.h" /* Enums for exception-handling support. */ enum exception_event_kind @@ -11078,7 +11079,6 @@ until_break_command (const char *arg, int from_tty, int anywhere) struct gdbarch *frame_gdbarch; struct frame_id stack_frame_id; struct frame_id caller_frame_id; - struct cleanup *old_chain; int thread; struct thread_info *tp; struct until_break_fsm *sm; @@ -11111,8 +11111,6 @@ until_break_command (const char *arg, int from_tty, int anywhere) tp = inferior_thread (); thread = tp->global_num; - old_chain = make_cleanup (null_cleanup, NULL); - /* Note linespec handling above invalidates the frame chain. Installing a breakpoint also invalidates the frame chain (as it may need to switch threads), so do any frame handling before @@ -11127,6 +11125,14 @@ until_break_command (const char *arg, int from_tty, int anywhere) one. */ breakpoint_up caller_breakpoint; + + gdb::optional lj_deleter; + auto lj_deletion_func + = [=] () + { + delete_longjmp_breakpoint (thread); + }; + if (frame_id_p (caller_frame_id)) { struct symtab_and_line sal2; @@ -11141,7 +11147,7 @@ until_break_command (const char *arg, int from_tty, int anywhere) bp_until); set_longjmp_breakpoint (tp, caller_frame_id); - make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); + lj_deleter.emplace (lj_deletion_func); } /* set_momentary_breakpoint could invalidate FRAME. */ @@ -11164,7 +11170,7 @@ until_break_command (const char *arg, int from_tty, int anywhere) std::move (caller_breakpoint)); tp->thread_fsm = &sm->thread_fsm; - discard_cleanups (old_chain); + lj_deleter->cancel (); proceed (-1, GDB_SIGNAL_DEFAULT); } diff --git a/gdb/common/cleanup-function.h b/gdb/common/cleanup-function.h new file mode 100644 index 0000000000..89cc6d11c8 --- /dev/null +++ b/gdb/common/cleanup-function.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef COMMON_CLEANUP_FUNCTION_H +#define COMMON_CLEANUP_FUNCTION_H + +#include "common/function-view.h" + +/* A cleanup function is one that is run at the end of the current + scope. It is just a function of no arguments. A cleanup function + may be canceled by calling the "cancel" method. */ + +class cleanup_function +{ +public: + + explicit cleanup_function (gdb::function_view func) + : m_func (func) + { + } + + DISABLE_COPY_AND_ASSIGN (cleanup_function); + + ~cleanup_function () + { + m_func (); + } + + /* If this is called, then the wrapped function will not be called + on destruction. */ + void cancel () + { + m_func = do_nothing; + } + +private: + + /* The function to call. */ + gdb::function_view m_func; + + /* A helper function that is used as the value of m_func when cancel + is called. */ + static void do_nothing () + { + } +}; + +#endif /* COMMON_CLEANUP_FUNCTION_H */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 3c3add89ab..5c4c4171c5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -59,6 +59,7 @@ #include "top.h" #include "interps.h" #include "common/gdb_optional.h" +#include "common/cleanup-function.h" #include "source.h" /* Local functions: */ @@ -947,13 +948,6 @@ nexti_command (const char *count_string, int from_tty) step_1 (1, 1, count_string); } -void -delete_longjmp_breakpoint_cleanup (void *arg) -{ - int thread = * (int *) arg; - delete_longjmp_breakpoint (thread); -} - /* Data for the FSM that manages the step/next/stepi/nexti commands. */ @@ -1517,7 +1511,6 @@ until_next_command (int from_tty) struct symtab_and_line sal; struct thread_info *tp = inferior_thread (); int thread = tp->global_num; - struct cleanup *old_chain; struct until_next_fsm *sm; clear_proceed_status (0); @@ -1556,11 +1549,16 @@ until_next_command (int from_tty) tp->control.step_over_calls = STEP_OVER_ALL; set_longjmp_breakpoint (tp, get_frame_id (frame)); - old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); + auto lj_deletion_func + = [=] () + { + delete_longjmp_breakpoint (thread); + }; + cleanup_function lj_deleter (lj_deletion_func); sm = new_until_next_fsm (command_interp (), tp->global_num); tp->thread_fsm = &sm->thread_fsm; - discard_cleanups (old_chain); + lj_deleter.cancel (); proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); } diff --git a/gdb/inferior.h b/gdb/inferior.h index a82df1a52a..c63fa26b08 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -198,8 +198,6 @@ extern void continue_1 (int all_threads); extern void interrupt_target_1 (int all_threads); -extern void delete_longjmp_breakpoint_cleanup (void *arg); - extern void detach_command (const char *, int); extern void notice_new_inferior (struct thread_info *, int, int);