OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [watchpoint.exp] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
# Copyright (C) 1992, 1994, 1997, 1998 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 2 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, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-gdb@prep.ai.mit.edu
19
 
20
# This file was written by Fred Fish. (fnf@cygnus.com)
21
 
22
if $tracelevel then {
23
    strace $tracelevel
24
}
25
 
26
set prms_id 0
27
set bug_id 0
28
 
29
set testfile "watchpoint"
30
set srcfile ${testfile}.c
31
set binfile ${objdir}/${subdir}/${testfile}
32
 
33
set wp_set 1
34
 
35
if [get_compiler_info ${binfile}] {
36
    return -1
37
}
38
 
39
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41
}
42
 
43
# Prepare for watchpoint tests by setting up two breakpoints and one
44
# watchpoint.
45
#
46
# We use breakpoints at marker functions to get past all the startup code,
47
# so we can get to the watchpoints in a reasonable amount of time from a
48
# known starting point.
49
#
50
# For simplicity, so we always know how to reference specific breakpoints or
51
# watchpoints by number, we expect a particular ordering and numbering of
52
# each in the combined breakpoint/watchpoint table, as follows:
53
#
54
#       Number          What            Where
55
#       1               Breakpoint      marker1()
56
#       2               Breakpoint      marker2()
57
#       3               Watchpoint      ival3
58
 
59
proc initialize {} {
60
    global gdb_prompt
61
    global hex
62
    global decimal
63
    global srcfile
64
    global wp_set
65
 
66
    if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
67
      return 0;
68
    }
69
 
70
 
71
    if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
72
      return 0;
73
    }
74
 
75
 
76
    if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
77
      return 0;
78
    }
79
 
80
 
81
    # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
82
    # before running can cause the inferior to croak on HP-UX 11.0 for
83
    # reasons yet unknown, we've disabled the ability to set watches
84
    # without a running inferior.  Verify the restriction.
85
    #
86
    send_gdb "watch ival3\n"
87
    gdb_expect {
88
        -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
89
            pass "set watchpoint on ival3"
90
        }
91
        -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
92
            pass "set watchpoint on ival3"
93
            set wp_set 0
94
            return 1
95
        }
96
        timeout {
97
            fail "(timeout) set watchpoint on ival3"
98
            return 0
99
        }
100
    }
101
 
102
    # "info watch" is the same as "info break"
103
 
104
    if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
105
      return 0;
106
    }
107
 
108
 
109
    # After installing the watchpoint, we disable it until we are ready
110
    # to use it.  This allows the test program to run at full speed until
111
    # we get to the first marker function.
112
 
113
    if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
114
      return 0;
115
    }
116
 
117
 
118
    return 1
119
}
120
 
121
#
122
# Test simple watchpoint.
123
#
124
 
125
proc test_simple_watchpoint {} {
126
    global gdb_prompt
127
    global hex
128
    global decimal
129
    global wp_set
130
 
131
    # Ensure that the watchpoint is disabled when we startup.
132
 
133
    if { $wp_set } {
134
        if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
135
            return 0;
136
        }
137
    }
138
 
139
 
140
    # Run until we get to the first marker function.
141
 
142
    gdb_run_cmd
143
    set timeout 600
144
    gdb_expect {
145
        -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
146
            pass "run to marker1 in test_simple_watchpoint"
147
        }
148
        -re ".*$gdb_prompt $" {
149
            fail "run to marker1 in test_simple_watchpoint"
150
            return
151
        }
152
        timeout {
153
            fail "run to marker1 in test_simple_watchpoint (timeout)"
154
            return
155
        }
156
    }
157
 
158
    if { !$wp_set } {
159
        # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
160
        # before running can cause the inferior to croak on HP-UX 11.0
161
        # for reasons yet unknown, we've disabled the ability to set
162
        # watches without a running inferior.  The following testpoints used
163
        # to be in [initialize].
164
        #
165
        send_gdb "watch ival3\n"
166
        gdb_expect {
167
            -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" {
168
                pass "set watchpoint on ival3"
169
            }
170
            -re ".*$gdb_prompt $" { fail "set watchpoint on ival3"  }
171
            timeout { fail "set watchpoint on ival3 (timeout)"  }
172
        }
