1# Copyright 2004-2013 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.c creates a backtrace containing a signal 18# handler registered using sigaction's sa_sigaction / SA_SIGINFO. 19# Some OS's (e.g., GNU/Linux) use different signal trampolines for 20# sa_sigaction and sa_handler. 21 22# This test first confirms that GDB can backtrace through the 23# alternative sa_sigaction signal handler, and second that GDB can 24# nexti/stepi out of such a handler. 25 26if [target_info exists gdb,nosignals] { 27 verbose "Skipping siginfo.exp because of nosignals." 28 continue 29} 30 31 32set testfile siginfo 33set srcfile ${testfile}.c 34set binfile ${objdir}/${subdir}/${testfile} 35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 36 untested "Couldn't compile ${srcfile}.c" 37 return -1 38} 39 40# get things started 41gdb_exit 42gdb_start 43gdb_reinitialize_dir $srcdir/$subdir 44gdb_load ${binfile} 45 46gdb_test "display/i \$pc" 47 48# Advance to main 49if { ![runto_main] } then { 50 gdb_suppress_tests; 51} 52 53# Pass all the alarms straight through (but verbosely) 54# gdb_test "handle SIGALRM print pass nostop" 55# gdb_test "handle SIGVTALRM print pass nostop" 56# gdb_test "handle SIGPROF print pass nostop" 57 58# Run to the signal handler, validate the backtrace. 59gdb_test "break handler" 60gdb_test "continue" ".* handler .*" "continue to stepi handler" 61gdb_test_sequence "bt" "backtrace for nexti" { 62 "\[\r\n\]+.0 \[^\r\n\]* handler " 63 "\[\r\n\]+.1 .signal handler called." 64 "\[\r\n\]+.2 \[^\r\n\]* main " 65} 66 67# Check that GDB can step the inferior back to main 68set test "step out of handler" 69gdb_test_multiple "step" "${test}" { 70 -re "Could not insert single-step breakpoint.*$gdb_prompt $" { 71 setup_kfail gdb/1736 sparc*-*-openbsd* 72 fail "$test (could not insert single-step breakpoint)" 73 } 74 -re "done = 1;.*${gdb_prompt} $" { 75 send_gdb "$i\n" 76 exp_continue 77 } 78 -re "\} .. handler .*${gdb_prompt} $" { 79 send_gdb "step\n" 80 exp_continue 81 } 82 -re "$inferior_exited_re normally.*${gdb_prompt} $" { 83 kfail gdb/1613 "$test (program exited)" 84 } 85 -re "(while ..done|return 0).*${gdb_prompt} $" { 86 # After stepping out of a function /r signal-handler, GDB will 87 # advance the inferior until it is at the first instruction of 88 # a code-line. While typically things return to the middle of 89 # the "while..." (and hence GDB advances the inferior to the 90 # "return..." line) it is also possible for the return to land 91 # on the first instruction of "while...". Accept both cases. 92 pass "$test" 93 } 94} 95