]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/watchthreads.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchthreads.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2004, 2007 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # Check that GDB can support multiple watchpoints across threads.
20
21 if $tracelevel {
22 strace $tracelevel
23 }
24
25 set prms_id 0
26 set bug_id 0
27
28 # This test verifies that a watchpoint is detected in the proper thread
29 # so the test is only meaningful on a system with hardware watchpoints.
30 if [target_info exists gdb,no_hardware_watchpoints] {
31 return 0;
32 }
33
34 set testfile "watchthreads"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
38 return -1
39 }
40
41 gdb_exit
42 gdb_start
43 gdb_reinitialize_dir $srcdir/$subdir
44 gdb_load ${binfile}
45
46 gdb_test "set can-use-hw-watchpoints 1" "" ""
47
48 #
49 # Run to `main' where we begin our tests.
50 #
51
52 if ![runto_main] then {
53 gdb_suppress_tests
54 }
55
56 set args_0 0
57 set args_1 0
58
59 # Watch values that will be modified by distinct threads.
60 gdb_test "watch args\[0\]" "Hardware watchpoint 2: args\\\[0\\\]"
61 gdb_test "watch args\[1\]" "Hardware watchpoint 3: args\\\[1\\\]"
62
63 set init_line [expr [gdb_get_line_number "Init value"]+1]
64 set inc_line [gdb_get_line_number "Loop increment"]
65
66 # Loop and continue to allow both watchpoints to be triggered.
67 for {set i 0} {$i < 30} {incr i} {
68 set test_flag 0
69 gdb_test_multiple "continue" "threaded watch loop" {
70 -re "Hardware watchpoint 2: args\\\[0\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*watchthreads.c:$init_line.*$gdb_prompt $"
71 { set args_0 1; set test_flag 1 }
72 -re "Hardware watchpoint 3: args\\\[1\\\].*Old value = 0.*New value = 1.*main \\\(\\\) at .*watchthreads.c:$init_line.*$gdb_prompt $"
73 { set args_1 1; set test_flag 1 }
74 -re "Hardware watchpoint 2: args\\\[0\\\].*Old value = $args_0.*New value = [expr $args_0+1].*in thread_function \\\(arg=0x0\\\) at .*watchthreads.c:$inc_line.*$gdb_prompt $"
75 { set args_0 [expr $args_0+1]; set test_flag 1 }
76 -re "Hardware watchpoint 3: args\\\[1\\\].*Old value = $args_1.*New value = [expr $args_1+1].*in thread_function \\\(arg=0x1\\\) at .*watchthreads.c:$inc_line.*$gdb_prompt $"
77 { set args_1 [expr $args_1+1]; set test_flag 1 }
78 }
79 # If we fail above, don't bother continuing loop
80 if { $test_flag == 0 } {
81 set i 30;
82 }
83 }
84
85 # Print success message if loop succeeded.
86 if { $test_flag == 1 } {
87 pass "threaded watch loop"
88 }
89
90 # Verify that we hit first watchpoint in main thread.
91 set message "first watchpoint on args\[0\] hit"
92 if { $args_0 > 0 } {
93 pass $message
94 } else {
95 fail $message
96 }
97
98 # Verify that we hit second watchpoint in main thread.
99 set message "first watchpoint on args\[1\] hit"
100 if { $args_1 > 0 } {
101 pass $message
102 } else {
103 fail $message
104 }
105
106 # Verify that we hit first watchpoint in child thread.
107 set message "watchpoint on args\[0\] hit in thread"
108 if { $args_0 > 1 } {
109 pass $message
110 } else {
111 fail $message
112 }
113
114 # Verify that we hit second watchpoint in child thread.
115 set message "watchpoint on args\[1\] hit in thread"
116 if { $args_1 > 1 } {
117 pass $message
118 } else {
119 fail $message
120 }
121
122 # Verify that all watchpoint hits are accounted for.
123 set message "combination of threaded watchpoints = 30"
124 if { [expr $args_0+$args_1] == 30 } {
125 pass $message
126 } else {
127 fail $message
128 }