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