btrace: allow recording to be started (and stopped) for running threads
authorMarkus Metzger <markus.t.metzger@intel.com>
Wed, 30 Nov 2016 10:05:38 +0000 (11:05 +0100)
committerMarkus Metzger <markus.t.metzger@intel.com>
Wed, 1 Feb 2017 13:37:07 +0000 (14:37 +0100)
commitcd4007e43421a2f974f51574b6e2b52b9b1a7a50
treeaf9f62f65a58aa8966041b743d645248778dd457
parentcf77c34ea71c27c3cb6dd31c9448249276e8a8a6
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.
gdb/ChangeLog
gdb/btrace.c
gdb/record-btrace.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.btrace/enable-running.c [new file with mode: 0644]
gdb/testsuite/gdb.btrace/enable-running.exp [new file with mode: 0644]