summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/ena-dis-br.exp
blob: f7be9868e8985089245cdd354328595958b23120 (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
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#   Copyright (C) 1997, 1998, 1999 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

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

if $tracelevel then {
	strace $tracelevel
	}

global usestubs

#
# test running programs
#
set prms_id 0
set bug_id 0

set testfile "break"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

proc rerun_to_main {} {
  global gdb_prompt

  if [target_info exists use_gdb_stub] {
    gdb_run_cmd
    gdb_expect {
      -re ".*Breakpoint .*main .*$gdb_prompt $"\
	      {pass "rerun to main" ; return 0}
      -re "$gdb_prompt $"\
	      {fail "rerun to main" ; return 0}
      timeout {fail "(timeout) rerun to main" ; return 0}
    }
  } else {
    send_gdb "run\n"
    gdb_expect {
      -re "Starting program.*$gdb_prompt $"\
	      {pass "rerun to main" ; return 0}
      -re "$gdb_prompt $"\
	      {fail "rerun to main" ; return 0}
      timeout {fail "(timeout) rerun to main" ; return 0}
    }
  }
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

if ![runto_main] then { fail "enable/disable break tests suppressed" }

# Verify that we can set a breakpoint (the location is irrelevant),
# then enable it (yes, it's already enabled by default), then hit it.
#
send_gdb "break marker1\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
          {pass "break marker1"}
  -re "$gdb_prompt $"\
          {fail "break marker1"}
  timeout {fail "(timeout) break marker1"}
}

send_gdb "enable $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "enable break marker1"}
  timeout {fail "(timeout) enable break marker1"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*$gdb_prompt $"\
          {pass "info break marker1"}
  -re "$gdb_prompt $"\
          {fail "info break marker1"}
  timeout {fail "(timeout) info break marker1"}
}

send_gdb "continue\n"
gdb_expect {
  -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
          {pass "continue to break marker1"}
  -re "$gdb_prompt $"\
          {fail "continue to break marker1"}
  timeout {fail "(timeout) continue to break marker1"}
}

send_gdb "delete $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "delete break marker1"}
  timeout {fail "(timeout) delete break marker1"}
}

# Verify that we can set a breakpoint to be self-disabling after
# the first time it triggers.
#
send_gdb "break marker2\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\
          {pass "break marker2"}
  -re "$gdb_prompt $"\
          {fail "break marker2"}
  timeout {fail "(timeout) break marker2"}
}

send_gdb "enable once $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "enable once break marker2"}
  timeout {fail "(timeout) enable once break marker2"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*$gdb_prompt $"\
          {pass "info auto-disabled break marker2"}
  -re "$gdb_prompt $"\
          {fail "info auto-disabled break marker2"}
  timeout {fail "(timeout) info auto-disabled break marker2"}
}

send_gdb "continue\n"
gdb_expect {
  -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $"\
          {pass "continue to auto-disabled break marker2"}
  -re "$gdb_prompt $"\
          {fail "continue to auto-disabled break marker2"}
  timeout {fail "(timeout) continue to auto-disabled break marker2"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*$gdb_prompt $"\
          {pass "info auto-disabled break marker2"}
  -re "$gdb_prompt $"\
          {fail "info auto-disabled break marker2"}
  timeout {fail "(timeout) info auto-disabled break marker2"}
}

# Verify that we don't stop at a disabled breakpoint.
#
gdb_continue_to_end "no stop"
rerun_to_main
gdb_continue_to_end "no stop at auto-disabled break marker2"

# Verify that we can set a breakpoint to be self-deleting after
# the first time it triggers.
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

send_gdb "break marker3\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line (45|50).*$gdb_prompt $"\
          {pass "break marker3"}
  -re "$gdb_prompt $"\
          {fail "break marker3"}
  timeout {fail "(timeout) break marker3"}
}

send_gdb "enable del $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "enable del break marker3"}
  timeout {fail "(timeout) enable del break marker3"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*$gdb_prompt $"\
          {pass "info auto-deleted break marker2"}
  -re "$gdb_prompt $"\
          {fail "info auto-deleted break marker2"}
  timeout {fail "(timeout) info auto-deleted break marker2"}
}

