1 # Copyright 2011 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.
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.
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/>.
15 load_lib "trace-support.exp";
21 if {[skip_shlib_tests]} {
25 set testfile "change-loc"
26 set libfile1 "change-loc-1"
27 set libfile2 "change-loc-2"
28 set srcfile $testfile.c
29 set executable $testfile
30 set libsrc1 $srcdir/$subdir/$libfile1.c
31 set libsrc2 $srcdir/$subdir/$libfile2.c
32 set binfile $objdir/$subdir/$testfile
33 set lib_sl1 $objdir/$subdir/$libfile1.sl
34 set lib_sl2 $objdir/$subdir/$libfile2.sl
38 if [get_compiler_info ${binfile}] {
42 # Some targets have leading underscores on assembly symbols.
43 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
45 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
46 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
47 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
48 untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
52 clean_restart $executable
54 gdb_load_shlibs $lib_sl1
55 gdb_load_shlibs $lib_sl2
58 fail "Can't run to main to check for trace support"
62 if { ![gdb_target_supports_trace] } then {
63 unsupported "Current target does not support trace"
67 if [is_amd64_regs_target] {
69 } elseif [is_x86_like_target] {
76 # Set tracepoint during tracing experiment.
78 proc tracepoint_change_loc_1 { trace_type } {
85 set old_pf_prefix $pf_prefix
86 set pf_prefix "$pf_prefix 1 $trace_type:"
88 clean_restart ${testfile}
90 fail "Can't run to main"
91 set pf_prefix $old_pf_prefix
94 gdb_test_no_output "delete break 1"
96 # Set a tracepoint we'll never meet. Just to avoid the complain after
97 # type `tstart' later.
99 gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
100 "set tracepoint on main"
102 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
103 "breakpoint on marker"
105 gdb_test_no_output "tstart"
107 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
108 "continue to marker 1"
109 # Set a tracepoint during tracing.
110 gdb_test "${trace_type} set_tracepoint" ".*" "set tracepoint on set_tracepoint"
112 gdb_trace_setactions "set action for tracepoint" "" \
113 "collect \$$pcreg" "^$"
115 # tracepoint has two locations after shlib change-loc-1 is loaded.
116 gdb_test "info trace" \
117 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
118 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
119 "tracepoint with two locations"
121 gdb_test_multiple "continue" "continue to marker 2" {
122 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
123 pass "continue to marker 2"
125 -re ".*$gdb_prompt $" {
126 kfail "gdb/13392" "continue to marker 2"
127 set pf_prefix $old_pf_prefix
131 # tracepoint has three locations after shlib change-loc-2 is loaded.
132 gdb_test "info trace" \
133 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
134 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
135 "tracepoint with three locations"
137 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
138 "continue to marker 3"
140 # shlib is unloaded, there are still three locations, but one is pending.
141 gdb_test "info trace" \
142 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
143 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* \<PENDING\>\[\t \]+set_tracepoint.*" \
144 "tracepoint with two locations (unload)"
146 gdb_test_no_output "tstop"
148 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
149 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
151 set pf_prefix $old_pf_prefix
154 # Set pending tracepoint.
156 proc tracepoint_change_loc_2 { trace_type } {
165 set old_pf_prefix $pf_prefix
166 set pf_prefix "$pf_prefix 2 $trace_type:"
170 gdb_reinitialize_dir $srcdir/$subdir
172 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
173 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
174 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
178 gdb_trace_setactions "set action for tracepoint" "" \
179 "collect \$$pcreg" "^$"
181 # tracepoint has no location information now.
182 gdb_test "info trace" \
183 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
184 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint.*" \
185 "single pending tracepoint info (without symbols)"
188 # tracepoint has one location after executable is loaded.
189 gdb_test "info trace" \
190 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
191 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
192 "tracepoint with one location"
195 gdb_test_multiple "break main" "set breakpoint on main" {
196 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
197 set main_bp $expect_out(1,string)
203 ".*Breakpoint.*main.*at.*$srcfile.*" \
205 gdb_test_no_output "delete break $main_bp"
207 # tracepoint has two locations after shlib change-loc-1 is loaded.
208 gdb_test "info trace" \
209 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
210 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
211 "tracepoint with two locations"
213 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
214 "breakpoint on marker"
216 # tracepoint with two locations will be downloaded and installed.
217 gdb_test_no_output "tstart"
219 gdb_test_multiple "continue" "continue to marker 1" {
220 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
221 pass "continue to marker 1"
223 -re ".*$gdb_prompt $" {
224 kfail "gdb/13392" "continue to marker 1"
225 set pf_prefix $old_pf_prefix
230 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
231 "continue to marker 2"
233 # tracepoint has three locations after shlib change-loc-2 is loaded.
234 gdb_test "info trace" \
235 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
236 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
237 "tracepoint with three locations"
239 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
240 "continue to marker 3"
242 # shlib is unloaded, there are still three locations, but one is pending.
243 gdb_test "info trace" \
244 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
245 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* \<PENDING\>\[\t \]+set_tracepoint.*" \
246 "tracepoint with two locations (unload)"
248 gdb_test_no_output "tstop"
250 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
251 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
252 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
253 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
255 set pf_prefix $old_pf_prefix
258 tracepoint_change_loc_1 "trace"
259 tracepoint_change_loc_2 "trace"
261 # Re-compile test case with IPA.
262 set libipa $objdir/../gdbserver/libinproctrace.so
263 gdb_load_shlibs $libipa
265 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
266 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
267 untested change-loc.exp
271 tracepoint_change_loc_1 "ftrace"
272 tracepoint_change_loc_2 "ftrace"