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 25if ![gdb_trace_common_supports_arch] { 26 unsupported "no trace-common.h support for arch" 27 return -1 28} 29if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ 30 executable {debug nowarnings}] != "" } { 31 untested "failed to compile" 32 return -1 33} 34gdb_reinitialize_dir $srcdir/$subdir 35 36# If testing on a remote host, download the source file. 37# remote_download host $srcdir/$subdir/$srcfile 38 39gdb_file_cmd $binfile 40 41# define relative source line numbers: 42# all subsequent line numbers are relative to this first one (baseline) 43set baseline [gdb_find_recursion_test_baseline $srcfile] 44if {$baseline == -1} { 45 fail "could not find gdb_recursion_test function" 46 return 47} 48 49set testline1 [expr $baseline + 4] 50set testline2 [expr $baseline + 5] 51set testline3 [expr $baseline + 6] 52set testline4 [expr $baseline + 7] 53set testline5 [expr $baseline + 8] 54set testline6 [expr $baseline + 9] 55 56# 57# test save-trace command 58# 59 60# setup a set of tracepoints to save 61 62gdb_delete_tracepoints 63 64foreach x { 1 2 3 4 5 6 } { 65 set testline [expr \$testline$x] 66 set trcpt [gdb_gettpnum $testline] 67 set trcpt$x $trcpt 68 gdb_test "passcount $x" \ 69 "Setting tracepoint $trcpt.* to $x" \ 70 "set passcount for tracepoint $trcpt" 71 72 gdb_test_no_output "condition $trcpt $x - 1 == $x / 2" \ 73 "set condition for tracepoint $trcpt" 74 75 gdb_trace_setactions "set actions for tracepoint $x" \ 76 "" \ 77 "collect q$x" "^$" \ 78 "while-stepping $x" "^$" \ 79 "collect q$x" "^$" \ 80 "end" "^$" 81} 82 83gdb_test "ftrace fast_tracepoint_loc" \ 84 "Fast tracepoint $decimal at $hex: file .*$srcfile, line $decimal.*" \ 85 "set a fast tracepoint" 86 87gdb_test_no_output "set default-collect gdb_char_test, gdb_long_test - 100" \ 88 "set default-collect" 89 90# Save tracepoint definitions to a file, at path SAVE_PATH. 91proc gdb_save_tracepoints { save_path } { 92 set save_path_regexp [string_to_regexp $save_path] 93 remote_file host delete $save_path 94 gdb_test "save tracepoints $save_path" \ 95 "Saved to file '$save_path_regexp'." \ 96 "save tracepoint definitions" 97} 98 99# Load tracepoint definitions from a file, from path SAVE_PATH. 100proc gdb_load_tracepoints { save_path } { 101 # Cleanup existing tracepoints/collections 102 gdb_delete_tracepoints 103 gdb_test_no_output "set default-collect" "clear default-collect" 104 105 gdb_test "info tracepoints" "No tracepoints." "delete tracepoints" 106 107 gdb_test "source $save_path" "Tracepoint \[0-9\]+ at .*" \ 108 "read back saved tracepoints" 109} 110 111proc gdb_verify_tracepoints { testname } { 112 global gdb_prompt 113 114 set ws "\[\t \]+" 115 set nl "\[\r\n\]+" 116 set ourstate 1 117 set result "pass" 118 gdb_test_multiple "info tracepoints" "$testname" { 119 -re "\[0-9\]+\[\t \]+tracepoint\[\t \]+keep y\[\t \]+0x\[0-9a-fA-F\]+ in gdb_recursion_test\[^\r\n\]+\r\n\[ \t]+trace only if \[0-9\] - 1 == \[0-9\] / 2" { 120# if { $expect_out(1,string) != $ourstate } { 121# set result "fail" 122# } 123 incr ourstate 124 exp_continue 125 } 126 -re "$gdb_prompt $" { 127 if { $ourstate >= 7 } { 128 set result "pass" 129 } else { 130 set result "fail" 131 } 132 } 133 default { 134 set result "fail" 135 } 136 } 137 $result $testname 138 139 gdb_test "show default-collect" \ 140 "The list of expressions to collect by default is \"gdb_char_test, gdb_long_test - 100\"..*" \ 141 "verify default-collect" 142} 143 144proc do_save_load_test { save_path } { 145 # Save current tracepoint definitions to a file 146 gdb_save_tracepoints $save_path 147 148 # Clear existing tracepoints and reload from file 149 gdb_load_tracepoints $save_path 150 151 # Check if they match the expected tracepoints 152 gdb_verify_tracepoints "verify recovered tracepoints" 153} 154 155gdb_verify_tracepoints "verify trace setup" 156 157with_test_prefix "relative" { 158 set filepath [standard_output_file "savetrace-relative.tr"] 159 160 # This only works because the pwd is a prefix of the standard output 161 # directory. If this assumption becomes false, then this test needs to be 162 # changed (the relative path from [pwd] to the standard output directory 163 # will become a bit more complicated to compute). 164 if {[string first [pwd] $filepath] != 0} { 165 error "[pwd] is not a prefix of $filepath." 166 } 167 168 set filepath [string map "[pwd] ." $filepath] 169 do_save_load_test "$filepath" 170} 171 172with_test_prefix "absolute" { 173 do_save_load_test [standard_output_file "savetrace-absolute.tr"] 174} 175 176# invalid filename 177# [deferred -- not sure what a good invalid filename would be] 178 179# save-trace (file already exists) 180# [expect it to clobber the old one] 181 182# help save tracepoints 183 184gdb_test "help save tracepoints" \ 185 "Save current tracepoint definitions as a script.*" \ 186 "verify help save tracepoints" 187