OSDN Git Service

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