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