173
 
174
        set wp_set 1
175
 
176
        # "info watch" is the same as "info break"
177
 
178
        send_gdb "info watch\n"
179
        gdb_expect {
180
            -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
181
                pass "watchpoint found in watchpoint/breakpoint table"
182
            }
183
            -re ".*$gdb_prompt $" {
184
                fail "watchpoint found in watchpoint/breakpoint table"
185
            }
186
            timeout {
187
               fail "watchpoint found in watchpoint/breakpoint table"
188
            }
189
        }
190
 
191
        # After installing the watchpoint, we disable it until we are ready
192
        # to use it.  This allows the test program to run at full speed until
193
        # we get to the first marker function.
194
 
195
        send_gdb "disable 3\n"
196
        gdb_expect {
197
            -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
198
            -re ".*$gdb_prompt $" { fail "disable watchpoint"  }
199
            timeout { fail "disable watchpoint (timeout)"  }
200
        }
201
    }
202
 
203
    # After reaching the marker function, enable the watchpoint.
204
 
205
    if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
206
      return ;
207
    }
208
 
209
 
210
    gdb_test "break func1" "Breakpoint.*at.*"
211
    gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
212
 
213
    gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
214
        "continue to breakpoint at func1"
215
 
216
    # Continue until the first change, from -1 to 0
217
 
218
    send_gdb "cont\n"
219
    gdb_expect {
220
        -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
221
            pass "watchpoint hit, first time"
222
        }
223
        -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
224
            setup_xfail "m68*-*-*" 2597
225
            fail "thought it hit breakpoint at func1 twice"
226
            gdb_test "delete \$func1_breakpoint_number" ""
227
            gdb_test "continue" "\
228
Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
229
                "watchpoint hit, first time"
230
        }
231
        -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
232
        timeout { fail "watchpoint hit, first time (timeout)" ; return }
233
        eof { fail "watchpoint hit, first time (eof)" ; return }
234
    }
235
 
236
    # Check that the hit count is reported correctly
237
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
238
 
239
    gdb_test "delete \$func1_breakpoint_number" ""
240
 
241
    # Continue until the next change, from 0 to 1.
242
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
243
 
244
    # Check that the hit count is reported correctly
245
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
246
 
247
    # Continue until the next change, from 1 to 2.
248
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
249
 
250
    # Check that the hit count is reported correctly
251
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "Watchpoint hit count is 3"
252
 
253
    # Continue until the next change, from 2 to 3.
254
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
255
 
256
    # Check that the hit count is reported correctly
257
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
258
 
259
    # Continue until the next change, from 3 to 4.
260
    # Note that this one is outside the loop.
261
 
262
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
263
 
264
    # Check that the hit count is reported correctly
265
    gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
266
 
267
    # Continue until we hit the finishing marker function.
268
    # Make sure we hit no more watchpoints.
269
 
270
    gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
271
        "continue to marker2"
272
 
273
    # Disable the watchpoint so we run at full speed until we exit.
274
 
275
    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
276
      return ;
277
    }
278
 
279
 
280
    # Run until process exits.
281
 
282
    if [target_info exists gdb,noresults] { return }
283
 
284
    gdb_continue_to_end "continue to exit in test_simple_watchpoint"
285
}
286
 
287
# Test disabling watchpoints.
288
 
289
proc test_disabling_watchpoints {} {
290
    global gdb_prompt
291
    global binfile
292
    global srcfile
293
    global decimal
294
    global hex
295
 
296
    # "info watch" is the same as "info break"
297
    gdb_test "info watch" "\[0-9\]+\[ \]*breakpoint.*marker1.*\r\n\[0-9\]+\[ \]*breakpoint.*marker2.*\r\n\[0-9]+\[ \]*.*watchpoint.*ival3\r\n\.*\[0-9\]+ times.*" "watchpoints found in watchpoint/breakpoint table"
298
 
299
    # Ensure that the watchpoint is disabled when we startup.
300
 
301
    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
302
      return 0;
303
    }
