1# Copyright 1998-2015 Free Software Foundation, Inc. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This file was written by Michael Snyder (msnyder@cygnus.com) 17 18load_lib "trace-support.exp" 19 20 21gdb_exit 22gdb_start 23 24standard_testfile actions.c 25 26if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \ 27 executable {debug nowarnings}] != "" } { 28 untested tfind.exp 29 return -1 30} 31gdb_load $binfile 32gdb_test "tstop" ".*" "" 33gdb_test "tfind none" ".*" "" 34 35# 6.2 test help tstart 36gdb_test "help tstart" \ 37 "Start trace data collection\.\[\r\n\]+Usage: tstart \\\[ <notes> \.\.\. \\\]\[\r\n\]+Any arguments supplied are recorded with the trace as a note and\[\r\n\]+reported by tstatus \\(if the target supports trace notes\\)\." \ 38 "6.2: help tstart" 39# 7.2 test help tstop 40gdb_test "help tstop" \ 41 "Stop trace data collection\.\[\r\n\]+Usage: tstop \\\[ <notes> \.\.\. \\\]\[\r\n\]+Any arguments supplied are recorded with the trace as a stop reason and\[\r\n\]+reported by tstatus \\(if the target supports trace notes\\)\." \ 42 "7.2: help tstop" 43 44# 8.38 test help tfind 45gdb_test "help tfind" "Select a trace frame.*" \ 46 "8.38: help tfind" 47gdb_test "help tfind pc" "Select a trace frame by PC.*" \ 48 "8.38: help tfind PC" 49gdb_test "help tfind end" "De-select any trace frame.*" \ 50 "8.38: help tfind end" 51gdb_test "help tfind none" "De-select any trace frame.*" \ 52 "8.38: help tfind none" 53gdb_test "help tfind line" "Select a trace frame by source line.*" \ 54 "8.38: help tfind line" 55gdb_test "help tfind start" "Select the first trace frame.*" \ 56 "8.38: help tfind start" 57gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \ 58 "8.38: help tfind range" 59gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \ 60 "8.38: help tfind tracepoint" 61 62runto_main 63gdb_reinitialize_dir $srcdir/$subdir 64 65if { ![gdb_target_supports_trace] } then { 66 unsupported "Current target does not support trace" 67 return 1 68 69} 70 71# If testing on a remote host, download the source file. 72# remote_download host $srcdir/$subdir/$srcfile 73 74# define relative source line numbers: 75# all subsequent line numbers are relative to this first one (baseline) 76set baseline [gdb_find_recursion_test_baseline $srcfile] 77if { $baseline == -1 } then { 78 fail "Could not find gdb_recursion_test function" 79 return 80} 81 82set testline1 [expr $baseline + 1] 83set testline2 [expr $baseline + 5] 84set testline3 [expr $baseline + 6] 85set testline4 [expr $baseline + 7] 86set testline5 [expr $baseline + 8] 87 88# 89# test tfind command 90# 91 92gdb_delete_tracepoints 93set tdp1 [gdb_gettpnum "\*gdb_recursion_test"] 94set tdp2 [gdb_gettpnum $testline2] 95set tdp3 [gdb_gettpnum $testline3] 96set tdp4 [gdb_gettpnum $testline4] 97set tdp5 [gdb_gettpnum $testline5] 98if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \ 99 $tdp4 <= 0 || $tdp5 <= 0 } then { 100 fail "setting tracepoints" 101 return 102} 103 104# 6.1 test tstart command 105 106set return_me 1 107gdb_test_multiple "tstart" "6.1: tstart" { 108 -re "Trace can only be run on remote targets.*$gdb_prompt $" { 109 fail "6.1: tstart (not connected to remote?)" 110 } 111 -re "Target does not support this command.*$gdb_prompt $" { 112 fail "6.1: tstart (connected to wrong target?)" 113 } 114 -re "Target returns error code.*$gdb_prompt $" { 115 fail "6.1: tstart (connected to wrong target?)" 116 } 117 -re "$gdb_prompt $" { 118 pass "6.1: tstart" 119 set return_me 0 120 } 121} 122 123if { $return_me == 1 } then { 124 return -1 125} 126 127# test tstatus (when trace on) 128gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on" 129 130gdb_test "break end" ".*" "" 131gdb_test "continue" \ 132 "Continuing.*Breakpoint $decimal, end.*" \ 133 "run trace experiment" 134 135# 7.1 test tstop command 136 137set return_me 1 138gdb_test_multiple "tstop" "7.1: tstop" { 139 -re "Trace can only be run on remote targets.*$gdb_prompt $" { 140 fail "7.1: tstop (not connected to remote?)" 141 } 142 -re "Target does not support this command.*$gdb_prompt $" { 143 fail "7.1: tstop (connected to wrong target?)" 144 } 145 -re "Target returns error code.*$gdb_prompt $" { 146 fail "7.1: tstop (connected to wrong target?)" 147 } 148 -re "$gdb_prompt $" { 149 pass "7.1: tstop" 150 set return_me 0 151 } 152} 153 154if { $return_me == 1 } then { 155 return -1 156} 157 158# test tstatus (when trace off) 159gdb_test "tstatus" "Trace stopped by a tstop command.*" \ 160 "test tstatus off after tstop" 161 162## record starting PC 163set save_pc [gdb_readexpr "(unsigned long) \$pc"] 164if { $save_pc == -1 } then { 165 fail "could not read PC" 166 return 167} 168 169# 8.7 tfind start 170## check $trace_frame == 0 171gdb_tfind_test "8.7: tfind start command" "start" "0" 172## check $pc != startPC 173gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \ 174 "x 1 x" \ 175 "8.7b: tfind start" 176 177# 8.8 tfind none 178## check $trace_frame == -1 179gdb_tfind_test "8.8: tfind none" "none" "-1" 180## check $pc == startPC 181gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \ 182 "x 1 x" \ 183 "8.8b: tfind none (restores non-trace PC)" 184 185# 8.9 tfind end 186## check $trace_frame == -1 187gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1" 188## check $pc == startPC 189gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \ 190 "x 1 x" \ 191 "8.9b: tfind end (restores non-tracing PC)" 192 193# 8.1 tfind n 194## check $trace_frame == n 195gdb_tfind_test "8.1: tfind 1" "1" "1" 196## check $trace_line corresponds to tracepoint for frame n 197gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)" 198 199# 8.28 tfind invalid n (big number) 200## check "not found" error 201## check $trace_frame != n 202gdb_test "tfind 32767" \ 203 "failed to find.*" \ 204 "8.28: tfind <n> command rejects invalid frame number" 205 206gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \ 207 "x 0 x" \ 208 "8.28: tfind <n> rejected bad input (32767)" 209 210# 8.31 tfind negative n 211## check error 212gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input" 213## check $trace_frame != -n 214gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \ 215 "8.31: tfind <n> rejected negative input (-3)" 216 217# 8.10 tfind <no arg> 218## check $trace_frame += 1 219 220gdb_tfind_test "8.10: tfind start" "start" "0" 221gdb_test "print \$trace_line" "$baseline" \ 222 "8.10: tfind 0 (correct line $baseline)" 223gdb_tfind_test "8.10: tfind noargument 1" "" "1" 224gdb_test "print \$trace_line" "$testline2" \ 225 "8.10: tfind 1 (correct line $testline2)" 226gdb_tfind_test "8.10: tfind noargument 2" "" "2" 227gdb_test "print \$trace_line" "$testline3" \ 228 "8.10: tfind 2 (correct line $testline3)" 229gdb_tfind_test "8.10: tfind noargument 3" "" "3" 230gdb_test "print \$trace_line" "$testline4" \ 231 "8.10: tfind 3 (correct line $testline4)" 232 233gdb_tfind_test "8.11: tfind 3" "3" "3" 234gdb_test "print \$trace_line" "$testline4" \ 235 "8.11: tfind 3 (correct line $testline4)" 236gdb_tfind_test "8.11: tfind backward 2" "-" "2" 237gdb_test "print \$trace_line" "$testline3" \ 238 "8.11: tfind 2 (correct line $testline3)" 239gdb_tfind_test "8.11: tfind backward 1" "-" "1" 240gdb_test "print \$trace_line" "$testline2" \ 241 "8.11: tfind 1 (correct line $testline2)" 242gdb_tfind_test "8.11: tfind backward 0" "-" "0" 243gdb_test "print \$trace_line" "$baseline" \ 244 "8.11: tfind 0 (correct line $baseline)" 245 246gdb_tfind_test "8.12: tfind none" "none" "-1" 247gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \ 248 "\$tracepoint" "$tdp2" 249gdb_test "print \$trace_line" "$testline2" \ 250 "8.12: tfind tracepoint <n> (line $testline2)" 251 252gdb_tfind_test "8.25: tfind none" "none" "-1" 253gdb_test "tfind tracepoint 0" "failed to find.*" \ 254 "8.25: tfind tracepoint rejects zero" 255gdb_test "tfind tracepoint 32767" "failed to find.*" \ 256 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)" 257gdb_test "tfind tracepoint -1" "failed to find.*" \ 258 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)" 259 260# 8.37 tfind tracepoint n where n no longer exists (but used to) 261gdb_test_no_output "delete trace $tdp2" "" 262gdb_tfind_test "8.37: tfind none" "none" "-1" 263gdb_tfind_test "8.37: tfind deleted tracepoint" \ 264 "tracepoint $tdp2" \ 265 "\$tracepoint" "$tdp2" 266gdb_test "print \$trace_line" "$testline2" \ 267 "8.37: tfind deleted tracepoint (line $testline2)" 268 269# 8.13 tfind tracepoint <no arg> 270## check $tracepoint same before and after, $trace_frame changed 271 272gdb_tfind_test "8.13: tfind none" "none" "-1" 273gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \ 274 "\$tracepoint" "$tdp1" 275gdb_test "print \$trace_line" "$baseline" \ 276 "8.13: tfind tracepoint $tdp1 (line $baseline)" 277gdb_test_no_output "set \$save_frame = \$trace_frame" "" 278gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \ 279 "\$tracepoint" "$tdp1" 280gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \ 281 "x 0 x" \ 282 "8.13: tracepoint <no arg>, tracepoint number unchanged" 283 284# 1.12 set tracepoint in prologue 285# 286# tdp1 was set at *gdb_recursion_test (ie. the hard address of the 287# function, before the prologue). Test to see that it succeeded. 288# Current pc should be equal to the address of the function. 289 290gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \ 291 "x 1 x" \ 292 "1.12: set tracepoint in prologue" 293 294# 8.14 tfind pc x 295## check pc == x, $trace_frame != -1 296gdb_tfind_test "8.14: tfind 3" "3" "3" 297gdb_test "print \$trace_line" "$testline4" \ 298 "8.14: tfind 3 (line $testline4)" 299 300gdb_test_no_output "set \$test_pc = \$pc" "" 301gdb_tfind_test "8.14: tfind none" "none" "-1" 302gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1" 303gdb_test "print \$trace_line" "$testline4" \ 304 "8.14: tfind pc x (line $testline4)" 305gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \ 306 "x 1 x" \ 307 "8.14: tfind pc x" 308 309# 8.15 tfind pc <no arg> 310## check pc same before and after, $trace_frame changed 311gdb_tfind_test "8.15: tfind 3" "3" "3" 312gdb_test "print \$trace_line" "$testline4" \ 313 "8.15: tfind 3 (line $testline4)" 314gdb_test_no_output "set \$test_pc = \$pc" "" 315gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1" 316gdb_test "print \$trace_line" "$testline4" \ 317 "8.15: tfind pc (line $testline4)" 318gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \ 319 "8.15: trace frame didn't change" 320 321# 8.26 tfind pc invalid x 322## check error, pc != x (trace_frame unchanged?) 323gdb_tfind_test "8.26: tfind start" "start" "0" 324gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero" 325gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1" 326 327# 8.16 tfind line n 328## check #trace_frame != -1, $trace_line == n 329gdb_tfind_test "8.16: tfind none" "none" "-1" 330gdb_tfind_test "8.16: tfind line $testline3" \ 331 "line $testline3" \ 332 "\$trace_line == $testline3" "1" 333 334# 8.17 tfind line <no arg> (# 8.19, 8.20) 335## check $trace_line changed, no error, pc changed, frame changed, tdp changed 336gdb_tfind_test "8.17: tfind none" "none" "-1" 337gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1" 338gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1" 339 340# 8.36 tfind and disassembly 341gdb_tfind_test "8.36: tfind start" "start" "0" 342set timeout 60 343# look for disassembly of function label 344gdb_test "disassemble gdb_c_test" \ 345 "<(\.\[0-9\]+|)>:.*End of assembler dump.*" \ 346 "8.36: trace disassembly" 347 348gdb_test "tfind line 0" \ 349 "out of range.*|failed to find.*|No line 0 in .*" \ 350 "8.18: tfind line 0" 351gdb_test "tfind line 32767" \ 352 "out of range.*|failed to find.*|No line 32767 in .*" \ 353 "8.27: tfind line 32767" 354gdb_test "tfind line NoSuChFiLe.c:$baseline" \ 355 "No source file named.*" \ 356 "8.27: tfind line in bad source file" 357 358# 8.32 tfind invalid subcommand (tfind foo) 359## check error 360gdb_test "tfind NoSuChOpTiOn 21" \ 361 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \ 362 "8.32: tfind with bad subcommand" 363 364# Finished! 365gdb_tfind_test "8.17: tfind none" "none" "-1" 366