1 # Copyright (C) 2011-2021 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"
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]
32 set exec_opts [list debug shlib=$lib_sl]
34 if [get_compiler_info] {
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"
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 fail "cannot run to main."
61 set python_file [gdb_remote_download host \
62 ${srcdir}/${subdir}/${testfile}.py]
64 gdb_test_no_output "set confirm off" "disable confirmation"
65 gdb_test "source $python_file" "Python script imported.*" \
66 "import python scripts"
67 gdb_breakpoint "increase_1"
68 gdb_test "continue" "Breakpoint .*at.*" "continue to the function to finish"
70 # set FinishBreakpoint
72 gdb_test "python finishbp_default = gdb.FinishBreakpoint ()" \
73 "Temporary breakpoint.*" "set FinishBreakpoint with default frame value"
74 gdb_test "python finishbp = MyFinishBreakpoint (gdb.parse_and_eval ('a'), gdb.newest_frame ())" \
75 "Temporary breakpoint.*" "set FinishBreakpoint"
76 gdb_test "python print (finishbp.return_value)" "None.*" \
77 "check return_value at init"
81 gdb_test "continue" "MyFinishBreakpoint stop with.*return_value is: -5.*#0.*increase.*" \
82 "check MyFinishBreakpoint hit"
83 gdb_test "python print (finishbp.return_value)" "-5.*" "check return_value"
85 gdb_test "python print (finishbp_default.hit_count)" "1.*" "check finishBP on default frame has been hit"
86 gdb_test "python print (finishbp.is_valid())" "False.*"\
87 "ensure that finish bp is invalid afer normal hit"
89 # check FinishBreakpoint in main no allowed
91 gdb_test "finish" "main.*" "return to main()"
92 gdb_test "python MyFinishBreakpoint (None, gdb.selected_frame ())" \
93 "ValueError: \"FinishBreakpoint\" not meaningful in the outermost frame..*" \
94 "check FinishBP not allowed in main"
97 # Test FinishBreakpoint with no debug symbol
100 clean_restart ${testfile}
101 gdb_load_shlib ${lib_sl}
103 gdb_test "source $python_file" "Python script imported.*" \
104 "import python scripts"
105 set cond_line [gdb_get_line_number "Condition Break."]
107 if ![runto_main] then {
108 fail "cannot run to main."
112 gdb_test "print do_nothing" "no debug info.*" "ensure that shared lib has no debug info"
113 gdb_breakpoint "do_nothing" {temporary}
114 gdb_test "continue" "Temporary breakpoint .*in \\.?do_nothing.*" \
115 "continue to do_nothing"
117 gdb_test "python finishBP = SimpleFinishBreakpoint(gdb.newest_frame())" \
118 "SimpleFinishBreakpoint init" \
119 "set finish breakpoint"
120 gdb_test "continue" "SimpleFinishBreakpoint stop.*" "check FinishBreakpoint hit"
121 gdb_test "python print (finishBP.return_value)" "None" "check return value without debug symbol"
124 # Test FinishBreakpoint in function returned by longjmp
127 clean_restart ${testfile}
128 gdb_load_shlib ${lib_sl}
130 gdb_test "source $python_file" "Python script imported.*" \
131 "import python scripts"
133 if ![runto call_longjmp_1] then {
134 perror "couldn't run to breakpoint call_longjmp"
138 gdb_test "python finishbp = SimpleFinishBreakpoint(gdb.newest_frame())" \
139 "SimpleFinishBreakpoint init" \
140 "set finish breakpoint"
141 gdb_test "break [gdb_get_line_number "after longjmp."]" "Breakpoint.* at .*" \
142 "set BP after the jump"
143 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" \
144 "check FinishBP out of scope notification"
145 gdb_test "python print (finishbp.is_valid())" "False.*"\
146 "ensure that finish bp is invalid afer out of scope notification"
149 # Test FinishBreakpoint in BP condition evaluation
150 # (finish in dummy frame)
153 clean_restart ${testfile}
154 gdb_load_shlib ${lib_sl}
156 gdb_test "source $python_file" "Python script imported.*" \
157 "import python scripts"
160 if ![runto_main] then {
161 fail "cannot run to main."
165 gdb_test "break ${cond_line} if test_1(i,8)" "Breakpoint .* at .*" \
166 "set a conditional BP"
167 gdb_test "python TestBreakpoint()" "TestBreakpoint init" \
168 "set FinishBP in a breakpoint condition"
169 gdb_test "continue" \
170 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
171 "don't allow FinishBreakpoint on dummy frames"
172 gdb_test "print i" "8" "check stopped location"
175 # Test FinishBreakpoint in BP condition evaluation
176 # (finish in normal frame)
179 clean_restart ${testfile}
180 gdb_load_shlib ${lib_sl}
182 gdb_test "source $python_file" "Python script imported.*" \
183 "import python scripts"
185 if ![runto_main] then {
186 fail "cannot run to main."
190 gdb_test "break ${cond_line} if test(i,8)" \
191 "Breakpoint .* at .*" "set conditional BP"
192 gdb_test "python TestBreakpoint()" "TestBreakpoint init" "set BP in condition"
194 gdb_test "continue" \
195 "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.*" \
196 "stop in condition function"
198 gdb_test "continue" "Continuing.*" "finish condition evaluation"
199 gdb_test "continue" "Breakpoint.*" "stop at conditional breakpoint"
200 gdb_test "print i" "8" "check stopped location"
203 # Test FinishBreakpoint in explicit inferior function call
206 clean_restart ${testfile}
207 gdb_load_shlib ${lib_sl}
209 gdb_test "source $python_file" "Python script imported.*" \
210 "import python scripts"
212 if ![runto_main] then {
213 fail "cannot run to main."
217 # return address in dummy frame
219 gdb_test "python TestExplicitBreakpoint('increase_1')" "Breakpoint.*at.*" \
220 "prepare TestExplicitBreakpoint"
221 gdb_test "print increase_1(&i)" \
222 "\"FinishBreakpoint\" cannot be set on a dummy frame.*" \
223 "don't allow FinishBreakpoint on dummy frames"
225 # return address in normal frame
228 gdb_test "python TestExplicitBreakpoint(\"increase_1\")" "Breakpoint.*at.*" \
229 "prepare TestExplicitBreakpoint"
230 gdb_test "print increase(&i)" \
231 "SimpleFinishBreakpoint init.*SimpleFinishBreakpoint stop.*The program being debugged stopped while in a function called from GDB.*" \
232 "FinishBP stop at during explicit function call"
236 # Test FinishBreakpoint when inferior exits
239 if ![runto "test_exec_exit"] then {
240 fail "cannot run to test_exec_exit."
244 gdb_test_no_output "set var self_exec = 0" "switch to exit() test"
245 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exit()"
246 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exit"
249 # Test FinishBreakpoint when inferior execs
252 if ![runto "test_exec_exit"] then {
253 fail "cannot run to test_exec_exit."
257 gdb_test "python SimpleFinishBreakpoint(gdb.newest_frame())" "SimpleFinishBreakpoint init" "set FinishBP after the exec"
258 gdb_test "catch exec" "Catchpoint.*\(exec\).*"
259 gdb_test "continue" "SimpleFinishBreakpoint out of scope.*" "catch out of scope after exec"