summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Metzger <markus.t.metzger@intel.com>2016-06-10 11:24:21 +0200
committerMarkus Metzger <markus.t.metzger@intel.com>2016-07-06 08:31:22 +0200
commit31d025c07d3536fb50f226db74c836595a9e361a (patch)
tree11b8d4e6581066f43aa5e63fe76165a000a0e436
parent8c62f01902b29b582eca5f28757b0018a7fb4179 (diff)
downloadbinutils-gdb-users/mmetzger/record-goto-mi.tar.gz
btrace: record stop moves to the end of the traceusers/mmetzger/record-goto-mi
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
-rw-r--r--gdb/record-btrace.c59
-rw-r--r--gdb/testsuite/gdb.btrace/non-stop.c6
-rw-r--r--gdb/testsuite/gdb.btrace/non-stop.exp19
-rw-r--r--gdb/testsuite/gdb.btrace/stop.exp70
4 files changed, 147 insertions, 7 deletions
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 1998e43fcd0..7da78bc508c 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -97,6 +97,11 @@ static struct cmd_list_element *show_record_btrace_pt_cmdlist;
} \
while (0)
+static void record_btrace_set_replay (struct thread_info *tp,
+ const struct btrace_insn_iterator *it);
+
+static void record_btrace_stop_replaying (struct thread_info *tp);
+
/* Update the branch trace for the current thread and return a pointer to its
thread_info.
@@ -252,9 +257,57 @@ record_btrace_stop_recording (struct target_ops *self)
record_btrace_auto_disable ();
- ALL_NON_EXITED_THREADS (tp)
- if (tp->btrace.target != NULL)
- btrace_disable (tp);
+ /* In non-stop mode, we indicate the implicit move of each replaying thread.
+ In stop-all mode, we indicate the implicit move of the selected thread if
+ it is replaying. Other threads are silently moved. The MI notification
+ will indicate that all threads have been stopped which should be enough to
+ indicate this implicit move to front-ends. */
+ if (non_stop)
+ {
+ ALL_NON_EXITED_THREADS (tp)
+ if (tp->btrace.target != NULL)
+ {
+ if (btrace_is_replaying (tp))
+ {
+ printf_filtered (_("Thread %s (%s) stopped replaying.\n"),
+ print_thread_id (tp),
+ target_pid_to_str (tp->ptid));
+ record_btrace_set_replay (tp, NULL);
+ }
+
+ btrace_disable (tp);
+ }
+ }
+ else
+ {
+ int send_stopped = 0;
+
+ /* If the selected thread is replaying, we do an implicit "record goto
+ end" to make it stop replaying and indicate this to front-ends. This
+ causes the updated location to be printed for the selected thread.
+
+ If it isn't replaying, we will send an unspecific stopped notification
+ to front-ends at the end. This doesn't print the (unchanged) location
+ but indicates to front-ends that other thread's locations may have
+ changed. */
+ tp = inferior_thread ();
+ if (tp != NULL && btrace_is_replaying (tp))
+ record_btrace_set_replay (tp, NULL);
+ else
+ send_stopped = 1;
+
+ ALL_NON_EXITED_THREADS (tp)
+ if (tp->btrace.target != NULL)
+ {
+ /* Stop replaying before we disable tracing to clear TP's register
+ state in addition to the btrace state. */
+ record_btrace_stop_replaying (tp);
+ btrace_disable (tp);
+ }
+
+ if (send_stopped)
+ observer_notify_normal_stop (NULL, 0);
+ }
}
/* The to_close method of target record-btrace. */
diff --git a/gdb/testsuite/gdb.btrace/non-stop.c b/gdb/testsuite/gdb.btrace/non-stop.c
index c5870df39d3..b4a7191952a 100644
--- a/gdb/testsuite/gdb.btrace/non-stop.c
+++ b/gdb/testsuite/gdb.btrace/non-stop.c
@@ -27,7 +27,9 @@ test (void *arg)
i = 0; /* bp.1 */
for (; i < 10; ++i) global += i; /* loop */
- return arg; /* bp.2 */
+ global *= 2; /* bp.2 */
+
+ return arg; /* bp.3 */
}
int
@@ -41,5 +43,5 @@ main (void)
pthread_join (th, NULL);
- return 0; /* bp.3 */
+ return 0;
}
diff --git a/gdb/testsuite/gdb.btrace/non-stop.exp b/gdb/testsuite/gdb.btrace/non-stop.exp
index 0d5cbe2d5a3..8dad07c10ed 100644
--- a/gdb/testsuite/gdb.btrace/non-stop.exp
+++ b/gdb/testsuite/gdb.btrace/non-stop.exp
@@ -239,7 +239,22 @@ with_test_prefix "no progress" {
}
# now that both threads stopped replaying we may resume recording
-with_test_prefix "cont to end" {
+with_test_prefix "resume recording" {
gdb_breakpoint $bp_3
- gdb_cont_to_bp_line "$srcfile:$bp_3" all 1
+ gdb_cont_to_bp_line "$srcfile:$bp_3" all 2
+}
+
+# when we stop recording we get notifications for replaying threads
+with_test_prefix "stop" {
+ gdb_test "thread 1" ".*"
+ gdb_test "thread apply 2 record goto begin" ".*"
+
+ gdb_test "record stop" [multi_line \
+ "Thread 2 \[^\\\r\\\n\]* stopped replaying\." \
+ "\[^\\\r\\\n\]*$srcfile:$bp_3" \
+ "$bp_3\[^\\\r\\\n\]* bp\.3 \[^\\\r\\\n\]*" \
+ "Process record is stopped and all execution logs are deleted\." \
+ ]
+
+ gdb_test "info record" "No record target is currently active\."
}
diff --git a/gdb/testsuite/gdb.btrace/stop.exp b/gdb/testsuite/gdb.btrace/stop.exp
new file mode 100644
index 00000000000..074bab8a9c2
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/stop.exp
@@ -0,0 +1,70 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2016 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+standard_testfile record_goto.c
+
+# start inferior
+if [prepare_for_testing $testfile.exp $testfile $srcfile] {
+ return -1
+}
+
+# we use the list command to check the current source location
+gdb_test "set listsize 1"
+
+if ![runto_main] {
+ return -1
+}
+
+# trace the call to the test function
+gdb_test_no_output "record btrace" "move: enable"
+gdb_test "next" ".*main\.3.*" "move: trace"
+
+# move to the beginning of the trace
+gdb_test "record goto begin" ".*main\.2.*" "move: navigate"
+
+# when we stop recording, we move back to the end of the trace
+gdb_test "record stop" "main\.3.*Process record is stopped.*" "move: stop"
+
+# check that we're really there
+gdb_test "list" ".*main\.3.*" "move: at end of trace"
+
+if ![runto_main] {
+ return -1
+}
+
+# trace the call to the test function
+gdb_test_no_output "record btrace" "already: enable"
+gdb_test "next" ".*main\.3.*" "already: trace"
+
+# we're already at the end so we didn't have to move
+gdb_test_multiple "record stop" "already: stop" {
+ -re "main.*$gdb_prompt $" {
+ fail "already: stop"
+ }
+ -re "Process record is stopped\[^\\\r\\\n\]*\r\n$gdb_prompt $" {
+ pass "already: stop"
+ }
+ -re "$gdb_prompt $" {
+ fail "already: stop"
+ }
+}
+
+# check that we're really there
+gdb_test "list" ".*main\.3.*" "already: at end of trace"