]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/signals-state-child.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / signals-state-child.exp
CommitLineData
1d506c26 1# Copyright 2016-2024 Free Software Foundation, Inc.
f348d89a
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 gdb's (or gdbserver's) own signal handling does not
17# interfere with the signal actions (dispositions, etc.) and mask
18# their spawned children inherit.
19#
20# - If gdb inherits some signal set to SIG_IGN, so should the
21# inferior, even if gdb itself chooses not to ignore the signal.
22#
23# - If gdb inherits some signal set to SIG_DFL, so should the inferior
24# even if gdb itself ignores that signal.
25#
26# This requires special support in gdb/gdbserver because the exec
27# family of functions does not reset the signal disposition of signals
28# that are set to SIG_IGN, nor signal masks and flags.
29
30standard_testfile
31
3589529e
YQ
32if {![is_remote host] && ![is_remote target]} {
33 set gdb_txt [standard_output_file gdb.txt]
34 set standalone_txt [standard_output_file standalone.txt]
35 set purely_local 1
36} else {
37 set gdb_txt gdb.txt
38 set standalone_txt standalone.txt
39 set purely_local 0
40}
41
42remote_file host delete $gdb_txt
43remote_file host delete $standalone_txt
44remote_file target delete $gdb_txt
45remote_file target delete $standalone_txt
f348d89a
PA
46
47set options [list debug "additional_flags=-DOUTPUT_TXT=\"$gdb_txt\""]
48if {[build_executable $testfile.exp $testfile $srcfile $options]} {
5b362f04 49 untested "failed to compile"
f348d89a
PA
50 return -1
51}
52
53set options [list debug "additional_flags=-DOUTPUT_TXT=\"$standalone_txt\""]
54if {[build_executable $testfile.exp $testfile-standalone $srcfile $options]} {
5b362f04 55 untested "failed to compile"
f348d89a
PA
56 return -1
57}
58
59# Run the program directly, and dump its initial signal actions and
60# mask in "standalone.txt".
61
1b79c725
TV
62if { [is_remote target] } {
63 set target_binfile_standalone \
64 [gdb_remote_download target $binfile-standalone]
65
66 # Ensure that target_binfile_standalone is absolute, to work around
67 # current dir not being included in PATH.
68 set target_binfile_standalone \
69 [remote_file target absolute $target_binfile_standalone]
70 if { $target_binfile_standalone == "" } {
71 # Not supported by default, but supported in for instance
72 # remote-gdbserver-on-localhost.exp.
73 unsupported "require failed: remote_file target absolute"
74 return
75 }
76} else {
77 set target_binfile_standalone $binfile-standalone
78}
79
f348d89a
PA
80# Use remote_spawn instead of remote_exec, like how we spawn gdb.
81# This is in order to take the same code code paths in dejagnu
82# compared to when running the program through gdb. E.g., because
83# local_exec uses -ignore SIGHUP, while remote_spawn does not, if we
84# used remote_exec, the test program would start with SIGHUP ignored
85# when run standalone, but not when run through gdb.
1b79c725 86set res [remote_spawn target "$target_binfile_standalone"]
f348d89a 87if { $res < 0 || $res == "" } {
1b79c725 88 untested "spawning \$target_binfile_standalone failed"
f348d89a 89 return 1
f348d89a 90}
a0cfd0ca
TV
91
92set wait_status [remote_wait target 60]
93set have_standalone [expr [lindex $wait_status 0] == 0]
94gdb_assert { $have_standalone } "collect standalone signals state"
3589529e 95remote_close target
f348d89a
PA
96
97# Now run the program through gdb, and dump its initial signal actions
98# and mask in "gdb.txt".
99
100clean_restart $binfile
101
65a33d75 102if {![runto_main]} {
f348d89a
PA
103 return -1
104}
105
106gdb_continue_to_end "collect signals state under gdb"
107
a0cfd0ca
TV
108set test "signals states are identical"
109if { ! $have_standalone } {
110 untested $test
111 return -1
112}
113
3589529e
YQ
114if {!$purely_local} {
115 # Copy file from target to host through build.
116 remote_download host [remote_upload target gdb.txt] gdb.txt
117 remote_download host [remote_upload target standalone.txt] standalone.txt
118}
119
f348d89a
PA
120# Diff the .txt files. They should be identical.
121gdb_test "shell diff -s $standalone_txt $gdb_txt" \
122 "Files .* are identical.*" \
a0cfd0ca 123 $test
1b79c725
TV
124
125if { [is_remote target] } {
126 remote_file target delete gdb.txt
127 remote_file target delete standalone.txt
128}