This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] Test sigaltstack
- From: Andrew Cagney <cagney at gnu dot org>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 01 Apr 2004 18:56:28 -0500
- Subject: [patch/rfc] Test sigaltstack
Hello,
This tests GDB doing a backtrace, and then finishing, an out-of-order
sequence of sigaltstacks. It turns up a few bugs so I'd better fix them
before committing :-)
Andrew
2004-04-01 Andrew Cagney <cagney@redhat.com>
* gdb.base/sigaltstack.c: New file.
* gdb.base/sigaltstack.exp: New file.
Index: gdb.base/sigaltstack.c
===================================================================
RCS file: gdb.base/sigaltstack.c
diff -N gdb.base/sigaltstack.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/sigaltstack.c 1 Apr 2004 23:52:02 -0000
@@ -0,0 +1,103 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2004 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <signal.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+/* NOTE: Intentionally out-of-order. This to ensure that there is
+ always both an assending and a desending signal trampoline
+ transition (func -> tramp -> func) in the stack backtrace. For
+ instance, given a stack that grows using increasing addresses
+ (e.g., PA-RISC), outer.sp < tramp.sp < middle.sp, but middle.sp >
+ tramp.sp < inner.sp. This way we can test GDB can unwinding
+ through unorderd stack sequences. */
+enum level { MAIN, OUTER, INNER, MIDDLE, LEAF, NR_LEVELS };
+
+/* Alternative stacks. Note that due to "enum level" the stack
+ addresses are not ordered. */
+unsigned char altstack[NR_LEVELS][SIGSTKSZ];
+
+/* Levels completed flag. */
+volatile enum level level;
+
+void catcher (int signal);
+
+void
+thrower (enum level next_level, int sig, int itimer)
+{
+ level = next_level;
+ /* Set up the altstack. */
+ {
+ void *stack = altstack[level];
+ struct sigaltstack alt;
+ alt.ss_sp = stack;
+ alt.ss_size = SIGSTKSZ;
+ alt.ss_flags = 0;
+ if (sigaltstack (&alt, NULL) < 0)
+ {
+ perror ("sigaltstack");
+ exit (0);
+ }
+ }
+ /* Set up the signal handler so that it uses the altstack. */
+ {
+ struct sigaction act;
+ memset (&act, 0, sizeof (act));
+ act.sa_handler = catcher;
+ act.sa_flags |= SA_ONSTACK;
+ sigaction (sig, &act, NULL);
+ }
+ /* Set up the alarm. */
+ {
+ struct itimerval itime;
+ memset (&itime, 0, sizeof (itime));
+ itime.it_value.tv_usec = 250 * 1000;
+ setitimer (itimer, &itime, NULL);
+ }
+ /* Wait. */
+ while (level != LEAF);
+}
+
+void
+catcher (int signal)
+{
+ /* Find the next level. */
+ switch (level)
+ {
+ case OUTER:
+ thrower (MIDDLE, SIGVTALRM, ITIMER_VIRTUAL);
+ break;
+ case MIDDLE:
+ thrower (INNER, SIGPROF, ITIMER_PROF);
+ break;
+ case INNER:
+ level = LEAF;
+ return;
+ }
+}
+
+
+main ()
+{
+ level = MAIN;
+ thrower (OUTER, SIGALRM, ITIMER_REAL);
+}
Index: gdb.base/sigaltstack.exp
===================================================================
RCS file: gdb.base/sigaltstack.exp
diff -N gdb.base/sigaltstack.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb.base/sigaltstack.exp 1 Apr 2004 23:52:02 -0000
@@ -0,0 +1,82 @@
+# Copyright 2004 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if [target_info exists gdb,nosignals] {
+ verbose "Skipping signals.exp because of nosignals."
+ continue
+}
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile sigaltstack
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+# get things started
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# Pass all the alarms straight through (but verbosely)
+gdb_test "handle SIGALRM print pass nostop"
+gdb_test "handle SIGVTALRM print pass nostop"
+gdb_test "handle SIGPROF print pass nostop"
+
+# Advance to main
+if { ![runto_main] } then {
+ gdb_suppress_tests;
+}
+
+# Stop in handle, when at the inner most level
+gdb_test "break catcher if level == INNER"
+gdb_test "continue" ".* catcher .*" "continue to catch"
+# step off the assignment
+gdb_test "next"
+
+# Full backtrace?
+send_gdb "bt\n"
+gdb_expect_list "backtrace" ".*$gdb_prompt $" {
+ "\[\r\n\]+.0 \[^\r\n\]* catcher "
+ "\[\r\n\]+.1 .signal handler called."
+ "\[\r\n\]+.2 \[^\r\n\]* thrower .next_level=INNER"
+ "\[\r\n\]+.3 \[^\r\n\]* catcher "
+ "\[\r\n\]+.4 .signal handler called."
+ "\[\r\n\]+.5 \[^\r\n\]* thrower .next_level=MIDDLE"
+ "\[\r\n\]+.6 \[^\r\n\]* catcher "
+ "\[\r\n\]+.7 .signal handler called."
+ "\[\r\n\]+.8 \[^\r\n\]* thrower .next_level=OUTER"
+ "\[\r\n\]+.9 \[^\r\n\]* main .*"
+}
+
+# Finish?
+gdb_test "finish" "signal handler called." "finish from catch LEAF"
+gdb_test "finish" "thrower .next_level=INNER, .*" "finish to throw INNER"
+gdb_test "finish" "catcher .*" "finish to catch INNER"
+gdb_test "finish" "signal handler called.*" "finish from catch INNER"
+gdb_test "finish" "thrower .next_level=MIDDLE, .*" "finish to MIDDLE"
+gdb_test "finish" "catcher .*" "finish to catch MIDDLE"
+gdb_test "finish" "signal handler called." "finish from catch MIDDLE"
+gdb_test "finish" "thrower .next_level=OUTER, .*" "finish to OUTER"
+gdb_test "finish" "main .*" "finish to MAIN"