304
 
305
 
306
    # Run until we get to the first marker function.
307
 
308
    gdb_run_cmd
309
    set timeout 600
310
    gdb_expect {
311
        -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
312
            pass "run to marker1 in test_disabling_watchpoints"
313
        }
314
        -re ".*$gdb_prompt $" {
315
            fail "run to marker1 in test_disabling_watchpoints"
316
            return
317
        }
318
        timeout {
319
            fail "run to marker1 in test_disabling_watchpoints (timeout)"
320
            return
321
        }
322
    }
323
 
324
    # After reaching the marker function, enable the watchpoint.
325
 
326
    if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
327
      return ;
328
    }
329
 
330
 
331
    # Continue until the first change, from -1 to 0
332
    # Don't check the old value, because on VxWorks the variable value
333
    # will not have been reinitialized.
334
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
335
 
336
    # Continue until the next change, from 0 to 1.
337
    gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, second time"
338
 
339
    # Disable the watchpoint but leave breakpoints
340
 
341
    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
342
      return 0;
343
    }
344
 
345
 
346
    # Check watchpoint list, looking for the entry that confirms the
347
    # watchpoint is disabled.
348
    gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
349
 
350
    # Continue until we hit the finishing marker function.
351
    # Make sure we hit no more watchpoints.
352
    gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
353
        "disabled watchpoint skipped"
354
 
355
    if [target_info exists gdb,noresults] { return }
356
 
357
    gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
358
}
359
 
360
# Test stepping and other mundane operations with watchpoints enabled
361
proc test_stepping {} {
362
    global gdb_prompt
363
 
364
    if [runto marker1] then {
365
        gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
366
 
367
        # Well, let's not be too mundane.  It should be a *bit* of a challenge
368
        gdb_test "break func2 if 0" "Breakpoint.*at.*"
369
        gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
370
 
371
        # The problem is that GDB confuses stepping through the call
372
        # dummy with hitting the breakpoint at the end of the call dummy.
373
        # Will be fixed once all architectures define
374
        # CALL_DUMMY_BREAKPOINT_OFFSET.
375
        setup_xfail "*-*-*"
376
        # This doesn't occur if the call dummy starts with a call,
377
        # because we are out of the dummy by the first time the inferior
378
        # stops.
379
        clear_xfail "d10v*-*-*"
380
        clear_xfail "m68*-*-*"
381
        clear_xfail "i*86*-*-*"
382
        clear_xfail "vax-*-*"
383
        # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
384
        clear_xfail "alpha-*-*"
385
        clear_xfail "mips*-*-*"
386
        clear_xfail "sparc-*-*"
387
        clear_xfail "hppa*-*-*bsd*"
388
        # It works with the generic inferior function calling code too.
389
        clear_xfail "mn10200*-*-*"
390
        clear_xfail "mn10300*-*-*"
391
        # The following architectures define CALL_DUMMY_HAS_COMPLETED.
392
        clear_xfail "hppa*-*-*hpux*"
393
        gdb_test "p func1 ()" "= 73" \
394
        "calling function with watchpoint enabled"
395
 
396
        #
397
        # "finish" brings us back to main.
398
        # On some targets (e.g. alpha) gdb will stop from the finish in midline
399
        # of the marker1 call. This is due to register restoring code on
400
        # the alpha and might be caused by stack adjustment instructions
401
        # on other targets. In this case we will step once more.
402
        #
403
 
404
        send_gdb "finish\n"
405
        gdb_expect {
406
            -re "Run.*exit from.*marker1.* at" {
407
                pass "finish from marker1"
408
            }
409
            default { fail "finish from marker1 (timeout)" ; return }
410
        }
411
 
412
        gdb_expect {
413
            -re "marker1 \\(\\);.*$gdb_prompt $" {
414
                send_gdb "step\n"
415
                exp_continue
416
            }
417
            -re "func1 \\(\\);.*$gdb_prompt $" {
418
                pass "back at main from marker1"
419
            }
420
            -re ".*$gdb_prompt $" {
421
                fail "back at main from marker1"
422
            }
423
            default { fail "back at main from marker1 (timeout)" ; return }
424
        }
425
 
426
        gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
427
 
428
        # Now test that "until" works.  It's a bit tricky to test
429
        # "until", because compilers don't always arrange the code
430
        # exactly the same way, and we might get slightly different
431
        # sequences of statements.  But the following should be true
432
        # (if not it is a compiler or a debugger bug): The user who
433
        # does "until" at every statement of a loop should end up
434
        # stepping through the loop once, and the debugger should not
435
        # stop for any of the remaining iterations.
436
 
437
        gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
438
        gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
439
        send_gdb "until\n"
440
        gdb_expect {
441
            -re "(for \\(count = 0|\}).*$gdb_prompt $" {
442
                gdb_test "until" "ival1 = count; /. Outside loop ./" \
443
                    "until out of loop"
444
            }
445
            -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
446
                pass "until out of loop"
447
            }
448
            -re ".*$gdb_prompt $" {
449
                fail "until out of loop"
450
            }
451
            default { fail "until out of loop (timeout)" ; return }
452
        }
453
 
454
        gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
455
    }
