summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-framefilter.exp
blob: 2f81abed403d9d18440cbf73316312823c60a014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Copyright (C) 2013-2015 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file is part of the GDB testsuite.  It tests Python-based
# frame-filters.

load_lib gdb-python.exp

standard_testfile

# We cannot use prepare_for_testing as we have to set the safe-patch
# to check objfile and progspace printers.
if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
    return -1
}

# Start with a fresh gdb.
gdb_exit
gdb_start

# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }

# Make the -gdb.py script available to gdb, it is automagically loaded by gdb.
# Care is taken to put it in the same directory as the binary so that
# gdb will find it.
set remote_obj_python_file \
    [remote_download \
	 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
	 [standard_output_file ${testfile}-gdb.py]]

gdb_reinitialize_dir $srcdir/$subdir
gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
    "set auto-load safe-path"
gdb_load ${binfile}
# Verify gdb loaded the script.
gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
    "Test auto-load had loaded python scripts"

if ![runto_main] then {
    perror "couldn't run to breakpoint"
    return
}
gdb_test_no_output "set python print-stack full" \
    "Set python print-stack to full"

# Load global frame-filters
set remote_python_file [gdb_remote_download host \
			    ${srcdir}/${subdir}/${testfile}.py]
gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
    "Load python file"

gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"]
gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"]
gdb_continue_to_breakpoint "Inner test breakpoint"

# Test multiple local blocks.
gdb_test "bt full no-filters" \
    ".*#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.*" \
    "bt full no-filters"
gdb_test "bt full" \
    ".*#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.*" \
    "bt full with filters"

# Test pagination can be aborted even for frame filters.
gdb_test_no_output "set height 5" "pagination quit - set height limited"
foreach bttype [list "bt" "bt full"] {
    set test "pagination quit - $bttype"
    gdb_test_multiple "$bttype" $test {
	-re "$pagination_prompt$" {
	    pass $test
	}
    }
    gdb_test "q" "^q\r\nQuit" "pagination quit - $bttype - q"
}
gdb_test_no_output "set height unlimited" "pagination quit - set height unlimited"

gdb_continue_to_breakpoint "Backtrace end breakpoint"

# Test set/show
gdb_test "info frame-filter" \
    ".*900.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
    "info frame filter before setting priority"
gdb_test "show frame-filter priority global Elider" \
    "Priority of filter 'Elider' in list 'global' is: 900" \
    "show frame-filter priority global Elider before setting"
gdb_test_no_output  "set frame-filter priority global Elider 1000" \
    "set frame-filter priotiy global Elider 1000"
gdb_test "show frame-filter priority global Elider" \
        "Priority of filter 'Elider' in list 'global' is: 1000" \
        "show frame-filter priority global Elider after setting"
gdb_test "info frame-filter" \
    ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
    "info frame filter after setting priority"

# Test enable/disable
gdb_test "info frame-filter" \
    ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
    "info frame filter before disable frame filter"
gdb_test_no_output  "disable frame-filter global Elider" \
    "disable frame-filter global Elider"
gdb_test "info frame-filter" \
    ".*1000.*No.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
    "info frame filter after disable frame filter"
gdb_test_no_output  "enable frame-filter global Elider" \
    "enable frame-filter global Elider"
gdb_test "info frame-filter" \
    ".*1000.*Yes.*Elider.*100.*Yes.*Reverse.*10.*.*No.*Object.*1.*" \
    "info frame filter after reenabling frame filter"

# Test no-filters
gdb_test "bt no-filters" \
    ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" \
    "bt no-filters"

# Test reverse
gdb_test "bt" \
    ".*#0.*cnuf_dne.*#22.*in 1cnuf.*#27.*in niam \\(\\).*" \
    "bt with frame filters"

# Disable Reverse
gdb_test_no_output "disable frame-filter global Reverse" \
    "disable frame-filter global Reverse"
gdb_test "bt" \
    ".*#0.*end_func.*#22.*in func1.*#27.*in main \\(\\).*" \
    "bt with frame-filter Reverse disabled"
gdb_test "bt -2" \
    ".*#26.*func5.*#27.*in main \\(\\).*" \
    "bt -2 with frame-filter Reverse disabled"
