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.133.124]) by sourceware.org (Postfix) with ESMTPS id 548FB3858C20 for ; Mon, 3 Apr 2023 14:01:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 548FB3858C20 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=1680530494; 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=DYOfRVNQdFwTA404Q16e4AmmOsos6fnIsr58RBqFNIw=; b=Yf+ty7gHG8qd/oHd61jsI/B03VMvZQBKQzjukyEAkzKk7eZCNNZm3WdNwOo+G0h/Px/cb9 rGvCwuuwrNXrD8/MLy7fm7ekyfk7waqaGBPVEMy41Jr2cbvYyI6y8sT5N8/Hm7CB5d2BSB rkyK/yo7bUXGScqj83bOO5/sLSXiEw0= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-9YfqZ5nkPZGlL6xdahmLIQ-1; Mon, 03 Apr 2023 10:01:32 -0400 X-MC-Unique: 9YfqZ5nkPZGlL6xdahmLIQ-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-1805c875a3fso4450902fac.17 for ; Mon, 03 Apr 2023 07:01:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680530491; 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=DYOfRVNQdFwTA404Q16e4AmmOsos6fnIsr58RBqFNIw=; b=YUaLvEiYR/OBM/xGuNU24xtaIvm7fLEO4ffQ4Q8SZizMAhIBYHGUrJTm5SW47Jpnec Tq4S5JAliGPmT8iAxavo4hxQPhdU3kZBWNGYEfg1bW7zCP9h2IWY2XMPTbMXPaKHaTdu nTc6kwIV3dMS2tvCQ+jC0+Euh4rFR0+LVRkbuGOHcR/Ef5iVqmtH2u5kdHXJobWxhaia TL2H2rj9KyajGceOMYXd18yNvZ+cuCeMGc1qcW2CqhFYIMe1MREwguErn42+AOEWb8Fc uVfTxnGIp4apQH+NMcDtt/k/EVH3ReMmxM1eptuRGdtsFdrgWAuFt2wEDJgBqtBjC6Um S5rw== X-Gm-Message-State: AAQBX9dFjrV5rYOdF1/kUhDMaGt08mfGfwrxXbgdki0qKsuU7G3glIGi f5+jk462KOSwBlzdvp8VFjK3wqC092OYPIDv2/Mh/7rAU0CUTZIxk8oPCqWA09CNxIV5uOfi8B6 M6KxtTRMJGGbk9t3HLYR4Dd+3F8GnG6p+aSZWGVXTTn0Ia1L8q8pZX3tgj1bVS2KDb8mj+dKquG 16bY26FQ== X-Received: by 2002:a9d:77c7:0:b0:6a1:7b61:1fd0 with SMTP id w7-20020a9d77c7000000b006a17b611fd0mr6121266otl.3.1680530491634; Mon, 03 Apr 2023 07:01:31 -0700 (PDT) X-Google-Smtp-Source: AKy350b5vHFk+xBbkTBmxvyoPcAq9iSOqzHSQYCwdZ/kigqyONsiw2WwZGxfnSjefo274EcNG5WxmA== X-Received: by 2002:a9d:77c7:0:b0:6a1:7b61:1fd0 with SMTP id w7-20020a9d77c7000000b006a17b611fd0mr6121193otl.3.1680530490375; Mon, 03 Apr 2023 07:01:30 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 76-20020a370b4f000000b0074680682acdsm2787653qkl.76.2023.04.03.07.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 07:01:30 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv6 4/6] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Mon, 3 Apr 2023 15:01:16 +0100 Message-Id: <85f7992eb9099fd39ca14a2210830f5bac25fdd7.1680530116.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.7 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 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 526df313ea7..ea8f103a589 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 5e9cdc2fa0e..beb488ffd1e 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 } { - 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 4159288a39c..74f7def7dce 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} { - 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