-# Copyright (C) 1992, 1994 Free Software Foundation, Inc.
+# Copyright (C) 1992, 1994, 1997 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
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Please email any bugs, comments, and/or additions to this file to:
set prms_id 0
set bug_id 0
-set binfile "watchpoint"
-set srcfile $binfile.c
-
-if ![file exists $objdir/$subdir/$binfile] then {
- perror "$objdir/$subdir/$binfile does not exist."
- return 0
+set testfile "watchpoint"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ perror "Couldn't compile ${srcfile}"
+ return -1
}
-
# Prepare for watchpoint tests by setting up two breakpoints and one
# watchpoint.
#
# 3 Watchpoint ival3
proc initialize {} {
- global prompt
+ global gdb_prompt
global hex
global decimal
global srcfile
- send "break marker1\n"
- expect {
- -re "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*$prompt $" {
- pass "set breakpoint at marker1"
- }
- -re ".*$prompt $" { fail "set breakpoint at marker1" ; return 0 }
- timeout { fail "set breakpoint at marker1 (timeout)" ; return 0 }
+ if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
+ return 0;
}
- send "break marker2\n"
- expect {
- -re "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*$prompt $" {
- pass "set breakpoint at marker2"
- }
- -re ".*$prompt $" { fail "set breakpoint at marker2" ; return 0 }
- timeout { fail "set breakpoint at marker2 (timeout)" ; return 0 }
+
+ if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
+ return 0;
}
- send "info break\n"
- expect {
- -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n$prompt $" { pass "info break in watchpoint.exp" }
- -re ".*$prompt $" { fail "info break in watchpoint.exp" ; return 0 }
- timeout { fail "info break in watchpoint.exp (timeout)" ; return 0 }
+
+ if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
+ return 0;
}
- send "watch ival3\n"
- expect {
- -re ".*\[Ww\]atchpoint 3: ival3\r\n$prompt $" {
- pass "set watchpoint on ival3"
- }
- -re ".*$prompt $" { fail "set watchpoint on ival3" ; return 0 }
- timeout { fail "set watchpoint on ival3 (timeout)" ; return 0 }
+
+ if [gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3" "set watchpoint on ival3" ] {
+ return 0;
}
+
# "info watch" is the same as "info break"
- send "info watch\n"
- expect {
- -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$prompt $" {
- pass "watchpoint found in watchpoint/breakpoint table"
- }
- -re ".*$prompt $" {
- fail "watchpoint found in watchpoint/breakpoint table" ; return 0
- }
- timeout {
- fail "watchpoint found in watchpoint/breakpoint table" ; return 0
- }
+ if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
+ return 0;
}
+
# After installing the watchpoint, we disable it until we are ready
# to use it. This allows the test program to run at full speed until
# we get to the first marker function.
- send "disable 3\n"
- expect {
- -re "disable 3\r\n$prompt $" { pass "disable watchpoint" }
- -re ".*$prompt $" { fail "disable watchpoint" ; return 0 }
- timeout { fail "disable watchpoint (timeout)" ; return 0 }
+ if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
+ return 0;
}
+
return 1
}
#
proc test_simple_watchpoint {} {
- global prompt
+ global gdb_prompt
global hex
global decimal
# Ensure that the watchpoint is disabled when we startup.
- send "disable 3\n"
- expect {
- -re "^disable 3\r\n$prompt $" {
- pass "disable watchpoint in test_simple_watchpoint"
- }
- -re ".*$prompt $" {
- fail "disable watchpoint in test_simple_watchpoint"
- return 0
- }
- timeout {
- fail "disable watchpoint in test_simple_watchpoint (timeout)"
- return 0
- }
+ if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
+ return 0;
}
+
# Run until we get to the first marker function.
gdb_run_cmd
- expect {
- -re "Breakpoint 1, marker1 .*$prompt $" {
+ set timeout 600
+ gdb_expect {
+ -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
pass "run to marker1 in test_simple_watchpoint"
}
- -re ".*$prompt $" {
+ -re ".*$gdb_prompt $" {
fail "run to marker1 in test_simple_watchpoint"
return
}
# After reaching the marker function, enable the watchpoint.
- send "enable 3\n"
- expect {
- -re "^enable 3\r\n$prompt $" { pass "enable watchpoint" }
- -re ".*$prompt $" { fail "enable watchpoint" ; return }
- timeout { fail "enable watchpoint (timeout)" ; return }
+ if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
+ return ;
}
+
gdb_test "break func1" "Breakpoint.*at.*"
gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
# Continue until the first change, from -1 to 0
- send "cont\n"
- expect {
- -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$prompt $" {
+ send_gdb "cont\n"
+ gdb_expect {
+ -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
pass "watchpoint hit, first time"
}
- -re "Continuing.*Breakpoint.*func1.*$prompt $" {
+ -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
setup_xfail "m68*-*-*" 2597
fail "thought it hit breakpoint at func1 twice"
gdb_test "delete \$func1_breakpoint_number" ""
Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
"watchpoint hit, first time"
}
- -re ".*$prompt $" { fail "watchpoint hit, first time" ; return }
+ -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
timeout { fail "watchpoint hit, first time (timeout)" ; return }
eof { fail "watchpoint hit, first time (eof)" ; return }
}
# Disable the watchpoint so we run at full speed until we exit.
- send "disable 3\n"
- expect {
- -re "^disable 3\r\n$prompt $" { pass "watchpoint disabled" }
- -re ".*$prompt $" { fail "watchpoint disabled" ; return }
- timeout { fail "watchpoint disabled (timeout)" ; return }
+ if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
+ return ;
}
+
# Run until process exits.
+ if [target_info exists gdb,noresults] { return }
+
gdb_test "cont" "Continuing.*Program exited normally.*" \
"continue to exit in test_simple_watchpoint"
}
# Test disabling watchpoints.
proc test_disabling_watchpoints {} {
- global prompt
+ global gdb_prompt
global binfile
global srcfile
global decimal
# Ensure that the watchpoint is disabled when we startup.
- send "disable 3\n"
- expect {
- -re "^disable 3\r\n$prompt $" {
- pass "disable watchpoint in test_disabling_watchpoints"
- }
- -re ".*$prompt $" {
- fail "disable watchpoint in test_disabling_watchpoints"
- return 0
- }
- timeout {
- fail "disable watchpoint in test_disabling_watchpoints (timeout)"
- return 0
- }
+ if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
+ return 0;
}
+
# Run until we get to the first marker function.
gdb_run_cmd
- expect {
- -re "Breakpoint 1, marker1 .*$prompt $" {
+ set timeout 600
+ gdb_expect {
+ -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
pass "run to marker1 in test_disabling_watchpoints"
}
- -re ".*$prompt $" {
+ -re ".*$gdb_prompt $" {
fail "run to marker1 in test_disabling_watchpoints"
return
}
# After reaching the marker function, enable the watchpoint.
- send "enable 3\n"
- expect {
- -re "^enable 3\r\n$prompt $" { pass "watchpoint enabled" }
- -re ".*$prompt $" { fail "watchpoint enabled" ; return }
- timeout { fail "watchpoint enabled (timeout)" ; return }
+ if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
+ return ;
}
+
# Continue until the first change, from -1 to 0
# Don't check the old value, because on VxWorks the variable value
# will not have been reinitialized.
# Disable the watchpoint but leave breakpoints
- send "disable 3\n"
- expect {
- -re "^disable 3\r\n$prompt $" {
- pass "disable watchpoint #2 in test_disabling_watchpoints"
- }
- -re ".*$prompt $" {
- "disable watchpoint #2 in test_disabling_watchpoints"
- return 0
- }
- timeout {
- "disable watchpoint #2 in test_disabling_watchpoints (timeout)"
- return 0
- }
+ if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
+ return 0;
}
+
# Check watchpoint list, looking for the entry that confirms the
# watchpoint is disabled.
gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
"disabled watchpoint skipped"
+ if [target_info exists gdb,noresults] { return }
+
gdb_test "cont" "Continuing.*Program exited normally.*" \
"continue to exit in test_disabling_watchpoints"
}
# Test stepping and other mundane operations with watchpoints enabled
proc test_stepping {} {
- global prompt
+ global gdb_prompt
if [runto marker1] then {
gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
clear_xfail "mips*-*-*"
clear_xfail "sparc-*-*"
clear_xfail "hppa*-*-*bsd*"
+ # It works with the generic inferior function calling code too.
+ clear_xfail "mn10200*-*-*"
gdb_test "p func1 ()" "= 73" \
"calling function with watchpoint enabled"
}
# on other targets. In this case we will step once more.
#
- send "finish\n"
- expect {
- -re "Run.*exit from.*marker1.*main.* at" { }
+ send_gdb "finish\n"
+ gdb_expect {
+ -re "Run.*exit from.*marker1.* at" { }
default { fail "finish from marker1" ; return }
}
- expect {
- -re "marker1 \\(\\);.*$prompt $" {
- send "step\n"
+
+ gdb_expect {
+ -re "marker1 \\(\\);.*$gdb_prompt $" {
+ send_gdb "step\n"
exp_continue
}
- -re "func1 \\(\\);.*$prompt $" {
+ -re "func1 \\(\\);.*$gdb_prompt $" {
pass "finish from marker1"
}
- -re ".*$prompt $" {
+ -re ".*$gdb_prompt $" {
fail "finish from marker1"
}
default { fail "finish from marker1" ; return }
gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
- send "until\n"
- expect {
- -re "(for \\(count = 0|\}).*$prompt $" {
+ 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 ./.*$prompt $" {
+ -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
pass "until out of loop"
}
- -re ".*$prompt $" {
+ -re ".*$gdb_prompt $" {
fail "until out of loop"
}
default { fail "until out of loop" ; return }
# Test stepping and other mundane operations with watchpoints enabled
proc test_watchpoint_triggered_in_syscall {} {
- global prompt
- global timeout
-
- set saved_timeout $timeout
+ global gdb_prompt
+ if [target_info exists gdb,noinferiorio] {
+ verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
+ return
+ }
# Run until we get to the first marker function.
set x 0
set y 0
gdb_test "set doread = 1" ""
- # Sometimes our string never gets to GDB?!? dejagnu bug? Whatever
- # the cause we'll set a reasonably short timeout and resend our
- # string again if we timeout.
- set timeout 10
- send "continue\n"
- send "123\n"
- expect {
+ # 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.
+ if [gdb_test "continue" "Continuing\\.\r\ntype stuff for buf now:" "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 ".*$prompt $" { }
- timeout {
- set timeout $saved_timeout
- send "123\n"
- exp_continue
- }
+ -re ".*$gdb_prompt $" { pass "sent 123" }
+ timeout { fail "sent 123 (timeout)" }
}
- # Restore the timeout value.
- set timeout $saved_timeout
-
# Examine the values in buf to see how many watchpoints we
# should have printed.
- send "print buf\[0\]\n"
- expect {
- -re ".*= 49.*$prompt $" { set y [expr $y+1] }
- -re ".*= 0" { }
- default { }
- timeout { }
- }
- send "print buf\[1\]\n"
- expect {
- -re ".*= 50.*$prompt $" { set y [expr $y+1] }
- -re ".*= 0" { }
- default { }
- timeout { }
- }
- send "print buf\[2\]\n"
- expect {
- -re ".*= 51.*$prompt $" { set y [expr $y+1] }
- -re ".*= 0" { }
- default { }
- timeout { }
- }
- send "print buf\[3\]\n"
- expect {
- -re ".*= 10.*$prompt $" { set y [expr $y+1] }
- -re ".*= 0" { }
- default { }
- timeout { }
+ 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.
# 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_test "cont" "Continuing.*Program exited normally.*" \
"continue to exit in test_watchpoint_triggered_in_syscall"
}
# itself changes. Should add some more complicated stuff here.
proc test_complex_watchpoint {} {
- global prompt
+ global gdb_prompt
if [runto marker4] then {
gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
# 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_test "cont" "Continuing.*Program exited normally.*" \
"continue to exit in test_complex_watchpoint"
}
# Start with a fresh gdb.
-gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
-gdb_load $objdir/$subdir/$binfile
+gdb_load $binfile
+set timeout 600
+verbose "Timeout now 600 sec.\n"
if [initialize] then {
- # Preserve the old timeout, and set a new one that should be
- # sufficient to step from marker1 to marker2 with watchpoints
- # set anywhere.
-
- set timeoutsave $timeout
- set timeout 60
-
test_simple_watchpoint
# The IDT/sim monitor only has 8 (!) open files, of which it uses
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $objdir/$subdir/$binfile
+ gdb_load $binfile
initialize
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $objdir/$subdir/$binfile
+ gdb_load $binfile
initialize
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $objdir/$subdir/$binfile
+ gdb_load $binfile
initialize
}
# Only enabled for some targets merely because it has not been tested
# elsewhere.
- if {[istarget "hppa*-*-*"] || [istarget "sparc*-*-sunos*"]} then {
+ # 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
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
- gdb_load $objdir/$subdir/$binfile
+ gdb_load $binfile
initialize
}
# Only enabled for some targets merely because it has not been tested
# elsewhere.
- if {[istarget "hppa*-*-*"] || [istarget "sparc*-*-sunos*"]} then {
+ if {[istarget "hppa*-*-*"] || \
+ [istarget "sparc*-*-sunos*"] || \
+ [istarget "m32r-*-*"]} then {
test_complex_watchpoint
}
-
- # Restore the preserved old timeout value.
-
- set timeout $timeoutsave
}