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