]>
Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2014-2016 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 | ||
19 | standard_testfile | |
20 | set 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. | |
25 | if {[skip_hw_watchpoint_tests]} { | |
26 | return 0 | |
27 | } | |
28 | ||
29 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ | |
30 | executable [list debug "incdir=${objdir}"]] != "" } { | |
31 | return -1 | |
32 | } | |
33 | ||
c79d856c PA |
34 | # The test proper. DISPLACED is true if we should try with displaced |
35 | # stepping. WITH_BP is true if we should try with a thread-specific | |
36 | # breakpoint (for the wrong thread) right after the instruction that | |
37 | # triggers the watchpoint. | |
38 | proc do_test { displaced with_bp } { | |
2adfaa28 | 39 | global executable |
ebc90b50 PA |
40 | global gdb_prompt |
41 | global hex | |
2adfaa28 PA |
42 | |
43 | if ${with_bp} { | |
44 | set prefix "with thread-specific bp" | |
45 | } else { | |
46 | set prefix "no thread-specific bp" | |
47 | } | |
c79d856c | 48 | with_test_prefix "displaced=$displaced: $prefix" { |
2adfaa28 PA |
49 | # Cover both stepping and non-stepping execution commands. |
50 | foreach command {"step" "next" "continue" } { | |
51 | with_test_prefix $command { | |
52 | clean_restart $executable | |
53 | ||
54 | if ![runto_main] { | |
55 | continue | |
56 | } | |
57 | ||
c79d856c PA |
58 | gdb_test_no_output "set displaced-stepping $displaced" |
59 | ||
2adfaa28 PA |
60 | gdb_breakpoint [gdb_get_line_number "set wait-thread breakpoint here"] |
61 | gdb_continue_to_breakpoint "run to wait-thread breakpoint" | |
7e0aa6aa | 62 | gdb_test "info threads" "\\\* 1 .* 2 .*" "info threads shows all threads" |
2adfaa28 PA |
63 | |
64 | gdb_test_no_output "set scheduler-locking on" | |
65 | ||
66 | delete_breakpoints | |
67 | ||
68 | gdb_breakpoint [gdb_get_line_number "set breakpoint child here"] | |
69 | gdb_test "thread 2" "Switching to .*" | |
70 | gdb_continue_to_breakpoint "run to breakpoint in thread 2" | |
ebc90b50 PA |
71 | |
72 | set address_triggers_watch "<invalid>" | |
73 | set after_address_triggers_watch "<invalid>" | |
74 | ||
75 | # Let the watchpoint trigger once (with the other | |
76 | # thread locked), in order to find both the address of | |
77 | # the instruction that triggers the watchpoint and the | |
78 | # address of the instruction immediately after. | |
79 | with_test_prefix "find addresses" { | |
80 | gdb_test "p watch_me = 0" " = 0" "clear watch_me" | |
81 | gdb_test "watch watch_me" "Hardware watchpoint .*" | |
82 | ||
83 | gdb_test "continue" \ | |
84 | "Hardware watchpoint.*: watch_me.*New value = 1.*" \ | |
85 | "continue to watchpoint" | |
86 | ||
87 | set msg "find addresses" | |
88 | gdb_test_multiple "disassemble" $msg { | |
89 | -re " ($hex) \[^\r\n\]*\r\n=> ($hex) .*$gdb_prompt $" { | |
90 | set address_triggers_watch $expect_out(1,string) | |
91 | set after_address_triggers_watch $expect_out(2,string) | |
92 | pass $msg | |
93 | } | |
94 | } | |
95 | ||
96 | delete_breakpoints | |
97 | } | |
98 | ||
07473109 PA |
99 | gdb_test "break *$address_triggers_watch" "Breakpoint .*" \ |
100 | "set breakpoint at address that triggers watch" | |
ebc90b50 PA |
101 | gdb_continue_to_breakpoint \ |
102 | "run to instruction that triggers watch in thread 2" | |
103 | ||
2adfaa28 PA |
104 | gdb_test "p counter = 0" " = 0" "unbreak loop in thread 2" |
105 | gdb_test "p watch_me = 0" " = 0" "clear watch_me" | |
106 | gdb_test "watch watch_me" "Hardware watchpoint .*" | |
107 | ||
108 | if ${with_bp} { | |
07473109 PA |
109 | gdb_test "b *$after_address_triggers_watch thread 1" \ |
110 | "Breakpoint .*" \ | |
111 | "set breakpoint specific to thread 1" | |
2adfaa28 PA |
112 | } |
113 | ||
114 | # Switch back to thread 1 and disable scheduler locking. | |
115 | gdb_test "thread 1" "Switching to .*" | |
116 | gdb_test_no_output "set scheduler-locking off" | |
117 | ||
d4569d7b PA |
118 | # Thread 2 is still stopped at a breakpoint that needs |
119 | # to be stepped over. However, the instruction that | |
120 | # is under the breakpoint triggers a watchpoint, which | |
121 | # should trap and be reported to the user. | |
2adfaa28 PA |
122 | gdb_test "$command" "Hardware watchpoint.*: watch_me.*New value = 1.*" |
123 | } | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
c79d856c PA |
128 | foreach displaced { "off" "on" } { |
129 | if { $displaced != "off" && ![support_displaced_stepping] } { | |
130 | continue | |
131 | } | |
132 | ||
133 | foreach with_bp { 0 1 } { | |
134 | do_test $displaced $with_bp | |
135 | } | |
136 | } |