From patchwork Tue Feb 28 16:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 65789 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 233273850200 for ; Tue, 28 Feb 2023 16:44:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 233273850200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677602677; bh=iypbPQAE4UmTNRtvLU/dMHjhWiX2EiHjyLJ0zpMVsMg=; 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=VA29DmeyfTJPv+TSgOuxpRsDekbkZcU47hdVSVPMp4D35Uo33YR3v7E1BwYbgFg7m OmF2y/sdTO132BM0OpNIamTVKlEEAvvrQRVQ/GFwKmQc9JRoK7tq7lP0aXDIpXhBcj eaz4ngjWEnkaiAAsEfZjM3gv4s8llvI6SYE8pGSQ= 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 2B9C13858CDB for ; Tue, 28 Feb 2023 16:42:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B9C13858CDB Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-569-KWnef1AsNQS-Ki-sq9W_Yw-1; Tue, 28 Feb 2023 11:42:36 -0500 X-MC-Unique: KWnef1AsNQS-Ki-sq9W_Yw-1 Received: by mail-ed1-f70.google.com with SMTP id cz22-20020a0564021cb600b004a245f58006so14958030edb.12 for ; Tue, 28 Feb 2023 08:42:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677602555; 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=iypbPQAE4UmTNRtvLU/dMHjhWiX2EiHjyLJ0zpMVsMg=; b=lnIRotFaUbMQx8w0lDVDjYwHrQVV16sPOVUkJzu+0eyt5MmgPNBv/MPJr2s4Nel3np dsoN2bp5v1rXpJSRZm0yQ2uwIvWXfD7ZT3olpga9YFh8G8MNdxsGY5092DBwQ4Pce0Kz ZlPlovo3wZljQgeYx/DlP/mnTAwX2/7KqybbWSFBgJXa+GRzxn9dt3hNF3fI/l37fHFF A3Xr+GP6ocZgtN3kn/KukC7algnSmqkLdfh6aUONQ6/6oG+rGAyzslYCCGWYtF8ia7uc +RPjSuyz0GE6AWCSPu/z37QgTY/EQFU64ium3mrnKdQN3wt53KHQlux3exfOrap8rZM6 XpVQ== X-Gm-Message-State: AO0yUKVxUwu9c8DdTCfWGhnIv/iQJUxZFwgacH50xcKiclte6FCC/Pbr 6lVWZFnmmSFis16WjbFjHYzjGZoD028iR3IRDtwyt2FJ0PFc2s7QYu5ljAFSUobbSBUIJ5nCJUK GFaJHBVb5NHM5O1NCLWfSJ/1kdK8QZ1wG6b9PCzd5qkbLdm7zrjC28d8VxT9gotUBwdEbIn0bsu 1krU0= X-Received: by 2002:a17:906:494e:b0:881:f2f:6633 with SMTP id f14-20020a170906494e00b008810f2f6633mr2931949ejt.50.1677602555115; Tue, 28 Feb 2023 08:42:35 -0800 (PST) X-Google-Smtp-Source: AK7set9S0bHJvHlEP6/fdEtH8KuwZ95KG+SdvoHOn7WSQknS6z4naaUBrqD+LDWw8UVnRMI07PJANg== X-Received: by 2002:a17:906:494e:b0:881:f2f:6633 with SMTP id f14-20020a170906494e00b008810f2f6633mr2931932ejt.50.1677602554737; Tue, 28 Feb 2023 08:42:34 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id b12-20020a1709064d4c00b008c673cd9ba2sm4698040ejv.126.2023.02.28.08.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 08:42:34 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv4 10/12] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Tue, 28 Feb 2023 16:42:15 +0000 Message-Id: <4c232b6b893a32882ea81aa4165c3e438df4dc6a.1677602051.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.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 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 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\\." \