1 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests the mechanism
17 # exposing values to Python.
19 if {[skip_shlib_tests]} {
20 untested py-finish-breakpoint.exp
24 load_lib gdb-python.exp
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
33 set libfile "py-events-shlib"
34 set libsrc $srcdir/$subdir/$libfile.c
35 set lib_sl [standard_output_file $libfile-nodebug.so]
39 set exec_opts [list debug shlib=$lib_sl]
41 if [get_compiler_info] {
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."
51 # Start with a fresh gdb.
52 clean_restart ${testfile}
54 set python_file ${srcdir}/${subdir}/${testfile}.py
57 # Skip all tests if Python scripting is not enabled.
58 if { [skip_python_tests] } { continue }
61 # Test FinishBreakpoint in normal conditions
64 clean_restart ${testfile}
65 gdb_load_shlibs ${lib_sl}
67 if ![runto_main] then {
68 fail "Cannot run to main."
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"
78 # set FinishBreakpoint
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"
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"
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"
97 # check FinishBreakpoint in main no allowed
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"
105 # Test FinishBreakpoint with no debug symbol
108 clean_restart ${testfile}
109 gdb_load_shlibs ${lib_sl}
111 gdb_test "source $python_file" "Python script imported.*" \
112 "import python scripts"
113 set cond_line [gdb_get_line_number "Condition Break."]
115 if ![runto_main] then {
116 fail "Cannot run to main."
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"
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"
132 # Test FinishBreakpoint in function returned by longjmp
135 clean_restart ${testfile}
136 gdb_load_shlibs ${lib_sl}
138 gdb_test "source $python_file" "Python script imported.*" \
139 "import python scripts"
141 if ![runto call_longjmp_1] then {
142 perror "couldn't run to breakpoint call_longjmp"
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"
157 # Test FinishBreakpoint in BP condition evaluation
158 # (finish in dummy frame)
161 clean_restart ${testfile}
162 gdb_load_shlibs ${lib_sl}
164 gdb_test "source $python_file" "Python script imported.*" \
165 "import python scripts"
168 if ![runto_main] then {
169 fail "Cannot run to main."
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"
183 # Test FinishBreakpoint in BP condition evaluation
184 # (finish in normal frame)
187 clean_restart ${testfile}
188 gdb_load_shlibs ${lib_sl}
190 gdb_test "source $python_file" "Python script imported.*" \
191 "import python scripts"
193 if ![runto_main] then {
194 fail "Cannot run to main."
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"
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"
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"
211 # Test FinishBreakpoint in explicit inferior function call
214 clean_restart ${testfile}
215 gdb_load_shlibs ${lib_sl}
217 gdb_test "source $python_file" "Python script imported.*" \
218 "import python scripts"
220 if ![runto_main] then {
221 fail "Cannot run to main."
225 # return address in dummy frame
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"
233 # return address in normal frame
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"
244 # Test FinishBreakpoint when inferior exits
247 if ![runto "test_exec_exit"] then {
248 fail "Cannot run to test_exec_exit."
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"
257 # Test FinishBreakpoint when inferior execs
260 if ![runto "test_exec_exit"] then {
261 fail "Cannot run to test_exec_exit."
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"