Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / signals-state-child.exp
blob938c69aa5a81d449290cf661123eb16cf0010ca4
1 # Copyright 2016-2023 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 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.
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.
23 # - If gdb inherits some signal set to SIG_DFL, so should the inferior
24 #   even if gdb itself ignores that signal.
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.
30 standard_testfile
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
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
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
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
59 # Run the program directly, and dump its initial signal actions and
60 # mask in "standalone.txt".
62 # Use remote_spawn instead of remote_exec, like how we spawn gdb.
63 # This is in order to take the same code code paths in dejagnu
64 # compared to when running the program through gdb.  E.g., because
65 # local_exec uses -ignore SIGHUP, while remote_spawn does not, if we
66 # used remote_exec, the test program would start with SIGHUP ignored
67 # when run standalone, but not when run through gdb.
68 set res [remote_spawn target "$binfile-standalone"]
69 if { $res < 0 || $res == "" } {
70     untested "spawning $binfile-standalone failed"
71     return 1
74 set wait_status [remote_wait target 60]
75 set have_standalone [expr [lindex $wait_status 0] == 0]
76 gdb_assert { $have_standalone } "collect standalone signals state"
77 remote_close target
79 # Now run the program through gdb, and dump its initial signal actions
80 # and mask in "gdb.txt".
82 clean_restart $binfile
84 if {![runto_main]} {
85     return -1
88 gdb_continue_to_end "collect signals state under gdb"
90 set test "signals states are identical"
91 if { ! $have_standalone } {
92     untested $test
93     return -1
96 if {!$purely_local} {
97     # Copy file from target to host through build.
98     remote_download host [remote_upload target gdb.txt] gdb.txt
99     remote_download host [remote_upload target standalone.txt] standalone.txt
102 # Diff the .txt files.  They should be identical.
103 gdb_test "shell diff -s $standalone_txt $gdb_txt" \
104     "Files .* are identical.*" \
105     $test