Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.python / py-finish-breakpoint.exp
blob776549cb7ed477bd66ef66c29e451c888a192471
1 # Copyright (C) 2011-2022 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 "skipping shared library tests"
21 return 0
24 load_lib gdb-python.exp
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 ""
31 standard_testfile
32 set exec_opts [list debug shlib=$lib_sl]
34 if [get_compiler_info] {
35 return -1
38 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
39 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
40 untested "failed to compile"
41 return -1
44 # Start with a fresh gdb.
45 clean_restart ${testfile}
47 if { [skip_python_tests] } { continue }
50 # Test FinishBreakpoint in normal conditions
53 clean_restart ${testfile}
54 gdb_load_shlib ${lib_sl}
56 if ![runto_main] then {
57 return 0
60 set python_file [gdb_remote_download host \
61 ${srcdir}/${subdir}/${testfile}.py]
63 gdb_test_no_output "set confirm off" "disable confirmation"
64 gdb_test "source $python_file" "Python script imported.*" \
65 "import python scripts, 1"
66 gdb_breakpoint "increase_1"
67 gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish"
69 # set FinishBreakpoint
71 gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \
72 "Temporary breakpoint.*" "set FinishBreakpoint with default frame value"
73 gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \
74 "Temporary breakpoint.*" "set FinishBreakpoint"
75 gdb_test "python print (finishbp.return_value)" "None.*" \
76 "check return_value at init"
78 # check normal bp hit
80 gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \
81 "check MyFinishBreakpoint hit"
82 gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value"
84 gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit"
85 gdb_test "python print (finishbp.is_valid())" "False.*"\
86 "ensure that finish bp is invalid afer normal hit"
88 # check FinishBreakpoint in main no allowed
90 gdb_test "finish" "main.*" "return to main()"
91 gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \
92 "ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \
93 "check FinishBP not allowed in main"
96 # Test FinishBreakpoint with no debug symbol
99 clean_restart ${testfile}
100 gdb_load_shlib ${lib_sl}
102 gdb_test "source $python_file" "Python script imported.*" \
103 "import python scripts, 2"
104 set cond_line [gdb_get_line_number "Condition Break."]
106 if ![runto_main] then {
107 return 0
110 gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info"
111 gdb_breakpoint "do_nothing" {temporary}
112 gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \
113 "continue to do_nothing"
115 gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
116 "SimpleFinishBreakpoint init" \
117 "set finish breakpoint for no debug symbol test"
118 gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
119 gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol"
122 # Test FinishBreakpoint in function returned by longjmp
125 clean_restart ${testfile}
126 gdb_load_shlib ${lib_sl}
128 gdb_test "source $python_file" "Python script imported.*" \
129 "import python scripts, 3"
131 if ![runto call_longjmp_1] then {
132 return
135 gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
136 "SimpleFinishBreakpoint init" \
137 "set finish breakpoint for longjmp test"
138 gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
139 "set BP after the jump"
140 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
141 "check FinishBP out of scope notification"
142 gdb_test "python print (finishbp.is_valid())" "False.*"\
143 "ensure that finish bp is invalid afer out of scope notification"
146 # Test FinishBreakpoint in BP condition evaluation
147 # (finish in dummy frame)
150 clean_restart ${testfile}
151 gdb_load_shlib ${lib_sl}
153 gdb_test "source $python_file" "Python script imported.*" \
154 "import python scripts, 4"
157 if ![runto_main] then {
158 return 0
161 gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
162 "set a conditional BP"
163 gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
164 "set FinishBP in a breakpoint condition"
165 gdb_test "continue" \
166 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
167 "don't allow FinishBreakpoint on dummy frames"
168 gdb_test "print i" "8" \
169 "check stopped location for stop in dummy frame case"
172 # Test FinishBreakpoint in BP condition evaluation
173 # (finish in normal frame)
176 clean_restart ${testfile}
177 gdb_load_shlib ${lib_sl}
179 gdb_test "source $python_file" "Python script imported.*" \
180 "import python scripts, 5"
182 if ![runto_main] then {
183 return 0
186 gdb_test "break ${cond_line} if test(i,8)" \
187 "Breakpoint .* at .*" "set conditional BP"
188 gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
190 gdb_test "continue" \
191 "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.*" \
192 "stop in condition function"
194 gdb_test "continue" "Continuing.*" "finish condition evaluation"
195 gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
196 gdb_test "print i" "8" \
197 "check stopped location for stop in normal frame case"
200 # Test FinishBreakpoint in explicit inferior function call
203 clean_restart ${testfile}
204 gdb_load_shlib ${lib_sl}
206 gdb_test "source $python_file" "Python script imported.*" \
207 "import python scripts, 6"
209 if ![runto_main] then {
210 return 0
213 # return address in dummy frame
215 gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
216 "prepare TestExplicitBreakpoint, return addr in dummy frame"
217 gdb_test "print increase_1(&i)" \
218 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
219 "don't allow FinishBreakpoint on dummy frames, return address in dummy frame"
221 # return address in normal frame
223 delete_breakpoints
224 gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
225 "prepare TestExplicitBreakpoint, return addr in normal frame"
226 gdb_test "print increase(&i)" \
227 "SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
228 "FinishBP stop at during explicit function call"
232 # Test FinishBreakpoint when inferior exits
235 if ![runto "test_exec_exit"] then {
236 return 0
239 gdb_test_no_output "set var self_exec = 0" "switch to exit() test"
240 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
241 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
244 # Test FinishBreakpoint when inferior execs
247 if ![runto "test_exec_exit"] then {
248 return 0
251 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
252 gdb_test "catch exec" "Catchpoint.*\(exec\).*"
253 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"