send_gdb "continue\n"
gdb_expect {
  -re ".*marker3 .*:(45|50).*$gdb_prompt $"\
          {pass "continue to auto-deleted break marker3"}
  -re "Breakpoint \[0-9\]*, marker3.*$gdb_prompt $"\
          {fail "continue to auto-deleted break marker3"}
  -re "$gdb_prompt $"\
          {fail "continue to auto-deleted break marker3"}
  timeout {fail "(timeout) continue to break marker3"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re ".*No breakpoint or watchpoint number.*$gdb_prompt $"\
          {pass "info auto-deleted break marker3"}
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\].*$gdb_prompt $"\
          {fail "info auto-deleted break marker3"}
  -re "$gdb_prompt $"\
          {fail "info auto-deleted break marker3"}
  timeout {fail "(timeout) info auto-deleted break marker3"}
}

# Verify that we can set a breakpoint and manually disable it (we've
# already proven that disabled bp's don't trigger).
#
send_gdb "break marker4\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line (46|51).*$gdb_prompt $"\
          {pass "break marker4"}
  -re "$gdb_prompt $"\
          {fail "break marker4"}
  timeout {fail "(timeout) break marker4"}
}

send_gdb "disable $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "disable break marker4"}
  timeout {fail "(timeout) disable break marker4"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*$gdb_prompt $"\
          {pass "info break marker4"}
  -re "$gdb_prompt $"\
          {fail "info break marker4"}
  timeout {fail "(timeout) info break marker4"}
}

# Verify that we can set a breakpoint with an ignore count N, which
# should cause the next N triggers of the bp to be ignored.  (This is
# a flavor of enablement/disablement, after all.)
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

send_gdb "break marker1\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
          {pass "break marker1"}
  -re "$gdb_prompt $"\
          {fail "break marker1"}
  timeout {fail "(timeout) break marker1"}
}

# Verify that an ignore of a non-existent breakpoint is gracefully
# handled.
#
send_gdb "ignore 999 2\n"
gdb_expect {
  -re "No breakpoint number 999..*$gdb_prompt $"\
          {pass "ignore non-existent break"}
  -re "$gdb_prompt $"\
          {fail "ignore non-existent break"}
  timeout {fail "(timeout) ignore non-existent break"}
}

# Verify that a missing ignore count is gracefully handled.
#
send_gdb "ignore $expect_out(1,string) \n"
gdb_expect {
  -re "Second argument .specified ignore-count. is missing..*$gdb_prompt $"\
          {pass "ignore break with missing ignore count"}
  -re "$gdb_prompt $"\
          {fail "ignore break with missing ignore count"}
  timeout {fail "(timeout) ignore break with missing ignore count"}
}

# Verify that a negative or zero ignore count is handled gracefully
# (they both are treated the same).
#
send_gdb "ignore $expect_out(1,string) -1\n"
gdb_expect {
  -re "Will stop next time breakpoint \[0-9\]* is reached..*$gdb_prompt $"\
          {pass "ignore break marker1 -1"}
  -re "$gdb_prompt $"\
          {fail "ignore break marker1 -1"}
  timeout {fail "(timeout) ignore break marker1 -1"}
}

send_gdb "ignore $expect_out(1,string) 0\n"
gdb_expect {
  -re "Will stop next time breakpoint \[0-9\]* is reached..*$gdb_prompt $"\
          {pass "ignore break marker1 0"}
  -re "$gdb_prompt $"\
          {fail "ignore break marker1 0"}
  timeout {fail "(timeout) ignore break marker1 0"}
}

send_gdb "ignore $expect_out(1,string) 1\n"
gdb_expect {
  -re "Will ignore next crossing of breakpoint \[0-9\]*.*$gdb_prompt $"\
          {pass "ignore break marker1"}
  -re "$gdb_prompt $"\
          {fail "ignore break marker1"}
  timeout {fail "(timeout) ignore break marker1"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*$gdb_prompt $"\
          {pass "info ignored break marker1"}
  -re "$gdb_prompt $"\
          {fail "info ignored break marker1"}
  timeout {fail "(timeout) info ignored break marker1"}
}

gdb_continue_to_end "no stop at ignored break marker1"
rerun_to_main

send_gdb "continue\n"
gdb_expect {
  -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
          {pass "continue to break marker1"}
  -re "$gdb_prompt $"\
          {fail "continue to break marker1"}
  timeout {fail "(timeout) continue to break marker1"}
}

# Verify that we can specify both an ignore count and an auto-delete.
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

send_gdb "break marker1\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
          {pass "break marker1"}
  -re "$gdb_prompt $"\
          {fail "break marker1"}
  timeout {fail "(timeout) break marker1"}
}

