summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/sigrepeat.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2005-01-24 22:00:59 +0000
committerAndrew Cagney <cagney@redhat.com>2005-01-24 22:00:59 +0000
commit0ffbea172bcf93d058390b90d36b15d95b51187b (patch)
tree5a70292175774e568b61cd30a0c8ccce02033962 /gdb/testsuite/gdb.base/sigrepeat.c
parent2c61edbc5281f05c05b8d0126cf3fca84dadb0ca (diff)
downloadgdb-0ffbea172bcf93d058390b90d36b15d95b51187b.tar.gz
Index: ChangeLog
2005-01-24 Andrew Cagney <cagney@gnu.org> * infrun.c (handle_inferior_event): Handle back-to-back and nested signals where the step_resume_breakpoint may have already been inserted. Index: testsuite/ChangeLog 2005-01-24 Andrew Cagney <cagney@gnu.org> * gdb.base/sigrepeat.exp, gdb.base/sigrepeat.c: New test.
Diffstat (limited to 'gdb/testsuite/gdb.base/sigrepeat.c')
-rw-r--r--gdb/testsuite/gdb.base/sigrepeat.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/sigrepeat.c b/gdb/testsuite/gdb.base/sigrepeat.c
new file mode 100644
index 00000000000..a21486dde47
--- /dev/null
+++ b/gdb/testsuite/gdb.base/sigrepeat.c
@@ -0,0 +1,104 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2004, 2005 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.
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/time.h>
+
+static volatile int done[2];
+static volatile int repeats[2];
+static int itimer[2] = { ITIMER_REAL, ITIMER_VIRTUAL };
+static int alarm[2] = { SIGALRM, SIGVTALRM };
+
+static void
+handler (int sig)
+{
+ int sigi;
+ switch (sig)
+ {
+ case SIGALRM: sigi = 0; break;
+ case SIGVTALRM: sigi = 1; break;
+ default: abort ();
+ }
+ if (repeats[sigi]++ > 3)
+ {
+ /* Hit with enough signals, cancel everything and get out. */
+ {
+ struct itimerval itime;
+ memset (&itime, 0, sizeof (itime));
+ setitimer (itimer[sigi], &itime, NULL);
+ }
+ {
+ struct sigaction action;
+ memset (&action, 0, sizeof (action));
+ action.sa_handler = SIG_IGN;
+ sigaction (sig, &action, NULL);
+ }
+ done[sigi] = 1;
+ return;
+ }
+ /* Set up a nested virtual timer. */
+ while (1)
+ {
+ /* Wait until a signal has become pending, that way when this
+ handler returns it will be immediatly delivered leading to
+ back-to-back signals. */
+ sigset_t set;
+ sigemptyset (&set);
+ if (sigpending (&set) < 0)
+ {
+ perror ("sigrepeat");
+ abort ();
+ }
+ if (sigismember (&set, sig))
+ break;
+ }
+} /* handler */
+
+main ()
+{
+ int i;
+ /* Set up the signal handler. */
+ for (i = 0; i < 2; i++)
+ {
+ struct sigaction action;
+ memset (&action, 0, sizeof (action));
+ action.sa_handler = handler;
+ sigaction (alarm[i], &action, NULL);
+ }
+
+ /* Set up a rapidly repeating timers. A timer, rather than SIGSEGV,
+ is used as after a timer handler returns the interrupted code can
+ safely resume. The intent is for the program to swamp GDB with a
+ backlog of pending signals. */
+ for (i = 0; i < 2; i++)
+ {
+ struct itimerval itime;
+ memset (&itime, 0, sizeof (itime));
+ itime.it_interval.tv_usec = 1;
+ itime.it_value.tv_usec = 250 * 1000;
+ setitimer (itimer[i], &itime, NULL);
+ }
+
+ /* Wait. */
+ while (!done[0] && !done[1]); /* infinite loop */
+ return 0;
+}