456
}
457
 
458
# Test stepping and other mundane operations with watchpoints enabled
459
proc test_watchpoint_triggered_in_syscall {} {
460
    global gdb_prompt
461
 
462
    if [target_info exists gdb,noinferiorio] {
463
        verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
464
        return
465
    }
466
    # Run until we get to the first marker function.
467
    set x 0
468
    set y 0
469
    set testname "Watch buffer passed to read syscall"
470
    if [runto marker2] then {
471
        gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
472
        gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
473
        gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
474
        gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
475
        gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
476
        gdb_test "break marker4" ".*Breakpoint.*"
477
 
478
        gdb_test "set doread = 1" ""
479
 
480
        # If we send_gdb "123\n" before gdb has switched the tty, then it goes
481
        # to gdb, not the inferior, and we lose.  So that is why we have
482
        # watchpoint.c prompt us, so we can wait for that prompt.
483
        send_gdb "continue\n";
484
        gdb_expect {
485
            -re "Continuing\\.\r\ntype stuff for buf now:" {
486
                pass "continue to read"
487
            }
488
            default {
489
                fail "continue to read";
490
                return ;
491
            }
492
        }
493
 
494
        send_gdb "123\n"
495
        gdb_expect {
496
            -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
497
            -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
498
            -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
499
            -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
500
            -re ".*$gdb_prompt $" { pass "sent 123" }
501
            timeout { fail "sent 123 (timeout)" }
502
        }
503
 
504
        # Examine the values in buf to see how many watchpoints we
505
        # should have printed.
506
        send_gdb "print buf\[0\]\n"
507
        gdb_expect {
508
            -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
509
            -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
510
            -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
511
            default { fail "print buf\[0\]"}
512
        }
513
        send_gdb "print buf\[1\]\n"
514
        gdb_expect {
515
            -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
516
            -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
517
            -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
518
            default { fail "print buf\[1\]"}
519
        }
520
        send_gdb "print buf\[2\]\n"
521
        gdb_expect {
522
            -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
523
            -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
524
            -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
525
            default { fail "print buf\[2\]"}
526
        }
527
        send_gdb "print buf\[3\]\n"
528
        gdb_expect {
529
            -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
530
            -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
531
            -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
532
            default { fail "print buf\[3\]" }
533
        }
534
 
535
        # Did we find what we were looking for?  If not, flunk it.
536
        if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
537
 
538
        # Continue until we hit the finishing marker function.
539
        # Make sure we hit no more watchpoints.
540
        gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
541
            "continue to marker4"
542
 
543
        # Disable everything so we can finish the program at full speed
544
        gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
545
 
546
        if [target_info exists gdb,noresults] { return }
547
 
548
        gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
549
    }
550
}
551
 
552
# Do a simple test of of watching through a pointer when the pointer
553
# itself changes.  Should add some more complicated stuff here.
554
 
