From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gPzwLRzJx2AYUQAAWB0awg (envelope-from ) for ; Mon, 14 Jun 2021 17:24:44 -0400 Received: by simark.ca (Postfix, from userid 112) id B7E9B1F163; Mon, 14 Jun 2021 17:24:44 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 623441E54D for ; Mon, 14 Jun 2021 17:24:43 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10C13397300A for ; Mon, 14 Jun 2021 21:24:43 +0000 (GMT) Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by sourceware.org (Postfix) with ESMTPS id DE5373857010 for ; Mon, 14 Jun 2021 21:24:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE5373857010 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f44.google.com with SMTP id m18so15974986wrv.2 for ; Mon, 14 Jun 2021 14:24:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zEWJo3zfHMO5X5ZrWZSQ10IFPuRd+GTMa7SqTEGy+Eg=; b=aPsnoOL1a5mGy09HTmtn10+2TT3SUt6QQuVCCVCn4/jXMhi7X/dXc5H+KEqzO6FPwe joWSNMSJD9paPZ/i83Hw2AJXHz8yPK6Qux4GEugIuwC95l4Qt69FJAEv50tgVxpYob05 eAkL2LQ6w3MdTv8Q0C2LrUE9ROCDul3nfypb9CD7Q+fBkxBX4aqnlkpmDx+HLD6thHSn yxQFY0Wq2j21XRbPq9D0e6PQNns3XQtJp0FdBkjuXcn5rZHpHuoaWjYswdEL0WG0QBIt Rq1miouS9w3B6lfurAxkZBYssLj3PYjlNrR/trm8fxL0s8XnTRlGT4T6yNLigV7c8kqU 6ICg== X-Gm-Message-State: AOAM532F22ggK6BFbpM55x7KJPzn7VHryqMHCppknrkQgWSszAPt6yZf C4A3Ne7Hg6nnlTbNj1tihwcpG3gViytkHw== X-Google-Smtp-Source: ABdhPJzA/RoHjpbuurngwWM+W+7/tAUZMu8UKG4q5guRpQbJiXSuzCxRN75vfUAR6SpTvGZu/1PJiQ== X-Received: by 2002:a5d:59a9:: with SMTP id p9mr20626148wrr.86.1623705854090; Mon, 14 Jun 2021 14:24:14 -0700 (PDT) Received: from localhost ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id t17sm205527wmi.47.2021.06.14.14.24.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Jun 2021 14:24:13 -0700 (PDT) From: Pedro Alves 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 Message-Id: <20210614212410.1612666-2-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210614212410.1612666-1-pedro@palves.net> References: <20210614212410.1612666-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 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 . */ + +#include +#include + +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 . + +# 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 . */ + +#include +#include +#include +#include +#include +#include + +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 ("
Error sigfillset(): "); + exit (2); + } + + done (); + + while (1) + { + int sig; + + /* Wait for queued signals. .*/ + if (sigwait (&signal_set, &sig) != 0) + { + perror ("
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 . + +# 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