From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wJppE3QnuWBoIwAAWB0awg (envelope-from ) for ; Thu, 03 Jun 2021 15:03:16 -0400 Received: by simark.ca (Postfix, from userid 112) id 4DB011F163; Thu, 3 Jun 2021 15:03:16 -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 C8E641E01F for ; Thu, 3 Jun 2021 15:03:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9015B398EC33 for ; Thu, 3 Jun 2021 19:03:14 +0000 (GMT) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by sourceware.org (Postfix) with ESMTPS id 183043857C75 for ; Thu, 3 Jun 2021 19:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 183043857C75 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-f53.google.com with SMTP id a11so5014544wrt.13 for ; Thu, 03 Jun 2021 12:02:50 -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=btcdqn4jKqIUJRPkkqOghf2ridGD30ujJbjSeK3P3lZ5SvDZ+BX0sWGcqP5K5X2zBp ucTQDqPUI9jQsXXkmiOk5iX2gD8zkmDNSdwAonnufjlazjOJFVACm6P3YrO/WtXnoGbZ eBtHWlXUEHavwhLwPovoBYwwZlgxGkn+VCd4b/wjGHIF3w+YpC0fXsd8jDt7ndI4gqwo nlI5RdO6+znvBHg0YSvdB0E8NUnYfmbO7eCBsMnGe+oLJHKZ32DQ1ARFG53vx4jxlyoj AHvVmjDtE0fCUr+O8Nmpmz9px9Aj9Rd2PAisdweBr/kNnpBw6ij/aS/sbBkFS6t7+Lov tQxg== X-Gm-Message-State: AOAM533dsCeKrW2Pj3j8Kvg+LcpOe8Z6MCowxFd5gaNhDYFtqjrXFP8d JArVz6iJ6fCuUD9GR2EqDt01xpA3dMXktA== X-Google-Smtp-Source: ABdhPJwoWgV/H424ejZywvfp1gmCNwHQiNn5jSKqnx5haaqdvfB83qMT04/1BvLUY6X8IWjaSOWo3g== X-Received: by 2002:adf:d20a:: with SMTP id j10mr442341wrh.188.1622746968430; Thu, 03 Jun 2021 12:02:48 -0700 (PDT) Received: from localhost ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id o9sm4060949wrw.69.2021.06.03.12.02.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Jun 2021 12:02:47 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 01/17] Test interrupting programs that block SIGINT [gdb/9425, gdb/14559] Date: Thu, 3 Jun 2021 20:02:27 +0100 Message-Id: <20210603190243.2609886-2-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210603190243.2609886-1-pedro@palves.net> References: <20210603190243.2609886-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