Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2016-2021 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 | ||
30 | standard_testfile | |
31 | ||
3589529e YQ |
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 | |
f348d89a PA |
46 | |
47 | set options [list debug "additional_flags=-DOUTPUT_TXT=\"$gdb_txt\""] | |
48 | if {[build_executable $testfile.exp $testfile $srcfile $options]} { | |
5b362f04 | 49 | untested "failed to compile" |
f348d89a PA |
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]} { | |
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 | ||
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. | |
3589529e | 68 | set res [remote_spawn target "$binfile-standalone"] |
f348d89a PA |
69 | if { $res < 0 || $res == "" } { |
70 | untested "spawning $binfile-standalone failed" | |
71 | return 1 | |
72 | } else { | |
73 | pass "collect standalone signals state" | |
74 | } | |
3589529e | 75 | remote_close target |
f348d89a PA |
76 | |
77 | # Now run the program through gdb, and dump its initial signal actions | |
78 | # and mask in "gdb.txt". | |
79 | ||
80 | clean_restart $binfile | |
81 | ||
82 | if { ! [ runto_main ] } then { | |
5b362f04 | 83 | untested "failed to compile" |
f348d89a PA |
84 | return -1 |
85 | } | |
86 | ||
87 | gdb_continue_to_end "collect signals state under gdb" | |
88 | ||
3589529e YQ |
89 | if {!$purely_local} { |
90 | # Copy file from target to host through build. | |
91 | remote_download host [remote_upload target gdb.txt] gdb.txt | |
92 | remote_download host [remote_upload target standalone.txt] standalone.txt | |
93 | } | |
94 | ||
f348d89a PA |
95 | # Diff the .txt files. They should be identical. |
96 | gdb_test "shell diff -s $standalone_txt $gdb_txt" \ | |
97 | "Files .* are identical.*" \ | |
98 | "signals states are identical" |