GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.base / step-test.exp
blob6e6f89b7872beeca68bb72820ac031892cfa21fe
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1997-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 # step-test.exp -- Expect script to test stepping in gdb
19 standard_testfile .c
21 remote_exec build "rm -f ${binfile}"
22 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
23 untested "failed to compile"
24 return -1
27 clean_restart ${binfile}
29 if {![runto_main]} {
30 return 0
33 # Set a breakpoint at line 45, if stepi then finish fails, we would
34 # run to the end of the program, which would mess up the rest of the tests.
36 # Vanilla step/next
38 gdb_test "next" ".*${decimal}.*x = 1;.*" "next 1"
39 gdb_test "step" ".*${decimal}.*y = 2;.*" "step 1"
41 # With count
43 gdb_test "next 2" ".*${decimal}.*w = w.*2;.*"
44 gdb_test "step 3" ".*${decimal}.*z = z.*5;.*"
45 gdb_test "next" ".*${decimal}.*callee.*OVER.*" "next 3"
47 # Step over call
49 gdb_test "next" ".*${decimal}.*callee.*INTO.*" "next over"
51 # Step into call
53 gdb_test "step" ".*${decimal}.*myglob.*" "step into"
55 # Step out of call
57 # I wonder if this is really portable. Are there any caller-saves
58 # platforms, on which `finish' will return you to some kind of pop
59 # instruction, which is attributed to the line containing the function
60 # call?
62 # On PA64, we end up at a different instruction than PA32.
63 # On IA-64, we also end up on callee instead of on the next line due
64 # to the restoration of the global pointer (which is a caller-save).
65 # Similarly on MIPS PIC targets.
66 set test "step out"
67 if { [istarget "ia64-*-*"] || [istarget "mips*-*-*"]} {
68 gdb_test_multiple "finish" "$test" {
69 -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" {
70 pass "$test"
72 -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" {
73 pass "$test"
76 } else {
77 gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out"
80 ### Testing nexti and stepi.
81 ###
82 ### test_i NAME COMMAND HERE THERE
83 ###
84 ### Send COMMAND to gdb over and over, while the output matches the
85 ### regexp HERE, followed by the gdb prompt. Pass if the output
86 ### eventually matches the regexp THERE, followed by the gdb prompt;
87 ### fail if we have to iterate more than a hundred times, we time out
88 ### talking to gdb, or we get output which is neither HERE nor THERE. :)
89 ###
90 ### Use NAME as the name of the test.
91 ###
92 ### The exact regexps used are "$HERE.*$gdb_prompt $"
93 ### and "$THERE.*$gdb_prompt $"
94 ###
95 proc test_i {name command here there} {
96 global gdb_prompt
98 set i 0
99 gdb_test_multiple "$command" "$name" {
100 -re "$here.*$gdb_prompt $" {
101 # Have we gone for too many steps without seeing any progress?
102 if {[incr i] >= 100} {
103 fail "$name (no progress after 100 steps)"
104 return
106 send_gdb "$command\n"
107 exp_continue
109 -re "$there.*$gdb_prompt $" {
110 # We've reached the next line. Rah.
111 pass "$name"
112 return
117 test_i "stepi to next line" "stepi" \
118 ".*${decimal}.*a.*5.* = a.*3" \
119 ".*${decimal}.*callee.*STEPI"
121 # Continue to step until we enter the function. Also keep stepping
122 # if this passes through a (useless) PLT entry.
123 test_i "stepi into function" "stepi" \
124 "(.*${decimal}.*callee.*STEPI|.* in callee@plt)" \
125 ".*callee \\(\\) at .*step-test\\.c"
127 # Continue to step until we reach the function's body. This makes it
128 # more likely that we've actually completed the prologue, so "finish"
129 # will work.
130 set alphanum_re "\[a-zA-Z0-9\]"
131 set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)"
132 test_i "stepi into function's first source line" "stepi" \
133 "(${decimal}.*int callee|$pic_thunk_re)" \
134 ".*${decimal}.*myglob.*; return 0;"
136 # Have to be careful here, if the finish does not work,
137 # then we may run to the end of the program, which
138 # will cause erroneous failures in the rest of the tests
139 set test "stepi: finish call"
140 gdb_test_multiple "finish" "$test" {
141 -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" {
142 pass "$test"
144 -re ".*(Program received|$inferior_exited_re).*$gdb_prompt $" {
145 # Oops... We ran to the end of the program... Better reset
146 if {![runto_main]} {
147 return 0
149 if {![runto step-test.c:45]} {
150 return 0
152 fail "$test"
154 -re ".*${decimal}.*callee.*STEPI.*$gdb_prompt $" {
155 # On PA64, we end up at a different instruction than PA32.
156 # On IA-64, we end up on callee instead of on the following line due
157 # to the restoration of the global pointer.
158 # Similarly on MIPS PIC targets.
159 if { [istarget "ia64-*-*"] || [istarget "mips*-*-*"] } {
160 test_i "$test" "stepi" \
161 ".*${decimal}.*callee.*STEPI" ".*${decimal}.*callee.*NEXTI"
162 } else {
163 fail "$test"
168 test_i "nexti over function" "nexti" \
169 ".*${decimal}.*callee.*NEXTI" \
170 ".*${decimal}.*y = w \\+ z;"
172 # On some platforms, if we try to step into a function call that
173 # passes a large structure by value, then we actually end up stepping
174 # into memcpy, bcopy, or some such --- GCC emits the call to pass the
175 # argument. Opinion is bitterly divided about whether this is the
176 # right behavior for GDB or not, but we'll catch it here, so folks
177 # won't forget about it.
178 # Update 4/4/2002 - Regardless of which opinion you have, you would
179 # probably have to agree that gdb is currently behaving as designed,
180 # in the absence of additional code to not stop in functions used
181 # internally by the compiler. Since the testsuite should be checking
182 # for conformance to the design, the correct behavior is to accept the
183 # cases where gdb stops in memcpy/bcopy.
185 gdb_test \
186 "break [gdb_get_line_number "step-test.exp: large struct by value"]" \
187 ".*Breakpoint.* at .*" \
188 "set breakpoint at call to large_struct_by_value"
189 gdb_test "continue" \
190 ".*Breakpoint ${decimal},.*large_struct_by_value.*" \
191 "run to pass large struct"
192 set test "large struct by value"
193 gdb_test_multiple "step" "$test" {
194 -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" {
195 pass "$test"
197 -re ".*(memcpy|bcopy).*$gdb_prompt $" {
198 send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $"
199 send_gdb "step\n"
200 exp_continue
204 gdb_continue_to_end