555
proc test_complex_watchpoint {} {
556
    global gdb_prompt
557
 
558
    if [runto marker4] then {
559
        gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
560
        gdb_test "break marker5" ".*Breakpoint.*"
561
 
562
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
563
 
564
        # Continue until we hit the marker5 function.
565
        # Make sure we hit no more watchpoints.
566
 
567
        gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
568
            "did not trigger wrong watchpoint"
569
 
570
        # Test watches of things declared locally in a function.
571
        # In particular, test that a watch of stack-based things
572
        # is deleted when the stack-based things go out of scope.
573
        #
574
        gdb_test "disable" "" "disable in test_complex_watchpoint"
575
        gdb_test "break marker6" ".*Breakpoint.*"
576
        gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
577
            "continue to marker6"
578
        gdb_test "break func2" ".*Breakpoint.*"
579
        gdb_test "cont" "Continuing.*func2.*"
580
 
581
        # Test a watch of a single stack-based variable, whose scope
582
        # is the function we're now in.  This should auto-delete when
583
        # execution exits the scope of the watchpoint.
584
        #
585
        gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
586
        gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
587
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
588
 
589
        gdb_test "cont" "Continuing.*func2.*"
590
        # We should be in "func2" again now.  Test a watch of an
591
        # expression which includes both a stack-based local and
592
        # something whose scope is larger than this invocation
593
        # of "func2".  This should also auto-delete.
594
        #
595
        gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
596
                 "set partially local watch"
597
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
598
                 "trigger1 partially local watch"
599
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
600
                 "trigger2 partially local watch"
601
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
602
                 "self-delete partially local watch"
603
 
604
        # We should be in "func2" again now.  Test a watch of a
605
        # static (non-stack-based) local.  Since this has scope
606
        # across any invocations of "func2", it should not auto-
607
        # delete.
608
        #
609
        gdb_test "cont" "Continuing.*func2.*"
610
        gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
611
                 "set static local watch"
612
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
613
                 "trigger static local watch"
614
        gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
615
                 "continue after trigger static local watch"
616
        gdb_test "info break" ".*watchpoint.*static_b.*" \
617
                 "static local watch did not self-delete"
618
 
619
        # We should be in "recurser" now.  Test a watch of a stack-
620
        # based local.  Symbols mentioned in a watchpoint are bound
621
        # at watchpoint-creation.  Thus, a watch of a stack-based
622
        # local to a recursing function should be bound only to that
623
        # one invocation, and should not trigger for other invocations.
624
        #
625
        gdb_test "tbreak recurser" ".*Breakpoint.*"
626
        gdb_test "cont" "Continuing.*recurser.*"
627
        gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
628
                 "set local watch in recursive call"
629
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
630
                 "trigger local watch in recursive call"
631
        gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
632
                 "self-delete local watch in recursive call"
633
 
634
        # Disable everything so we can finish the program at full speed
635
        gdb_test "disable" "" "disable in test_complex_watchpoint"
636
 
637
        if [target_info exists gdb,noresults] { return }
638
 
639
        gdb_continue_to_end "continue to exit in test_complex_watchpoint"
640
    }
641
}
642
 
643
# Start with a fresh gdb.
644
 
645
gdb_exit
646
gdb_start
647
gdb_reinitialize_dir $srcdir/$subdir
648
gdb_load $binfile
649
set timeout 600
650
verbose "Timeout now 600 sec.\n"
651
 
