2009-02-06 Pedro Alves <pedro@codesourcery.com>
[binutils-gdb.git] / gdb / testsuite / gdb.base / siginfo-obj.exp
blob0dea59ab8dfbd16db796a76898bca9a903de8554
1 # Copyright 2004, 2007, 2008 Free Software Foundation, Inc.
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.
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.
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/>.
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.
21 # This test confirms that we can inspect signal info using the
22 # $_siginfo convenience variable.
24 if [target_info exists gdb,nosignals] {
25 verbose "Skipping siginfo-obj.exp because of nosignals."
26 continue
29 if { ! [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
36 if $tracelevel then {
37 strace $tracelevel
40 set prms_id 0
41 set bug_id 0
43 set testfile siginfo-obj
44 set srcfile ${testfile}.c
45 set binfile ${objdir}/${subdir}/${testfile}
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
47 untested "Couldn't compile ${srcfile}.c"
48 return -1
51 # get things started
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_load ${binfile}
57 # Advance to main
58 if { ![runto_main] } then {
59 gdb_suppress_tests;
62 # Run to the signal.
63 gdb_test "continue" ".*Program received signal SIGSEGV.*" "continue to signal"
65 set ssi_addr ""
66 set test "Extract si_addr"
67 gdb_test_multiple "p \$_siginfo" "$test" {
68 -re "si_addr = ($hex).*$gdb_prompt $" {
69 set ssi_addr $expect_out(1,string)
70 pass "$test"
74 set test "Extract si_errno"
75 gdb_test_multiple "p \$_siginfo" "$test" {
76 -re "si_errno = (\[0-9\]\+).*$gdb_prompt $" {
77 set ssi_errno $expect_out(1,string)
78 pass "$test"
82 set test "Extract si_code"
83 gdb_test_multiple "p \$_siginfo" "$test" {
84 -re "si_code = (\[0-9\]\+).*$gdb_prompt $" {
85 set ssi_code $expect_out(1,string)
86 pass "$test"
90 set test "Extract si_signo"
91 gdb_test_multiple "p \$_siginfo" "$test" {
92 -re "si_signo = (\[0-9\]\+).*$gdb_prompt $" {
93 set ssi_signo $expect_out(1,string)
94 pass "$test"
98 set bp_location [gdb_get_line_number "set breakpoint here"]
100 gdb_test "break $bp_location"
101 gdb_test "continue" ".* handler .*" "continue to handler"
103 gdb_test "p ssi_addr" " = \\(void \\*\\) $ssi_addr"
104 gdb_test "p ssi_errno" " = $ssi_errno"
105 gdb_test "p ssi_code" " = $ssi_code"
106 gdb_test "p ssi_signo" " = $ssi_signo"
108 # Again, but this time, patch si_addr and check that the inferior sees
109 # the changed value.
111 # Advance to main
112 if { ![runto_main] } then {
113 gdb_suppress_tests;
116 # Run to the signal.
117 gdb_test "continue" ".*Program received signal SIGSEGV.*" "continue to signal"
119 set test "Set si_addr"
120 gdb_test "p \$_siginfo._sifields._sigfault.si_addr = 0x666" " = \\(void \\*\\) 0x666"
121 gdb_test "p \$_siginfo.si_errno = 666" " = 666"
122 gdb_test "p \$_siginfo.si_code = 999" " = 999"
123 gdb_test "p \$_siginfo.si_signo = 11" " = 11"
125 gdb_test "break $bp_location"
126 gdb_test "continue" ".* handler .*" "continue to handler"
128 gdb_test "p ssi_addr" " = \\(void \\*\\) 0x666"
129 gdb_test "p ssi_errno" " = 666"
130 gdb_test "p ssi_code" " = 999"
131 gdb_test "p ssi_signo" " = 11"