]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - 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
1 # Copyright 2016-2024 Free Software Foundation, Inc.
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
30 standard_testfile
31
32 if {![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
42 remote_file host delete $gdb_txt
43 remote_file host delete $standalone_txt
44 remote_file target delete $gdb_txt
45 remote_file target delete $standalone_txt
46
47 set options [list debug "additional_flags=-DOUTPUT_TXT=\"$gdb_txt\""]
48 if {[build_executable $testfile.exp $testfile $srcfile $options]} {
49 untested "failed to compile"
50 return -1
51 }
52
53 set options [list debug "additional_flags=-DOUTPUT_TXT=\"$standalone_txt\""]
54 if {[build_executable $testfile.exp $testfile-standalone $srcfile $options]} {
55 untested "failed to compile"
56 return -1
57 }
58
59 # Run the program directly, and dump its initial signal actions and
60 # mask in "standalone.txt".
61
62 if { [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
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.
86 set res [remote_spawn target "$target_binfile_standalone"]
87 if { $res < 0 || $res == "" } {
88 untested "spawning \$target_binfile_standalone failed"
89 return 1
90 }
91
92 set wait_status [remote_wait target 60]
93 set have_standalone [expr [lindex $wait_status 0] == 0]
94 gdb_assert { $have_standalone } "collect standalone signals state"
95 remote_close target
96
97 # Now run the program through gdb, and dump its initial signal actions
98 # and mask in "gdb.txt".
99
100 clean_restart $binfile
101
102 if {![runto_main]} {
103 return -1
104 }
105
106 gdb_continue_to_end "collect signals state under gdb"
107
108 set test "signals states are identical"
109 if { ! $have_standalone } {
110 untested $test
111 return -1
112 }
113
114 if {!$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
120 # Diff the .txt files. They should be identical.
121 gdb_test "shell diff -s $standalone_txt $gdb_txt" \
122 "Files .* are identical.*" \
123 $test
124
125 if { [is_remote target] } {
126 remote_file target delete gdb.txt
127 remote_file target delete standalone.txt
128 }