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