From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 1/3] btrace: Remove btrace disable cleanup
Date: Sun, 04 Mar 2018 20:56:00 -0000 [thread overview]
Message-ID: <20180304205605.13037-1-simon.marchi@polymtl.ca> (raw)
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<thread_info *> 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. */
--
2.16.1
next reply other threads:[~2018-03-04 20:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-04 20:56 Simon Marchi [this message]
2018-03-04 20:56 ` [PATCH 3/3] btrace: Remove ui_out cleanups Simon Marchi
2018-03-05 12:39 ` Metzger, Markus T
2018-03-05 22:16 ` Simon Marchi
2018-03-06 7:30 ` Metzger, Markus T
2018-03-06 14:40 ` Simon Marchi
2018-03-04 20:56 ` [PATCH 2/3] btrace: Remove VEC cleanups Simon Marchi
2018-03-05 12:39 ` Metzger, Markus T
2018-03-05 12:39 ` [PATCH 1/3] btrace: Remove btrace disable cleanup Metzger, Markus T
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180304205605.13037-1-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox