Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 01/16] Test interrupting programs that block SIGINT [gdb/9425, gdb/14559]
Date: Mon, 14 Jun 2021 22:23:55 +0100	[thread overview]
Message-ID: <20210614212410.1612666-2-pedro@palves.net> (raw)
In-Reply-To: <20210614212410.1612666-1-pedro@palves.net>

This adds a couple testcases that exercise interrupting programs that
block SIGINT.  One tests a program that uses sigprocmask to mask out
SIGINT, and the other tests a program that waits for SIGINT with
sigwait.  On GNU/Linux, it is currently impossible to interrupt such a
program with Ctrl-C, and you can't interrupt it with the "interrupt"
command in all-stop mode either.

These currently fail, and are suitably kfailed.  The rest of the
series will fix the fails.

Tested on GNU/Linux native, gdbserver, and gdbserver + "maint set
target-non-stop on".

gdb/testsuite/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	PR gdb/9425
	PR gdb/14559
	* gdb.base/sigint-masked-out.c: New file.
	* gdb.base/sigint-masked-out.exp: New file.
	* gdb.base/sigint-sigwait.c: New file.
	* gdb.base/sigint-sigwait.exp: New file.

Change-Id: Iddb70c0a2c92550027fccb6f51ecba1292d233c8
---
 gdb/testsuite/gdb.base/sigint-masked-out.c   |  43 ++++++++
 gdb/testsuite/gdb.base/sigint-masked-out.exp | 101 ++++++++++++++++++
 gdb/testsuite/gdb.base/sigint-sigwait.c      |  80 ++++++++++++++
 gdb/testsuite/gdb.base/sigint-sigwait.exp    | 105 +++++++++++++++++++
 4 files changed, 329 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/sigint-masked-out.c
 create mode 100644 gdb/testsuite/gdb.base/sigint-masked-out.exp
 create mode 100644 gdb/testsuite/gdb.base/sigint-sigwait.c
 create mode 100644 gdb/testsuite/gdb.base/sigint-sigwait.exp

diff --git a/gdb/testsuite/gdb.base/sigint-masked-out.c b/gdb/testsuite/gdb.base/sigint-masked-out.c
new file mode 100644
index 00000000000..dce28182add
--- /dev/null
+++ b/gdb/testsuite/gdb.base/sigint-masked-out.c
@@ -0,0 +1,43 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2021 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <signal.h>
+
+static void
+done ()
+{
+}
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+  sigset_t sigs;
+
+  alarm (30);
+
+  sigfillset (&sigs);
+  sigprocmask (SIG_SETMASK, &sigs, NULL);
+
+  done ();
+
+  while (1)
+    sleep (1);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/sigint-masked-out.exp b/gdb/testsuite/gdb.base/sigint-masked-out.exp
new file mode 100644
index 00000000000..0391152e93a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/sigint-masked-out.exp
@@ -0,0 +1,101 @@
+# Copyright 2021 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Make sure that we can interrupt an inferior that has all signals
+# masked out, including SIGINT, with both Ctrl-C and the "interrupt"
+# command.
+
+standard_testfile
+
+if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
+    return -1
+}
+
+# Test interrupting with Ctrl-C.
+
+proc_with_prefix test_ctrl_c {} {
+    global binfile
+    global gdb_prompt
+
+    clean_restart $binfile
+
+    if ![runto "done"] {
+	fail "can't run to done function"
+	return
+    }
+
+    gdb_test_multiple "continue" "" {
+	-re "Continuing" {
+	    pass $gdb_test_name
+	}
+    }
+
+    after 200
+
+    send_gdb "\003"
+
+    gdb_test_multiple "" "ctrl-c stops process" {
+	-timeout 5
+	-re -wrap "(received signal SIGINT|stopped).*" {
+	    pass $gdb_test_name
+	}
+	timeout {
+	    setup_kfail "gdb/9425" *-*-*
+	    fail "$gdb_test_name (timeout)"
+	}
+    }
+}
+
+# Test interrupting with the "interrupt" command.
+
+proc_with_prefix test_interrupt_cmd {} {
+    global binfile
+    global gdb_prompt
+
+    clean_restart $binfile
+
+    if ![runto "done"] {
+	fail "can't run to done function"
+	return
+    }
+
+    gdb_test_multiple "continue&" "" {
+	-re "Continuing\\.\r\n$gdb_prompt " {
+	    pass $gdb_test_name
+	}
+    }
+
+    after 200
+
+    gdb_test_multiple "interrupt" "" {
+	-re "$gdb_prompt " {
+	    pass $gdb_test_name
+	}
+    }
+
+    gdb_test_multiple "" "interrupt cmd stops process" {
+	-timeout 5
+	-re "(received signal SIGINT|stopped)" {
+	    pass $gdb_test_name
+	}
+	timeout {
+	    setup_kfail "gdb/14559" *-*-*
+	    fail "$gdb_test_name (timeout)"
+	}
+    }
+}
+
+test_ctrl_c
+test_interrupt_cmd
diff --git a/gdb/testsuite/gdb.base/sigint-sigwait.c b/gdb/testsuite/gdb.base/sigint-sigwait.c
new file mode 100644
index 00000000000..8d1408c5955
--- /dev/null
+++ b/gdb/testsuite/gdb.base/sigint-sigwait.c
@@ -0,0 +1,80 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2021 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+static void
+handle_sigint (int signo)
+{
+}
+
+static void
+done ()
+{
+}
+
+int
+main (int argc, char **argv)
+{
+  sigset_t signal_set;
+  struct sigaction s;
+
+  alarm (30);
+
+  s.sa_flags = SA_RESTART;
+  s.sa_handler = handle_sigint;
+
+  if (sigaction (SIGINT, &s, NULL) < 0)
+    {
+      perror ("<%s> Error sigaction: ");
+      exit (2);
+    }
+
+  if (sigfillset (&signal_set) < 0)
+    {
+      perror ("<main> Error sigfillset(): ");
+      exit (2);
+    }
+
+  done ();
+
+  while (1)
+    {
+      int sig;
+
+      /* Wait for queued signals.  .*/
+      if (sigwait (&signal_set, &sig) != 0)
+	{
+	  perror ("<main> Error sigwait(): ");
+	  exit (1);
+	}
+
+      /* Process signal.  */
+      if (sig == SIGINT)
+	{
+	  printf ("Terminating.\n");
+	  exit (0);
+	}
+
+      printf ("Unhandled signal [%s]\n", strsignal (sig));
+    }
+}
diff --git a/gdb/testsuite/gdb.base/sigint-sigwait.exp b/gdb/testsuite/gdb.base/sigint-sigwait.exp
new file mode 100644
index 00000000000..1dd706fc1a4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/sigint-sigwait.exp
@@ -0,0 +1,105 @@
+# Copyright 2021 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Make sure that we can interrupt an inferior that has all signals
+# masked out, including SIGINT, and then waits for signals with
+# sigwait.  Test interrupting with both Ctrl-C and the "interrupt"
+# command.
+
+standard_testfile
+
+if {[build_executable "failed to build" $testfile $srcfile {debug}]} {
+    return -1
+}
+
+# Test interrupting with Ctrl-C.
+
+proc_with_prefix test_ctrl_c {} {
+    global binfile
+    global gdb_prompt
+
+    clean_restart $binfile
+
+    if ![runto "done"] {
+	fail "can't run to done function"
+	return
+    }
+
+    gdb_test_multiple "continue" "" {
+	-re "Continuing" {
+	    pass $gdb_test_name
+	}
+    }
+
+    after 200
+
+    send_gdb "\003"
+
+    global exited_normally_re
+
+    gdb_test_multiple "" "ctrl-c stops process" {
+	-re -wrap "(received signal SIGINT|stopped).*" {
+	    pass $gdb_test_name
+	}
+	-re -wrap "Inferior.*exited normally.*" {
+	    setup_kfail "gdb/9425" *-*-*
+	    fail "$gdb_test_name (the program exited)"
+	}
+    }
+}
+
+# Test interrupting with the "interrupt" command.
+
+proc_with_prefix test_interrupt_cmd {} {
+    global binfile
+    global gdb_prompt
+
+    clean_restart $binfile
+
+    if ![runto "done"] {
+	fail "can't run to done function"
+	return
+    }
+
+    gdb_test_multiple "continue&" "" {
+	-re "Continuing\\.\r\n$gdb_prompt " {
+	    pass $gdb_test_name
+	}
+    }
+
+    after 200
+
+    gdb_test_multiple "interrupt" "" {
+	-re "$gdb_prompt " {
+	    pass $gdb_test_name
+	}
+    }
+
+    global exited_normally_re
+
+    gdb_test_multiple "" "interrupt cmd stops process" {
+	-timeout 5
+	-re "(received signal SIGINT|stopped)" {
+	    pass $gdb_test_name
+	}
+	-re "Inferior.*exited normally" {
+	    setup_kfail "gdb/14559" *-*-*
+	    fail "$gdb_test_name (the program exited)"
+	}
+    }
+}
+
+test_ctrl_c
+test_interrupt_cmd
-- 
2.26.2


  reply	other threads:[~2021-06-14 21:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 21:23 [PATCH v2 00/16] Interrupting programs that block/ignore SIGINT Pedro Alves
2021-06-14 21:23 ` Pedro Alves [this message]
2021-06-14 21:23 ` [PATCH v2 02/16] prefork_hook: Remove 'args' parameter Pedro Alves
2021-06-14 21:23 ` [PATCH v2 03/16] Make gdb.base/long-inferior-output.exp fail fast Pedro Alves
2021-06-14 21:23 ` [PATCH v2 04/16] Fix gdb.multi/multi-term-settings.exp race Pedro Alves
2021-06-14 21:23 ` [PATCH v2 05/16] Don't check parent pid in gdb.threads/{ia64-sigill, siginfo-threads, watchthreads-reorder}.c Pedro Alves
2021-06-14 21:24 ` [PATCH v2 06/16] Special-case "set inferior-tty /dev/tty" Pedro Alves
2021-06-14 21:24 ` [PATCH v2 07/16] Make inferior/GDB share terminal in tests expecting output after detach Pedro Alves
2021-06-14 21:24 ` [PATCH v2 08/16] Make inferior/GDB share terminal in tests that exercise GDB/inferior reading same input Pedro Alves
2021-06-14 21:24 ` [PATCH v2 09/16] gdb.mi/mi-logging.exp, don't send input to GDB while the inferior is running Pedro Alves
2021-06-14 21:24 ` [PATCH v2 10/16] target_terminal::ours_for_output before printing signal received Pedro Alves
2021-06-14 21:24 ` [PATCH v2 11/16] Move scoped_ignore_sigttou to gdbsupport/ Pedro Alves
2021-06-17 21:49   ` Pedro Alves
2021-06-14 21:24 ` [PATCH v2 12/16] Always put inferiors in their own terminal/session [gdb/9425, gdb/14559] Pedro Alves
2021-06-14 21:24 ` [PATCH v2 13/16] exists_non_stop_target: Avoid flushing frames Pedro Alves
2021-06-14 21:24 ` [PATCH v2 14/16] convert previous_inferior_ptid to strong reference to thread_info Pedro Alves
2021-06-14 21:24 ` [PATCH v2 15/16] GNU/Linux: Interrupt/Ctrl-C with SIGSTOP instead of SIGINT [PR gdb/9425, PR gdb/14559] Pedro Alves
2021-07-08 23:05   ` Maciej W. Rozycki
2021-07-13 15:26     ` Pedro Alves
2021-06-14 21:24 ` [PATCH v2 16/16] Document pseudo-terminal and interrupting changes Pedro Alves
2021-06-15 12:56   ` Eli Zaretskii via Gdb-patches
2021-06-16  9:31     ` Pedro Alves
2021-06-16 12:29       ` Eli Zaretskii via Gdb-patches
2021-06-16 10:15     ` Pedro Alves
2021-06-16 12:15       ` Eli Zaretskii via Gdb-patches
2021-06-16 12:26         ` Pedro Alves
2021-06-16 13:05           ` Eli Zaretskii via Gdb-patches
2021-06-15 12:34 ` [PATCH v2 00/16] Interrupting programs that block/ignore SIGINT Eli Zaretskii via Gdb-patches
2021-06-16 11:27   ` Pedro Alves
2021-06-16 12:45     ` Eli Zaretskii via Gdb-patches
2021-06-18 10:12 ` Andrew Burgess
2021-06-24 18:12 ` Konstantin Kharlamov via Gdb-patches
2021-06-24 18:55   ` Pedro Alves
2021-06-29  1:15     ` Eldar Abusalimov via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210614212410.1612666-2-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox