• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revision31d025c07d3536fb50f226db74c836595a9e361a (tree)
Time2016-07-06 15:31:22
AuthorMarkus Metzger <markus.t.metzger@inte...>
CommiterMarkus Metzger

Log Message

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

Change Summary

Incremental Difference

--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -97,6 +97,11 @@ static struct cmd_list_element *show_record_btrace_pt_cmdlist;
9797 } \
9898 while (0)
9999
100+static void record_btrace_set_replay (struct thread_info *tp,
101+ const struct btrace_insn_iterator *it);
102+
103+static void record_btrace_stop_replaying (struct thread_info *tp);
104+
100105
101106 /* Update the branch trace for the current thread and return a pointer to its
102107 thread_info.
@@ -252,9 +257,57 @@ record_btrace_stop_recording (struct target_ops *self)
252257
253258 record_btrace_auto_disable ();
254259
255- ALL_NON_EXITED_THREADS (tp)
256- if (tp->btrace.target != NULL)
257- btrace_disable (tp);
260+ /* In non-stop mode, we indicate the implicit move of each replaying thread.
261+ In stop-all mode, we indicate the implicit move of the selected thread if
262+ it is replaying. Other threads are silently moved. The MI notification
263+ will indicate that all threads have been stopped which should be enough to
264+ indicate this implicit move to front-ends. */
265+ if (non_stop)
266+ {
267+ ALL_NON_EXITED_THREADS (tp)
268+ if (tp->btrace.target != NULL)
269+ {
270+ if (btrace_is_replaying (tp))
271+ {
272+ printf_filtered (_("Thread %s (%s) stopped replaying.\n"),
273+ print_thread_id (tp),
274+ target_pid_to_str (tp->ptid));
275+ record_btrace_set_replay (tp, NULL);
276+ }
277+
278+ btrace_disable (tp);
279+ }
280+ }
281+ else
282+ {
283+ int send_stopped = 0;
284+
285+ /* If the selected thread is replaying, we do an implicit "record goto
286+ end" to make it stop replaying and indicate this to front-ends. This
287+ causes the updated location to be printed for the selected thread.
288+
289+ If it isn't replaying, we will send an unspecific stopped notification
290+ to front-ends at the end. This doesn't print the (unchanged) location
291+ but indicates to front-ends that other thread's locations may have
292+ changed. */
293+ tp = inferior_thread ();
294+ if (tp != NULL && btrace_is_replaying (tp))
295+ record_btrace_set_replay (tp, NULL);
296+ else
297+ send_stopped = 1;
298+
299+ ALL_NON_EXITED_THREADS (tp)
300+ if (tp->btrace.target != NULL)
301+ {
302+ /* Stop replaying before we disable tracing to clear TP's register
303+ state in addition to the btrace state. */
304+ record_btrace_stop_replaying (tp);
305+ btrace_disable (tp);
306+ }
307+
308+ if (send_stopped)
309+ observer_notify_normal_stop (NULL, 0);
310+ }
258311 }
259312
260313 /* The to_close method of target record-btrace. */
--- a/gdb/testsuite/gdb.btrace/non-stop.c
+++ b/gdb/testsuite/gdb.btrace/non-stop.c
@@ -27,7 +27,9 @@ test (void *arg)
2727 i = 0; /* bp.1 */
2828 for (; i < 10; ++i) global += i; /* loop */
2929
30- return arg; /* bp.2 */
30+ global *= 2; /* bp.2 */
31+
32+ return arg; /* bp.3 */
3133 }
3234
3335 int
@@ -41,5 +43,5 @@ main (void)
4143
4244 pthread_join (th, NULL);
4345
44- return 0; /* bp.3 */
46+ return 0;
4547 }
--- 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" {
239239 }
240240
241241 # now that both threads stopped replaying we may resume recording
242-with_test_prefix "cont to end" {
242+with_test_prefix "resume recording" {
243243 gdb_breakpoint $bp_3
244- gdb_cont_to_bp_line "$srcfile:$bp_3" all 1
244+ gdb_cont_to_bp_line "$srcfile:$bp_3" all 2
245+}
246+
247+# when we stop recording we get notifications for replaying threads
248+with_test_prefix "stop" {
249+ gdb_test "thread 1" ".*"
250+ gdb_test "thread apply 2 record goto begin" ".*"
251+
252+ gdb_test "record stop" [multi_line \
253+ "Thread 2 \[^\\\r\\\n\]* stopped replaying\." \
254+ "\[^\\\r\\\n\]*$srcfile:$bp_3" \
255+ "$bp_3\[^\\\r\\\n\]* bp\.3 \[^\\\r\\\n\]*" \
256+ "Process record is stopped and all execution logs are deleted\." \
257+ ]
258+
259+ gdb_test "info record" "No record target is currently active\."
245260 }
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/stop.exp
@@ -0,0 +1,70 @@
1+# This testcase is part of GDB, the GNU debugger.
2+#
3+# Copyright 2016 Free Software Foundation, Inc.
4+#
5+# This program is free software; you can redistribute it and/or modify
6+# it under the terms of the GNU General Public License as published by
7+# the Free Software Foundation; either version 3 of the License, or
8+# (at your option) any later version.
9+#
10+# This program is distributed in the hope that it will be useful,
11+# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+# GNU General Public License for more details.
14+#
15+# You should have received a copy of the GNU General Public License
16+# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+# check for btrace support
19+if { [skip_btrace_tests] } { return -1 }
20+
21+standard_testfile record_goto.c
22+
23+# start inferior
24+if [prepare_for_testing $testfile.exp $testfile $srcfile] {
25+ return -1
26+}
27+
28+# we use the list command to check the current source location
29+gdb_test "set listsize 1"
30+
31+if ![runto_main] {
32+ return -1
33+}
34+
35+# trace the call to the test function
36+gdb_test_no_output "record btrace" "move: enable"
37+gdb_test "next" ".*main\.3.*" "move: trace"
38+
39+# move to the beginning of the trace
40+gdb_test "record goto begin" ".*main\.2.*" "move: navigate"
41+
42+# when we stop recording, we move back to the end of the trace
43+gdb_test "record stop" "main\.3.*Process record is stopped.*" "move: stop"
44+
45+# check that we're really there
46+gdb_test "list" ".*main\.3.*" "move: at end of trace"
47+
48+if ![runto_main] {
49+ return -1
50+}
51+
52+# trace the call to the test function
53+gdb_test_no_output "record btrace" "already: enable"
54+gdb_test "next" ".*main\.3.*" "already: trace"
55+
56+# we're already at the end so we didn't have to move
57+gdb_test_multiple "record stop" "already: stop" {
58+ -re "main.*$gdb_prompt $" {
59+ fail "already: stop"
60+ }
61+ -re "Process record is stopped\[^\\\r\\\n\]*\r\n$gdb_prompt $" {
62+ pass "already: stop"
63+ }
64+ -re "$gdb_prompt $" {
65+ fail "already: stop"
66+ }
67+}
68+
69+# check that we're really there
70+gdb_test "list" ".*main\.3.*" "already: at end of trace"