652
if [initialize] then {
653
 
654
    test_simple_watchpoint
655
 
656
    # The IDT/sim monitor only has 8 (!) open files, of which it uses
657
    # 4 (!).  So we have to make sure one program exits before
658
    # starting another one.
659
    if [istarget "mips-idt-*"] then {
660
        gdb_exit
661
        gdb_start
662
        gdb_reinitialize_dir $srcdir/$subdir
663
        gdb_load $binfile
664
        initialize
665
    }
666
 
667
    test_disabling_watchpoints
668
 
669
    # See above.
670
    if [istarget "mips-idt-*"] then {
671
        gdb_exit
672
        gdb_start
673
        gdb_reinitialize_dir $srcdir/$subdir
674
        gdb_load $binfile
675
        initialize
676
    }
677
 
678
    if ![target_info exists gdb,cannot_call_functions] {
679
        test_stepping
680
 
681
        # See above.
682
        if [istarget "mips-idt-*"] then {
683
            gdb_exit
684
            gdb_start
685
            gdb_reinitialize_dir $srcdir/$subdir
686
            gdb_load $binfile
687
            initialize
688
        }
689
    }
690
 
691
    # Only enabled for some targets merely because it has not been tested
692
    # elsewhere.
693
    # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
694
    # breakpoint before stopping for the watchpoint.  I don't know why.
695
    if {[istarget "hppa*-*-*"]} then {
696
        test_watchpoint_triggered_in_syscall
697
    }
698
 
699
    # See above.
700
    if [istarget "mips-idt-*"] then {
701
        gdb_exit
702
        gdb_start
703
        gdb_reinitialize_dir $srcdir/$subdir
704
        gdb_load $binfile
705
        initialize
706
    }
707
 
708
    # Only enabled for some targets merely because it has not been tested
709
    # elsewhere.
710
    if {[istarget "hppa*-*-*"] || \
711
            [istarget "sparc*-*-sunos*"] || \
712
            [istarget "m32r-*-*"]} then {
713
        test_complex_watchpoint
714
    }
715
 
716
    # Verify that a user can force GDB to use "slow" watchpoints.
717
    # (This proves rather little on kernels that don't support
718
    # fast watchpoints, but still...)
719
    #
720
    if ![runto_main] then { fail "watch tests suppressed" }
721
 
722
    send_gdb "set can-use-hw-watchpoints 0\n"
723
    gdb_expect {
724
      -re "$gdb_prompt $"\
725
              {pass "disable fast watches"}
726
      timeout {fail "(timeout) disable fast watches"}
727
    }
728
    send_gdb "show can-use-hw-watchpoints\n"
729
    gdb_expect {
730
      -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
731
              {pass "show disable fast watches"}
732
      -re "$gdb_prompt $"\
733
              {fail "show disable fast watches"}
734
      timeout {fail "(timeout) show disable fast watches"}
735
    }
736
    send_gdb "watch ival3 if  count > 1\n"
737
    gdb_expect {
738
      -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
739
              {pass "set slow conditional watch"}
740
      -re "$gdb_prompt $"\
741
              {fail "set slow conditional watch"}
742
      timeout {fail "(timeout) set slow conditional watch"}
743
    }
744
    send_gdb "continue\n"
745
    gdb_expect {
746
      -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
747
              {pass "trigger slow conditional watch"}
748
      -re "$gdb_prompt $"\
749
              {fail "trigger slow conditional watch"}
750
      timeout {fail "(timeout) trigger slow conditional watch"}
751
    }
752
 
753
    # We've explicitly disabled hardware watches.  Verify that GDB
754
    #
755
    #
756
    send_gdb "rwatch ival3\n"
757
    gdb_expect {
758
      -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
759
              {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
760
      -re "$gdb_prompt $"\
761
              {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
762
      timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
763
    }
764
 
765
    # Read- and access watchpoints are unsupported on HP-UX.  Verify
766
    # that GDB gracefully responds to requests to create them.
767
    #
768
    if [istarget "hppa*-*-hpux*"] then {
769
      send_gdb "set can-use-hw-watchpoints 1\n"
770
      gdb_expect {
771
        -re "$gdb_prompt $"\
772
                {pass "enable fast watches"}
773
        timeout {fail "(timeout) enable fast watches"}
774
      }
775
      send_gdb "rwatch ival3\n"
776
      gdb_expect {
777
        -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
778
                {pass "read watches disallowed"}
779
        -re "$gdb_prompt $"\
780
                {fail "read watches disallowed"}
781
        timeout {fail "(timeout) read watches disallowed"}
782
      }
783
 
784
      send_gdb "awatch ival3\n"
785
      gdb_expect {
786
        -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
787
                {pass "access watches disallowed"}
788
        -re "$gdb_prompt $"\
789
                {fail "access watches disallowed"}
790
        timeout {fail "(timeout) access watches disallowed"}
791
      }
792
    }
793
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.