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