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