diff options
author | Markus Metzger <markus.t.metzger@intel.com> | 2016-11-30 11:05:38 +0100 |
---|---|---|
committer | Markus Metzger <markus.t.metzger@intel.com> | 2017-02-01 14:37:07 +0100 |
commit | cd4007e43421a2f974f51574b6e2b52b9b1a7a50 (patch) | |
tree | af9f62f65a58aa8966041b743d645248778dd457 /gdb/btrace.c | |
parent | cf77c34ea71c27c3cb6dd31c9448249276e8a8a6 (diff) | |
download | gdb-cd4007e43421a2f974f51574b6e2b52b9b1a7a50.zip gdb-cd4007e43421a2f974f51574b6e2b52b9b1a7a50.tar.gz gdb-cd4007e43421a2f974f51574b6e2b52b9b1a7a50.tar.bz2 |
btrace: allow recording to be started (and stopped) for running threads
When recording is started for a running thread, GDB was able to start tracing
but then failed to read registers to insert the initial entry for the current
PC. We don't really need that initial entry if we don't know where exactly we
started recording. Skip that step to allow recording to be started while
threads are running.
If we do run into errors, we need to undo the tracing enable to not leak this
thread. The operation did not complete so our caller won't clean up this
thread.
For the BTRACE_FORMAT_PT btrace format, we don't need that initial entry since
it will be recorded in the trace. We can omit the call to btrace_add_pc.
gdb/
* btrace.c (btrace_enable): Do not call btrace_add_pc for
BTRACE_FORMAT_PT or if can_access_registers_ptid returns false.
(btrace_fetch): Assert can_access_registers_ptid.
* record-btrace.c (require_btrace_thread, record_btrace_info): Call
validate_registers_access.
testsuite/
* gdb.btrace/enable-running.c: New.
* gdb.btrace/enable-running.exp: New.
Diffstat (limited to 'gdb/btrace.c')
-rw-r--r-- | gdb/btrace.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/gdb/btrace.c b/gdb/btrace.c index d266af7..6d621e4 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1472,10 +1472,33 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf) tp->btrace.target = target_enable_btrace (tp->ptid, conf); - /* Add an entry for the current PC so we start tracing from where we - enabled it. */ - if (tp->btrace.target != NULL) - btrace_add_pc (tp); + /* We're done if we failed to enable tracing. */ + if (tp->btrace.target == NULL) + return; + + /* We need to undo the enable in case of errors. */ + TRY + { + /* Add an entry for the current PC so we start tracing from where we + enabled it. + + If we can't access TP's registers, TP is most likely running. In this + case, we can't really say where tracing was enabled so it should be + safe to simply skip this step. + + This is not relevant for BTRACE_FORMAT_PT since the trace will already + start at the PC at which tracing was enabled. */ + if (conf->format != BTRACE_FORMAT_PT + && can_access_registers_ptid (tp->ptid)) + btrace_add_pc (tp); + } + CATCH (exception, RETURN_MASK_ALL) + { + btrace_disable (tp); + + throw_exception (exception); + } + END_CATCH } /* See btrace.h. */ @@ -1709,6 +1732,9 @@ btrace_fetch (struct thread_info *tp) if (btinfo->replay != NULL) return; + /* We should not be called on running or exited threads. */ + gdb_assert (can_access_registers_ptid (tp->ptid)); + btrace_data_init (&btrace); cleanup = make_cleanup_btrace_data (&btrace); |