Remove duplicate skip_python_tests invocation
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-finish-breakpoint.exp
1 # Copyright (C) 2011-2019 Free Software Foundation, Inc.
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 the mechanism
17 # exposing values to Python.
18
19 if {[skip_shlib_tests]} {
20 untested "skipping shared library tests"
21 return 0
22 }
23
24 load_lib gdb-python.exp
25
26 set libfile "py-events-shlib"
27 set libsrc $srcdir/$subdir/$libfile.c
28 set lib_sl [standard_output_file $libfile-nodebug.so]
29 set lib_opts ""
30
31 standard_testfile
32 set exec_opts [list debug shlib=$lib_sl]
33
34 if [get_compiler_info] {
35 return -1
36 }
37
38 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
39 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
40 untested "failed to compile"
41 return -1
42 }
43
44 # Start with a fresh gdb.
45 clean_restart ${testfile}
46
47 if { [skip_python_tests] } { continue }
48
49 if { $gdb_py_is_py24 == 1 } {
50 # Python 2.4, 2.5 do not support the "ValueError as e" syntax used in
51 # the py-finish-breakpoint.py script.
52 untested "missing support on Python 2.4 and 2.5"
53 return 0
54 }
55
56 #
57 # Test FinishBreakpoint in normal conditions
58 #
59
60 clean_restart ${testfile}
61 gdb_load_shlib ${lib_sl}
62
63 if ![runto_main] then {
64 fail "cannot run to main."
65 return 0
66 }
67
68 set python_file [gdb_remote_download host \
69 ${srcdir}/${subdir}/${testfile}.py]
70
71 gdb_test_no_output "set confirm off" "disable confirmation"
72 gdb_test "source $python_file" "Python script imported.*" \
73 "import python scripts"
74 gdb_breakpoint "increase_1"
75 gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish"
76
77 # set FinishBreakpoint
78
79 gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \
80 "Temporary breakpoint.*" "set FinishBreakpoint with default frame value"
81 gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \
82 "Temporary breakpoint.*" "set FinishBreakpoint"
83 gdb_test "python print (finishbp.return_value)" "None.*" \
84 "check return_value at init"
85
86 # check normal bp hit
87
88 gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \
89 "check MyFinishBreakpoint hit"
90 gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value"
91
92 gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit"
93 gdb_test "python print (finishbp.is_valid())" "False.*"\
94 "ensure that finish bp is invalid afer normal hit"
95
96 # check FinishBreakpoint in main no allowed
97
98 gdb_test "finish" "main.*" "return to main()"
99 gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \
100 "ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \
101 "check FinishBP not allowed in main"
102
103 #
104 # Test FinishBreakpoint with no debug symbol
105 #
106
107 clean_restart ${testfile}
108 gdb_load_shlib ${lib_sl}
109
110 gdb_test "source $python_file" "Python script imported.*" \
111 "import python scripts"
112 set cond_line [gdb_get_line_number "Condition Break."]
113
114 if ![runto_main] then {
115 fail "cannot run to main."
116 return 0
117 }
118
119 gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info"
120 gdb_breakpoint "do_nothing" {temporary}
121 gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \
122 "continue to do_nothing"
123
124 gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
125 "SimpleFinishBreakpoint init" \
126 "set finish breakpoint"
127 gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
128 gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol"
129
130 #
131 # Test FinishBreakpoint in function returned by longjmp
132 #
133
134 clean_restart ${testfile}
135 gdb_load_shlib ${lib_sl}
136
137 gdb_test "source $python_file" "Python script imported.*" \
138 "import python scripts"
139
140 if ![runto call_longjmp_1] then {
141 perror "couldn't run to breakpoint call_longjmp"
142 continue
143 }
144
145 gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
146 "SimpleFinishBreakpoint init" \
147 "set finish breakpoint"
148 gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
149 "set BP after the jump"
150 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
151 "check FinishBP out of scope notification"
152 gdb_test "python print (finishbp.is_valid())" "False.*"\
153 "ensure that finish bp is invalid afer out of scope notification"
154
155 #
156 # Test FinishBreakpoint in BP condition evaluation
157 # (finish in dummy frame)
158 #
159
160 clean_restart ${testfile}
161 gdb_load_shlib ${lib_sl}
162
163 gdb_test "source $python_file" "Python script imported.*" \
164 "import python scripts"
165
166
167 if ![runto_main] then {
168 fail "cannot run to main."
169 return 0
170 }
171
172 gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
173 "set a conditional BP"
174 gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
175 "set FinishBP in a breakpoint condition"
176 gdb_test "continue" \
177 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
178 "don't allow FinishBreakpoint on dummy frames"
179 gdb_test "print i" "8" "check stopped location"
180
181 #
182 # Test FinishBreakpoint in BP condition evaluation
183 # (finish in normal frame)
184 #
185
186 clean_restart ${testfile}
187 gdb_load_shlib ${lib_sl}
188
189 gdb_test "source $python_file" "Python script imported.*" \
190 "import python scripts"
191
192 if ![runto_main] then {
193 fail "cannot run to main."
194 return 0
195 }
196
197 gdb_test "break ${cond_line} if test(i,8)" \
198 "Breakpoint .* at .*" "set conditional BP"
199 gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
200
201 gdb_test "continue" \
202 "test don't stop: 1.*test don't stop: 2.*test stop.*Error in testing breakpoint condition.*The program being debugged stopped while in a function called from GDB.*" \
203 "stop in condition function"
204
205 gdb_test "continue" "Continuing.*" "finish condition evaluation"
206 gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
207 gdb_test "print i" "8" "check stopped location"
208
209 #
210 # Test FinishBreakpoint in explicit inferior function call
211 #
212
213 clean_restart ${testfile}
214 gdb_load_shlib ${lib_sl}
215
216 gdb_test "source $python_file" "Python script imported.*" \
217 "import python scripts"
218
219 if ![runto_main] then {
220 fail "cannot run to main."
221 return 0
222 }
223
224 # return address in dummy frame
225
226 gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
227 "prepare TestExplicitBreakpoint"
228 gdb_test "print increase_1(&i)" \
229 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
230 "don't allow FinishBreakpoint on dummy frames"
231
232 # return address in normal frame
233
234 delete_breakpoints
235 gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
236 "prepare TestExplicitBreakpoint"
237 gdb_test "print increase(&i)" \
238 "SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
239 "FinishBP stop at during explicit function call"
240
241
242 #
243 # Test FinishBreakpoint when inferior exits
244 #
245
246 if ![runto "test_exec_exit"] then {
247 fail "cannot run to test_exec_exit."
248 return 0
249 }
250
251 gdb_test_no_output "set var self_exec = 0" "switch to exit() test"
252 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
253 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
254
255 #
256 # Test FinishBreakpoint when inferior execs
257 #
258
259 if ![runto "test_exec_exit"] then {
260 fail "cannot run to test_exec_exit."
261 return 0
262 }
263
264 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
265 gdb_test "catch exec" "Catchpoint.*\(exec\).*" "catch exec"
266 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"