]>
Commit | Line | Data |
---|---|---|
4a94e368 | 1 | # Copyright (C) 2013-2022 Free Software Foundation, Inc. |
1e611234 PM |
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 is part of the GDB testsuite. It tests Python-based | |
17 | # frame-filters. | |
18 | ||
19 | load_lib gdb-python.exp | |
20 | ||
21 | standard_testfile | |
22 | ||
23 | # We cannot use prepare_for_testing as we have to set the safe-patch | |
24 | # to check objfile and progspace printers. | |
25 | if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { | |
26 | return -1 | |
27 | } | |
28 | ||
29 | # Start with a fresh gdb. | |
30 | gdb_exit | |
31 | gdb_start | |
32 | ||
33 | # Skip all tests if Python scripting is not enabled. | |
34 | if { [skip_python_tests] } { continue } | |
35 | ||
17621150 TT |
36 | gdb_test "info frame-filter" \ |
37 | "No frame filters\\." \ | |
38 | "info frame filter before loading filters" | |
39 | ||
1e611234 PM |
40 | # Make the -gdb.py script available to gdb, it is automagically loaded by gdb. |
41 | # Care is taken to put it in the same directory as the binary so that | |
42 | # gdb will find it. | |
43 | set remote_obj_python_file \ | |
5277208d | 44 | [gdb_remote_download host ${srcdir}/${subdir}/${testfile}-gdb.py \ |
74c2c1f4 | 45 | ${testfile}-gdb.py] |
1e611234 PM |
46 | |
47 | gdb_reinitialize_dir $srcdir/$subdir | |
48 | gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \ | |
49 | "set auto-load safe-path" | |
50 | gdb_load ${binfile} | |
51 | # Verify gdb loaded the script. | |
74c2c1f4 | 52 | gdb_test "info auto-load python-scripts" "Yes.*${testfile}-gdb.py.*" \ |
1e611234 PM |
53 | "Test auto-load had loaded python scripts" |
54 | ||
b0e16ca5 | 55 | if {![runto_main]} { |
1e611234 PM |
56 | return |
57 | } | |
58 | gdb_test_no_output "set python print-stack full" \ | |
cd2ddb6c | 59 | "set python print-stack to full" |
1e611234 | 60 | |
c7e4c0a6 PW |
61 | # Verify that 'bt', 'bt -no-filters' print the same info |
62 | # when there are no filters, no matching filters, or matching filters. | |
63 | # In particular, no address should be printed, as the default for | |
64 | # backtrace -frame-info is 'location', and the breakpoint we just hit | |
65 | # is at the beginning of a line. | |
66 | # Same tests done again after having loaded the filters. | |
67 | gdb_test "bt 1" "#0 main .*" "bt 1, no filter loaded" | |
68 | gdb_test "bt -no-filters 1" "#0 main .*" "bt -no-filters 1, no filter loaded" | |
69 | ||
70 | ||
1e611234 | 71 | # Load global frame-filters |
8448e842 TT |
72 | set remote_python_file [gdb_remote_download host \ |
73 | ${srcdir}/${subdir}/${testfile}.py] | |
72ca0410 | 74 | gdb_test_no_output "source ${remote_python_file}" "load python file" |
1e611234 | 75 | |
c7e4c0a6 PW |
76 | # Re-verify the frame-info printed once filters are loaded. |
77 | # For the first check, the Reverse filter is matching. | |
78 | gdb_test "bt 1" "#0 niam .*" "bt 1, filters loaded" | |
79 | gdb_test "bt -no-filters 1" "#0 main .*" "bt -no-filters 1, filters loaded" | |
80 | ||
1e611234 PM |
81 | gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"] |
82 | gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"] | |
83 | gdb_continue_to_breakpoint "Inner test breakpoint" | |
84 | ||
85 | # Test multiple local blocks. | |
86 | gdb_test "bt full no-filters" \ | |
d1e36019 | 87 | ".*#0.*end_func.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" |
1e611234 PM |
88 | gdb_test "bt full" \ |
89 | ".*#0.*cnuf_dne.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" \ | |
90 | "bt full with filters" | |
91 | ||
63cc30e9 JK |
92 | # Test pagination can be aborted even for frame filters. |
93 | gdb_test_no_output "set height 5" "pagination quit - set height limited" | |
94 | foreach bttype [list "bt" "bt full"] { | |
95 | set test "pagination quit - $bttype" | |
96 | gdb_test_multiple "$bttype" $test { | |
97 | -re "$pagination_prompt$" { | |
98 | pass $test | |
99 | } | |
100 | } | |
101 | gdb_test "q" "^q\r\nQuit" "pagination quit - $bttype - q" | |
102 | } | |
103 | gdb_test_no_output "set height unlimited" "pagination quit - set height unlimited" | |
104 | ||
1e611234 PM |
105 | gdb_continue_to_breakpoint "Backtrace end breakpoint" |
106 | ||
107 | # Test set/show | |
108 | gdb_test "info frame-filter" \ | |
109 | ".*900.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \ | |
110 | "info frame filter before setting priority" | |
111 | gdb_test "show frame-filter priority global Elider" \ | |
112 | "Priority of filter 'Elider' in list 'global' is: 900" \ | |
113 | "show frame-filter priority global Elider before setting" | |
114 | gdb_test_no_output "set frame-filter priority global Elider 1000" \ | |
115 | "set frame-filter priotiy global Elider 1000" | |
116 | gdb_test "show frame-filter priority global Elider" \ | |
117 | "Priority of filter 'Elider' in list 'global' is: 1000" \ | |
118 | "show frame-filter priority global Elider after setting" | |
119 | gdb_test "info frame-filter" \ | |
120 | ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \ | |
121 | "info frame filter after setting priority" | |
803b47e5 TT |
122 | gdb_test "set frame-filter priority global NoSuchFilter 900" \ |
123 | "frame-filter 'NoSuchFilter' not found." \ | |
124 | "set priority of a non-existing filter" | |
1e611234 PM |
125 | |
126 | # Test enable/disable | |
127 | gdb_test "info frame-filter" \ | |
128 | ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \ | |
129 | "info frame filter before disable frame filter" | |
130 | gdb_test_no_output "disable frame-filter global Elider" \ | |
131 | "disable frame-filter global Elider" | |
132 | gdb_test "info frame-filter" \ | |
133 | ".*1000.*No.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \ | |
134 | "info frame filter after disable frame filter" | |
135 | gdb_test_no_output "enable frame-filter global Elider" \ | |
136 | "enable frame-filter global Elider" | |
137 | gdb_test "info frame-filter" \ | |
138 | ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \ | |
139 | "info frame filter after reenabling frame filter" | |
803b47e5 TT |
140 | gdb_test "disable frame-filter global NoSuchFilter" \ |
141 | "frame-filter 'NoSuchFilter' not found." \ | |
142 | "disable a non-existing filter" | |
1e611234 PM |
143 | |
144 | # Test no-filters | |
145 | gdb_test "bt no-filters" \ | |
d1e36019 | 146 | ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" |
1e611234 PM |
147 | |
148 | # Test reverse | |
149 | gdb_test "bt" \ | |
150 | ".*#0.*cnuf_dne.*#22.*in 1cnuf.*#27.*in niam \\(\\).*" \ | |
151 | "bt with frame filters" | |
152 | ||
153 | # Disable Reverse | |
154 | gdb_test_no_output "disable frame-filter global Reverse" \ | |
155 | "disable frame-filter global Reverse" | |
156 | gdb_test "bt" \ | |
157 | ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" \ | |
158 | "bt with frame-filter Reverse disabled" | |
159 | gdb_test "bt -2" \ | |
160 | ".*#26.*func5.*#27.*in main \\(\\).*" \ | |
161 | "bt -2 with frame-filter Reverse disabled" | |
162 | gdb_test "bt 3" \ | |
6893c19a | 163 | ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\)\[^#\]*More stack frames follow.*" \ |
1e611234 PM |
164 | "bt 3 with frame-filter Reverse disabled" |
165 | gdb_test "bt no-filter full" \ | |
166 | ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*" \ | |
167 | "bt no-filters full with Reverse disabled" | |
168 | gdb_test "bt full" \ | |
169 | ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\).*#23.*in func2 \\(f=3\\).*elided = $hex \"Elided frame\".*fb = \{nothing = $hex \"Elided Foo Bar\", f = 84, s = 38\}.*bf = $hex.*" \ | |
170 | "bt full with Reverse disabled" | |
978d6c75 TT |
171 | gdb_test "bt full hide" \ |
172 | ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\)\[^#\]*#24.*in func3 \\(i=3\\).*" \ | |
173 | "bt full hide with Reverse disabled" | |
1e611234 | 174 | |
c7e4c0a6 PW |
175 | # Re-enable Reverse |
176 | gdb_test_no_output "enable frame-filter global Reverse" \ | |
177 | "re-enable frame-filter global Reverse" | |
178 | ||
1e611234 PM |
179 | # Test set print frame-arguments |
180 | # none | |
181 | gdb_test_no_output "set print frame-arguments none" \ | |
182 | "turn off frame arguments" | |
183 | gdb_test "bt no-filter 1" \ | |
184 | "#0.*end_func \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \ | |
185 | "bt no-filter 1 no args" | |
186 | gdb_test "bt 1" \ | |
c7e4c0a6 | 187 | "#0.*cnuf_dneThe End \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \ |
1e611234 PM |
188 | "bt 1 no args" |
189 | ||
190 | # scalars | |
191 | gdb_test_no_output "set print frame-arguments scalars" \ | |
192 | "turn frame arguments to scalars only" | |
193 | gdb_test "bt no-filter 1" \ | |
194 | "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \ | |
195 | "bt no-filter 1 scalars" | |
196 | gdb_test "bt 1" \ | |
c7e4c0a6 | 197 | "#0.*cnuf_dneThe End \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \ |
1e611234 PM |
198 | "bt 1 scalars" |
199 | ||
c7e4c0a6 PW |
200 | # presence |
201 | gdb_test_no_output "set print frame-arguments presence" \ | |
202 | "turn frame arguments to presence only" | |
203 | gdb_test "bt no-filter 1" \ | |
204 | "#0.*end_func \\(\.\.\.\\) at .*py-framefilter.c.*" \ | |
205 | "bt no-filter 1 presence" | |
206 | gdb_test "bt 1" \ | |
207 | "#0.*cnuf_dneThe End \\(\.\.\.\\) at .*py-framefilter.c.*" \ | |
208 | "bt 1 presence" | |
209 | ||
210 | # Test set print frame-info, with only presence for args. | |
211 | # short-location | |
212 | gdb_test_no_output "set print frame-info short-location" \ | |
213 | "frame-info short-location" | |
214 | gdb_test "bt no-filter 1" \ | |
215 | "#0.*end_func \\(\.\.\.\\)\r\n.*" \ | |
216 | "bt no-filter 1 short-location" | |
217 | gdb_test "bt 1" \ | |
218 | "#0.*cnuf_dneThe End \\(\.\.\.\\)\r\n.*" \ | |
219 | "bt 1 short-location" | |
220 | ||
221 | # source-and-location | |
222 | gdb_test_no_output "set print frame-info source-and-location" \ | |
223 | "frame-info source-and-location" | |
224 | gdb_test "bt no-filter 1" \ | |
225 | "#0.*end_func \\(\.\.\.\\) at .*py-framefilter.c.*\r\n.*\[1-9\]\[0-9\]*.*" \ | |
226 | "bt no-filter 1 source-and-location" | |
227 | gdb_test "bt 1" \ | |
228 | "#0.*cnuf_dneThe End \\(\.\.\.\\) at .*py-framefilter.c.*\r\n.*\[1-9\]\[0-9\]*.*" \ | |
229 | "bt 1 source-and-location" | |
230 | ||
231 | # source-line | |
232 | gdb_test_no_output "set print frame-info source-line" \ | |
233 | "frame-info source-line" | |
234 | gdb_test "bt no-filter 1" \ | |
235 | "\[1-9\]\[0-9\]*\[ \t\]*return; /\\* Backtrace end breakpoint \\*/.*" \ | |
236 | "bt no-filter 1 source-line" | |
237 | gdb_test "bt 1" \ | |
238 | "\[1-9\]\[0-9\]*\[ \t\]*return; /\\* Backtrace end breakpoint \\*/.*" \ | |
239 | "bt 1 source-line" | |
240 | ||
241 | # set print frame-info back to auto. | |
242 | gdb_test_no_output "set print frame-info auto" \ | |
243 | "frame-info auto" | |
244 | ||
1e611234 PM |
245 | # all |
246 | gdb_test_no_output "set print frame-arguments all" \ | |
247 | "turn on frame arguments" | |
248 | gdb_test "bt no-filter 1" \ | |
249 | "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \ | |
250 | "bt no-filter 1 all args" | |
251 | gdb_test "bt 1" \ | |
c7e4c0a6 | 252 | "#0.*cnuf_dneThe End \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \ |
1e611234 PM |
253 | "bt 1 all args" |
254 | ||
255 | # set print address off | |
256 | gdb_test_no_output "set print address off" \ | |
257 | "Turn off address printing" | |
258 | gdb_test "bt no-filter 1" \ | |
259 | "#0 end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \ | |
260 | "bt no-filter 1 no address" | |
261 | gdb_test "bt 1" \ | |
c7e4c0a6 | 262 | "#0 cnuf_dneThe End \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \ |
1e611234 PM |
263 | "bt 1 no addresss" |
264 | ||
0740f8d8 TT |
265 | gdb_test_no_output "set python print-stack message" \ |
266 | "Set python print-stack to message for Error filter" | |
267 | gdb_test_no_output "enable frame-filter global Error" \ | |
268 | "enable frame-filter global Error" | |
269 | set test "bt 1 with Error filter" | |
270 | gdb_test_multiple "bt 1" $test { | |
2708dbbd | 271 | -re "Python Exception .*: whoops\r\n.*$gdb_prompt $" { |
0740f8d8 TT |
272 | pass $test |
273 | } | |
274 | } | |
275 | ||
4ca59a9f TT |
276 | # Now verify that we can see a quit. |
277 | gdb_test_no_output "python name_error = KeyboardInterrupt" \ | |
278 | "Change ErrorFilter to throw KeyboardInterrupt" | |
279 | gdb_test "bt 1" "Quit" "bt 1 with KeyboardInterrupt" | |
280 | ||
281 | ||
1e611234 PM |
282 | # Test with no debuginfo |
283 | ||
284 | # We cannot use prepare_for_testing as we have to set the safe-patch | |
285 | # to check objfile and progspace printers. | |
286 | if {[build_executable $testfile.exp $testfile $srcfile {nodebug}] == -1} { | |
287 | return -1 | |
288 | } | |
289 | ||
290 | # Start with a fresh gdb. | |
291 | gdb_exit | |
292 | gdb_start | |
293 | ||
294 | # Skip all tests if Python scripting is not enabled. | |
295 | if { [skip_python_tests] } { continue } | |
296 | ||
297 | # Make the -gdb.py script available to gdb, it is automagically loaded by gdb. | |
298 | # Care is taken to put it in the same directory as the binary so that | |
299 | # gdb will find it. | |
300 | set remote_obj_python_file \ | |
5277208d | 301 | [gdb_remote_download host ${srcdir}/${subdir}/${testfile}-gdb.py \ |
74c2c1f4 | 302 | ${testfile}-gdb.py] |
1e611234 PM |
303 | |
304 | gdb_reinitialize_dir $srcdir/$subdir | |
305 | gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \ | |
306 | "set auto-load safe-path for no debug info" | |
307 | gdb_load ${binfile} | |
308 | ||
309 | # Verify gdb loaded the script. | |
74c2c1f4 | 310 | gdb_test "info auto-load python-scripts" "Yes.*${testfile}-gdb.py.*" \ |
1e611234 | 311 | "Set autoload path for no debug info tests" |
b0e16ca5 | 312 | if {![runto_main]} { |
1e611234 PM |
313 | return |
314 | } | |
315 | ||
316 | gdb_test_no_output "set python print-stack full" \ | |
317 | "set python print-stack full for no debuginfo tests" | |
318 | ||
319 | # Load global frame-filters | |
8448e842 TT |
320 | set remote_python_file [gdb_remote_download host \ |
321 | ${srcdir}/${subdir}/${testfile}.py] | |
72ca0410 | 322 | gdb_test_no_output "source ${remote_python_file}" \ |
cd2ddb6c | 323 | "load python file for no debuginfo tests" |
1e611234 PM |
324 | |
325 | # Disable Reverse | |
326 | gdb_test_no_output "disable frame-filter global Reverse" \ | |
6c466447 | 327 | "disable frame-filter global Reverse for no debuginfo" |
1e611234 PM |
328 | gdb_test "bt" \ |
329 | ".*#0..*in main \\(\\).*" \ | |
330 | "bt for no debuginfo" | |
331 | gdb_test "bt full" \ | |
332 | ".*#0..*in main \\(\\).*" \ | |
333 | "bt full for no debuginfo" | |
334 | gdb_test "bt no-filters" \ | |
335 | ".*#0..*in main \\(\\).*" \ | |
336 | "bt no filters for no debuginfo" | |
337 | gdb_test "bt no-filters full" \ | |
338 | ".*#0..*in main \\(\\).*" \ | |
339 | "bt no-filters full no debuginfo" |