gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.threads / next-fork-other-thread.exp
blob5960bb9ba1004078cc3a8f5d08fcb464915335c9
1 # Copyright 2022 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test doing a "next" on a thread during which forks or vforks happen in other
17 # threads.
19 standard_testfile
21 # Line where to stop the main thread.
22 set break_here_line [gdb_get_line_number "break here"]
24 # Build executables, one for each fork flavor.
25 foreach_with_prefix fork_func {fork vfork} {
26 set opts [list debug pthreads additional_flags=-DFORK_FUNC=${fork_func}]
27 if { [build_executable "failed to prepare" \
28 ${testfile}-${fork_func} ${srcfile} $opts] } {
29 return
33 # If testing against GDBserver, consume all it its output.
35 proc drain_gdbserver_output { } {
36 if { [info exists ::server_spawn_id] } {
37 gdb_test_multiple "" "" {
38 -i "$::server_spawn_id"
39 -timeout 0
40 -re ".+" {
41 exp_continue
47 # Run the test with the given parameters:
49 # - FORK_FUNC: fork flavor, "fork" or "vfork".
50 # - TARGET-NON-STOP: "maintenance set target-non-stop" value, "auto", "on" or
51 # "off".
52 # - NON-STOP: "set non-stop" value, "on" or "off".
53 # - DISPLACED-STEPPING: "set displaced-stepping" value, "auto", "on" or "off".
55 proc do_test { fork_func target-non-stop non-stop displaced-stepping } {
56 save_vars { ::GDBFLAGS } {
57 append ::GDBFLAGS " -ex \"maintenance set target-non-stop ${target-non-stop}\""
58 append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
59 clean_restart ${::binfile}-${fork_func}
62 gdb_test_no_output "set displaced-stepping ${displaced-stepping}"
64 if { ![runto_main] } {
65 return
68 # The "Detached after (v)fork" messages get in the way in non-stop, disable
69 # them.
70 gdb_test_no_output "set print inferior-events off"
72 # Advance the next-ing thread to the point where we'll execute the nexts.
73 # Leave the breakpoint in: it will force GDB to step over it while next-ing,
74 # which exercises some additional code paths.
75 gdb_test "break $::break_here_line" "Breakpoint $::decimal at $::hex.*"
76 gdb_test "continue" "hit Breakpoint $::decimal, main.*"
78 # Next an arbitrary number of times over the lines of the loop.
80 # It is useful to bump this number to a larger value (e.g. 200) to stress
81 # test more, but it makes the test case run for considerably longer. If
82 # you increase the number of loops, you might want to adjust the alarm
83 # time in the .c file accordingly.
84 for { set i 0 } { $i < 20 } { incr i } {
85 # If testing against GDBserver, the forking threads cause a lot of
86 # "Detaching from process XYZ" messages to appear. If we don't consume
87 # that output, GDBserver eventually blocks on a full stderr. Drain it
88 # once every loop. It may not be needed for 20 iterations, but it's
89 # needed if you increase to 200 iterations.
90 drain_gdbserver_output
92 with_test_prefix "i=$i" {
93 if { [gdb_test "next" "other line.*" "next to other line"] != 0 } {
94 return
97 if { [gdb_test "next" "for loop.*" "next to for loop"] != 0 } {
98 return
101 if { [gdb_test "next" "break here.*" "next to break here"] != 0} {
102 return
108 foreach_with_prefix fork_func {fork vfork} {
109 foreach_with_prefix target-non-stop {auto on off} {
110 foreach_with_prefix non-stop {off on} {
111 foreach_with_prefix displaced-stepping {auto on off} {
112 do_test ${fork_func} ${target-non-stop} ${non-stop} ${displaced-stepping}