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