gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced...
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / forking-threads-plus-breakpoint.exp
CommitLineData
b811d2c2 1# Copyright (C) 2015-2020 Free Software Foundation, Inc.
863d01bd
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# This test verifies that several threads forking while another thread
17# is constantly stepping over a breakpoint is properly handled.
18
19standard_testfile
20
21set linenum [gdb_get_line_number "set break here"]
22
23if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
24 return -1
25}
26
6b2e4f10
PA
27# Assume yes.
28set displaced_stepping_supported 1
29
30# "set displaced on" only tells gdb to use displaced stepping if
31# possible. Probe for actual support.
32
33proc probe_displaced_stepping_support {} {
34 global displaced_stepping_supported
35 global binfile gdb_prompt
36
37 with_test_prefix "probe displaced-stepping support" {
38 clean_restart $binfile
39
40 gdb_test_no_output "set displaced on"
41 if ![runto_main] then {
bc6c7af4 42 fail "can't run to main"
6b2e4f10
PA
43 return 0
44 }
45
46 # We're stopped at the main breakpoint. If displaced stepping is
47 # supported, we'll see related debug output while we step past
48 # that breakpoint.
49 gdb_test_no_output "set debug displaced 1"
50 gdb_test_multiple "next" "probe" {
e088209c 51 -re "displaced: prepared successfully .*$gdb_prompt $" {
6b2e4f10
PA
52 pass "supported"
53 }
54 -re ".*$gdb_prompt $" {
55 set displaced_stepping_supported 0
56 pass "not supported"
57 }
58 }
59 }
60}
61
863d01bd
PA
62# The test proper. If COND_BP_TARGET is true, then test with
63# conditional breakpoints evaluated on the target side, if possible.
64# DETACH_ON_FORK is used as value for the "set detach-on-fork"
65# setting. If "on", this exercises GDB explicitly continuing the fork
66# child until exit. If "off", this exercises GDB detaching the fork
6b2e4f10
PA
67# child. DISPLACED indicates whether to use displaced stepping or
68# not.
69proc do_test { cond_bp_target detach_on_fork displaced } {
863d01bd
PA
70 global GDBFLAGS
71 global srcfile testfile binfile
72 global decimal gdb_prompt
73 global linenum
74 global is_remote_target
75
76 set saved_gdbflags $GDBFLAGS
77 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""]
78 clean_restart $binfile
79 set GDBFLAGS $saved_gdbflags
80
81 if ![runto_main] then {
bc6c7af4 82 fail "can't run to main"
863d01bd
PA
83 return 0
84 }
85
40fb20d0
YQ
86 if {$cond_bp_target} {
87 set test "set breakpoint condition-evaluation target"
88 gdb_test_multiple $test $test {
89 -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" {
90 # Target doesn't support breakpoint condition
91 # evaluation on its side. Skip the test.
92 return 0
93 }
94 -re "^$test\r\n$gdb_prompt $" {
95 }
96 }
97 } else {
98 gdb_test_no_output "set breakpoint condition-evaluation host"
99 }
100
863d01bd 101 gdb_test_no_output "set detach-on-fork $detach_on_fork"
6b2e4f10 102 gdb_test_no_output "set displaced $displaced"
863d01bd
PA
103
104 gdb_test "break $linenum if zero == 1" \
105 "Breakpoint .*" \
106 "set breakpoint that evals false"
107
108 set test "continue &"
109 gdb_test_multiple $test $test {
110 -re "$gdb_prompt " {
111 pass $test
112 }
113 }
114
115 set fork_count 0
116 set ok 0
117
7868401b
DB
118 with_timeout_factor 10 {
119 set test "inferior 1 exited"
120 gdb_test_multiple "" $test {
121 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
122 set ok 1
123 pass $test
124 }
125 -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" {
126 incr fork_count
127 if {$fork_count <= 100} {
128 exp_continue
129 } else {
130 fail "$test (too many forks)"
131 }
863d01bd
PA
132 }
133 }
134 }
135
136 if {!$ok} {
137 # No use testing further.
138 return
139 }
140
141 gdb_test "info threads" "No threads\." \
142 "no threads left"
143
144 gdb_test "info inferiors" \
121b3efd 145 "Num\[ \t\]+Description\[ \t\]+Connection\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \
863d01bd
PA
146 "only inferior 1 left"
147}
148
6b2e4f10
PA
149probe_displaced_stepping_support
150
863d01bd 151foreach_with_prefix cond_bp_target {1 0} {
f6a9d9c7 152 foreach_with_prefix detach_on_fork {"on" "off"} {
863d01bd
PA
153 # Disable "off" for now. The test does pass with
154 # detach-on-fork off (at the time of writing), but gdb seems
155 # to slow down quadratically as inferiors are created, and
156 # then the test takes annoyingly long to complete...
6b2e4f10
PA
157 if {$detach_on_fork == "off"} {
158 continue
159 }
160
161 foreach_with_prefix displaced {"on" "off"} {
162 if {$displaced == "on" && !$displaced_stepping_supported} {
163 continue
164 }
165
166 do_test $cond_bp_target $detach_on_fork $displaced
167 }
863d01bd
PA
168 }
169}
This page took 0.578591 seconds and 4 git commands to generate.