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