From patchwork Sun Mar 4 20:56:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 26190 Received: (qmail 20510 invoked by alias); 4 Mar 2018 20:56:18 -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 20324 invoked by uid 89); 4 Mar 2018 20:56:16 -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= 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, 04 Mar 2018 20:56:15 +0000 X-ASG-Debug-ID: 1520196968-0c856e618922f100001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id RWgiXhmwRpCVdJwq (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 04 Mar 2018 15:56:08 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) by smtp.ebox.ca (Postfix) with ESMTP id 152F1441B21; Sun, 4 Mar 2018 15:56:08 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-251-162.qc.cable.ebox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/3] btrace: Remove btrace disable cleanup Date: Sun, 4 Mar 2018 15:56:03 -0500 X-ASG-Orig-Subj: [PATCH 1/3] btrace: Remove btrace disable cleanup Message-Id: <20180304205605.13037-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1520196968 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: 2716 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.48563 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes This patch removes a cleanup that disables btrace on threads in case of failure, so we don't leave it enabled for some the threads and disabled for the rest. gdb/ChangeLog: * record-btrace.c (record_btrace_disable_callback): Remove. (struct scoped_btrace_disable): New. (record_btrace_open): Use scoped_btrace_disable. --- gdb/record-btrace.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index d9a1dc593f..b04a7e5049 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -159,16 +159,6 @@ record_btrace_enable_warn (struct thread_info *tp) END_CATCH } -/* Callback function to disable branch tracing for one thread. */ - -static void -record_btrace_disable_callback (void *arg) -{ - struct thread_info *tp = (struct thread_info *) arg; - - btrace_disable (tp); -} - /* Enable automatic tracing of new threads. */ static void @@ -223,12 +213,42 @@ record_btrace_push_target (void) observer_notify_record_changed (current_inferior (), 1, "btrace", format); } +/* Disable btrace on a set of threads on scope exit. */ + +struct scoped_btrace_disable +{ + scoped_btrace_disable () = default; + + DISABLE_COPY_AND_ASSIGN (scoped_btrace_disable); + + ~scoped_btrace_disable () + { + for (thread_info *tp : m_threads) + btrace_disable (tp); + } + + void add_thread (thread_info *thread) + { + m_threads.push_front (thread); + } + + void discard () + { + m_threads.clear (); + } + +private: + std::forward_list m_threads; +}; + /* The to_open method of target record-btrace. */ static void record_btrace_open (const char *args, int from_tty) { - struct cleanup *disable_chain; + /* If we fail to enable btrace for one thread, disable it for the threads for + which it was successfully enabled. */ + scoped_btrace_disable btrace_disable; struct thread_info *tp; DEBUG ("open"); @@ -240,18 +260,17 @@ record_btrace_open (const char *args, int from_tty) gdb_assert (record_btrace_thread_observer == NULL); - disable_chain = make_cleanup (null_cleanup, NULL); ALL_NON_EXITED_THREADS (tp) if (args == NULL || *args == 0 || number_is_in_list (args, tp->global_num)) { btrace_enable (tp, &record_btrace_conf); - make_cleanup (record_btrace_disable_callback, tp); + btrace_disable.add_thread (tp); } record_btrace_push_target (); - discard_cleanups (disable_chain); + btrace_disable.discard (); } /* The to_stop_recording method of target record-btrace. */