2004-07-27 23:40:49 +00:00
# This testcase is part of GDB, the GNU debugger.
2015-01-01 09:32:14 +00:00
# Copyright 2004-2015 Free Software Foundation, Inc.
2004-07-27 23:40:49 +00:00
# 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
2007-08-23 18:14:19 +00:00
# the Free Software Foundation; either version 3 of the License, or
2004-07-27 23:40:49 +00:00
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2007-08-23 18:14:19 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2004-07-27 23:40:49 +00:00
# Check that GDB can support multiple watchpoints across threads.
# This test verifies that a watchpoint is detected in the proper thread
# so the test is only meaningful on a system with hardware watchpoints.
2011-02-21 14:57:38 +00:00
if {[skip_hw_watchpoint_multi_tests]} {
return 0
2004-07-27 23:40:49 +00:00
}
2007-10-01 00:17:58 +00:00
proc target_no_stopped_data { } {
return [istarget s390*-*-*]
}
* gdb.threads/watchpoint-fork.exp (test): Use
standard_output_file. Don't declare objdir.
* gdb.threads/attach-into-signal.exp: Use standard_testfile,
standard_output_file.
* gdb.threads/attach-stopped.exp: Use standard_testfile.
* gdb.threads/bp_in_thread.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/corethreads.exp: Use standard_testfile.
* gdb.threads/execl.exp: Use standard_testfile,
standard_output_file, clean_restart.
* gdb.threads/fork-child-threads.exp: Use standard_testfile,
clean_restart.
* gdb.threads/fork-thread-pending.exp: Use standard_testfile,
clean_restart.
* gdb.threads/gcore-thread.exp: Use standard_testfile. Remove
incdir.
* gdb.threads/hand-call-in-threads.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/ia64-sigill.exp: Use standard_testfile.
* gdb.threads/interrupted-hand-call.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/killed.exp: Use standard_testfile, clean_restart.
Remove incdir.
* gdb.threads/leader-exit.exp: Use standard_testfile.
* gdb.threads/linux-dp.exp: Use standard_testfile, clean_restart.
* gdb.threads/local-watch-wrong-thread.exp: Use standard_testfile,
clean_restart.
* gdb.threads/manythreads.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/multi-create.exp: Use standard_testfile,
clean_restart.
* gdb.threads/no-unwaited-for-left.exp: Use standard_testfile.
* gdb.threads/non-ldr-exc-1.exp: Use standard_testfile.
* gdb.threads/non-ldr-exc-2.exp: Use standard_testfile.
* gdb.threads/non-ldr-exc-3.exp: Use standard_testfile.
* gdb.threads/non-ldr-exc-4.exp: Use standard_testfile.
* gdb.threads/pending-step.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/print-threads.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/pthread_cond_wait.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/pthreads.exp: Use standard_testfile, clean_restart.
Remove incdir.
* gdb.threads/schedlock.exp: Use standard_testfile. Remove
incdir.
* gdb.threads/sigthread.exp: Use standard_testfile,
clean_restart.
* gdb.threads/staticthreads.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/switch-threads.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/thread-execl.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/thread-find.exp: Use standard_testfile,
clean_restart.
* gdb.threads/thread-specific.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/thread-unwindonsignal.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/thread_check.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/thread_events.exp: Use standard_testfile. Remove
incdir.
* gdb.threads/threadapply.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/threxit-hop-specific.exp: Use standard_testfile,
clean_restart. Remove incdir.
* gdb.threads/tls-nodebug.exp: Use standard_testfile,
clean_restart.
* gdb.threads/tls-shared.exp: Use standard_testfile,
clean_restart, standard_output_file.
* gdb.threads/tls-var.exp: Use standard_testfile,
standard_output_file.
* gdb.threads/tls.exp: Use standard_testfile, clean_restart.
Remove incdir.
* gdb.threads/watchthreads-reorder.exp: Use standard_testfile.
* gdb.threads/watchthreads.exp: Use standard_testfile. Remove
incdir.
* gdb.threads/watchthreads2.exp: Use standard_testfile,
clean_restart. Remove incdir.
2012-06-26 19:23:20 +00:00
standard_testfile
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
2004-07-27 23:40:49 +00:00
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
2010-06-03 23:54:18 +00:00
gdb_test_no_output "set can-use-hw-watchpoints 1" ""
2004-07-27 23:40:49 +00:00
#
# Run to `main' where we begin our tests.
#
if ![runto_main] then {
gdb_suppress_tests
}
set args_0 0
set args_1 0
# Watch values that will be modified by distinct threads.
gdb_test "watch args\[0\]" "Hardware watchpoint 2: args\\\[0\\\]"
gdb_test "watch args\[1\]" "Hardware watchpoint 3: args\\\[1\\\]"
2009-04-27 15:38:43 +00:00
set hwwp_2_enabled 1
set hwwp_3_enabled 1
2004-07-27 23:40:49 +00:00
2009-04-27 15:38:43 +00:00
set init_line [gdb_get_line_number "Init value"]
2004-10-12 22:49:17 +00:00
set inc_line [gdb_get_line_number "Loop increment"]
2007-10-01 00:17:58 +00:00
set main_loc "main \\\(\\\) at .*watchthreads.c:$init_line"
set thread0_loc "thread_function \\\(arg=0x0\\\) at .*watchthreads.c:$inc_line"
set thread1_loc "thread_function \\\(arg=0x1\\\) at .*watchthreads.c:$inc_line"
2004-10-12 22:49:17 +00:00
2004-07-27 23:40:49 +00:00
# Loop and continue to allow both watchpoints to be triggered.
for {set i 0} {$i < 30} {incr i} {
2007-10-01 00:17:58 +00:00
set test_flag_0 0
set test_flag_1 0
2004-07-27 23:40:49 +00:00
set test_flag 0
gdb_test_multiple "continue" "threaded watch loop" {
2007-10-01 00:17:58 +00:00
-re "(.*Hardware watchpoint.*)$gdb_prompt $" {
# At least one hardware watchpoint was hit. Check if both were.
set string $expect_out(1,string)
if [regexp "Hardware watchpoint 2: args\\\[0\\\]\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $args_0\[^\r\]*\r\[^\r\]*New value = [expr $args_0+1]\r" $string] {
incr args_0
incr test_flag_0
}
if [regexp "Hardware watchpoint 3: args\\\[1\\\]\[^\r\]*\r\[^\r\]*\r\[^\r\]*Old value = $args_1\[^\r\]*\r\[^\r\]*New value = [expr $args_1+1]\r" $string] {
incr args_1
incr test_flag_1
}
set expected_loc "bogus location"
if { $test_flag_0 == 1 && $test_flag_1 == 0 && $args_0 == 1 } {
set expected_loc $main_loc
} elseif { $test_flag_0 == 0 && $test_flag_1 == 1 && $args_1 == 1 } {
set expected_loc $main_loc
} elseif { $test_flag_0 == 1 && $test_flag_1 == 0 } {
set expected_loc $thread0_loc
} elseif { $test_flag_0 == 0 && $test_flag_1 == 1 } {
set expected_loc $thread1_loc
} elseif { $test_flag_0 + $test_flag_1 == 2 } {
# On S/390, or any other system which can not report the
# stopped data address, it is OK to report two watchpoints
# at once in this test. Make sure the reported location
# corresponds to at least one of the watchpoints (and not,
# e.g., __nptl_create_event). On other systems, we should
# report the two watchpoints serially.
if { [target_no_stopped_data] } {
set expected_loc "($main_loc|$thread0_loc|$thread1_loc)"
}
}
if [ regexp "$expected_loc" $string ] {
set test_flag 1
} else {
fail "threaded watch loop"
}
2009-04-27 15:38:43 +00:00
# If one of the watchpoints is disabled, we'd better not stop there.
if { !$hwwp_2_enabled && $test_flag_0 } {
fail "disabled hw watchpoint 2 triggered"
}
if { !$hwwp_3_enabled && $test_flag_1 } {
fail "disabled hw watchpoint 3 triggered"
}
# If we get to 10 in one of the watched locations disable it so we
# see some of the other watched location.
# 10 is chosen so we're guaranteed to come through here.
if { $hwwp_2_enabled && $hwwp_3_enabled } {
if { $args_0 >= 10 && $hwwp_2_enabled } {
2010-06-02 21:53:28 +00:00
gdb_test_no_output "disable 2" "disable first watchpoint at 10"
2009-04-27 15:38:43 +00:00
set hwwp_2_enabled 0
} elseif { $args_1 >= 10 && $hwwp_3_enabled } {
2010-06-02 21:53:28 +00:00
gdb_test_no_output "disable 3" "disable first watchpoint at 10"
2009-04-27 15:38:43 +00:00
set hwwp_3_enabled 0
}
}
2007-10-01 00:17:58 +00:00
}
2004-07-27 23:40:49 +00:00
}
2007-10-01 00:17:58 +00:00
2004-07-27 23:40:49 +00:00
# If we fail above, don't bother continuing loop
if { $test_flag == 0 } {
2013-06-07 17:31:09 +00:00
set i 30
2004-07-27 23:40:49 +00:00
}
}
# Print success message if loop succeeded.
if { $test_flag == 1 } {
pass "threaded watch loop"
}
# Verify that we hit first watchpoint in main thread.
set message "first watchpoint on args\[0\] hit"
if { $args_0 > 0 } {
pass $message
} else {
fail $message
}
# Verify that we hit second watchpoint in main thread.
set message "first watchpoint on args\[1\] hit"
if { $args_1 > 0 } {
pass $message
} else {
fail $message
}
# Verify that we hit first watchpoint in child thread.
set message "watchpoint on args\[0\] hit in thread"
if { $args_0 > 1 } {
pass $message
} else {
fail $message
}
# Verify that we hit second watchpoint in child thread.
set message "watchpoint on args\[1\] hit in thread"
if { $args_1 > 1 } {
pass $message
} else {
fail $message
}
# Verify that all watchpoint hits are accounted for.
set message "combination of threaded watchpoints = 30"
2007-10-01 00:17:58 +00:00
if { [target_no_stopped_data] } {
# See above. If we allow two watchpoints to be hit at once, we
# may have more than 30 hits total.
set result [expr $args_0 + $args_1 >= 30]
} else {
set result [expr $args_0 + $args_1 == 30]
}
if { $result } {
2004-07-27 23:40:49 +00:00
pass $message
} else {
fail $message
}