]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/siginfo-obj.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / siginfo-obj.exp
CommitLineData
1d506c26 1# Copyright 2004-2024 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
450d26c8 24require {!target_info exists gdb,nosignals}
4aa995e1 25
5f3ef828 26require supports_get_siginfo_type
4aa995e1 27
4aa995e1 28
0ab77f5f
TT
29standard_testfile
30
5b362f04 31if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
4aa995e1
PA
32 return -1
33}
34
4aa995e1 35# Advance to main
65a33d75 36if {![runto_main]} {
c8ee3f04 37 return 0
4aa995e1
PA
38}
39
40# Run to the signal.
c2b75043
LM
41gdb_test "continue" ".*Program received signal SIGSEGV.*" \
42 "continue to signal, 1st"
4aa995e1 43
9015683b
TT
44# Try to generate a core file, for a later test.
45set gcorefile [standard_output_file $testfile.gcore]
46set gcore_created [gdb_gcore_cmd $gcorefile "save a core file"]
47
4aa995e1 48set ssi_addr ""
bc6c7af4 49set test "extract si_addr"
4aa995e1
PA
50gdb_test_multiple "p \$_siginfo" "$test" {
51 -re "si_addr = ($hex).*$gdb_prompt $" {
52 set ssi_addr $expect_out(1,string)
53 pass "$test"
54 }
55}
56
bc6c7af4 57set test "extract si_errno"
4aa995e1
PA
58gdb_test_multiple "p \$_siginfo" "$test" {
59 -re "si_errno = (\[0-9\]\+).*$gdb_prompt $" {
60 set ssi_errno $expect_out(1,string)
61 pass "$test"
62 }
63}
64
bc6c7af4 65set test "extract si_code"
4aa995e1
PA
66gdb_test_multiple "p \$_siginfo" "$test" {
67 -re "si_code = (\[0-9\]\+).*$gdb_prompt $" {
68 set ssi_code $expect_out(1,string)
69 pass "$test"
70 }
71}
72
bc6c7af4 73set test "extract si_signo"
4aa995e1
PA
74gdb_test_multiple "p \$_siginfo" "$test" {
75 -re "si_signo = (\[0-9\]\+).*$gdb_prompt $" {
76 set ssi_signo $expect_out(1,string)
77 pass "$test"
78 }
79}
80
81set bp_location [gdb_get_line_number "set breakpoint here"]
82
c2b75043
LM
83with_test_prefix "validate siginfo fields" {
84 gdb_test "break $bp_location"
85 gdb_test "continue" ".* handler .*" "continue to handler"
86 gdb_test "p ssi_addr" " = \\(void \\*\\) $ssi_addr"
87 gdb_test "p ssi_errno" " = $ssi_errno"
88 gdb_test "p ssi_code" " = $ssi_code"
89 gdb_test "p ssi_signo" " = $ssi_signo"
90}
4aa995e1
PA
91
92# Again, but this time, patch si_addr and check that the inferior sees
93# the changed value.
94
95# Advance to main
65a33d75 96if {![runto_main]} {
c8ee3f04 97 return 0
4aa995e1
PA
98}
99
100# Run to the signal.
c2b75043
LM
101gdb_test "continue" ".*Program received signal SIGSEGV.*" \
102 "continue to signal, 2nd"
4aa995e1 103
bc6c7af4 104set test "set si_addr"
4aa995e1
PA
105gdb_test "p \$_siginfo._sifields._sigfault.si_addr = 0x666" " = \\(void \\*\\) 0x666"
106gdb_test "p \$_siginfo.si_errno = 666" " = 666"
107gdb_test "p \$_siginfo.si_code = 999" " = 999"
108gdb_test "p \$_siginfo.si_signo = 11" " = 11"
109
c2b75043
LM
110with_test_prefix "validate modified siginfo fields" {
111 gdb_test "break $bp_location"
112 gdb_test "continue" ".* handler .*" "continue to handler"
113 gdb_test "p ssi_addr" " = \\(void \\*\\) 0x666"
114 gdb_test "p ssi_errno" " = 666"
115 gdb_test "p ssi_code" " = 999"
116 gdb_test "p ssi_signo" " = 11"
117}
9015683b
TT
118
119# Test siginfo preservation in core files.
120if {$gcore_created} {
121 clean_restart $binfile
122
123 gdb_test "core $gcorefile" "Core was generated by.*" \
124 "core [file tail $gcorefile]"
125
126 gdb_test "p \$_siginfo.si_signo" " = $ssi_signo" \
127 "p \$_siginfo.si_signo from core file"
128 gdb_test "p \$_siginfo.si_errno" " = $ssi_errno" \
129 "p \$_siginfo.si_errno from core file"
130 gdb_test "p \$_siginfo.si_code" " = $ssi_code" \
131 "p \$_siginfo.si_code from core file"
132 gdb_test "p \$_siginfo._sifields._sigfault.si_addr" \
133 " = \\(void \\*\\) $ssi_addr" \
134 "p \$_siginfo._sifields._sigfault.si_addr from core file"
135}