btrace: record stop moves to the end of the trace

With the btrace record target the "record stop" command implicitly moves all
traced threads to the end of their respective history.  Unlike record full,
record btrace does not trace data and is therefore not able to resume debugging
at the current replay position.

We forgot to actually change the replay position before disabling tracing.  This
resulted in STOP_PC remaining at its old position if the current thread had been
replaying, which, in turn, resulted in GDB commands such as list or backtrace
using the wrong context.

Fix it by moving the selected thread to the end of its recorded history.
Together with the preceding patches, this will result in a front-end
notification for the selected thread if it had been replaying.  Stop replaying
other threads silently, i.e. without a front-end notification.

If the selected thread isn't replaying, notify front-ends without printing the
(unchanged) frame.  This results in a *stopped MI notification without any
thread information.

In non-stop mode, move all replaying threads to the end of their respective
histories.  This will result in a front-end notification and in the updated
location to be printed for each replaying thread.  We prefix the output with
the thread number like this:

    (gdb) record stop
    Thread 1 (Thread 0x7ffff7fcc740 (LWP 66711)) stopped replaying.
    test (arg=0x0) at gdb.btrace/multi-thread-step.c:34
    34        global = 42; /* bp.2 */
    Thread 2 (Thread 0x7ffff74fb700 (LWP 66716)) stopped replaying.
    test (arg=0x0) at gdb.btrace/multi-thread-step.c:34
    34        global = 42; /* bp.2 */
    Process record is stopped and all execution logs are deleted.

Thanks to Marc Khouzam <marc.khouzam@ericsson.com> for reporting this.

Signed-off-by: Markus Metzger  <markus.t.metzger@intel.com>

gdb/
	* record-btrace.c (record_btrace_set_replay)
	(record_btrace_stop_replaying): New declaration.
	(record_btrace_stop_recording): Call record_btrace_set_replay,
	record_btrace_stop_replaying, and observer_notify_normal_stop.

testsuite/
	* gdb.btrace/non-stop.exp: Test "record stop".
	* gdb.btrace/non-stop.c (test): Add statement to break at.
	* gdb.btrace/stop.exp: New.

Change-Id: I10565a8e4f8bc3c63f79c3ef6595e9f84e3d8100
4 files changed