Introduce gdb.FinishBreakpoint in Python
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-finish-breakpoint.exp
1 # Copyright (C) 2011 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 $tracelevel then {
20 strace $tracelevel
21 }
22
23 if {[skip_shlib_tests]} {
24 untested py-finish-breakpoint.exp
25 return 0
26 }
27
28 load_lib gdb-python.exp
29
30 set libfile "py-events-shlib"
31 set libsrc $srcdir/$subdir/$libfile.c
32 set lib_sl $objdir/$subdir/$libfile-nodebug.so
33 set lib_opts ""
34
35 set testfile "py-finish-breakpoint"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38 set exec_opts [list debug shlib=$lib_sl]
39
40 if [get_compiler_info ${binfile}] {
41 return -1
42 }
43
44 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
45 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
46 untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
47 return -1
48 }
49
50 # Start with a fresh gdb.
51 clean_restart ${testfile}
52
53 set python_file ${srcdir}/${subdir}/${testfile}.py
54
55
56 # Skip all tests if Python scripting is not enabled.
57 if { [skip_python_tests] } { continue }
58
59 #
60 # Test FinishBreakpoint in normal conditions
61 #
62
63 clean_restart ${testfile}
64 gdb_load_shlibs ${lib_sl}
65
66 if ![runto_main] then {
67 fail "Cannot run to main."
68 return 0
69 }
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_shlibs ${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.*" "continue to do_nothing"
122
123 gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
124 "SimpleFinishBreakpoint init" \
125 "set finish breakpoint"
126 gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
127 gdb_test "python print finishBP.return_value" "None" "check return value without debug symbol"
128
129 #
130 # Test FinishBreakpoint in function returned by longjmp
131 #
132
133 clean_restart ${testfile}
134 gdb_load_shlibs ${lib_sl}
135
136 gdb_test "source $python_file" "Python script imported.*" \
137 "import python scripts"
138
139 if ![runto call_longjmp_1] then {
140 perror "couldn't run to breakpoint call_longjmp"
141 continue
142 }
143
144 gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
145 "SimpleFinishBreakpoint init" \
146 "set finish breakpoint"
147 gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
148 "set BP after the jump"
149 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
150 "check FinishBP out of scope notification"
151 gdb_test "python print finishbp.is_valid()" "False.*"\
152 "ensure that finish bp is invalid afer out of scope notification"
153
154 #
155 # Test FinishBreakpoint in BP condition evaluation
156 # (finish in dummy frame)
157 #
158
159 clean_restart ${testfile}
160 gdb_load_shlibs ${lib_sl}
161
162 gdb_test "source $python_file" "Python script imported.*" \
163 "import python scripts"
164
165
166 if ![runto_main] then {
167 fail "Cannot run to main."
168 return 0
169 }
170
171 gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
172 "set a conditional BP"
173 gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
174 "set FinishBP in a breakpoint condition"
175 gdb_test "continue" \
176 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
177 "don't allow FinishBreakpoint on dummy frames"
178 gdb_test "print i" "8" "check stopped location"
179
180 #
181 # Test FinishBreakpoint in BP condition evaluation
182 # (finish in normal frame)
183 #
184
185 clean_restart ${testfile}
186 gdb_load_shlibs ${lib_sl}
187
188 gdb_test "source $python_file" "Python script imported.*" \
189 "import python scripts"
190
191 if ![runto_main] then {
192 fail "Cannot run to main."
193 return 0
194 }
195
196 gdb_test "break ${cond_line} if test(i,8)" \
197 "Breakpoint .* at .*" "set conditional BP"
198 gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
199
200 gdb_test "continue" \
201 "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.*" \
202 "stop in condition function"
203
204 gdb_test "continue" "Continuing.*" "finish condition evaluation"
205 gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
206 gdb_test "print i" "8" "check stopped location"
207
208 #
209 # Test FinishBreakpoint in explicit inferior function call
210 #
211
212 clean_restart ${testfile}
213 gdb_load_shlibs ${lib_sl}
214
215 gdb_test "source $python_file" "Python script imported.*" \
216 "import python scripts"
217
218 if ![runto_main] then {
219 fail "Cannot run to main."
220 return 0
221 }
222
223 # return address in dummy frame
224
225 gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
226 "prepare TestExplicitBreakpoint"
227 gdb_test "print increase_1(&i)" \
228 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
229 "don't allow FinishBreakpoint on dummy frames"
230
231 # return address in normal frame
232
233 delete_breakpoints
234 gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
235 "prepare TestExplicitBreakpoint"
236 gdb_test "print increase(&i)" \
237 "SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
238 "FinishBP stop at during explicit function call"
239
240
241 #
242 # Test FinishBreakpoint when inferior exits
243 #
244
245 if ![runto "test_exec_exit"] then {
246 fail "Cannot run to test_exec_exit."
247 return 0
248 }
249
250 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
251 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
252
253 #
254 # Test FinishBreakpoint when inferior execs
255 #
256
257 if ![runto "test_exec_exit"] then {
258 fail "Cannot run to test_exec_exit."
259 return 0
260 }
261
262 gdb_test_no_output "set var do_exit = 0" "switch to execve() test"
263 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
264 gdb_test "catch exec" "Catchpoint.*\(exec\).*" "catch exec"
265 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"
This page took 0.038914 seconds and 4 git commands to generate.