xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/sigaltstack.exp (revision 15a984a0d95c8f96abe9717ee6241762c55dc106)
1# Copyright 2004-2020 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 sigaltstack.c creates a backtrace containing nested
18# signal handlers on an alternative stack.  This in turn leads to a
19# non-contiguous (and possibly non-monotonic) backtrace - stack
20# address jump at the normal-alt stack boundary.
21
22# This test confirms that GDB can both backtrace through and finish
23# such a stack.
24
25if [target_info exists gdb,nosignals] {
26    verbose "Skipping sigaltstack.exp because of nosignals."
27    continue
28}
29
30
31standard_testfile .c
32
33if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34    untested "failed to compile"
35    return -1
36}
37
38# get things started
39clean_restart ${binfile}
40
41# Pass all the alarms straight through (but verbosely)
42gdb_test "handle SIGALRM print pass nostop"
43gdb_test "handle SIGVTALRM print pass nostop"
44gdb_test "handle SIGPROF print pass nostop"
45
46# Advance to main
47if ![runto_main] then {
48    fail "can't run to main"
49    return 0
50}
51
52# Stop in handle, when at the inner most level
53gdb_test "break catcher if level == INNER"
54gdb_test "continue" ".* catcher .*" "continue to catch"
55# step off the assignment
56gdb_test "next"
57
58# Full backtrace?
59gdb_test_sequence "bt" "backtrace" {
60    "\[\r\n\]+.0 \[^\r\n\]* catcher "
61    "\[\r\n\]+.1  .signal handler called."
62    "\[\r\n\]+.2 \[^\r\n\]* thrower .next_level=INNER"
63    "\[\r\n\]+.3 \[^\r\n\]* catcher "
64    "\[\r\n\]+.4  .signal handler called."
65    "\[\r\n\]+.5 \[^\r\n\]* thrower .next_level=OUTER"
66    "\[\r\n\]+.6 \[^\r\n\]* catcher "
67    "\[\r\n\]+.7 \[^\r\n\]* main "
68}
69
70proc finish_test { pattern msg } {
71    global gdb_prompt
72
73    gdb_test_multiple "finish" $msg {
74	-re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
75	    # Some platforms use a special read-only page for signal
76	    # trampolines.  We can't set a breakpoint there, and we
77	    # don't gracefully fall back to single-stepping.
78	    setup_kfail gdb/8841 "i?86-*-linux*"
79	    setup_kfail gdb/8841 "*-*-openbsd*"
80	    setup_kfail gdb/8841 "nios2-*-linux*"
81	    fail "$msg (could not set breakpoint)"
82	}
83	-re "$pattern.*${gdb_prompt} $" {
84	    pass $msg
85	}
86    }
87}
88
89# Finish?
90finish_test "signal handler called." "finish from catch LEAF"
91finish_test "thrower .next_level=INNER, .*" "finish to throw INNER"
92finish_test "catcher .*" "finish to catch INNER"
93finish_test "signal handler called.*" "finish from catch INNER"
94finish_test "thrower .next_level=OUTER, .*" "finish to OUTER"
95finish_test "catcher .*" "finish to catch MAIN"
96finish_test "main .*" "finish to MAIN"
97