1 1.1.1.6 christos # Copyright 2016-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test that gdb's (or gdbserver's) own signal handling does not 17 1.1 christos # interfere with the signal actions (dispositions, etc.) and mask 18 1.1 christos # their spawned children inherit. 19 1.1 christos # 20 1.1 christos # - If gdb inherits some signal set to SIG_IGN, so should the 21 1.1 christos # inferior, even if gdb itself chooses not to ignore the signal. 22 1.1 christos # 23 1.1 christos # - If gdb inherits some signal set to SIG_DFL, so should the inferior 24 1.1 christos # even if gdb itself ignores that signal. 25 1.1 christos # 26 1.1 christos # This requires special support in gdb/gdbserver because the exec 27 1.1 christos # family of functions does not reset the signal disposition of signals 28 1.1 christos # that are set to SIG_IGN, nor signal masks and flags. 29 1.1 christos 30 1.1 christos standard_testfile 31 1.1 christos 32 1.1 christos if {![is_remote host] && ![is_remote target]} { 33 1.1 christos set gdb_txt [standard_output_file gdb.txt] 34 1.1 christos set standalone_txt [standard_output_file standalone.txt] 35 1.1 christos set purely_local 1 36 1.1 christos } else { 37 1.1 christos set gdb_txt gdb.txt 38 1.1 christos set standalone_txt standalone.txt 39 1.1 christos set purely_local 0 40 1.1 christos } 41 1.1 christos 42 1.1 christos remote_file host delete $gdb_txt 43 1.1 christos remote_file host delete $standalone_txt 44 1.1 christos remote_file target delete $gdb_txt 45 1.1 christos remote_file target delete $standalone_txt 46 1.1 christos 47 1.1 christos set options [list debug "additional_flags=-DOUTPUT_TXT=\"$gdb_txt\""] 48 1.1 christos if {[build_executable $testfile.exp $testfile $srcfile $options]} { 49 1.1.1.2 christos untested "failed to compile" 50 1.1 christos return -1 51 1.1 christos } 52 1.1 christos 53 1.1 christos set options [list debug "additional_flags=-DOUTPUT_TXT=\"$standalone_txt\""] 54 1.1 christos if {[build_executable $testfile.exp $testfile-standalone $srcfile $options]} { 55 1.1.1.2 christos untested "failed to compile" 56 1.1 christos return -1 57 1.1 christos } 58 1.1 christos 59 1.1 christos # Run the program directly, and dump its initial signal actions and 60 1.1 christos # mask in "standalone.txt". 61 1.1 christos 62 1.1.1.6 christos if { [is_remote target] } { 63 1.1.1.6 christos set target_binfile_standalone \ 64 1.1.1.6 christos [gdb_remote_download target $binfile-standalone] 65 1.1.1.6 christos 66 1.1.1.6 christos # Ensure that target_binfile_standalone is absolute, to work around 67 1.1.1.6 christos # current dir not being included in PATH. 68 1.1.1.6 christos set target_binfile_standalone \ 69 1.1.1.6 christos [remote_file target absolute $target_binfile_standalone] 70 1.1.1.6 christos if { $target_binfile_standalone == "" } { 71 1.1.1.6 christos # Not supported by default, but supported in for instance 72 1.1.1.6 christos # remote-gdbserver-on-localhost.exp. 73 1.1.1.6 christos unsupported "require failed: remote_file target absolute" 74 1.1.1.6 christos return 75 1.1.1.6 christos } 76 1.1.1.6 christos } else { 77 1.1.1.6 christos set target_binfile_standalone $binfile-standalone 78 1.1.1.6 christos } 79 1.1.1.6 christos 80 1.1 christos # Use remote_spawn instead of remote_exec, like how we spawn gdb. 81 1.1 christos # This is in order to take the same code code paths in dejagnu 82 1.1 christos # compared to when running the program through gdb. E.g., because 83 1.1 christos # local_exec uses -ignore SIGHUP, while remote_spawn does not, if we 84 1.1 christos # used remote_exec, the test program would start with SIGHUP ignored 85 1.1 christos # when run standalone, but not when run through gdb. 86 1.1.1.6 christos set res [remote_spawn target "$target_binfile_standalone"] 87 1.1 christos if { $res < 0 || $res == "" } { 88 1.1.1.6 christos untested "spawning \$target_binfile_standalone failed" 89 1.1 christos return 1 90 1.1 christos } 91 1.1.1.5 christos 92 1.1.1.5 christos set wait_status [remote_wait target 60] 93 1.1.1.5 christos set have_standalone [expr [lindex $wait_status 0] == 0] 94 1.1.1.5 christos gdb_assert { $have_standalone } "collect standalone signals state" 95 1.1 christos remote_close target 96 1.1 christos 97 1.1 christos # Now run the program through gdb, and dump its initial signal actions 98 1.1 christos # and mask in "gdb.txt". 99 1.1 christos 100 1.1 christos clean_restart $binfile 101 1.1 christos 102 1.1.1.5 christos if {![runto_main]} { 103 1.1 christos return -1 104 1.1 christos } 105 1.1 christos 106 1.1 christos gdb_continue_to_end "collect signals state under gdb" 107 1.1 christos 108 1.1.1.5 christos set test "signals states are identical" 109 1.1.1.5 christos if { ! $have_standalone } { 110 1.1.1.5 christos untested $test 111 1.1.1.5 christos return -1 112 1.1.1.5 christos } 113 1.1.1.5 christos 114 1.1 christos if {!$purely_local} { 115 1.1 christos # Copy file from target to host through build. 116 1.1 christos remote_download host [remote_upload target gdb.txt] gdb.txt 117 1.1 christos remote_download host [remote_upload target standalone.txt] standalone.txt 118 1.1 christos } 119 1.1 christos 120 1.1 christos # Diff the .txt files. They should be identical. 121 1.1 christos gdb_test "shell diff -s $standalone_txt $gdb_txt" \ 122 1.1 christos "Files .* are identical.*" \ 123 1.1.1.5 christos $test 124 1.1.1.6 christos 125 1.1.1.6 christos if { [is_remote target] } { 126 1.1.1.6 christos remote_file target delete gdb.txt 127 1.1.1.6 christos remote_file target delete standalone.txt 128 1.1.1.6 christos } 129