Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.threads / next-fork-exec-other-thread.exp
blob34136056238d48e12c0dbf85094fdd3c5b2b90a4
1 # Copyright 2022-2024 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 # This test was adapted from next-fork-other-thread.exp. The .c file
17 # was adapted from the reproducer for this bug:
19 # https://sourceware.org/bugzilla/show_bug.cgi?id=30387#
21 # That bug demonstrates a problem with software-singlestep in gdbserver.
22 # Prior to being fixed, this test also demonstrated that bug for a
23 # 32-bit ARM target.  (Use RUNTESTFLAGS="--target_board=native-gdbserver".)
24 # It has been reproduced on a Raspberry Pi running Ubunutu server
25 # 20.04.5 LTS with 32-bit kernel + 32-bit userland.  It was NOT reproducible
26 # using a circa 2023 Raspberry Pi OS w/ 64-bit kernel and 32-bit userland.
28 standard_testfile
30 # Line where to stop the main thread.
31 set break_here_line [gdb_get_line_number "break here"]
33 # Build executables, one for each fork flavor.
34 foreach_with_prefix fork_func {fork vfork} {
35     set opts [list debug pthreads additional_flags=-DFORK_FUNC=${fork_func}]
36     if { [build_executable "failed to prepare" \
37             ${testfile}-${fork_func} ${srcfile} $opts] } {
38         return
39     }
42 # If testing against GDBserver, consume all it its output.
44 proc drain_gdbserver_output { } {
45     if { [info exists ::server_spawn_id] } {
46         gdb_test_multiple "" "" {
47             -i "$::server_spawn_id"
48             -timeout 0
49             -re ".+" {
50               exp_continue
51             }
52         }
53     }
56 # Run the test with the given parameters:
58 #   - FORK_FUNC: fork flavor, "fork" or "vfork".
59 #   - TARGET-NON-STOP: "maintenance set target-non-stop" value, "auto", "on" or
60 #     "off".
61 #   - NON-STOP: "set non-stop" value, "on" or "off".
62 #   - DISPLACED-STEPPING: "set displaced-stepping" value, "auto", "on" or "off".
64 proc do_test { fork_func target-non-stop non-stop displaced-stepping } {
65     save_vars { ::GDBFLAGS } {
66         append ::GDBFLAGS " -ex \"maintenance set target-non-stop ${target-non-stop}\""
67         append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
68         clean_restart ${::binfile}-${fork_func}
69     }
71     gdb_test_no_output "set displaced-stepping ${displaced-stepping}"
73     if { ![runto_main] } {
74         return
75     }
77     # The "Detached after (v)fork" messages get in the way in non-stop, disable
78     # them.
79     gdb_test_no_output "set print inferior-events off"
81     # Advance the next-ing thread to the point where we'll execute the nexts.
82     # Leave the breakpoint in: it will force GDB to step over it while next-ing,
83     # which exercises some additional code paths.
84     gdb_test "break $::break_here_line" "Breakpoint $::decimal at $::hex.*"
85     gdb_test "continue" "hit Breakpoint $::decimal, worker_b.*"
87     # Next an arbitrary number of times over the lines of the loop.
88     for { set i 0 } { $i < 30 } { incr i } {
89         # If testing against GDBserver, the forking threads cause a lot of
90         # "Detaching from process XYZ" messages to appear.  If we don't consume
91         # that output, GDBserver eventually blocks on a full stderr.  Drain it
92         # once every loop.  It may not be needed for 20 iterations, but it's
93         # needed if you increase to 200 iterations.
94         drain_gdbserver_output
96         with_test_prefix "i=$i" {
97             if { [gdb_test "next" "other line.*" "next to other line"] != 0 } {
98                 return
99             }
101             if { [gdb_test "next" "for loop.*" "next to for loop"] != 0 } {
102                 return
103             }
105             if { [gdb_test "next" "break here.*" "next to break here"] != 0} {
106                 return
107             }
108         }
109     }
112 foreach_with_prefix fork_func {fork vfork} {
113     foreach_with_prefix target-non-stop {auto on off} {
114         # This file was copied from next-fork-other-thread.exp and
115         # then adapted for the a case which also involves an exec in
116         # addition to the fork.  Ideally, we should test non-stop "on"
117         # in addition to "off", but, for this test, that results in a
118         # number of failures occur preceded by the message:
119         #
120         # Cannot execute this command while the selected thread is running.
121         #
122         # That seems like correct behavior to me, but perhaps the
123         # non-stop case can be made to work; if so, simply add "on"
124         # after "off" on the line below...
125         foreach_with_prefix non-stop {off} {
126             foreach_with_prefix displaced-stepping {auto on off} {
127                 do_test ${fork_func} ${target-non-stop} ${non-stop} ${displaced-stepping}
128             }
129         }
130     }