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