1 # Copyright 2004, 2007-2008, 2010-2012 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 # Multi-threaded siginfo test.
19 if [target_info exists gdb,nosignals] {
20 verbose "Skipping siginfo-thread.exp because of nosignals."
24 if { ! [istarget "i?86-*-linux*"]
25 && ! [istarget "x86_64-*-linux*"]
26 && ! [istarget "arm*-*-linux*"] } {
27 verbose "Skipping siginfo-thread.exp because of lack of support."
33 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" \
34 "${binfile}" executable {debug}] != "" } {
38 clean_restart $binfile
41 if { ![runto_main] } then {
46 gdb_test "continue" ".*Program received signal SIGSEGV.*" "continue to signal"
48 # Try to generate a core file, for a later test.
49 set gcorefile [standard_output_file $testfile.gcore]
50 set gcore_created [gdb_gcore_cmd $gcorefile "save a core file"]
53 set test "Extract si_addr"
54 gdb_test_multiple "p \$_siginfo" "$test" {
55 -re "si_addr = ($hex).*$gdb_prompt $" {
56 set ssi_addr $expect_out(1,string)
61 set test "Extract si_errno"
62 gdb_test_multiple "p \$_siginfo" "$test" {
63 -re "si_errno = (\[0-9\]\+).*$gdb_prompt $" {
64 set ssi_errno $expect_out(1,string)
69 set test "Extract si_code"
70 gdb_test_multiple "p \$_siginfo" "$test" {
71 -re "si_code = (\[0-9\]\+).*$gdb_prompt $" {
72 set ssi_code $expect_out(1,string)
77 set test "Extract si_signo"
78 gdb_test_multiple "p \$_siginfo" "$test" {
79 -re "si_signo = (\[0-9\]\+).*$gdb_prompt $" {
80 set ssi_signo $expect_out(1,string)
85 set bp_location [gdb_get_line_number "set breakpoint here"]
87 gdb_test "break $bp_location"
88 gdb_test "continue" ".* handler .*" "continue to handler"
90 gdb_test "p ssi_addr" " = \\(void \\*\\) $ssi_addr"
91 gdb_test "p ssi_errno" " = $ssi_errno"
92 gdb_test "p ssi_code" " = $ssi_code"
93 gdb_test "p ssi_signo" " = $ssi_signo"
95 gdb_test "thread 1" ".*"
96 # siginfo is available here -- it shows SIGSTOP -- so we test to make
97 # sure that we have a different signal from the SEGV thread.
98 gdb_test "p \$_siginfo.si_signo == $ssi_signo" " = 0" \
99 "test signal in main thread"
101 # Test siginfo preservation in core files.
102 if {$gcore_created} {
103 clean_restart $binfile
105 gdb_test "core $gcorefile" "Core was generated by.*" \
106 "core [file tail $gcorefile]"
108 gdb_test "p \$_siginfo.si_signo" " = $ssi_signo" \
109 "p \$_siginfo.si_signo from core file"
110 gdb_test "p \$_siginfo.si_errno" " = $ssi_errno" \
111 "p \$_siginfo.si_errno from core file"
112 gdb_test "p \$_siginfo.si_code" " = $ssi_code" \
113 "p \$_siginfo.si_code from core file"
114 gdb_test "p \$_siginfo._sifields._sigfault.si_addr" \
115 " = \\(void \\*\\) $ssi_addr" \
116 "p \$_siginfo._sifields._sigfault.si_addr from core file"
118 # We don't know which thread will be signalled, so we simply
119 # ensure that only one thread got a SEGV.
120 gdb_test_no_output "set variable \$count = 0"
121 foreach thread {1 2} {
122 gdb_test "thread $thread" ".*" "select thread $thread with core file"
124 "set variable \$count += (\$_siginfo.si_signo == $ssi_signo)" \
125 "update counter in thread $thread"
127 gdb_test "print \$count" " = 1"