From patchwork Sun Apr 1 03:17:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 26530 Received: (qmail 39339 invoked by alias); 1 Apr 2018 03:18:03 -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 39263 invoked by uid 89); 1 Apr 2018 03:18:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=switching, inspecting X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Apr 2018 03:17:59 +0000 X-ASG-Debug-ID: 1522552673-0c856e6189752580001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 0LktkRIsZyT5qb3J (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 31 Mar 2018 23:17:54 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id CFD9D441B21; Sat, 31 Mar 2018 23:17:53 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-164-54.qc.cable.ebox.net[192.222.164.54] X-Barracuda-Apparent-Source-IP: 192.222.164.54 X-Barracuda-RBL-IP: 192.222.164.54 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] Replace make_cleanup_restore_current_traceframe with RAII class Date: Sat, 31 Mar 2018 23:17:52 -0400 X-ASG-Orig-Subj: [PATCH] Replace make_cleanup_restore_current_traceframe with RAII class Message-Id: <20180401031752.15146-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1522552674 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3605 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.49478 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes I put the constructor in tracepoint.c because it needs to read traceframe_number, and I prefer to do that than to expose traceframe_number. gdb/ChangeLog: * tracepoint.c (struct current_traceframe_cleanup): Remove. (do_restore_current_traceframe_cleanup): Remove. (restore_current_traceframe_cleanup_dtor): Remove. (make_cleanup_restore_current_traceframe): Remove. (scoped_restore_current_traceframe::scoped_restore_current_traceframe): New. * tracepoint.h (struct scoped_restore_current_traceframe): New. * infrun.c (fetch_inferior_event): Use scoped_restore_current_traceframe. --- gdb/infrun.c | 3 ++- gdb/tracepoint.c | 40 +++------------------------------------- gdb/tracepoint.h | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 6648698df6f1..d89f8137f4a0 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3877,9 +3877,10 @@ fetch_inferior_event (void *client_data) debugging. If we're looking at traceframes while the target is running, we're going to need to get back to that mode after handling the event. */ + gdb::optional maybe_restore_traceframe; if (non_stop) { - make_cleanup_restore_current_traceframe (); + maybe_restore_traceframe.emplace (); set_current_traceframe (-1); } diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 954d039caf78..92343b0e7c64 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -3012,43 +3012,9 @@ set_current_traceframe (int num) clear_traceframe_info (); } -/* A cleanup used when switching away and back from tfind mode. */ - -struct current_traceframe_cleanup -{ - /* The traceframe we were inspecting. */ - int traceframe_number; -}; - -static void -do_restore_current_traceframe_cleanup (void *arg) -{ - struct current_traceframe_cleanup *old - = (struct current_traceframe_cleanup *) arg; - - set_current_traceframe (old->traceframe_number); -} - -static void -restore_current_traceframe_cleanup_dtor (void *arg) -{ - struct current_traceframe_cleanup *old - = (struct current_traceframe_cleanup *) arg; - - xfree (old); -} - -struct cleanup * -make_cleanup_restore_current_traceframe (void) -{ - struct current_traceframe_cleanup *old = - XNEW (struct current_traceframe_cleanup); - - old->traceframe_number = traceframe_number; - - return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old, - restore_current_traceframe_cleanup_dtor); -} +scoped_restore_current_traceframe::scoped_restore_current_traceframe () +: m_traceframe_number (traceframe_number) +{} /* Given a number and address, return an uploaded tracepoint with that number, creating if necessary. */ diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index 8613cb2dd69e..02f4bf70890d 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -321,7 +321,22 @@ extern int get_tracepoint_number (void); etc.). */ extern void set_current_traceframe (int num); -struct cleanup *make_cleanup_restore_current_traceframe (void); +struct scoped_restore_current_traceframe +{ + scoped_restore_current_traceframe (); + + ~scoped_restore_current_traceframe () + { + set_current_traceframe (m_traceframe_number); + } + + DISABLE_COPY_AND_ASSIGN (scoped_restore_current_traceframe); + +private: + + /* The traceframe we were inspecting. */ + int m_traceframe_number; +}; void free_actions (struct breakpoint *);