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