1 # Copyright (C) 2013-2016 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests Python-based
19 load_lib gdb-python.exp
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} {
29 # Start with a fresh gdb.
33 # Skip all tests if Python scripting is not enabled.
34 if { [skip_python_tests] } { continue }
36 gdb_test "info frame-filter" \
37 "No frame filters\\." \
38 "info frame filter before loading filters"
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
43 set remote_obj_python_file \
45 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
46 [standard_output_file ${testfile}-gdb.py]]
48 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
50 "set auto-load safe-path"
52 # Verify gdb loaded the script.
53 gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
54 "Test auto-load had loaded python scripts"
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
60 gdb_test_no_output "set python print-stack full" \
61 "Set python print-stack to full"
63 # Load global frame-filters
64 set remote_python_file [gdb_remote_download host \
65 ${srcdir}/${subdir}/${testfile}.py]
66 gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
69 gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
70 gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"]
71 gdb_continue_to_breakpoint "Inner test breakpoint"
73 # Test multiple local blocks.
74 gdb_test "bt full no-filters" \
75 ".*#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.*" \
78 ".*#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.*" \
79 "bt full with filters"
81 # Test pagination can be aborted even for frame filters.
82 gdb_test_no_output "set height 5" "pagination quit - set height limited"
83 foreach bttype [list "bt" "bt full"] {
84 set test "pagination quit - $bttype"
85 gdb_test_multiple "$bttype" $test {
86 -re "$pagination_prompt$" {
90 gdb_test "q" "^q\r\nQuit" "pagination quit - $bttype - q"
92 gdb_test_no_output "set height unlimited" "pagination quit - set height unlimited"
94 gdb_continue_to_breakpoint "Backtrace end breakpoint"
97 gdb_test "info frame-filter" \
98 ".*900.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
99 "info frame filter before setting priority"
100 gdb_test "show frame-filter priority global Elider" \
101 "Priority of filter 'Elider' in list 'global' is: 900" \
102 "show frame-filter priority global Elider before setting"
103 gdb_test_no_output "set frame-filter priority global Elider 1000" \
104 "set frame-filter priotiy global Elider 1000"
105 gdb_test "show frame-filter priority global Elider" \
106 "Priority of filter 'Elider' in list 'global' is: 1000" \
107 "show frame-filter priority global Elider after setting"
108 gdb_test "info frame-filter" \
109 ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
110 "info frame filter after setting priority"
112 # Test enable/disable
113 gdb_test "info frame-filter" \
114 ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
115 "info frame filter before disable frame filter"
116 gdb_test_no_output "disable frame-filter global Elider" \
117 "disable frame-filter global Elider"
118 gdb_test "info frame-filter" \
119 ".*1000.*No.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
120 "info frame filter after disable frame filter"
121 gdb_test_no_output "enable frame-filter global Elider" \
122 "enable frame-filter global Elider"
123 gdb_test "info frame-filter" \
124 ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
125 "info frame filter after reenabling frame filter"
128 gdb_test "bt no-filters" \
129 ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" \
134 ".*#0.*cnuf_dne.*#22.*in 1cnuf.*#27.*in niam \\(\\).*" \
135 "bt with frame filters"
138 gdb_test_no_output "disable frame-filter global Reverse" \
139 "disable frame-filter global Reverse"
141 ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" \
142 "bt with frame-filter Reverse disabled"
144 ".*#26.*func5.*#27.*in main \\(\\).*" \
145 "bt -2 with frame-filter Reverse disabled"
147 ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*" \
148 "bt 3 with frame-filter Reverse disabled"
149 gdb_test "bt no-filter full" \
150 ".*#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\}.*" \
151 "bt no-filters full with Reverse disabled"
153 ".*#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.*" \
154 "bt full with Reverse disabled"
156 # Test set print frame-arguments
158 gdb_test_no_output "set print frame-arguments none" \
159 "turn off frame arguments"
160 gdb_test "bt no-filter 1" \
161 "#0.*end_func \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \
162 "bt no-filter 1 no args"
164 "#0.*end_func \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \
168 gdb_test_no_output "set print frame-arguments scalars" \
169 "turn frame arguments to scalars only"
170 gdb_test "bt no-filter 1" \
171 "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \
172 "bt no-filter 1 scalars"
174 "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \
178 gdb_test_no_output "set print frame-arguments all" \
179 "turn on frame arguments"
180 gdb_test "bt no-filter 1" \
181 "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
182 "bt no-filter 1 all args"
184 "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
187 # set print address off
188 gdb_test_no_output "set print address off" \
189 "Turn off address printing"
190 gdb_test "bt no-filter 1" \
191 "#0 end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
192 "bt no-filter 1 no address"
194 "#0 end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
197 gdb_test_no_output "set python print-stack message" \
198 "Set python print-stack to message for Error filter"
199 gdb_test_no_output "enable frame-filter global Error" \
200 "enable frame-filter global Error"
201 set test "bt 1 with Error filter"
202 gdb_test_multiple "bt 1" $test {
203 -re "Python Exception .*whoops:.*$gdb_prompt $" {
208 # Test with no debuginfo
210 # We cannot use prepare_for_testing as we have to set the safe-patch
211 # to check objfile and progspace printers.
212 if {[build_executable $testfile.exp $testfile $srcfile {nodebug}] == -1} {
216 # Start with a fresh gdb.
220 # Skip all tests if Python scripting is not enabled.
221 if { [skip_python_tests] } { continue }
223 # Make the -gdb.py script available to gdb, it is automagically loaded by gdb.
224 # Care is taken to put it in the same directory as the binary so that
226 set remote_obj_python_file \
228 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
229 [standard_output_file ${testfile}-gdb.py]]
231 gdb_reinitialize_dir $srcdir/$subdir
232 gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
233 "set auto-load safe-path for no debug info"
236 # Verify gdb loaded the script.
237 gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
238 "Set autoload path for no debug info tests"
239 if ![runto_main] then {
240 perror "couldn't run to breakpoint"
244 gdb_test_no_output "set python print-stack full" \
245 "set python print-stack full for no debuginfo tests"
247 # Load global frame-filters
248 set remote_python_file [gdb_remote_download host \
249 ${srcdir}/${subdir}/${testfile}.py]
250 gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
251 "Load python file for no debuginfo tests"
254 gdb_test_no_output "disable frame-filter global Reverse" \
255 "disable frame-filter global Reverse for no debuginfo"
257 ".*#0..*in main \\(\\).*" \
258 "bt for no debuginfo"
260 ".*#0..*in main \\(\\).*" \
261 "bt full for no debuginfo"
262 gdb_test "bt no-filters" \
263 ".*#0..*in main \\(\\).*" \
264 "bt no filters for no debuginfo"
265 gdb_test "bt no-filters full" \
266 ".*#0..*in main \\(\\).*" \
267 "bt no-filters full no debuginfo"