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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# Copyright (C) 1988, 1990, 1991, 1992 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 2 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu
# This file was written by Rob Savoye. (rob@cygnus.com)
if $tracelevel then {
strace $tracelevel
}
#
# test running programs
#
set prms_id 0
set bug_id 0
set binfile "break"
set srcfile $binfile.c
if ![file exists $objdir/$subdir/$binfile] then {
perror "$objdir/$subdir/$binfile does not exist."
return 0
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load $objdir/$subdir/$binfile
#
# test simple breakpoint setting commands
#
#
# test deleting all breakpoints; note that gdb-init.exp provides a
# "delete_breakpoints" proc for general use elsewhere
#
send "delete breakpoints\n"
expect {
-re "Delete all breakpoints.*y or n. $"\
{ send "y\n"
expect {
-re ".*$prompt $"\
{ send "info breakpoints\n"
expect {
-re "No breakpoints or watchpoints..*$prompt $" { pass "Deleted all breakpoints" }
-re ".*$prompt $" { fail "Deleted all breakpoints" }
timeout { fail "Deleted all breakpoints" }
}
}
timeout { fail "Deleted all breakpoints" }
}
}
-re ".*$prompt $" { fail "Deleted all breakpoints" }
timeout { fail "Deleted all breakpoints" }
}
#
# test break at function
#
send "break main\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function" }
-re ".*$prompt $" { fail "breakpoint function" }
timeout { fail "(timeout) breakpoint function" }
}
#
# test break at function in file
#
send "break $srcfile:factorial\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function in file" }
-re ".*$prompt $" { fail "breakpoint function in file" }
timeout { fail "(timeout) breakpoint function in file" }
}
#
# test break at line number
#
send "break 60\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "breakpoint line number" }
-re ".*$prompt $" { fail "breakpoint line number" }
timeout { fail "(timeout) breakpoint line number" }
}
#
# test duplicate breakpoint
#
send "break 60\n"
expect {
-re "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60.*$prompt $"\
{ pass "breakpoint duplicate" }
-re ".*$prompt $" { fail "breakpoint duplicate" }
timeout { fail "(timeout) breakpoint duplicate" }
}
#
# test break at line number in file
#
send "break $srcfile:66\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "breakpoint line number in file" }
-re ".*$prompt $" { fail "breakpoint line number in file" }
timeout { fail "(timeout) breakpoint line number in file" }
}
#
# check to see what breakpoints are set
#
send "info break\n"
expect {
-re "Num Type\[ \]+Disp Enb Address\[ \]+What.*
\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:56.*
\[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:72.*
\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:66.*$prompt $" { pass "breakpoint info" }
-re ".*$prompt $" { fail "breakpoint info" }
timeout { fail "(timeout) breakpoint info" }
}
# FIXME: The rest of this test doesn't work with anything that can't
# handle arguments.
if [istarget "mips-idt-*"] then {
return
}
#
# run until the breakpoint at main is hit
#
if [istarget "*-*-vxworks"] then {
send "run vxmain \"2\"\n"
set timeout 120
} else {
send "run 2\n"
}
expect {
-re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.* \{.*$prompt $"\
{ pass "run until function breakpoint" }
-re ".*$prompt $" { fail "run until function breakpoint" }
timeout { fail "(timeout) run until function breakpoint" }
}
#
# run until the breakpoint at a line number
#
send "continue\n"
expect {
-re "continue.*Continuing..*Breakpoint \[0-9\]+, main .argc.*argv.* at .*$srcfile:60.*
60\[\t ]+printf.*factorial.*$prompt $" { pass "run until breakpoint set at a line number" }
-re ".*$prompt $" { fail "run until breakpoint set at a line number" }
timeout { fail "(timeout) run until breakpoint set at a line number" }
}
#
# Run until the breakpoint set in a function in a file
#
send "continue\n"
expect {
-re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=2. at .*$srcfile:72.*72\[\t ]+if .value > 1. \{.*$prompt $"\
{ send "continue\n"
expect {
-re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=1. at .*$srcfile:72.*72\[\t ]+if .value > 1.*$prompt $" { pass "run until file:function breakpoint" }
-re ".*$prompt $" { fail "run until file:function breakpoint" }
timeout { fail "(timeout) run until file:function breakpoint" }
}
}
-re ".*$prompt $" { fail "run until file:function breakpoint" }
timeout { fail "(timeout) run until file:function breakpoint" }
}
#
# run until the file:function breakpoint at a line number in a file
#
send "continue\n"
expect {
-re "continue.*Continuing..*Breakpoint \[0-9\]+, main .*argc.*argv.* at .*$srcfile:66.*66\[\t ]+return 0;.*$prompt $" { pass "run until file:linenum breakpoint" }
-re ".*$prompt $" { fail "run until file:linenum breakpoint" }
timeout { fail "(timeout) run until file:linenum breakpoint" }
}
#
# delete all breakpoints so we can start over, course this can be a test too
#
send "delete breakpoints\n"
expect {
-re "Delete all breakpoints.*y or n.*$" {
send "y\n"
expect {
-re ".*$prompt $" {
send "info breakpoints\n"
expect {
-re "No breakpoints or watchpoints..*$prompt $" {
pass "Deleted all breakpoints"
}
-re ".*$prompt $" { fail "Deleted all breakpoints" }
timeout { fail "Deleted all breakpoints" }
}
}
timeout { fail "Deleted all breakpoints" }
}
}
-re ".*$prompt $" { fail "Deleted all breakpoints" }
timeout { fail "Deleted all breakpoints" }
}
#
# test temporary breakpoint at function
#
send "tbreak main\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
pass "Temporary breakpoint function"
}
-re ".*$prompt $" {
pass "Temporary breakpoint function"
}
timeout {
fail "(timeout) breakpoint function"
}
}
#
# test break at function in file
#
send "tbreak $srcfile:factorial\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
pass "Temporary breakpoint function in file"
}
-re ".*$prompt $" {
pass "Temporary breakpoint function in file"
}
timeout {
fail "(timeout) breakpoint function in file"
}
}
#
# test break at line number
#
send "tbreak 60\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "Temporary breakpoint line number" }
-re ".*$prompt $" { pass "Temporary breakpoint line number" }
timeout { fail "(timeout) breakpoint line number" }
}
#
# test break at line number in file
#
send "tbreak $srcfile:66\n"
expect {
-re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "Temporary breakpoint line number in file" }
-re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
timeout { fail "(timeout) breakpoint line number in file" }
}
#
# check to see what breakpoints are set (temporary this time)
#
send "info break\n"
expect {
-re "Num Type.*Disp Enb Address.*What.*
\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:56.*
\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:72.*
\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:60.*
\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:66.*$prompt $" {
pass "Temporary breakpoint info"
}
-re ".*$prompt $" { fail "Temporary breakpoint info" }
timeout { fail "(timeout) Temporary breakpoint info" }
}
proc test_clear_command {} {
gdb_test "break main" "Breakpoint.*at"
gdb_test "break main" "Breakpoint.*at"
# We don't test that it deletes the correct breakpoints. We do at
# least test that it deletes more than one breakpoint.
gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+}
}
#
# Test "next" over recursive function call.
#
proc test_next_with_recursion {} {
global prompt
global decimal
# FIXME: should be using runto
send "kill\n"
expect {
-re ".*Kill the program being debugged.*y or n. $" {
send "y\n"
exp_continue
}
-re ".*$prompt $" {}
timeout { fail "killing inferior" ; return }
}
delete_breakpoints
send "break factorial\n"
expect {
-re "Breakpoint $decimal at .*$prompt" {}
timeout { fail "break at factorial" ; return }
}
# Run until we call factorial with 6
if [istarget "*-*-vxworks"] then {
send "run vxmain \"6\"\n"
} else {
send "run 6\n"
}
expect {
-re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
timeout { fail "run to factorial(6)" ; return }
}
# Continue until we call factorial recursively with 5.
send "continue\n"
expect {
-re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
timeout { fail "continue to factorial(5)" ; return }
}
# Do a backtrace just to confirm how many levels deep we are.
set result [gdb_test "backtrace" \
"#0\[ \t\]+ factorial .value=5." \
"backtrace from factorial(5)"]
if $result!=0 then { return }
# Now a "next" should position us at the recursive call, which
# we will be performing with 4.
send "next\n"
expect {
-re ".* factorial .value - 1.;.*$prompt $" {}
timeout { fail "next to recursive call (timeout)" ; return }
}
# Disable the breakpoint at the entry to factorial by deleting them all.
# The "next" should run until we return to the next line from this
# recursive call to factorial with 4.
# Buggy versions of gdb will stop instead at the innermost frame on
# the line where we are trying to "next" to.
delete_breakpoints
send "next\n"
expect {
-re "return .value.;.*$prompt $" {
# Note that the correct behavior is for GDB to *not* print the
# frame.
pass "next over recursive call"
}
-re ".*$prompt $" {
fail "next over recursive call" ; return
}
timeout { fail "next over recursive call (timeout)" ; return }
}
# OK, we should be back in the same stack frame we started from.
# Do a backtrace just to confirm.
set result [gdb_test "backtrace" \
"#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6." \
"backtrace from factorial(5)"]
if $result!=0 then { return }
# Continue until we exit. Should not stop again.
gdb_test "continue" "Continuing.\r\n720"\
"continue until exit in recursive next test"
}
test_clear_command
test_next_with_recursion
# Reset the default arguments for VxWorks
if [istarget "*-*-vxworks"] then {
set timeout 10
send "set args main\n"
expect -re ".*$prompt $" {}
}
if [istarget "a29k-*-udi"] then {
# FIXME: If PR 2415 is fixed, this is not needed.
gdb_target_udi
}
|