1# Copyright 2011-2015 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 15load_lib "trace-support.exp" 16 17if {[skip_shlib_tests]} { 18 return 0 19} 20 21standard_testfile 22set libfile1 "change-loc-1" 23set libfile2 "change-loc-2" 24set executable $testfile 25set libsrc1 $srcdir/$subdir/$libfile1.c 26set libsrc2 $srcdir/$subdir/$libfile2.c 27set lib_sl1 [standard_output_file $libfile1.sl] 28set lib_sl2 [standard_output_file $libfile2.sl] 29 30set lib_opts debug 31 32if [get_compiler_info] { 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" 58 return -1 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 72proc tracepoint_change_loc_1 { trace_type } { 73 with_test_prefix "1 $trace_type" { 74 global testfile 75 global srcfile 76 global pcreg 77 global gdb_prompt 78 79 clean_restart ${testfile} 80 if ![runto_main] { 81 fail "Can't run to main" 82 return -1 83 } 84 gdb_test_no_output "delete break 1" 85 86 # Set a tracepoint we'll never meet. Just to avoid the 87 # complain after type `tstart' later. 88 gdb_test "next" ".*" 89 gdb_test "trace main" \ 90 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \ 91 "set tracepoint on main" 92 93 gdb_test "break marker" \ 94 "Breakpoint.*at.* file .*$srcfile, line.*" \ 95 "breakpoint on marker" 96 97 gdb_test_no_output "tstart" 98 99 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 100 "continue to marker 1" 101 # Set a tracepoint during tracing. 102 set test "set tracepoint on set_tracepoint" 103 gdb_test_multiple "${trace_type} set_tracepoint" $test { 104 -re "Target returns error code .* too far .*$gdb_prompt $" { 105 if [string equal $trace_type "ftrace"] { 106 # The target was unable to install the fast tracepoint 107 # (e.g., jump pad too far from tracepoint). 108 pass "$test (too far)" 109 } else { 110 fail $test 111 } 112 } 113 -re "\r\n$gdb_prompt $" { 114 pass $test 115 } 116 } 117 118 gdb_trace_setactions "set action for tracepoint" "" \ 119 "collect \$$pcreg" "^$" 120 121 # tracepoint has two locations after shlib change-loc-1 is loaded. 122 gdb_test "info trace" \ 123 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 124\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \ 125 "tracepoint with two locations" 126 127 set test "continue to marker 2" 128 gdb_test_multiple "continue" $test { 129 -re "Target returns error code .* too far .*$gdb_prompt $" { 130 if [string equal $trace_type "ftrace"] { 131 # Expected if the target was unable to install the 132 # fast tracepoint (e.g., jump pad too far from 133 # tracepoint). 134 pass "$test (too far)" 135 # Skip the rest of the tests. 136 return 137 } else { 138 fail "continue to marker 2" 139 fail $test 140 } 141 142 } 143 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" { 144 pass "continue to marker 2" 145 } 146 } 147 148 # tracepoint has three locations after shlib change-loc-2 is 149 # loaded. 150 gdb_test "info trace" \ 151 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 152\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \ 153 "tracepoint with three locations" 154 155 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 156 "continue to marker 3" 157 158 # shlib is unloaded, there are still three locations, but one 159 # is pending. 160 gdb_test "info trace" \ 161 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 162\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.* 1634\.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).*" \ 164 "tracepoint with two locations (unload)" 165 166 gdb_test_no_output "tstop" 167 168 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \ 169 "tfind frame 0" 170 gdb_test "tfind" \ 171 "Target failed to find requested trace frame\\..*" 172 } 173} 174 175# Set pending tracepoint. 176 177proc tracepoint_change_loc_2 { trace_type } { 178 with_test_prefix "2 $trace_type" { 179 global srcdir 180 global srcfile 181 global subdir 182 global pcreg 183 global binfile 184 global gdb_prompt 185 186 gdb_exit 187 gdb_start 188 gdb_reinitialize_dir $srcdir/$subdir 189 190 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" { 191 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" { 192 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint" 193 } 194 } 195 196 gdb_trace_setactions "set action for tracepoint" "" \ 197 "collect \$$pcreg" "^$" 198 199 # tracepoint has no location information now. Make sure nothing 200 # else is displayed. 201 gdb_test "info trace" \ 202 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 203\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg\r" \ 204 "single pending tracepoint info (without symbols)" 205 206 gdb_load ${binfile} 207 # tracepoint has one location after executable is loaded. 208 gdb_test "info trace" \ 209 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 210\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \ 211 "tracepoint with one location" 212 213 set main_bp 0 214 gdb_test_multiple "break main" "set breakpoint on main" { 215 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" { 216 set main_bp $expect_out(1,string) 217 } 218 } 219 gdb_run_cmd 220 221 gdb_test "" \ 222 ".*Breakpoint.*main.*at.*$srcfile.*" \ 223 "run to main" 224 gdb_test_no_output "delete break $main_bp" 225 226 # tracepoint has two locations after shlib change-loc-1 is loaded. 227 gdb_test "info trace" \ 228 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 229\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \ 230 "tracepoint with two locations" 231 232 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \ 233 "breakpoint on marker" 234 235 # tracepoint with two locations will be downloaded and installed. 236 set test "tstart" 237 gdb_test_multiple "tstart" $test { 238 -re "^tstart\r\n$gdb_prompt $" { 239 pass "tstart" 240 } 241 -re "Target returns error code .* too far .*$gdb_prompt $" { 242 if [string equal $trace_type "ftrace"] { 243 # The target was unable to install the fast tracepoint 244 # (e.g., jump pad too far from tracepoint). 245 pass "$test (too far)" 246 # Skip the rest of the tests. 247 return 248 } else { 249 fail $test 250 } 251 } 252 } 253 254 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 255 "continue to marker 1" 256 257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 258 "continue to marker 2" 259 260 # tracepoint has three locations after shlib change-loc-2 is loaded. 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.* in func4 .*" \ 264 "tracepoint with three locations" 265 266 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 267 "continue to marker 3" 268 269 # shlib is unloaded, there are still three locations, but one is pending. 270 gdb_test "info trace" \ 271 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 272\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.* 2731\.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).*" \ 274 "tracepoint with two locations (unload)" 275 276 gdb_test_no_output "tstop" 277 278 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0" 279 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1" 280 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2" 281 gdb_test "tfind" "Target failed to find requested trace frame\\..*" 282 } 283} 284 285# Test that setting a tracepoint while the trace experiment is ongoing 286# doesn't work when we force-disable the InstallInTrace RSP feature. 287 288proc tracepoint_install_in_trace_disabled { trace_type } { 289 with_test_prefix "InstallInTrace disabled: $trace_type" { 290 global testfile 291 global srcfile 292 global pcreg 293 global gdb_prompt 294 295 clean_restart ${testfile} 296 if ![runto_main] { 297 fail "Can't run to main" 298 return -1 299 } 300 301 # This test only makes sense with the remote target. 302 if ![gdb_is_target_remote] { 303 return 304 } 305 306 gdb_test_no_output "delete break 1" 307 308 # Set a tracepoint we'll never meet. Just to avoid the 309 # complain after `tstart' later. 310 gdb_test "next" ".*" 311 gdb_test "trace main" \ 312 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \ 313 "set tracepoint on main" 314 315 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \ 316 "breakpoint on marker" 317 318 gdb_test_no_output "tstart" 319 320 # Force-disable the InstallInTrace RSP feature. 321 gdb_test_no_output "set remote install-in-trace-packet off" 322 323 # Set a tracepoint while a trace experiment is ongoing. 324 gdb_test "${trace_type} set_tracepoint" \ 325 "racepoint .* at .* set_tracepoint.*" \ 326 "set tracepoint on set_tracepoint" 327 328 gdb_trace_setactions "set action for tracepoint" "" \ 329 "collect \$$pcreg" "^$" 330 331 # Make sure the tracepoint is _not_ installed on the target. 332 gdb_test "info trace" \ 333 "Num Type\[ \]+Disp Enb Address\[ \]+What.* 334\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*installed on target.*\<MULTIPLE\>.*4\.1.* in func4.*not installed on target.*4\.2.* in func4.*not installed on target.*" \ 335 "tracepoint is not installed" 336 337 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ 338 "continue to marker" 339 340 gdb_test_no_output "tstop" 341 342 # Nothing should have been collected. 343 gdb_test "tfind" "Target failed to find requested trace frame\\..*" 344 } 345} 346 347tracepoint_change_loc_1 "trace" 348tracepoint_change_loc_2 "trace" 349tracepoint_install_in_trace_disabled "trace" 350 351# Re-compile test case with IPA. 352set libipa [get_in_proc_agent] 353gdb_load_shlibs $libipa 354 355if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \ 356 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } { 357 untested change-loc.exp 358 return -1 359} 360 361tracepoint_change_loc_1 "ftrace" 362tracepoint_change_loc_2 "ftrace" 363tracepoint_install_in_trace_disabled "ftrace" 364