gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / change-loc.exp
CommitLineData
8acc9f48 1# Copyright 2011-2013 Free Software Foundation, Inc.
1e4d1764
YQ
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 3 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15load_lib "trace-support.exp";
16
1e4d1764
YQ
17if {[skip_shlib_tests]} {
18 return 0
19}
20
497a5eb0 21standard_testfile
1e4d1764
YQ
22set libfile1 "change-loc-1"
23set libfile2 "change-loc-2"
1e4d1764
YQ
24set executable $testfile
25set libsrc1 $srcdir/$subdir/$libfile1.c
26set libsrc2 $srcdir/$subdir/$libfile2.c
497a5eb0
TT
27set lib_sl1 [standard_output_file $libfile1.sl]
28set lib_sl2 [standard_output_file $libfile2.sl]
1e4d1764
YQ
29
30set lib_opts debug
31
4c93b1db 32if [get_compiler_info] {
1e4d1764
YQ
33 return -1
34}
35
36# Some targets have leading underscores on assembly symbols.
37set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
38
39if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
40 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
41 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
42 untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
43 return -1
44}
45
46clean_restart $executable
47
48gdb_load_shlibs $lib_sl1
49gdb_load_shlibs $lib_sl2
50
51if ![runto_main] {
52 fail "Can't run to main to check for trace support"
53 return -1
54}
55
56if { ![gdb_target_supports_trace] } then {
57 unsupported "Current target does not support trace"
ae59b1da 58 return -1
1e4d1764
YQ
59}
60
61if [is_amd64_regs_target] {
62 set pcreg "rip"
63} elseif [is_x86_like_target] {
64 set pcreg "eip"
65} else {
66 set pcreg "pc"
67}
68
69
70# Set tracepoint during tracing experiment.
71
0f4d39d5 72proc tracepoint_change_loc_1 { trace_type } { with_test_prefix "1 $trace_type" {
1e4d1764
YQ
73 global testfile
74 global srcfile
75 global pcreg
76 global gdb_prompt
1e4d1764
YQ
77
78 clean_restart ${testfile}
79 if ![runto_main] {
80 fail "Can't run to main"
1e4d1764
YQ
81 return -1
82 }
83 gdb_test_no_output "delete break 1"
84
85 # Set a tracepoint we'll never meet. Just to avoid the complain after
86 # type `tstart' later.
87 gdb_test "next" ".*"
88 gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
89 "set tracepoint on main"
90
91 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
92 "breakpoint on marker"
93
94 gdb_test_no_output "tstart"
95
96 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
97 "continue to marker 1"
98 # Set a tracepoint during tracing.
f4647387
YQ
99 set test "set tracepoint on set_tracepoint"
100 gdb_test_multiple "${trace_type} set_tracepoint" $test {
101 -re "Target returns error code .* too far .*$gdb_prompt $" {
102 if [string equal $trace_type "ftrace"] {
103 # The target was unable to install the fast tracepoint
104 # (e.g., jump pad too far from tracepoint).
105 pass "$test (too far)"
106 } else {
107 fail $test
108 }
109 }
110 -re "\r\n$gdb_prompt $" {
111 pass $test
112 }
113 }
1e4d1764
YQ
114
115 gdb_trace_setactions "set action for tracepoint" "" \
116 "collect \$$pcreg" "^$"
117
118 # tracepoint has two locations after shlib change-loc-1 is loaded.
119 gdb_test "info trace" \
120 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
121\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
122 "tracepoint with two locations"
123
f4647387
YQ
124 set test "continue to marker 2"
125 gdb_test_multiple "continue" $test {
126 -re "Target returns error code .* too far .*$gdb_prompt $" {
127 if [string equal $trace_type "ftrace"] {
128 # Expected if the target was unable to install the
129 # fast tracepoint (e.g., jump pad too far from
130 # tracepoint).
131 pass "$test (too far)"
132 # Skip the rest of the tests.
133 return
134 } else {
135 fail "continue to marker 2"
136 fail $test
137 }
138
139 }
140 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
141 pass "continue to marker 2"
142 }
bfccc43c 143 }
f4647387 144
1e4d1764
YQ
145 # tracepoint has three locations after shlib change-loc-2 is loaded.
146 gdb_test "info trace" \
147 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
148\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
149 "tracepoint with three locations"
150
bfccc43c
YQ
151 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
152 "continue to marker 3"
153
154 # shlib is unloaded, there are still three locations, but one is pending.
155 gdb_test "info trace" \
156 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
f2a8bc8a
YQ
157\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
1584\.1.* in func4.*\tinstalled on target\r\n(4\.2.* in func4.*\tinstalled on target\r\n4\.3.* \<PENDING\>\[\t \]+set_tracepoint|4\.2.* \<PENDING\>\[\t \]+set_tracepoint.*4\.3.* in func4.*\tinstalled on target).*" \
bfccc43c
YQ
159 "tracepoint with two locations (unload)"
160
1e4d1764
YQ
161 gdb_test_no_output "tstop"
162
1e4d1764
YQ
163 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
164 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
6a5870ce 165}}
1e4d1764 166
bfccc43c
YQ
167# Set pending tracepoint.
168
0f4d39d5 169proc tracepoint_change_loc_2 { trace_type } { with_test_prefix "2 $trace_type" {
bfccc43c
YQ
170 global srcdir
171 global srcfile
172 global subdir
173 global pcreg
174 global binfile
175 global gdb_prompt
bfccc43c
YQ
176
177 gdb_exit
178 gdb_start
179 gdb_reinitialize_dir $srcdir/$subdir
180
181 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
182 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
183 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
184 }
185 }
186
187 gdb_trace_setactions "set action for tracepoint" "" \
188 "collect \$$pcreg" "^$"
189
f2a8bc8a
YQ
190 # tracepoint has no location information now. Make sure nothing
191 # else is displayed.
bfccc43c
YQ
192 gdb_test "info trace" \
193 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
f2a8bc8a 194\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg\r" \
bfccc43c
YQ
195 "single pending tracepoint info (without symbols)"
196
197 gdb_load ${binfile}
198 # tracepoint has one location after executable is loaded.
199 gdb_test "info trace" \
200 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
201\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
202 "tracepoint with one location"
203
204 set main_bp 0
205 gdb_test_multiple "break main" "set breakpoint on main" {
206 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
207 set main_bp $expect_out(1,string)
208 }
209 }
210 gdb_run_cmd
211
212 gdb_test "" \
213 ".*Breakpoint.*main.*at.*$srcfile.*" \
214 "run to main"
215 gdb_test_no_output "delete break $main_bp"
216
217 # tracepoint has two locations after shlib change-loc-1 is loaded.
218 gdb_test "info trace" \
219 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
220\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
221 "tracepoint with two locations"
222
223 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
224 "breakpoint on marker"
225
226 # tracepoint with two locations will be downloaded and installed.
f4647387
YQ
227 set test "tstart"
228 gdb_test_multiple "tstart" $test {
229 -re "^tstart\r\n$gdb_prompt $" {
230 pass "tstart"
231 }
232 -re "Target returns error code .* too far .*$gdb_prompt $" {
233 if [string equal $trace_type "ftrace"] {
234 # The target was unable to install the fast tracepoint
235 # (e.g., jump pad too far from tracepoint).
236 pass "$test (too far)"
237 # Skip the rest of the tests.
238 return
239 } else {
240 fail $test
241 }
bfccc43c
YQ
242 }
243 }
244
f4647387
YQ
245 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
246 "continue to marker 1"
247
bfccc43c
YQ
248 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
249 "continue to marker 2"
250
251 # tracepoint has three locations after shlib change-loc-2 is loaded.
252 gdb_test "info trace" \
253 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
254\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
255 "tracepoint with three locations"
256
257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
258 "continue to marker 3"
259
260 # shlib is unloaded, there are still three locations, but one is pending.
261 gdb_test "info trace" \
262 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
f2a8bc8a
YQ
263\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
2641\.1.* in func4.*\tinstalled on target\r\n(1\.2.* in func4.*\tinstalled on target\r\n1\.3.* \<PENDING\>\[\t \]+set_tracepoint|1\.2.* \<PENDING\>\[\t \]+set_tracepoint\r\n1\.3.* in func4.*\tinstalled on target).*" \
bfccc43c
YQ
265 "tracepoint with two locations (unload)"
266
267 gdb_test_no_output "tstop"
268
269 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
270 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
271 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
272 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
6a5870ce 273}}
1e4d1764
YQ
274
275tracepoint_change_loc_1 "trace"
bfccc43c 276tracepoint_change_loc_2 "trace"
1e4d1764
YQ
277
278# Re-compile test case with IPA.
c0d4d1c0 279set libipa [get_in_proc_agent]
1e4d1764
YQ
280gdb_load_shlibs $libipa
281
282if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
283 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
284 untested change-loc.exp
285 return -1
286}
287
288tracepoint_change_loc_1 "ftrace"
bfccc43c 289tracepoint_change_loc_2 "ftrace"
This page took 0.206454 seconds and 4 git commands to generate.