]>
Commit | Line | Data |
---|---|---|
8acc9f48 | 1 | # Copyright 2012-2013 Free Software Foundation, Inc. |
4403d8e9 JK |
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 case for forgotten hw-watchpoints after fork()-off of a process. | |
17 | ||
18 | set testfile watchpoint-fork | |
19 | ||
20 | if [is_remote target] { | |
21 | kfail "remote/13584" "gdbserver does not support debugging across fork" | |
22 | return | |
23 | } | |
24 | ||
0f4d39d5 | 25 | proc test {type symbol} { with_test_prefix "$type" { |
0efbbabc | 26 | global testfile subdir srcdir gdb_prompt |
4403d8e9 JK |
27 | |
28 | set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c | |
29 | ||
4403d8e9 JK |
30 | # no threads |
31 | ||
aed555c9 PA |
32 | with_test_prefix "singlethreaded" { |
33 | set executable ${testfile}-${type}-st | |
0efbbabc TT |
34 | set srcfile_main ${testfile}-st.c |
35 | if {[build_executable $testfile.exp $executable \ | |
36 | [list $srcfile_main ${testfile}-${type}.c] \ | |
37 | [list debug additional_flags=-D$symbol]] == -1} { | |
38 | return -1 | |
aed555c9 | 39 | } |
0efbbabc | 40 | |
aed555c9 PA |
41 | clean_restart $executable |
42 | ||
43 | if [target_info exists gdb,no_hardware_watchpoints] { | |
44 | # The software watchpoint functionality is in GDB an unrelated test. | |
45 | gdb_test_no_output "set can-use-hw-watchpoints 0" | |
46 | } | |
47 | ||
48 | gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\." | |
49 | gdb_test_no_output "set follow-fork-mode $type" | |
50 | gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\." | |
51 | # Testcase uses it for the `follow-fork-mode child' type. | |
52 | gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*" | |
53 | ||
54 | if ![runto_main] { | |
55 | return | |
56 | } | |
57 | ||
58 | gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint" | |
59 | ||
60 | # It is never hit but it should not be left over in the fork()ed-off child. | |
61 | if [skip_hw_breakpoint_tests] { | |
62 | set hbreak "break" | |
63 | } else { | |
64 | set hbreak "hbreak" | |
65 | } | |
66 | gdb_test "$hbreak marker" | |
67 | ||
68 | gdb_breakpoint "mark_exit" | |
69 | ||
70 | gdb_test "continue" \ | |
71 | "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work" | |
72 | gdb_test "continue" \ | |
73 | "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work" | |
74 | gdb_test "continue" \ | |
75 | "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork" | |
76 | gdb_test "continue" \ | |
77 | "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork" | |
78 | gdb_test "continue" \ | |
79 | "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork" | |
80 | gdb_test "continue" \ | |
81 | "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork" | |
82 | gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish" | |
4403d8e9 | 83 | } |
4403d8e9 JK |
84 | |
85 | # threads | |
86 | ||
87 | if [target_info exists gdb,no_hardware_watchpoints] { | |
88 | # Watchpoint hits would get detected in unexpected threads. | |
4403d8e9 JK |
89 | return |
90 | } | |
91 | ||
aed555c9 PA |
92 | with_test_prefix "multithreaded" { |
93 | set executable ${testfile}-${type}-mt | |
94 | set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c | |
0efbbabc | 95 | if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" [standard_output_file ${executable}] executable [list debug "additional_flags=-D$symbol -DTHREAD"]] != "" } { |
aed555c9 PA |
96 | untested ${testfile}.exp |
97 | return | |
98 | } | |
99 | clean_restart $executable | |
100 | ||
101 | gdb_test_no_output "set follow-fork-mode $type" | |
102 | # Testcase uses it for the `follow-fork-mode child' type. | |
103 | gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*" | |
104 | ||
105 | if ![runto_main] { | |
106 | return | |
107 | } | |
108 | ||
109 | gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint" | |
110 | ||
111 | # It should not be left over in the fork()ed-off child. | |
112 | gdb_test "$hbreak marker" {reakpoint [0-9]+.*} | |
113 | ||
114 | gdb_breakpoint "mark_exit" | |
115 | ||
116 | gdb_test "continue" \ | |
117 | "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work" | |
118 | gdb_test "continue" \ | |
119 | "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work" | |
120 | gdb_test "continue" \ | |
121 | "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A" | |
122 | gdb_test "continue" \ | |
123 | "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B" | |
124 | gdb_test "continue" \ | |
125 | "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork" | |
126 | gdb_test "continue" \ | |
127 | "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork" | |
128 | gdb_test "continue" \ | |
129 | "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork" | |
130 | gdb_test "continue" \ | |
131 | "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork" | |
132 | gdb_test "continue" \ | |
133 | "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork" | |
134 | gdb_test "continue" \ | |
135 | "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork" | |
136 | gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish" | |
4403d8e9 | 137 | } |
6a5870ce | 138 | }} |
4403d8e9 JK |
139 | |
140 | test parent FOLLOW_PARENT | |
141 | ||
142 | # Only GNU/Linux is known to support `set follow-fork-mode child'. | |
143 | if [istarget "*-*-linux*"] { | |
144 | test child FOLLOW_CHILD | |
145 | } else { | |
146 | untested "${testfile}: child" | |
147 | } |