📄 watchpoint.exp
字号:
gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp" # Now test that "until" works. It's a bit tricky to test # "until", because compilers don't always arrange the code # exactly the same way, and we might get slightly different # sequences of statements. But the following should be true # (if not it is a compiler or a debugger bug): The user who # does "until" at every statement of a loop should end up # stepping through the loop once, and the debugger should not # stop for any of the remaining iterations. gdb_test "until" "ival1 = count.*" "until to ival1 assignment" gdb_test "until" "ival3 = count.*" "until to ival3 assignment" send_gdb "until\n" gdb_expect { -re "(for \\(count = 0|\}).*$gdb_prompt $" { gdb_test "until" "ival1 = count; /. Outside loop ./" \ "until out of loop" } -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" { pass "until out of loop" } -re ".*$gdb_prompt $" { fail "until out of loop" } default { fail "until out of loop (timeout)" ; return } } gdb_test "step" "ival2 = count.*" "step to ival2 assignment" }}# Test stepping and other mundane operations with watchpoints enabledproc test_watchpoint_triggered_in_syscall {} { global gdb_prompt # These tests won't work without printf support. if [gdb_skip_stdio_test "watchpoints triggered in syscall"] { return; } # Run until we get to the first marker function. set x 0 set y 0 set testname "Watch buffer passed to read syscall" if [runto marker2] then { gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]" gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]" gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]" gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]" gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]" gdb_test "break marker4" ".*Breakpoint.*" gdb_test "set doread = 1" "" # If we send_gdb "123\n" before gdb has switched the tty, then it goes # to gdb, not the inferior, and we lose. So that is why we have # watchpoint.c prompt us, so we can wait for that prompt. send_gdb "continue\n"; gdb_expect { -re "Continuing\\.\r\ntype stuff for buf now:" { pass "continue to read" } default { fail "continue to read"; return ; } } send_gdb "123\n" gdb_expect { -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } -re ".*$gdb_prompt $" { pass "sent 123" } timeout { fail "sent 123 (timeout)" } } # Examine the values in buf to see how many watchpoints we # should have printed. send_gdb "print buf\[0\]\n" gdb_expect { -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"} -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"} -re ".*$gdb_prompt $" { fail "print buf\[0\]"} default { fail "print buf\[0\]"} } send_gdb "print buf\[1\]\n" gdb_expect { -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"} -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"} -re ".*$gdb_prompt $" { fail "print buf\[1\]"} default { fail "print buf\[1\]"} } send_gdb "print buf\[2\]\n" gdb_expect { -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"} -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"} -re ".*$gdb_prompt $" { fail "print buf\[2\]"} default { fail "print buf\[2\]"} } send_gdb "print buf\[3\]\n" gdb_expect { -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"} -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"} -re ".*$gdb_prompt $" { fail "print buf\[3\]" } default { fail "print buf\[3\]" } } # Did we find what we were looking for? If not, flunk it. if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"} # Continue until we hit the finishing marker function. # Make sure we hit no more watchpoints. gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \ "continue to marker4" # Disable everything so we can finish the program at full speed gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall" if [target_info exists gdb,noresults] { return } gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall" }}# Do a simple test of of watching through a pointer when the pointer# itself changes. Should add some more complicated stuff here.proc test_complex_watchpoint {} { global gdb_prompt if [runto marker4] then { gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val" gdb_test "break marker5" ".*Breakpoint.*" gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint" # Continue until we hit the marker5 function. # Make sure we hit no more watchpoints. gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \ "did not trigger wrong watchpoint" # Test watches of things declared locally in a function. # In particular, test that a watch of stack-based things # is deleted when the stack-based things go out of scope. # gdb_test "disable" "" "disable in test_complex_watchpoint" gdb_test "break marker6" ".*Breakpoint.*" gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \ "continue to marker6" gdb_test "break func2" ".*Breakpoint.*" gdb_test "cont" "Continuing.*func2.*" # Test a watch of a single stack-based variable, whose scope # is the function we're now in. This should auto-delete when # execution exits the scope of the watchpoint. # gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch" gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch" gdb_test "cont" "Continuing.*func2.*" # We should be in "func2" again now. Test a watch of an # expression which includes both a stack-based local and # something whose scope is larger than this invocation # of "func2". This should also auto-delete. # gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \ "set partially local watch" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \ "trigger1 partially local watch" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \ "trigger2 partially local watch" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \ "self-delete partially local watch" # We should be in "func2" again now. Test a watch of a # static (non-stack-based) local. Since this has scope # across any invocations of "func2", it should not auto- # delete. # gdb_test "cont" "Continuing.*func2.*" gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \ "set static local watch" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \ "trigger static local watch" gdb_test "cont" "Continuing.*marker6 \\(\\).*" \ "continue after trigger static local watch" gdb_test "info break" ".*watchpoint.*static_b.*" \ "static local watch did not self-delete" # We should be in "recurser" now. Test a watch of a stack- # based local. Symbols mentioned in a watchpoint are bound # at watchpoint-creation. Thus, a watch of a stack-based # local to a recursing function should be bound only to that # one invocation, and should not trigger for other invocations. # gdb_test "tbreak recurser" ".*Breakpoint.*" gdb_test "cont" "Continuing.*recurser.*" gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \ "set local watch in recursive call" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \ "trigger local watch in recursive call" gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \ "self-delete local watch in recursive call" # Disable everything so we can finish the program at full speed gdb_test "disable" "" "disable in test_complex_watchpoint" if [target_info exists gdb,noresults] { return } gdb_continue_to_end "continue to exit in test_complex_watchpoint" }}proc test_watchpoint_and_breakpoint {} { global gdb_prompt # This is a test for PR gdb/38, which involves setting a # watchpoint right after you've reached a breakpoint. if [runto func3] then { gdb_breakpoint [gdb_get_line_number "second x assignment"] gdb_continue_to_breakpoint "second x assignment" gdb_test "watch x" ".*atchpoint \[0-9\]+: x" gdb_test_multiple "next" "next after watch x" { -re ".*atchpoint \[0-9\]+: x\r\n\r\nOld value = 0\r\nNew value = 1\r\n.*$gdb_prompt $" { pass "next after watch x" } -re "\[0-9\]+\[\t \]+y = 1;\r\n$gdb_prompt $" { kfail "gdb/38" "next after watch x" } } }} # Start with a fresh gdb.gdb_exitgdb_startgdb_reinitialize_dir $srcdir/$subdirgdb_load $binfileset prev_timeout $timeoutset timeout 600 verbose "Timeout now 600 sec.\n"if [initialize] then { test_simple_watchpoint # The IDT/sim monitor only has 8 (!) open files, of which it uses # 4 (!). So we have to make sure one program exits before # starting another one. if [istarget "mips-idt-*"] then { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile initialize } test_disabling_watchpoints # See above. if [istarget "mips-idt-*"] then { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile initialize } if ![target_info exists gdb,cannot_call_functions] { test_stepping # See above. if [istarget "mips-idt-*"] then { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile initialize } } # Only enabled for some targets merely because it has not been tested # elsewhere. # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 # breakpoint before stopping for the watchpoint. I don't know why. if {[istarget "hppa*-*-*"]} then { test_watchpoint_triggered_in_syscall } # See above. if [istarget "mips-idt-*"] then { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile initialize } # Only enabled for some targets merely because it has not been tested # elsewhere. if {[istarget "hppa*-*-*"] || \ [istarget "sparc*-*-sunos*"] || \ [istarget "m32r-*-*"]} then { test_complex_watchpoint } # Verify that a user can force GDB to use "slow" watchpoints. # (This proves rather little on kernels that don't support # fast watchpoints, but still...) # if ![runto_main] then { fail "watch tests suppressed" } send_gdb "set can-use-hw-watchpoints 0\n" gdb_expect { -re "$gdb_prompt $"\ {pass "disable fast watches"} timeout {fail "(timeout) disable fast watches"} } send_gdb "show can-use-hw-watchpoints\n" gdb_expect { -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\ {pass "show disable fast watches"} -re "$gdb_prompt $"\ {fail "show disable fast watches"} timeout {fail "(timeout) show disable fast watches"} } send_gdb "watch ival3 if count > 1\n" gdb_expect { -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\ {pass "set slow conditional watch"} -re "$gdb_prompt $"\ {fail "set slow conditional watch"} timeout {fail "(timeout) set slow conditional watch"} } send_gdb "continue\n" gdb_expect { -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\ {pass "trigger slow conditional watch"} -re "$gdb_prompt $"\ {fail "trigger slow conditional watch"} timeout {fail "(timeout) trigger slow conditional watch"} } # We've explicitly disabled hardware watches. Verify that GDB # # send_gdb "rwatch ival3\n" gdb_expect { -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\ {pass "rwatch disallowed when can-set-hw-watchpoints cleared"} -re "$gdb_prompt $"\ {fail "rwatch disallowed when can-set-hw-watchpoints cleared"} timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"} } # Read- and access watchpoints are unsupported on HP-UX. Verify # that GDB gracefully responds to requests to create them. # if [istarget "hppa*-*-hpux*"] then { send_gdb "set can-use-hw-watchpoints 1\n" gdb_expect { -re "$gdb_prompt $"\ {pass "enable fast watches"} timeout {fail "(timeout) enable fast watches"} } send_gdb "rwatch ival3\n" gdb_expect { -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\ {pass "read watches disallowed"} -re "$gdb_prompt $"\ {fail "read watches disallowed"} timeout {fail "(timeout) read watches disallowed"} } send_gdb "awatch ival3\n" gdb_expect { -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\ {pass "access watches disallowed"} -re "$gdb_prompt $"\ {fail "access watches disallowed"} timeout {fail "(timeout) access watches disallowed"} } } # See above. if [istarget "mips-idt-*"] then { gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $binfile initialize } test_watchpoint_and_breakpoint}# Restore old timeoutset timeout $prev_timeoutverbose "Timeout now $timeout sec.\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -