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.
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";
17 if {[skip_shlib_tests]} {
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
34 if [get_compiler_info ${binfile}] {
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]]
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."
48 clean_restart $executable
50 gdb_load_shlibs $lib_sl1
51 gdb_load_shlibs $lib_sl2
54 fail "Can't run to main to check for trace support"
58 if { ![gdb_target_supports_trace] } then {
59 unsupported "Current target does not support trace"
63 if [is_amd64_regs_target] {
65 } elseif [is_x86_like_target] {
72 # Set tracepoint during tracing experiment.
74 proc tracepoint_change_loc_1 { trace_type } { with_test_prefix "1 $trace_type" {
80 clean_restart ${testfile}
82 fail "Can't run to main"
85 gdb_test_no_output "delete break 1"
87 # Set a tracepoint we'll never meet. Just to avoid the complain after
88 # type `tstart' later.
90 gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
91 "set tracepoint on main"
93 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
94 "breakpoint on marker"
96 gdb_test_no_output "tstart"
98 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
99 "continue to marker 1"
100 # Set a tracepoint during tracing.
101 set test "set tracepoint on set_tracepoint"
102 gdb_test_multiple "${trace_type} set_tracepoint" $test {
103 -re "Target returns error code .* too far .*$gdb_prompt $" {
104 if [string equal $trace_type "ftrace"] {
105 # The target was unable to install the fast tracepoint
106 # (e.g., jump pad too far from tracepoint).
107 pass "$test (too far)"
112 -re "\r\n$gdb_prompt $" {
117 gdb_trace_setactions "set action for tracepoint" "" \
118 "collect \$$pcreg" "^$"
120 # tracepoint has two locations after shlib change-loc-1 is loaded.
121 gdb_test "info trace" \
122 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
123 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
124 "tracepoint with two locations"
126 set test "continue to marker 2"
127 gdb_test_multiple "continue" $test {
128 -re "Target returns error code .* too far .*$gdb_prompt $" {
129 if [string equal $trace_type "ftrace"] {
130 # Expected if the target was unable to install the
131 # fast tracepoint (e.g., jump pad too far from
133 pass "$test (too far)"
134 # Skip the rest of the tests.
137 fail "continue to marker 2"
142 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
143 pass "continue to marker 2"
147 # tracepoint has three locations after shlib change-loc-2 is loaded.
148 gdb_test "info trace" \
149 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
150 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
151 "tracepoint with three locations"
153 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
154 "continue to marker 3"
156 # shlib is unloaded, there are still three locations, but one is pending.
157 gdb_test "info trace" \
158 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
159 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*(4\.2.* in func4.*4\.3.* \<PENDING\>\[\t \]+set_tracepoint|4\.2.* \<PENDING\>\[\t \]+set_tracepoint\r\n4\.3.* in func4).*" \
160 "tracepoint with two locations (unload)"
162 gdb_test_no_output "tstop"
164 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
165 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
168 # Set pending tracepoint.
170 proc tracepoint_change_loc_2 { trace_type } { with_test_prefix "2 $trace_type" {
180 gdb_reinitialize_dir $srcdir/$subdir
182 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
183 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
184 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
188 gdb_trace_setactions "set action for tracepoint" "" \
189 "collect \$$pcreg" "^$"
191 # tracepoint has no location information now.
192 gdb_test "info trace" \
193 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
194 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint.*" \
195 "single pending tracepoint info (without symbols)"
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"
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)
213 ".*Breakpoint.*main.*at.*$srcfile.*" \
215 gdb_test_no_output "delete break $main_bp"
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"
223 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
224 "breakpoint on marker"
226 # tracepoint with two locations will be downloaded and installed.
228 gdb_test_multiple "tstart" $test {
229 -re "^tstart\r\n$gdb_prompt $" {
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.
245 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
246 "continue to marker 1"
248 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
249 "continue to marker 2"
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"
257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
258 "continue to marker 3"
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.*
263 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*(1\.2.* in func4.*1\.3.* \<PENDING\>\[\t \]+set_tracepoint|1\.2.* \<PENDING\>\[\t \]+set_tracepoint\r\n1\.3.* in func4).*" \
264 "tracepoint with two locations (unload)"
266 gdb_test_no_output "tstop"
268 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
269 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
270 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
271 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
274 tracepoint_change_loc_1 "trace"
275 tracepoint_change_loc_2 "trace"
277 # Re-compile test case with IPA.
278 set libipa $objdir/../gdbserver/libinproctrace.so
279 gdb_load_shlibs $libipa
281 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
282 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
283 untested change-loc.exp
287 tracepoint_change_loc_1 "ftrace"
288 tracepoint_change_loc_2 "ftrace"