2012-01-16 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / change-loc.exp
1 # Copyright 2011-2012 Free Software Foundation, Inc.
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
15 load_lib "trace-support.exp";
16
17 if {[skip_shlib_tests]} {
18 return 0
19 }
20
21 set testfile "change-loc"
22 set libfile1 "change-loc-1"
23 set libfile2 "change-loc-2"
24 set srcfile $testfile.c
25 set executable $testfile
26 set libsrc1 $srcdir/$subdir/$libfile1.c
27 set libsrc2 $srcdir/$subdir/$libfile2.c
28 set binfile $objdir/$subdir/$testfile
29 set lib_sl1 $objdir/$subdir/$libfile1.sl
30 set lib_sl2 $objdir/$subdir/$libfile2.sl
31
32 set lib_opts debug
33
34 if [get_compiler_info ${binfile}] {
35 return -1
36 }
37
38 # Some targets have leading underscores on assembly symbols.
39 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
40
41 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
42 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
43 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
44 untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
45 return -1
46 }
47
48 clean_restart $executable
49
50 gdb_load_shlibs $lib_sl1
51 gdb_load_shlibs $lib_sl2
52
53 if ![runto_main] {
54 fail "Can't run to main to check for trace support"
55 return -1
56 }
57
58 if { ![gdb_target_supports_trace] } then {
59 unsupported "Current target does not support trace"
60 return -1;
61 }
62
63 if [is_amd64_regs_target] {
64 set pcreg "rip"
65 } elseif [is_x86_like_target] {
66 set pcreg "eip"
67 } else {
68 set pcreg "pc"
69 }
70
71
72 # Set tracepoint during tracing experiment.
73
74 proc tracepoint_change_loc_1 { trace_type } {
75 global testfile
76 global srcfile
77 global pcreg
78 global gdb_prompt
79 global pf_prefix
80
81 set old_pf_prefix $pf_prefix
82 set pf_prefix "$pf_prefix 1 $trace_type:"
83
84 clean_restart ${testfile}
85 if ![runto_main] {
86 fail "Can't run to main"
87 set pf_prefix $old_pf_prefix
88 return -1
89 }
90 gdb_test_no_output "delete break 1"
91
92 # Set a tracepoint we'll never meet. Just to avoid the complain after
93 # type `tstart' later.
94 gdb_test "next" ".*"
95 gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
96 "set tracepoint on main"
97
98 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
99 "breakpoint on marker"
100
101 gdb_test_no_output "tstart"
102
103 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
104 "continue to marker 1"
105 # Set a tracepoint during tracing.
106 gdb_test "${trace_type} set_tracepoint" ".*" "set tracepoint on set_tracepoint"
107
108 gdb_trace_setactions "set action for tracepoint" "" \
109 "collect \$$pcreg" "^$"
110
111 # tracepoint has two locations after shlib change-loc-1 is loaded.
112 gdb_test "info trace" \
113 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
114 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
115 "tracepoint with two locations"
116
117 gdb_test_multiple "continue" "continue to marker 2" {
118 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
119 pass "continue to marker 2"
120 }
121 -re ".*$gdb_prompt $" {
122 kfail "gdb/13392" "continue to marker 2"
123 set pf_prefix $old_pf_prefix
124 return
125 }
126 }
127 # tracepoint has three locations after shlib change-loc-2 is loaded.
128 gdb_test "info trace" \
129 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
130 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
131 "tracepoint with three locations"
132
133 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
134 "continue to marker 3"
135
136 # shlib is unloaded, there are still three locations, but one is pending.
137 gdb_test "info trace" \
138 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
139 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* \<PENDING\>\[\t \]+set_tracepoint.*" \
140 "tracepoint with two locations (unload)"
141
142 gdb_test_no_output "tstop"
143
144 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
145 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
146
147 set pf_prefix $old_pf_prefix
148 }
149
150 # Set pending tracepoint.
151
152 proc tracepoint_change_loc_2 { trace_type } {
153 global srcdir
154 global srcfile
155 global subdir
156 global pcreg
157 global binfile
158 global gdb_prompt
159 global pf_prefix
160
161 set old_pf_prefix $pf_prefix
162 set pf_prefix "$pf_prefix 2 $trace_type:"
163
164 gdb_exit
165 gdb_start
166 gdb_reinitialize_dir $srcdir/$subdir
167
168 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
169 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
170 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
171 }
172 }
173
174 gdb_trace_setactions "set action for tracepoint" "" \
175 "collect \$$pcreg" "^$"
176
177 # tracepoint has no location information now.
178 gdb_test "info trace" \
179 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
180 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint.*" \
181 "single pending tracepoint info (without symbols)"
182
183 gdb_load ${binfile}
184 # tracepoint has one location after executable is loaded.
185 gdb_test "info trace" \
186 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
187 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
188 "tracepoint with one location"
189
190 set main_bp 0
191 gdb_test_multiple "break main" "set breakpoint on main" {
192 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
193 set main_bp $expect_out(1,string)
194 }
195 }
196 gdb_run_cmd
197
198 gdb_test "" \
199 ".*Breakpoint.*main.*at.*$srcfile.*" \
200 "run to main"
201 gdb_test_no_output "delete break $main_bp"
202
203 # tracepoint has two locations after shlib change-loc-1 is loaded.
204 gdb_test "info trace" \
205 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
206 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
207 "tracepoint with two locations"
208
209 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
210 "breakpoint on marker"
211
212 # tracepoint with two locations will be downloaded and installed.
213 gdb_test_no_output "tstart"
214
215 gdb_test_multiple "continue" "continue to marker 1" {
216 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
217 pass "continue to marker 1"
218 }
219 -re ".*$gdb_prompt $" {
220 kfail "gdb/13392" "continue to marker 1"
221 set pf_prefix $old_pf_prefix
222 return
223 }
224 }
225
226 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
227 "continue to marker 2"
228
229 # tracepoint has three locations after shlib change-loc-2 is loaded.
230 gdb_test "info trace" \
231 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
232 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
233 "tracepoint with three locations"
234
235 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
236 "continue to marker 3"
237
238 # shlib is unloaded, there are still three locations, but one is pending.
239 gdb_test "info trace" \
240 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
241 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* \<PENDING\>\[\t \]+set_tracepoint.*" \
242 "tracepoint with two locations (unload)"
243
244 gdb_test_no_output "tstop"
245
246 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
247 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
248 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
249 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
250
251 set pf_prefix $old_pf_prefix
252 }
253
254 tracepoint_change_loc_1 "trace"
255 tracepoint_change_loc_2 "trace"
256
257 # Re-compile test case with IPA.
258 set libipa $objdir/../gdbserver/libinproctrace.so
259 gdb_load_shlibs $libipa
260
261 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
262 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
263 untested change-loc.exp
264 return -1
265 }
266
267 tracepoint_change_loc_1 "ftrace"
268 tracepoint_change_loc_2 "ftrace"
This page took 0.036219 seconds and 5 git commands to generate.