Make gdb.threads/step-over-trips-on-watchpoint.exp effective on !x86
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / step-over-trips-on-watchpoint.exp
CommitLineData
32d0add0 1# Copyright (C) 2014-2015 Free Software Foundation, Inc.
2adfaa28
PA
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# Test that when a step-over trips on a watchpoint, that watchpoint is
17# reported.
18
19standard_testfile
20set executable ${testfile}
21
22# This test verifies that a watchpoint is detected in a multithreaded
23# program so the test is only meaningful on a system with hardware
24# watchpoints.
25if {[skip_hw_watchpoint_tests]} {
26 return 0
27}
28
29if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
30 executable [list debug "incdir=${objdir}"]] != "" } {
31 return -1
32}
33
34proc do_test { with_bp } {
35 global executable
ebc90b50
PA
36 global gdb_prompt
37 global hex
2adfaa28
PA
38
39 if ${with_bp} {
40 set prefix "with thread-specific bp"
41 } else {
42 set prefix "no thread-specific bp"
43 }
44 with_test_prefix $prefix {
45 # Cover both stepping and non-stepping execution commands.
46 foreach command {"step" "next" "continue" } {
47 with_test_prefix $command {
48 clean_restart $executable
49
50 if ![runto_main] {
51 continue
52 }
53
54 gdb_breakpoint [gdb_get_line_number "set wait-thread breakpoint here"]
55 gdb_continue_to_breakpoint "run to wait-thread breakpoint"
56 gdb_test "info threads" "2 .*\\\* 1.*" "info threads shows all threads"
57
58 gdb_test_no_output "set scheduler-locking on"
59
60 delete_breakpoints
61
62 gdb_breakpoint [gdb_get_line_number "set breakpoint child here"]
63 gdb_test "thread 2" "Switching to .*"
64 gdb_continue_to_breakpoint "run to breakpoint in thread 2"
ebc90b50
PA
65
66 set address_triggers_watch "<invalid>"
67 set after_address_triggers_watch "<invalid>"
68
69 # Let the watchpoint trigger once (with the other
70 # thread locked), in order to find both the address of
71 # the instruction that triggers the watchpoint and the
72 # address of the instruction immediately after.
73 with_test_prefix "find addresses" {
74 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
75 gdb_test "watch watch_me" "Hardware watchpoint .*"
76
77 gdb_test "continue" \
78 "Hardware watchpoint.*: watch_me.*New value = 1.*" \
79 "continue to watchpoint"
80
81 set msg "find addresses"
82 gdb_test_multiple "disassemble" $msg {
83 -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" {
84 set address_triggers_watch $expect_out(1,string)
85 set after_address_triggers_watch $expect_out(2,string)
86 pass $msg
87 }
88 }
89
90 delete_breakpoints
91 }
92
93 gdb_breakpoint "*$address_triggers_watch"
94 gdb_continue_to_breakpoint \
95 "run to instruction that triggers watch in thread 2"
96
2adfaa28
PA
97 gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2"
98 gdb_test "p watch_me = 0" " = 0" "clear watch_me"
99 gdb_test "watch watch_me" "Hardware watchpoint .*"
100
101 if ${with_bp} {
102 # Set a thread-specific breakpoint (for the wrong
103 # thread) right after instruction that triggers
104 # the watchpoint.
ebc90b50 105 gdb_test "b *$after_address_triggers_watch thread 1"
2adfaa28
PA
106 }
107
108 # Switch back to thread 1 and disable scheduler locking.
109 gdb_test "thread 1" "Switching to .*"
110 gdb_test_no_output "set scheduler-locking off"
111
112 # Thread 2 is still stopped at a breakpoint that needs to be
ebc90b50
PA
113 # stepped over before proceeding thread 1. However, the
114 # instruction that is under the breakpoint triggers a
115 # watchpoint, which should trap and be reported to the
116 # user.
2adfaa28
PA
117 gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*"
118 }
119 }
120 }
121}
122
123do_test 0
124do_test 1
This page took 0.137759 seconds and 4 git commands to generate.