From: Simon Marchi Date: Tue, 6 Mar 2018 14:51:32 +0000 (-0500) Subject: btrace: Remove btrace disable cleanup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=228f15081e22abed7ea336126caba26de5a3b791;p=binutils-gdb.git btrace: Remove btrace disable cleanup 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ff6eb559e6c..ef89b4da114 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-03-06 Simon Marchi + + * record-btrace.c (record_btrace_disable_callback): Remove. + (struct scoped_btrace_disable): New. + (record_btrace_open): Use scoped_btrace_disable. + 2018-03-06 Andrew Burgess * riscv-tdep.c (riscv_return_value): Change type to ULONGEST for diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 48eda543515..0d2407274fb 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. */