send_gdb "ignore $expect_out(1,string) 1\n"
gdb_expect {
  -re "Will ignore next crossing of breakpoint \[0-9\]*.*$gdb_prompt $"\
          {pass "ignore break marker1"}
  -re "$gdb_prompt $"\
          {fail "ignore break marker1"}
  timeout {fail "(timeout) ignore break marker1"}
}

send_gdb "enable del $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "enable del break marker1"}
  timeout {fail "(timeout) enable del break marker1"}
}

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*$gdb_prompt $"\
          {pass "info break marker1"}
  -re "$gdb_prompt $"\
          {fail "info break marker1"}
  timeout {fail "(timeout) info break marker2"}
}

gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
rerun_to_main

send_gdb "continue\n"
gdb_expect {
  -re ".*marker1 .*:4\[38\].*$gdb_prompt $"\
          {pass "continue to ignored & auto-deleted break marker1"}
  -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $"\
          {fail "continue to ignored & auto-deleted break marker1"}
  -re "$gdb_prompt $"\
          {fail "continue to ignored & auto-deleted break marker1"}
  timeout {fail "(timeout) continue to ignored & auto-deleted break marker1"}
}

# Verify that a disabled breakpoint's ignore count isn't updated when
# the bp is encountered.
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

send_gdb "break marker1\n"
gdb_expect {
  -re "Breakpoint (\[0-9\]*) at .*, line 4\[38\].*$gdb_prompt $"\
          {pass "break marker1"}
  -re "$gdb_prompt $"\
          {fail "break marker1"}
  timeout {fail "(timeout) break marker1"}
}

send_gdb "ignore $expect_out(1,string) 10\n"
gdb_expect {
  -re "Will ignore next 10 crossings of breakpoint \[0-9\]*.*$gdb_prompt $"\
          {pass "ignore break marker1"}
  -re "$gdb_prompt $"\
          {fail "ignore break marker1"}
  timeout {fail "(timeout) ignore break marker1"}
}

send_gdb "disable $expect_out(1,string)\n"
gdb_expect {
  -re "$gdb_prompt $"\
          {pass "disable break marker1"}
  timeout {fail "(timeout) disable break marker1"}
}

gdb_continue_to_end "no stop at ignored & disabled break marker1"
rerun_to_main

send_gdb "info break $expect_out(1,string)\n"
gdb_expect {
  -re "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*$gdb_prompt $"\
          {pass "info ignored & disabled break marker1"}
  -re "$gdb_prompt $"\
          {fail "info ignored & disabled break marker1"}
  timeout {fail "(timeout) info ignored & disabled break marker1"}
}

# Verify that GDB correctly handles the "continue" command with an argument,
# which is an ignore count to set on the currently stopped-at breakpoint.
# (Also verify that GDB gracefully handles the case where the inferior
# isn't stopped at a breakpoint.)
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

send_gdb "break 79\n"
gdb_expect {
  -re "Breakpoint \[0-9\]*.*, line 79.*$gdb_prompt $"\
          {pass "prepare to continue with ignore count"}
  -re "$gdb_prompt $"\
          {fail "prepare to continue with ignore count"}
  timeout {fail "(timeout) prepare to continue with ignore count"}
}
send_gdb "continue 2\n"
gdb_expect {
  -re "Will ignore next crossing of breakpoint \[0-9\]*.  Continuing..*$gdb_prompt $"\
          {pass "continue with ignore count"}
  -re "$gdb_prompt $"\
          {fail "continue with ignore count"}
  timeout {fail "(timeout) continue with ignore count"}
}

send_gdb "next\n"
gdb_expect {
  -re ".*81\[ \t\]*marker1.*$gdb_prompt $"\
          {pass "step after continue with ignore count"}
  -re "$gdb_prompt $"\
          {fail "step after continue with ignore count"}
  timeout {fail "(timeout) step after continue with ignore count"}
}

# ??rehrauer: Huh.  This appears to be an actual bug.  (No big
# surprise, since this feature hasn't been tested...)  Looks like
# GDB is currently trying to set the ignore count of bp # -1!
#
setup_xfail hppa_*_*
send_gdb "continue 2\n"
gdb_expect {
  -re "Not stopped at any breakpoint; argument ignored..*$gdb_prompt $"\
          {pass "continue with ignore count, not stopped at bpt"}
  -re "No breakpoint number -1.*$gdb_prompt $"\
          {xfail "(DTS'd) continue with ignore count, not stopped at bpt"}
  -re "$gdb_prompt $"\
          {fail "continue with ignore count, not stopped at bpt"}
  timeout {fail "(timeout) step after continue with ignore count, not stopped at bpt"}
}

gdb_exit
return 0