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 66AAD3857B98 for ; Wed, 7 Jun 2023 10:01:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66AAD3857B98 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=1686132092; 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=qmALBBPNvNEjEL0bJXuk51LOsQ+0sC7VJTYKxzDgIWs=; b=JM5lFV75CZ5cB6ynHAEFGeIxzq4BTGjnzEMxkTE08+lYgowtbW2OI2rLz8SskrkRi8/NXA CIDI/9FkFsrRTUcS3SGNRgaE656NZoWs4xCsf3lGgzovUJT98zBE6KET8VOpOtN3jRVGqF jDV2MOSbH+x4rSz2CMuewRH0j/6Sjnw= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-xOynNJyWOKCWrcHp2W0pgw-1; Wed, 07 Jun 2023 06:01:30 -0400 X-MC-Unique: xOynNJyWOKCWrcHp2W0pgw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-30af779d6e6so3254809f8f.3 for ; Wed, 07 Jun 2023 03:01:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686132089; x=1688724089; 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=qmALBBPNvNEjEL0bJXuk51LOsQ+0sC7VJTYKxzDgIWs=; b=FHp/cqF0oiJqw2nbB4mcKLhbhxzh6yafLilXtOjSZTpVcD/Rgi0yHsWxW8uD+hJVuq eEILreUpdV2cJARRr+rYbqAbmZc1X1zcjZ+vNQPlaV36HN/u5nViqCcwOaPGCcRC0TOs ItJbwKRD8CQSpcDOMVd6lAAn8qhnL6ALidMSWRN4o7qui6A/broi3yxK+xR/lTTkFOqL BbJD/KQsuGb81YXOLvHujYLj5DJa8WpaPFVy4MDVu/CKQx7YtHuSCLh3d+8SDWJVwA+8 iZX0UMoDgy3/WNwkUEw+Ggq5MzvmI2wryjWLNmzIFReyJ4ED58a0A3bu980v4xW0em8c AQUA== X-Gm-Message-State: AC+VfDw7tA35jXOZ8t+yXXgy/qj+nI0kDkgY5LjFkxuKWa4V3mvJXJA5 yvDPEAkxbolI3FY+C6sa8O51p5p5TavV9atR/OiFv2YLW3WdNzNw3A5qpg9lSeQGXEZT6CpGC0V tLF1cHrUCAsSZaFRmE3SwDxXlnxpVpaQ9xtXXT562ORM605dBQC98Rko2XtsMWob3Rk1LBzm6SN crkdOIng== X-Received: by 2002:a5d:60d2:0:b0:30e:590f:78d1 with SMTP id x18-20020a5d60d2000000b0030e590f78d1mr1215987wrt.63.1686132089325; Wed, 07 Jun 2023 03:01:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FGM5CLHnlwY9laVRk5Kphd69VzA+AVuKhAAtIgL5ZmXWxJoFnQ9Lt9IN2fzwcaac/yzpTrg== X-Received: by 2002:a5d:60d2:0:b0:30e:590f:78d1 with SMTP id x18-20020a5d60d2000000b0030e590f78d1mr1215971wrt.63.1686132088960; Wed, 07 Jun 2023 03:01:28 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id s9-20020a5d5109000000b003063a1cdaf2sm15096269wrt.48.2023.06.07.03.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 03:01:28 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv8 4/6] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Wed, 7 Jun 2023 11:01:16 +0100 Message-Id: <0d839e4d9288c80fb4cba0b7f02ea6fd52b20fc6.1686131880.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,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 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. Due to the changes to how get_remote_thread_info is now called in remote.c, one of the overloads of get_remote_thread_info is no longer used and can be deleted. --- gdb/remote.c | 23 +++++++++---------- gdb/testsuite/gdb.base/infcall-timeout.exp | 11 +-------- .../infcall-from-bp-cond-timeout.exp | 11 +-------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 02ff3a12bdb..d50802bc4a0 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2729,8 +2729,6 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached, } static remote_thread_info *get_remote_thread_info (thread_info *thread); -static remote_thread_info *get_remote_thread_info (remote_target *target, - ptid_t ptid); /* Add thread PTID to GDB's thread list. Tag it as executing/running according to EXECUTING and RUNNING respectively. If SILENT_P (or the @@ -2870,15 +2868,6 @@ get_remote_thread_info (thread_info *thread) return gdb::checked_static_cast (thread->priv.get ()); } -/* Return PTID's private thread data, creating it if necessary. */ - -static remote_thread_info * -get_remote_thread_info (remote_target *target, ptid_t ptid) -{ - thread_info *thr = target->find_thread (ptid); - return get_remote_thread_info (thr); -} - /* Call this function as a result of 1) A halt indication (T packet) containing a thread id 2) A direct query of currthread @@ -8263,7 +8252,8 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, } remote_notice_new_inferior (ptid, false); - remote_thread_info *remote_thr = get_remote_thread_info (this, ptid); + thread_info *tinfo = this->find_thread (ptid); + remote_thread_info *remote_thr = get_remote_thread_info (tinfo); remote_thr->core = stop_reply->core; remote_thr->stop_reason = stop_reply->stop_reason; remote_thr->watch_data_address = stop_reply->watch_data_address; @@ -8276,6 +8266,15 @@ 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) + { + if (tinfo->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 729d8d8734a..2af598e044d 100644 --- a/gdb/testsuite/gdb.base/infcall-timeout.exp +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp @@ -44,18 +44,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 { ([target_info gdb_protocol] == "remote" - || [target_info gdb_protocol] == "extended-remote") - && !$target_non_stop } { - 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 3e74958589c..a94c6a58192 100644 --- a/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp +++ b/gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp @@ -91,18 +91,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 { ([target_info gdb_protocol] == "remote" - || [target_info gdb_protocol] == "extended-remote") - && !$target_non_stop} { - 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