From patchwork Tue Jan 31 17:27:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 64038 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58700384F033 for ; Tue, 31 Jan 2023 17:52:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58700384F033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675187557; bh=0bZvBYG/LqW6MraOXUJL7beXwNy6n0wxQDb+gDvAHKM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IzYsyU1MvgOFoPGzIrTMT7tYE8XD69FVkqnUMXNNHju1HTr/rSpavaeYnNyjN5Fsc iC8V5OiQGDfOD+BOajdVpiIC5UmWY/7def6xog5SLRG5IBMqt7zyObafJrMhGZ9KoV yIj854DAOrmvE1U5AV+puBUv80P7YXrA7ppl3XuE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id ACF5338582A1 for ; Tue, 31 Jan 2023 17:50:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACF5338582A1 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-615-t9Qasmo5OaW-tbVJwBA82Q-1; Tue, 31 Jan 2023 12:27:44 -0500 X-MC-Unique: t9Qasmo5OaW-tbVJwBA82Q-1 Received: by mail-qt1-f200.google.com with SMTP id a13-20020ac8108d000000b003b7ea9814a2so6866033qtj.2 for ; Tue, 31 Jan 2023 09:27:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0bZvBYG/LqW6MraOXUJL7beXwNy6n0wxQDb+gDvAHKM=; b=LcFw6BKnK0drzdrPL179683BtoprR2J5HBd0PfQri/IqKvYCiIXio+Bk/hIvsp9Kcz UXmFQJSR+VSr4DbC2aMMoysdG3/pjnRma9NJqzBI42vxBqiSwQGGwOd9S3ZOJ8iCXu3x N9EHS75FLXucK2LlS7zA+SHdo+Ibg5X7GpCFGVkANN2YYpOLJri5Flw39br21IUgpLlm zrN+FMUlZBFsotxc4kPSj1b3FJbFTMFN5rlCheny5MSYylByQlwudOB8rZXXSMll1i9V 5gJmD7uPkvpT+MaoudPlSf6QStcbher7xG42KJdBXPxhv/aF/OCSuXLuh+KgZyKpglCx fQPQ== X-Gm-Message-State: AO0yUKXizf/qDxrWG5saLKwvn5EOisQcKtPMgpUr8lGoYSvrM+ULrh3+ R1aWch7xXUtQ9Xm/LcqnAHMkF7p4aiQtZ99KNq7OLPcmxKlzwF0icqc0OkhFjHQsITDZwnZLZKa 6Fz+1dYNHWScVowTLA0jhkyza238V5XeqyFHO04e/Oozq/7HvMxJyrAyjjsUqwFUPoFDKfq2izg == X-Received: by 2002:a05:622a:1445:b0:3b9:a641:aa66 with SMTP id v5-20020a05622a144500b003b9a641aa66mr6990931qtx.15.1675186063368; Tue, 31 Jan 2023 09:27:43 -0800 (PST) X-Google-Smtp-Source: AK7set9X1JD6V/MnurBNhrpt+zHkewL1uwwOYJz+rqiD+6IoA2PY6O2VoEvxtHd/j3anYmitTnSTvw== X-Received: by 2002:a05:622a:1445:b0:3b9:a641:aa66 with SMTP id v5-20020a05622a144500b003b9a641aa66mr6990897qtx.15.1675186062954; Tue, 31 Jan 2023 09:27:42 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id a26-20020aed279a000000b003b8484fdfccsm6251904qtd.42.2023.01.31.09.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 09:27:42 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 11/13] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Tue, 31 Jan 2023 17:27:16 +0000 Message-Id: <97a59b0b300f2510c40237c129d26e302fe702da.1675185990.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently, if the remote target is not running in non-stop mode, then, when GDB calls remote_target::stop, we end up sending an interrupt packet \x03 to the remote target. If the user interrupts the inferior from the GDB prompt (e.g. by typing Ctrl-c), then GDB calls remote_target::interrupt, which also ends up sending the interrupt packet. The problem here is that both of these mechanisms end up sending the interrupt packet, which means, when the target stops with a SIGINT, and this is reported back to GDB, we have no choice but to report this to the user as a SIGINT stop event. Now maybe this is the correct thing to do, after all the target has been stopped with SIGINT. However, this leads to an unfortunate change in behaviour when comparing non-stop vs all-stop mode. When running in non-stop mode, and remote_target::stop is called, the target will be stopped with a vCont packet, and this stop is then reported back to GDB as GDB_SIGNAL_0, this will cause GDB to print a message like: Program stopped. Or: Thread NN "binary name" stopped. In contrast, when non-stop mode is off, we get messages like: Program received SIGINT, Segmentation fault. Or: Thread NN "binary name" received SIGINT, Segmentation fault. In this commit I propose making use of thread_info::stop_requested within remote.c to know if the stop was triggered by GDB (and the SIGINT should be hidden) or if the stop was a user interrupt, and the SIGINT should be printed. In remote_target::process_stop_reply if the inferior stopped with SIGINT and the thread_info::stop_requested flag is set, then we change the stop signal to GDB_SIGNAL_0. Two of the tests added in the previous commit exposed this issue. In the previous commit the tests looked for either of the above patterns. In this commit I've updated these tests to only look for the "stopped" based messages. This commit is the reason why the previous commit took care to set the thread_info::stop_requested flag in infcall.c. --- gdb/remote.c | 10 ++++++++++ gdb/testsuite/gdb.base/infcall-timeout.exp | 9 +-------- .../gdb.threads/infcall-from-bp-cond-timeout.exp | 9 +-------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index ba7a7520cb4..604d75b9689 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8275,6 +8275,16 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, } else { + /* If this stop was actually requested by GDB then we can hide + the SIGINT from the user. */ + if (status->kind () == TARGET_WAITKIND_STOPPED + && status->sig () == GDB_SIGNAL_INT) + { + thread_info *thr = find_thread_ptid (this, ptid); + if (thr->stop_requested) + status->set_stopped (GDB_SIGNAL_0); + } + /* If the target works in all-stop mode, a stop-reply indicates that all the target's threads stopped. */ for (thread_info *tp : all_non_exited_threads (this)) diff --git a/gdb/testsuite/gdb.base/infcall-timeout.exp b/gdb/testsuite/gdb.base/infcall-timeout.exp index a5b0111ed04..bd6b2bfac3e 100644 --- a/gdb/testsuite/gdb.base/infcall-timeout.exp +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp @@ -45,16 +45,9 @@ proc_with_prefix run_test { target_async target_non_stop } { gdb_test_no_output "set direct-call-timeout 5" - # When non-stop mode is off we get slightly different output from GDB. - if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { - set stopped_line_pattern "Program received signal SIGINT, Interrupt\\." - } else { - set stopped_line_pattern "Program stopped\\." - } - gdb_test "print function_that_never_returns ()" \ [multi_line \ - $stopped_line_pattern \ + "Program stopped\\." \ ".*" \ "The program being debugged timed out while in a function called from GDB\\." \ "GDB remains in the frame where the timeout occurred\\." \ diff --git a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp index 3341ff33f19..9ba38e6896a 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -92,16 +92,9 @@ proc run_test { target_async target_non_stop other_thread_bp } { "get number for segfault breakpoint"] } - # When non-stop mode is off we get slightly different output from GDB. - if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } { - set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" received signal SIGINT, Interrupt\\." - } else { - set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." - } - gdb_test "continue" \ [multi_line \ - $stopped_line_pattern \ + "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \ ".*" \ "Error in testing condition for breakpoint ${bp_num}:" \ "The program being debugged timed out while in a function called from GDB\\." \