From patchwork Fri Oct 21 08:43:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 59268 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 CDF65385383B for ; Fri, 21 Oct 2022 08:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDF65385383B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666341968; bh=y7dPvGCpD+W598dc6+zdAwz6IliS1cJiJ/REWurOutk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LbNnavW57/Tav+aYGbxaVsoi2RMtpv6xZFKoiV/MGHAy43A0HPu7ultSINi+T9ZgW EC/kzZqjKKZC3XqfpTOU7MbPv5bLWs2GTCDLcMzvvJpYK2P3rlHpZH2aXny/nBcYrF qhP1l9RKoaN8AM+2Eytr4iIvA6x/VA22ybsUr9ro= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id A0F33385354F for ; Fri, 21 Oct 2022 08:44:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0F33385354F Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-520-pLmSuEcbOBKO9oSW6lNDeQ-1; Fri, 21 Oct 2022 04:44:08 -0400 X-MC-Unique: pLmSuEcbOBKO9oSW6lNDeQ-1 Received: by mail-wm1-f72.google.com with SMTP id v125-20020a1cac83000000b003bd44dc5242so3020474wme.7 for ; Fri, 21 Oct 2022 01:44:08 -0700 (PDT) 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=y7dPvGCpD+W598dc6+zdAwz6IliS1cJiJ/REWurOutk=; b=CWeWMK6xP9PsMCkGTgjZVaxVqjnAkmazzviv0llUSYekR1J+Kgfgw8Vtb8i4FxYiIA eOe92MvrUwqXGrEPRl4kIVdIKCt9zF3k01wbjjwAz/mRs3/eI6N+RfNVqleOgrWDbqXk 5d9tsXCaCsao/h5BhwflZbDy8sFN7C8/wd7VjPf96l4/MjYceQRIzQ1PegA8UzE6o9jA 7TJIsg6S2998P6tEwa4kO9SLYDzJKL0NbiuCQufom1tpV7WigPaOPAwVE/oSMPaEaxYy OK2kuAL22VOYQI1HI+wOvhvqeaOFoyQBZ+VhZV8xwAgaq0A7NAAYHLD46Yi9j2Olb6tz 3rVw== X-Gm-Message-State: ACrzQf3QQji+DF16C1+o63307lV9tgcCkqYEwxVINsxc1WJDyrHvGnjR AKAJhRmb6oM+Z4xm6lBc5o0EyidRnA1MUfrBepP58JILai8LeR6p22grBrxzXqpZgZLbgF4fVLZ RkZ09CEfHuiSfTb3h/C/Y8c00fGGHgQyQCt5TFm/yWElONkXCpc2EVIuO0Rj710cef5drayoWyA == X-Received: by 2002:a5d:5b1b:0:b0:236:39af:f2a6 with SMTP id bx27-20020a5d5b1b000000b0023639aff2a6mr4446361wrb.549.1666341847252; Fri, 21 Oct 2022 01:44:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Sglp2MfnaKIygNIPrkf8i0KrpZ8TiZRQtaxn2mxo2sfUDAAea114MBhaIi3vIGN+k5l6/uw== X-Received: by 2002:a5d:5b1b:0:b0:236:39af:f2a6 with SMTP id bx27-20020a5d5b1b000000b0023639aff2a6mr4446343wrb.549.1666341846871; Fri, 21 Oct 2022 01:44:06 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id v21-20020a05600c15d500b003b4e009deb2sm2002079wmf.41.2022.10.21.01.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 01:44:06 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 12/12] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Fri, 21 Oct 2022 09:43:48 +0100 Message-Id: <2733503b33b89407c2b0ea67baa93dc604169db1.1666341010.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.9 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 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 a mechanism where we can track that a stop has been requested for a particular thread through remote_target::stop, then, when the stop arrives, we can convert the SIGINT to a GDB_SIGNAL_0. With this done GDB will now display the "stopped" based messages rather than the "received SIGINT" messages. 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. --- gdb/remote.c | 17 +++++++++++++++++ gdb/testsuite/gdb.base/infcall-timeout.exp | 9 +-------- .../infcall-from-bp-cond-timeout.exp | 9 +-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 17c2d17c8fe..141f7d3656f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1139,6 +1139,10 @@ struct remote_thread_info : public private_thread_info std::string name; int core = -1; + /* Only used when not in non-stop mode. Set to true when a stop is + requested for the thread. */ + bool stop_requested = false; + /* Thread handle, perhaps a pthread_t or thread_t value, stored as a sequence of bytes. */ gdb::byte_vector thread_handle; @@ -7112,6 +7116,12 @@ remote_target::stop (ptid_t ptid) /* We don't currently have a way to transparently pause the remote target in all-stop mode. Interrupt it instead. */ remote_interrupt_as (); + + /* Record that this thread's stop is a result of GDB asking for the + stop, rather than the user asking for an interrupt. We can use + this information to adjust the waitstatus when it arrives. */ + remote_thread_info *remote_thr = get_remote_thread_info (this, ptid); + remote_thr->stop_requested = true; } } @@ -8095,9 +8105,16 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, /* If the target works in non-stop mode, a stop-reply indicates that only this thread stopped. */ remote_thr->set_not_resumed (); + gdb_assert (!remote_thr->stop_requested); } else { + if (status->kind () == TARGET_WAITKIND_STOPPED + && status->sig () == GDB_SIGNAL_INT + && remote_thr->stop_requested) + status->set_stopped (GDB_SIGNAL_0); + remote_thr->stop_requested = false; + /* 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 2bca092aaf8..64b294b2f98 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\\." \ ".*" \ "timeout waiting for inferior function to complete" \ "An error occurred while in a function called from GDB\\." \ 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 17beba75db0..bbeb49eb41e 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -69,16 +69,9 @@ proc run_test { other_thread_bp target_async target_non_stop } { "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}:" \ "timeout waiting for inferior function to complete" \