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