Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2013-2015 Free Software Foundation, Inc. |
73c1d57e YQ |
2 | # |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | load_lib "trace-support.exp" | |
17 | ||
18 | standard_testfile | |
19 | ||
20 | if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { | |
21 | untested $testfile.exp | |
22 | return -1 | |
23 | } | |
24 | ||
25 | if ![runto_main] { | |
26 | fail "Can't run to main to check for trace support" | |
27 | return -1 | |
28 | } | |
29 | ||
30 | if ![gdb_target_supports_trace] { | |
31 | unsupported "target does not support trace" | |
32 | return -1 | |
33 | } | |
34 | ||
35 | # Set tracepoints, start tracing and collect data. | |
36 | ||
37 | proc set_tracepoint_and_collect { } { | |
38 | global testfile srcfile | |
39 | ||
40 | # Start with a fresh gdb. | |
41 | clean_restart ${testfile} | |
42 | if ![runto_main] { | |
43 | fail "Can't run to main" | |
44 | return -1 | |
45 | } | |
46 | gdb_test "break end" "Breakpoint \[0-9\] at .*" | |
47 | gdb_test "trace start" "Tracepoint \[0-9\] at .*" | |
48 | gdb_trace_setactions "set action for tracepoint" "" \ | |
49 | "collect testglob" "^$" \ | |
50 | "collect constglob" "^$" | |
51 | ||
52 | gdb_test_no_output "tstart" | |
53 | gdb_test "continue" ".*Breakpoint.* end .*at.*$srcfile.*" \ | |
54 | "continue to end" | |
55 | gdb_test_no_output "tstop" | |
56 | } | |
57 | ||
58 | with_test_prefix "live" { | |
59 | set_tracepoint_and_collect | |
60 | ||
61 | gdb_test "print testglob" " = 2" | |
62 | gdb_test "print testglob_not_collected" " = 12" | |
63 | gdb_test "print constglob" " = 10000" | |
64 | gdb_test "print constglob_not_collected" " = 100" | |
65 | } | |
66 | ||
67 | with_test_prefix "live target tfind" { | |
68 | gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \ | |
69 | "tfind 0" | |
70 | gdb_test "print testglob" " = 1" | |
71 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
72 | gdb_test "print constglob" " = 10000" | |
73 | gdb_test "print constglob_not_collected" " = 100" | |
74 | gdb_test "tfind" "Target failed to find requested trace frame." \ | |
75 | "tfind does not find a second frame" | |
76 | } | |
77 | ||
78 | # Save trace frames to trace file. | |
79 | set tracefile [standard_output_file ${testfile}] | |
80 | gdb_test "tsave ${tracefile}.tfile" \ | |
81 | "Trace data saved to file '${tracefile}.tfile'.*" \ | |
82 | "save tfile trace" | |
83 | ||
84 | # Test read memory when changing target from remote to ${target}. | |
85 | ||
86 | proc test_from_remote { target } { | |
87 | global gdb_prompt testfile | |
88 | global tracefile | |
89 | ||
90 | with_test_prefix "remote to ${target}" { | |
91 | set_tracepoint_and_collect | |
92 | ||
93 | # Change target to ${target}. | |
94 | set test "change target" | |
95 | gdb_test_multiple "target ${target} ${tracefile}.${target}" "$test" { | |
96 | -re "A program is being debugged already. Kill it. .y or n. " { | |
97 | send_gdb "y\n" | |
98 | exp_continue | |
99 | } | |
100 | -re "$gdb_prompt $" { | |
101 | pass "$test" | |
102 | } | |
103 | } | |
104 | ||
105 | with_test_prefix "w/o setting traceframe" { | |
1527aea8 YQ |
106 | gdb_test "print testglob" " = <unavailable>" |
107 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
73c1d57e YQ |
108 | gdb_test "print constglob" " = 10000" |
109 | gdb_test "print constglob_not_collected" " = 100" | |
110 | } | |
111 | with_test_prefix "w/ setting traceframe" { | |
112 | gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \ | |
113 | "tfind 0" | |
114 | gdb_test "print testglob" " = 1" | |
115 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
116 | gdb_test "print constglob" " = 10000" | |
117 | gdb_test "print constglob_not_collected" " = 100" | |
118 | gdb_test "tfind" "Target failed to find requested trace frame." \ | |
119 | "tfind does not find a second frame" | |
120 | } | |
121 | } | |
122 | } | |
123 | ||
124 | test_from_remote "tfile" | |
125 | ||
126 | # Test read memory when changing target from exec to ${target} | |
127 | ||
128 | proc teset_from_exec { target } { | |
129 | global srcdir subdir binfile testfile | |
130 | global tracefile | |
131 | ||
132 | # Restart GDB and read the trace data in ${target} target. | |
133 | gdb_exit | |
134 | gdb_start | |
135 | gdb_reinitialize_dir $srcdir/$subdir | |
136 | gdb_file_cmd $binfile | |
137 | ||
138 | gdb_test "target ${target} ${tracefile}.${target}" ".*" \ | |
139 | "change to ${target} target" | |
140 | ||
141 | with_test_prefix "exec to ${target} w/o setting traceframe" { | |
1527aea8 YQ |
142 | gdb_test "print testglob" " = <unavailable>" |
143 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
73c1d57e YQ |
144 | gdb_test "print constglob" " = 10000" |
145 | gdb_test "print constglob_not_collected" " = 100" | |
146 | } | |
147 | ||
148 | with_test_prefix "exec to ${target} w/ setting traceframe" { | |
149 | gdb_test "tfind 0" "Found trace frame 0, tracepoint \[0-9\]+.*" \ | |
150 | "tfind 0" | |
151 | gdb_test "print testglob" " = 1" | |
152 | gdb_test "print testglob_not_collected" " = <unavailable>" | |
153 | gdb_test "print constglob" " = 10000" | |
154 | gdb_test "print constglob_not_collected" " = 100" | |
155 | gdb_test "tfind" "Target failed to find requested trace frame." \ | |
156 | "tfind does not find a second frame" | |
157 | } | |
158 | } | |
159 | ||
160 | teset_from_exec "tfile" |