OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [testsuite/] [gdb.base/] [watchpoint.exp] - Blame information for rev 330

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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