summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.twreverse/finish-reverse.exp
blob: 2bfa99fbb5e140668dc9dc07362dea0abe3ea08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Copyright 2008 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

set testfile "finish-reverse"
set srcfile ${testfile}.c

if { [prepare_for_testing $testfile.exp "$testfile" $srcfile] } {
    return -1
}

global hex
global decimal

proc test_start_of_line { line_text test_msg } {
    global gdb_prompt
    global decimal
    global hex

    send_gdb "info line\n"
    gdb_expect {
	-re "Line $decimal of .* starts at address ($hex) .*$gdb_prompt $" {
	    set line_begin $expect_out(1,string)
	}
	default {
	    fail "Get line address in test_start_of_line"
	}
    }
    send_gdb "info reg pc\n"
    gdb_expect {
	-re ".*: ($hex)\r\n*$gdb_prompt $" {
	    set stop_pc $expect_out(1,string)
	}
	default {
	    fail"Get stop pc in test_start_of_line"
	}
    }
    gdb_test "print $line_begin == $stop_pc" \
	" = 1\[\r\n\]*" \
	"test_start_of_line, $test_msg"
}

runto main

# FIXME 'record' command should say something so we know it's working.
gdb_test "record" "" "start recording"

# Test finish from void func

set breakloc [gdb_get_line_number "VOID FUNC" "$srcfile"]
gdb_test "break void_func" \
    "Breakpoint $decimal at .*/$srcfile, line $breakloc\." \
    "set breakpoint on void_func"
gdb_continue_to_breakpoint "void_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from void_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " call to void_func .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " void_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}

# Test finish from char func

set breakloc [gdb_get_line_number "CHAR FUNC" "$srcfile"]
gdb_test "break char_func" \
    "Breakpoint $decimal at .*/$srcfile, line $breakloc\." \
    "set breakpoint on char_func"
gdb_continue_to_breakpoint "char_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from char_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " void_checkpoint .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " char_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}

# Test finish from short func

set breakloc [gdb_get_line_number "SHORT FUNC" "$srcfile"]
gdb_test "break short_func" \
    "Breakpoint $decimal at .* line $breakloc\." \
    "set breakpoint on short_func"
gdb_continue_to_breakpoint "short_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from short_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " char_checkpoint .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " short_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}

# Test finish from int func

set breakloc [gdb_get_line_number "INT FUNC" "$srcfile"]
gdb_test "break int_func" \
    "Breakpoint $decimal at .* line $breakloc\." \
    "set breakpoint on int_func"
gdb_continue_to_breakpoint "int_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from int_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " short_checkpoint .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " int_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}

# Test finish from long func

set breakloc [gdb_get_line_number "LONG FUNC" "$srcfile"]
gdb_test "break long_func" \
    "Breakpoint $decimal at .* line $breakloc\." \
    "set breakpoint on long_func"
gdb_continue_to_breakpoint "long_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from long_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " int_checkpoint .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " long_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}

# Test finish from long long func

set breakloc [gdb_get_line_number "LONG LONG FUNC" "$srcfile"]
gdb_test "break long_long_func" \
    "Breakpoint $decimal at .* line $breakloc\." \
    "set breakpoint on long_long_func"
gdb_continue_to_breakpoint "long_long_func" ".*/$srcfile:$breakloc.*"

set test_msg "finish from long_long_func"
gdb_test_multiple "finish" "$test_msg" {
    -re " long_checkpoint .*$gdb_prompt $" {
	send_gdb "step\n"
	exp_continue
    }
    -re " long_long_checkpoint .*$gdb_prompt $" {
	pass "$test_msg"
    }
}


###
###
###

# Now switch to reverse
gdb_test "set exec-dir reverse" "" "set reverse execution"

# Test reverse finish from long long func

set breakloc [gdb_get_line_number "LONG LONG FUNC" "$srcfile"]
gdb_continue_to_breakpoint "long_long_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from long_long_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* long_checkpoint.*$gdb_prompt $" {
	test_start_of_line "long_checkpoint" "$test_msg"
    }
}

# Test reverse finish from long func

set breakloc [gdb_get_line_number "LONG FUNC" "$srcfile"]
gdb_continue_to_breakpoint "long_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from long_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* int_checkpoint.*$gdb_prompt $" {
	test_start_of_line "int_checkpoint" "$test_msg"
    }
}

# Test reverse finish from int func

set breakloc [gdb_get_line_number "INT FUNC" "$srcfile"]
gdb_continue_to_breakpoint "int_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from int_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* short_checkpoint.*$gdb_prompt $" {
	test_start_of_line "short_checkpoint" "$test_msg"
    }
}

# Test reverse finish from short func

set breakloc [gdb_get_line_number "SHORT FUNC" "$srcfile"]
gdb_continue_to_breakpoint "short_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from short_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* char_checkpoint.*$gdb_prompt $" {
	test_start_of_line "char_checkpoint" "$test_msg"
    }
}

# Test reverse finish from char func

set breakloc [gdb_get_line_number "CHAR FUNC" "$srcfile"]
gdb_continue_to_breakpoint "char_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from char_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* void_checkpoint.*$gdb_prompt $" {
	test_start_of_line "void_checkpoint" "$test_msg"
    }
}

# Test reverse finish from void func

set breakloc [gdb_get_line_number "VOID FUNC" "$srcfile"]
gdb_continue_to_breakpoint "void_func" ".*/$srcfile:$breakloc.*"

set test_msg "reverse finish from void_func"
gdb_test_multiple "finish" "$test_msg" {
    -re ".* call to void_func.*$gdb_prompt $" {
	test_start_of_line "call to void_func" "$test_msg"
    }
}

return 0