gdb_test "bt 3" \
    ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*" \
    "bt 3 with frame-filter Reverse disabled"
gdb_test "bt no-filter full" \
    ".*#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\}.*" \
    "bt no-filters full with Reverse disabled"
gdb_test "bt full" \
    ".*#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.*" \
    "bt full with Reverse disabled"

# Test set print frame-arguments
# none
gdb_test_no_output "set print frame-arguments none" \
    "turn off frame arguments"
gdb_test "bt no-filter 1" \
    "#0.*end_func \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \
    "bt no-filter 1 no args"
gdb_test "bt 1" \
    "#0.*end_func \\(foo=\.\.\., bar=\.\.\., fb=\.\.\., bf=\.\.\.\\) at .*py-framefilter.c.*" \
    "bt 1 no args"

# scalars
gdb_test_no_output "set print frame-arguments scalars" \
    "turn frame arguments to scalars only"
gdb_test "bt no-filter 1" \
    "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \
    "bt no-filter 1 scalars"
gdb_test "bt 1" \
    "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\.\.\.\\) at .*py-framefilter.c.*" \
    "bt 1 scalars"

# all
gdb_test_no_output "set print frame-arguments all" \
    "turn on frame arguments"
gdb_test "bt no-filter 1" \
    "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
    "bt no-filter 1 all args"
gdb_test "bt 1" \
    "#0.*end_func \\(foo=21, bar=$hex \"Param\", fb=$hex, bf=\{nothing = $hex \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
    "bt 1 all args"

# set print address off
gdb_test_no_output "set print address off" \
    "Turn off address printing"
gdb_test "bt no-filter 1" \
    "#0  end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
    "bt no-filter 1 no address"
gdb_test "bt 1" \
    "#0  end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
    "bt 1 no addresss"

gdb_test_no_output "set python print-stack message" \
    "Set python print-stack to message for Error filter"
gdb_test_no_output  "enable frame-filter global Error" \
    "enable frame-filter global Error"
set test "bt 1 with Error filter"
gdb_test_multiple "bt 1" $test {
    -re "Python Exception .*whoops:.*$gdb_prompt $" {
	pass $test
    }
}

# Test with no debuginfo

# We cannot use prepare_for_testing as we have to set the safe-patch
# to check objfile and progspace printers.
if {[build_executable $testfile.exp $testfile $srcfile {nodebug}] == -1} {
    return -1
}

# Start with a fresh gdb.
gdb_exit
gdb_start

# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }

# Make the -gdb.py script available to gdb, it is automagically loaded by gdb.
# Care is taken to put it in the same directory as the binary so that
# gdb will find it.
set remote_obj_python_file \
    [remote_download \
	 host ${srcdir}/${subdir}/${testfile}-gdb.py.in \
	 [standard_output_file ${testfile}-gdb.py]]

gdb_reinitialize_dir $srcdir/$subdir
gdb_test_no_output "set auto-load safe-path ${remote_obj_python_file}" \
    "set auto-load safe-path for no debug info"
gdb_load ${binfile}

# Verify gdb loaded the script.
gdb_test "info auto-load python-scripts" "Yes.*/${testfile}-gdb.py.*" \
    "Set autoload path for no debug info tests"
if ![runto_main] then {
    perror "couldn't run to breakpoint"
    return
}

gdb_test_no_output "set python print-stack full" \
    "set python print-stack full for no debuginfo tests"

# Load global frame-filters
set remote_python_file [gdb_remote_download host \
			    ${srcdir}/${subdir}/${testfile}.py]
gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
    "Load python file for no debuginfo tests"

# Disable Reverse
gdb_test_no_output "disable frame-filter global Reverse" \
    "disable frame-filter global Reverse for no debuginfo"
gdb_test "bt" \
    ".*#0..*in main \\(\\).*" \
    "bt for no debuginfo"
gdb_test "bt full" \
    ".*#0..*in main \\(\\).*" \
    "bt full for no debuginfo"
gdb_test "bt no-filters" \
    ".*#0..*in main \\(\\).*" \
    "bt no filters for no debuginfo"
gdb_test "bt no-filters full" \
    ".*#0..*in main \\(\\).*" \
    "bt no-filters full no debuginfo"