1 # This testcase is part of GDB, the GNU debugger. 2 3 # Copyright 2018-2024 Free Software Foundation, Inc. 4 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 19 # Test 'frame apply [all | COUNT | -COUNT | level LEVEL...] [FLAG]... COMMAND'. 20 21 standard_testfile 22 23 if { [prepare_for_testing "failed to prepare" ${testfile}] } { 24 return -1 25 } 26 27 if {![runto setup_done]} { 28 return 0 29 } 30 31 set any "\[^\r\n\]*" 32 set ws "\[ \t\]\+" 33 set number "\[0-9]\+" 34 35 36 # Check all | COUNT | -COUNT | level LEVEL... with a simple command. 37 with_test_prefix "simple command" { 38 foreach_with_prefix frame_apply_args { 39 "all" 40 "6" 41 "-6" 42 "level 0-5" 43 "level 0-3 4-5" 44 "level 0 1-2 3-5" 45 "level 0 1 2 3 4 5" 46 "level 0-0 1-1 2-2 3-3 4-4 5-5" } { 47 set cmd "frame apply $frame_apply_args p /x 20" 48 gdb_test $cmd \ 49 [multi_line \ 50 "#0${ws}setup_done ${any}" \ 51 "\\\$\[0-9]+ = 0x14${any}" \ 52 "#1${ws}${any} f1 ${any}" \ 53 "\\\$\[0-9]+ = 0x14${any}" \ 54 "#2${ws}${any} f2 ${any}" \ 55 "\\\$\[0-9]+ = 0x14${any}" \ 56 "#3${ws}${any} f3 ${any}" \ 57 "\\\$\[0-9]+ = 0x14${any}" \ 58 "#4${ws}${any} f4 ${any}" \ 59 "\\\$\[0-9]+ = 0x14${any}" \ 60 "#5${ws}${any} main ${any}" \ 61 "\\\$\[0-9]+ = 0x14${any}" \ 62 ] \ 63 "run a simple command on all frames" 64 } 65 } 66 67 # Check frame apply on 3 innermost frames. 68 with_test_prefix "innermost 3" { 69 foreach_with_prefix frame_apply_args { 70 "3" 71 "level 0-2" } { 72 set cmd "frame apply $frame_apply_args p /x 20" 73 gdb_test $cmd \ 74 [multi_line \ 75 "#0${ws}setup_done ${any}" \ 76 "\\\$\[0-9]+ = 0x14${any}" \ 77 "#1${ws}${any} f1 ${any}" \ 78 "\\\$\[0-9]+ = 0x14${any}" \ 79 "#2${ws}${any} f2 ${any}" \ 80 "\\\$\[0-9]+ = 0x14${any}" \ 81 ] \ 82 "run a simple command on the 3 innermost frames" 83 } 84 } 85 86 # Check frame apply on 3 outermost frames. 87 with_test_prefix "outermost 3" { 88 foreach_with_prefix frame_apply_args { 89 "-3" } { 90 set cmd "frame apply $frame_apply_args p /x 20" 91 gdb_test $cmd \ 92 [multi_line \ 93 "#3${ws}${any} f3 ${any}" \ 94 "\\\$\[0-9]+ = 0x14${any}" \ 95 "#4${ws}${any} f4 ${any}" \ 96 "\\\$\[0-9]+ = 0x14${any}" \ 97 "#5${ws}${any} main ${any}" \ 98 "\\\$\[0-9]+ = 0x14${any}" \ 99 ] \ 100 "run a simple command on the 3 outermost frames" 101 } 102 } 103 104 # Check -c (continue) and -s (silently continue) flags. 105 with_test_prefix "!cont !silent flags" { 106 foreach_with_prefix frame_apply_args { 107 "all" 108 "level 0-5" 109 } { 110 set cmd "frame apply $frame_apply_args p f3arg" 111 gdb_test $cmd \ 112 [multi_line \ 113 "#0${ws}setup_done ${any}" \ 114 "No symbol \\\"f3arg\\\" in current context." \ 115 ] \ 116 "run a failing command that aborts frame apply" 117 } 118 } 119 120 with_test_prefix "cont !silent flags" { 121 foreach_with_prefix frame_apply_args { 122 "all -c" 123 "level 0-5 -c"} { 124 set cmd "frame apply $frame_apply_args p f3arg" 125 gdb_test $cmd \ 126 [multi_line \ 127 "#0${ws}setup_done ${any}" \ 128 "No symbol \\\"f3arg\\\" in current context." \ 129 "#1${ws}${any} f1 ${any}" \ 130 "No symbol \\\"f3arg\\\" in current context." \ 131 "#2${ws}${any} f2 ${any}" \ 132 "No symbol \\\"f3arg\\\" in current context." \ 133 "#3${ws}${any} f3 ${any}" \ 134 "\\\$\[0-9]+ = 3${any}" \ 135 "#4${ws}${any} f4 ${any}" \ 136 "No symbol \\\"f3arg\\\" in current context." \ 137 "#5${ws}${any} main ${any}" \ 138 "No symbol \\\"f3arg\\\" in current context." \ 139 ] \ 140 "run a command failing in all frames except #3, -c to continue" 141 } 142 } 143 144 with_test_prefix "!cont silent flags" { 145 foreach_with_prefix cmd_and_args { 146 "frame apply all -s" 147 "faas" 148 "frame apply level 0-5 -s"} { 149 set cmd "$cmd_and_args p f3arg" 150 gdb_test $cmd \ 151 [multi_line \ 152 "#3${ws}${any} f3 ${any}" \ 153 "\\\$\[0-9]+ = 3${any}" \ 154 ] \ 155 "run a command failing in all frames except #3, -s to silently continue" 156 } 157 } 158 159 # Check quietness. 160 with_test_prefix "!quiet flag" { 161 foreach_with_prefix frame_apply_args { 162 "2" 163 "level 0-1"} { 164 set cmd "frame apply $frame_apply_args p /x 20" 165 gdb_test $cmd \ 166 [multi_line \ 167 "#0${ws}setup_done ${any}" \ 168 "\\\$\[0-9]+ = 0x14${any}" \ 169 "#1${ws}${any} f1 ${any}" \ 170 "\\\$\[0-9]+ = 0x14${any}" \ 171 ] \ 172 "run a command, printing location" 173 } 174 } 175 176 with_test_prefix "quiet flag" { 177 foreach_with_prefix frame_apply_args { 178 "2 -q" 179 "level 0-1 -q"} { 180 set cmd "frame apply $frame_apply_args p /x 20" 181 gdb_test $cmd \ 182 [multi_line \ 183 "\\\$\[0-9]+ = 0x14${any}" \ 184 "\\\$\[0-9]+ = 0x14${any}" \ 185 ] \ 186 "run a command with -q quiet flag, printing only command results" 187 } 188 } 189 190 # Check multiple flags together. 191 with_test_prefix "quiet silent flags" { 192 foreach_with_prefix frame_apply_args { 193 "all -q -s -q" 194 "level 0-5 -q -s -q"} { 195 set cmd "frame apply $frame_apply_args p f3arg" 196 gdb_test $cmd \ 197 "\\\$\[0-9]+ = 3${any}" \ 198 "run a command failing in all frames except #3, -s to silently continue, quiet" 199 } 200 } 201 202 # Check invalid flag combinations. 203 gdb_test "frame apply all -c -s p f3arg" \ 204 "frame apply all: -c and -s are mutually exclusive" \ 205 "check -c and -s cannot be used simultaneously" 206 207 # Check some cases of missing or wrong args. 208 gdb_test "frame apply" "Missing COUNT argument." "missing COUNT" 209 gdb_test "frame apply -c" "Invalid COUNT argument." "invalid COUNT arg" 210 gdb_test "frame apply level 4-2 p 1" "inverted range" "inverted range" 211 gdb_test "frame apply level 0-3" \ 212 "Please specify a command to apply on the selected frames" \ 213 "missing command" 214 gdb_test "faas" "Please specify a command to apply on all frames" \ 215 "missing command for faas" 216