Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2004-2020 Free Software Foundation, Inc. |
4aa995e1 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 | ||
17 | # The program siginfo-obj.c arranges for a signal handler registered | |
18 | # using sigaction's sa_sigaction / SA_SIGINFO to be called with | |
19 | # si_addr filled in. | |
20 | ||
21 | # This test confirms that we can inspect signal info using the | |
22 | # $_siginfo convenience variable. | |
23 | ||
24 | if [target_info exists gdb,nosignals] { | |
25 | verbose "Skipping siginfo-obj.exp because of nosignals." | |
26 | continue | |
27 | } | |
28 | ||
4d7be007 | 29 | if { ![supports_get_siginfo_type] } { |
4aa995e1 PA |
30 | verbose "Skipping siginfo-obj.exp because of lack of support." |
31 | return | |
32 | } | |
33 | ||
4aa995e1 | 34 | |
0ab77f5f TT |
35 | standard_testfile |
36 | ||
5b362f04 | 37 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { |
4aa995e1 PA |
38 | return -1 |
39 | } | |
40 | ||
4aa995e1 | 41 | # Advance to main |
c8ee3f04 PW |
42 | if ![runto_main] then { |
43 | fail "can't run to main" | |
44 | return 0 | |
4aa995e1 PA |
45 | } |
46 | ||
47 | # Run to the signal. | |
c2b75043 LM |
48 | gdb_test "continue" ".*Program received signal SIGSEGV.*" \ |
49 | "continue to signal, 1st" | |
4aa995e1 | 50 | |
9015683b TT |
51 | # Try to generate a core file, for a later test. |
52 | set gcorefile [standard_output_file $testfile.gcore] | |
53 | set gcore_created [gdb_gcore_cmd $gcorefile "save a core file"] | |
54 | ||
4aa995e1 | 55 | set ssi_addr "" |
bc6c7af4 | 56 | set test "extract si_addr" |
4aa995e1 PA |
57 | gdb_test_multiple "p \$_siginfo" "$test" { |
58 | -re "si_addr = ($hex).*$gdb_prompt $" { | |
59 | set ssi_addr $expect_out(1,string) | |
60 | pass "$test" | |
61 | } | |
62 | } | |
63 | ||
bc6c7af4 | 64 | set test "extract si_errno" |
4aa995e1 PA |
65 | gdb_test_multiple "p \$_siginfo" "$test" { |
66 | -re "si_errno = (\[0-9\]\+).*$gdb_prompt $" { | |
67 | set ssi_errno $expect_out(1,string) | |
68 | pass "$test" | |
69 | } | |
70 | } | |
71 | ||
bc6c7af4 | 72 | set test "extract si_code" |
4aa995e1 PA |
73 | gdb_test_multiple "p \$_siginfo" "$test" { |
74 | -re "si_code = (\[0-9\]\+).*$gdb_prompt $" { | |
75 | set ssi_code $expect_out(1,string) | |
76 | pass "$test" | |
77 | } | |
78 | } | |
79 | ||
bc6c7af4 | 80 | set test "extract si_signo" |
4aa995e1 PA |
81 | gdb_test_multiple "p \$_siginfo" "$test" { |
82 | -re "si_signo = (\[0-9\]\+).*$gdb_prompt $" { | |
83 | set ssi_signo $expect_out(1,string) | |
84 | pass "$test" | |
85 | } | |
86 | } | |
87 | ||
88 | set bp_location [gdb_get_line_number "set breakpoint here"] | |
89 | ||
c2b75043 LM |
90 | with_test_prefix "validate siginfo fields" { |
91 | gdb_test "break $bp_location" | |
92 | gdb_test "continue" ".* handler .*" "continue to handler" | |
93 | gdb_test "p ssi_addr" " = \\(void \\*\\) $ssi_addr" | |
94 | gdb_test "p ssi_errno" " = $ssi_errno" | |
95 | gdb_test "p ssi_code" " = $ssi_code" | |
96 | gdb_test "p ssi_signo" " = $ssi_signo" | |
97 | } | |
4aa995e1 PA |
98 | |
99 | # Again, but this time, patch si_addr and check that the inferior sees | |
100 | # the changed value. | |
101 | ||
102 | # Advance to main | |
c8ee3f04 PW |
103 | if ![runto_main] then { |
104 | fail "can't run to main" | |
105 | return 0 | |
4aa995e1 PA |
106 | } |
107 | ||
108 | # Run to the signal. | |
c2b75043 LM |
109 | gdb_test "continue" ".*Program received signal SIGSEGV.*" \ |
110 | "continue to signal, 2nd" | |
4aa995e1 | 111 | |
bc6c7af4 | 112 | set test "set si_addr" |
4aa995e1 PA |
113 | gdb_test "p \$_siginfo._sifields._sigfault.si_addr = 0x666" " = \\(void \\*\\) 0x666" |
114 | gdb_test "p \$_siginfo.si_errno = 666" " = 666" | |
115 | gdb_test "p \$_siginfo.si_code = 999" " = 999" | |
116 | gdb_test "p \$_siginfo.si_signo = 11" " = 11" | |
117 | ||
c2b75043 LM |
118 | with_test_prefix "validate modified siginfo fields" { |
119 | gdb_test "break $bp_location" | |
120 | gdb_test "continue" ".* handler .*" "continue to handler" | |
121 | gdb_test "p ssi_addr" " = \\(void \\*\\) 0x666" | |
122 | gdb_test "p ssi_errno" " = 666" | |
123 | gdb_test "p ssi_code" " = 999" | |
124 | gdb_test "p ssi_signo" " = 11" | |
125 | } | |
9015683b TT |
126 | |
127 | # Test siginfo preservation in core files. | |
128 | if {$gcore_created} { | |
129 | clean_restart $binfile | |
130 | ||
131 | gdb_test "core $gcorefile" "Core was generated by.*" \ | |
132 | "core [file tail $gcorefile]" | |
133 | ||
134 | gdb_test "p \$_siginfo.si_signo" " = $ssi_signo" \ | |
135 | "p \$_siginfo.si_signo from core file" | |
136 | gdb_test "p \$_siginfo.si_errno" " = $ssi_errno" \ | |
137 | "p \$_siginfo.si_errno from core file" | |
138 | gdb_test "p \$_siginfo.si_code" " = $ssi_code" \ | |
139 | "p \$_siginfo.si_code from core file" | |
140 | gdb_test "p \$_siginfo._sifields._sigfault.si_addr" \ | |
141 | " = \\(void \\*\\) $ssi_addr" \ | |
142 | "p \$_siginfo._sifields._sigfault.si_addr from core file" | |
143 | } |