OSDN Git Service

2009-06-27 Michael Snyder <msnyder@vmware.com>
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.reverse / finish-reverse.exp
1 # Copyright 2008, 2009 Free Software Foundation, Inc.
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 'finish' with
17 # reverse debugging.
18
19 if ![target_info exists gdb,can_reverse] {
20     return
21 }
22
23 set testfile "finish-reverse"
24 set srcfile ${testfile}.c
25
26 if { [prepare_for_testing $testfile.exp "$testfile" $srcfile] } {
27     return -1
28 }
29
30 proc test_start_of_line { line_text test_msg } {
31     global gdb_prompt
32     global decimal
33     global hex
34
35     send_gdb "info line\n"
36     gdb_expect {
37         -re "Line $decimal of .* starts at address ($hex) .*$gdb_prompt $" {
38             set line_begin $expect_out(1,string)
39         }
40         default {
41             fail "Get line address in test_start_of_line"
42         }
43     }
44     send_gdb "info reg pc\n"
45     gdb_expect {
46         -re ".*: ($hex)\r\n*$gdb_prompt $" {
47             set stop_pc $expect_out(1,string)
48         }
49         default {
50             fail"Get stop pc in test_start_of_line"
51         }
52     }
53     gdb_test "print $line_begin == $stop_pc" \
54         " = 1\[\r\n\]*" \
55         "test_start_of_line, $test_msg"
56 }
57
58 runto main
59
60 if [target_info exists gdb,use_precord] {
61     # Activate process record/replay
62     gdb_test "record" "" "Turn on process record"
63     # FIXME: command ought to acknowledge, so we can test if it succeeded.
64 }
65
66 # Test finish from void func
67
68 set breakloc [gdb_get_line_number "VOID FUNC" "$srcfile"]
69 gdb_test "break void_func" \
70     "Breakpoint $decimal at .*/$srcfile, line $breakloc\." \
71     "set breakpoint on void_func"
72 gdb_continue_to_breakpoint "void_func" ".*/$srcfile:$breakloc.*"
73
74 set test_msg "finish from void_func"
75 gdb_test_multiple "finish" "$test_msg" {
76     -re " call to void_func .*$gdb_prompt $" {
77         send_gdb "step\n"
78         exp_continue
79     }
80     -re " void_checkpoint .*$gdb_prompt $" {
81         pass "$test_msg"
82     }
83 }
84
85 # Test finish from char func
86
87 set breakloc [gdb_get_line_number "CHAR FUNC" "$srcfile"]
88 gdb_test "break char_func" \
89     "Breakpoint $decimal at .*/$srcfile, line $breakloc\." \
90     "set breakpoint on char_func"
91 gdb_continue_to_breakpoint "char_func" ".*/$srcfile:$breakloc.*"
92
93 set test_msg "finish from char_func"
94 gdb_test_multiple "finish" "$test_msg" {
95     -re " void_checkpoint .*$gdb_prompt $" {
96         send_gdb "step\n"
97         exp_continue
98     }
99     -re " char_checkpoint .*$gdb_prompt $" {
100         pass "$test_msg"
101     }
102 }
103
104 # Test finish from short func
105
106 set breakloc [gdb_get_line_number "SHORT FUNC" "$srcfile"]
107 gdb_test "break short_func" \
108     "Breakpoint $decimal at .* line $breakloc\." \
109     "set breakpoint on short_func"
110 gdb_continue_to_breakpoint "short_func" ".*/$srcfile:$breakloc.*"
111
112 set test_msg "finish from short_func"
113 gdb_test_multiple "finish" "$test_msg" {
114     -re " char_checkpoint .*$gdb_prompt $" {
115         send_gdb "step\n"
116         exp_continue
117     }
118     -re " short_checkpoint .*$gdb_prompt $" {
119         pass "$test_msg"
120     }
121 }
122
123 # Test finish from int func
124
125 set breakloc [gdb_get_line_number "INT FUNC" "$srcfile"]
126 gdb_test "break int_func" \
127     "Breakpoint $decimal at .* line $breakloc\." \
128     "set breakpoint on int_func"
129 gdb_continue_to_breakpoint "int_func" ".*/$srcfile:$breakloc.*"
130
131 set test_msg "finish from int_func"
132 gdb_test_multiple "finish" "$test_msg" {
133     -re " short_checkpoint .*$gdb_prompt $" {
134         send_gdb "step\n"
135         exp_continue
136     }
137     -re " int_checkpoint .*$gdb_prompt $" {
138         pass "$test_msg"
139     }
140 }
141
142 # Test finish from long func
143
144 set breakloc [gdb_get_line_number "LONG FUNC" "$srcfile"]
145 gdb_test "break long_func" \
146     "Breakpoint $decimal at .* line $breakloc\." \
147     "set breakpoint on long_func"
148 gdb_continue_to_breakpoint "long_func" ".*/$srcfile:$breakloc.*"
149
150 set test_msg "finish from long_func"
151 gdb_test_multiple "finish" "$test_msg" {
152     -re " int_checkpoint .*$gdb_prompt $" {
153         send_gdb "step\n"
154         exp_continue
155     }
156     -re " long_checkpoint .*$gdb_prompt $" {
157         pass "$test_msg"
158     }
159 }
160
161 # Test finish from long long func
162
163 set breakloc [gdb_get_line_number "LONG LONG FUNC" "$srcfile"]
164 gdb_test "break long_long_func" \
165     "Breakpoint $decimal at .* line $breakloc\." \
166     "set breakpoint on long_long_func"
167 gdb_continue_to_breakpoint "long_long_func" ".*/$srcfile:$breakloc.*"
168
169 set test_msg "finish from long_long_func"
170 gdb_test_multiple "finish" "$test_msg" {
171     -re " long_checkpoint .*$gdb_prompt $" {
172         send_gdb "step\n"
173         exp_continue
174     }
175     -re " long_long_checkpoint .*$gdb_prompt $" {
176         pass "$test_msg"
177     }
178 }
179
180
181 ###
182 ###
183 ###
184
185 # Now switch to reverse
186 gdb_test "set exec-dir reverse" "" "set reverse execution"
187
188 # Test reverse finish from long long func
189
190 set breakloc [gdb_get_line_number "LONG LONG FUNC" "$srcfile"]
191 gdb_continue_to_breakpoint "long_long_func" ".*/$srcfile:$breakloc.*"
192
193 set test_msg "reverse finish from long_long_func"
194 gdb_test_multiple "finish" "$test_msg" {
195     -re ".* long_checkpoint.*$gdb_prompt $" {
196         test_start_of_line "long_checkpoint" "$test_msg"
197     }
198 }
199
200 # Test reverse finish from long func
201
202 set breakloc [gdb_get_line_number "LONG FUNC" "$srcfile"]
203 gdb_continue_to_breakpoint "long_func" ".*/$srcfile:$breakloc.*"
204
205 set test_msg "reverse finish from long_func"
206 gdb_test_multiple "finish" "$test_msg" {
207     -re ".* int_checkpoint.*$gdb_prompt $" {
208         test_start_of_line "int_checkpoint" "$test_msg"
209     }
210 }
211
212 # Test reverse finish from int func
213
214 set breakloc [gdb_get_line_number "INT FUNC" "$srcfile"]
215 gdb_continue_to_breakpoint "int_func" ".*/$srcfile:$breakloc.*"
216
217 set test_msg "reverse finish from int_func"
218 gdb_test_multiple "finish" "$test_msg" {
219     -re ".* short_checkpoint.*$gdb_prompt $" {
220         test_start_of_line "short_checkpoint" "$test_msg"
221     }
222 }
223
224 # Test reverse finish from short func
225
226 set breakloc [gdb_get_line_number "SHORT FUNC" "$srcfile"]
227 gdb_continue_to_breakpoint "short_func" ".*/$srcfile:$breakloc.*"
228
229 set test_msg "reverse finish from short_func"
230 gdb_test_multiple "finish" "$test_msg" {
231     -re ".* char_checkpoint.*$gdb_prompt $" {
232         test_start_of_line "char_checkpoint" "$test_msg"
233     }
234 }
235
236 # Test reverse finish from char func
237
238 set breakloc [gdb_get_line_number "CHAR FUNC" "$srcfile"]
239 gdb_continue_to_breakpoint "char_func" ".*/$srcfile:$breakloc.*"
240
241 set test_msg "reverse finish from char_func"
242 gdb_test_multiple "finish" "$test_msg" {
243     -re ".* void_checkpoint.*$gdb_prompt $" {
244         test_start_of_line "void_checkpoint" "$test_msg"
245     }
246 }
247
248 # Test reverse finish from void func
249
250 set breakloc [gdb_get_line_number "VOID FUNC" "$srcfile"]
251 gdb_continue_to_breakpoint "void_func" ".*/$srcfile:$breakloc.*"
252
253 set test_msg "reverse finish from void_func"
254 gdb_test_multiple "finish" "$test_msg" {
255     -re ".* call to void_func.*$gdb_prompt $" {
256         test_start_of_line "call to void_func" "$test_msg"
257     }
258 }
259
260 return 0