From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2E6893858428 for ; Wed, 18 Jan 2023 16:18:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E6893858428 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674058719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mp6tKE2xuHtRpqoeLvrY1EQy0IftAEggYKRvHDyxbkg=; b=Gp8rZDzMXN4N60hyizGZvVIsRMxWQlc6p3FXqPg5qNOBOdE5XbhLvkR9P3/qo//2BmyR8n uuD8uAleaEBLDDiwCKcl8vRhramyyZROGNDtq14zqYQTmP3+pULLTzrEJvZEOX8NJmRLXl omDK2E1XKyk86w68NVMlTlX70bH7/30= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-575-SgPm2-sFPFSRvZ0Rm96POg-1; Wed, 18 Jan 2023 11:18:38 -0500 X-MC-Unique: SgPm2-sFPFSRvZ0Rm96POg-1 Received: by mail-qv1-f70.google.com with SMTP id nk14-20020a056214350e00b0053472f03fedso7797322qvb.17 for ; Wed, 18 Jan 2023 08:18:38 -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=mp6tKE2xuHtRpqoeLvrY1EQy0IftAEggYKRvHDyxbkg=; b=lpZTRlbbWmuuAgaDN8YXS6aUrEy9YVix4Y/vNpiMB/Dma/SPeiUHrVCWuTvhbiBG4u jM/LY8opY28Uctn7QES5ZCRD/XyYxJaCRZmqDUnIWtr6g2fiTfHB7JK7b5uoLLTNL4ub lDrGlQfE51OYWCKzhLeFZS2/3oviG2Fe2RoDqagpt0wh4aKjDl+c7P6J4xMZIrLLXWqB nY052sQGlCHAIxsmDkECxrfKWFj/WaGeLjmJeYxA2WE741EVKB+IS0Zi+/7Fe5tDqVeS TEqurBIoONAufdV3deHGKNxgxpnvOy04ozXQNofYAb9370tzBmM9u+KzUhSS6PdWoXYq 8yjA== X-Gm-Message-State: AFqh2krb/U1j08DVM8pwRpdeRzUQew2D+r+cmHUrpcd7FwHQRXY8DyLO dNRhFjkfK2d+PN7vnDEb5gN/U+x2A9WB1NpSgzCSee2ZQcNwNcFUAZiy4F1IuFEIKR5cQWVcw8M eCkcckuDueXvKbmvp5+GqHLFwVeh8Gv9Uev41v3OsmMY/IUuzmJWAwikx9PpsN0fgVJlT80aZwA == X-Received: by 2002:a05:6214:37c9:b0:534:e068:322e with SMTP id nj9-20020a05621437c900b00534e068322emr11824956qvb.51.1674058717952; Wed, 18 Jan 2023 08:18:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXv9jOcdjIG+v4iUdM1A1QAiI72EzVDuJOcQGfM+l8VEINODFivOGpOf1hv/Z8Ej/dCgXqUdIQ== X-Received: by 2002:a05:6214:37c9:b0:534:e068:322e with SMTP id nj9-20020a05621437c900b00534e068322emr11824917qvb.51.1674058717588; Wed, 18 Jan 2023 08:18:37 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id u6-20020a05620a0c4600b007054feab4aesm22432763qki.27.2023.01.18.08.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 08:18:37 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 11/13] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Wed, 18 Jan 2023 16:18:07 +0000 Message-Id: <167045998eadfcb2015eb0b786e9aab56633b0ab.1674058360.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 218bca30d04..61781a24820 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; @@ -7114,6 +7118,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; } } @@ -8097,9 +8107,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 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\\." \ -- 2.25.4