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 A6A543858C31 for ; Mon, 15 May 2023 19:22:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6A543858C31 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=1684178549; 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=cISReAKOpjiQ5dFVb/50Nz3Wwf7ODReDce8Jnc0IveI=; b=atGN2CEdQ4LI7c0lG27pFxX2geizj6kI+6k297DIUfD7VgWke993YXs//OYK57TYsy9im0 Je6bHlZaeWS74AYGXUBWkY4O2u/DgxBJ62C7+kAFlFr9yRLBDnTjv2zTU2lZfEbjKBiJgA dwripv0bkZm2vXYx9J7CZT5JN5hRYzw= 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-121-aRbKha_dMzyxPFdVX4v-qQ-1; Mon, 15 May 2023 15:22:26 -0400 X-MC-Unique: aRbKha_dMzyxPFdVX4v-qQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3062a46bf21so7813359f8f.1 for ; Mon, 15 May 2023 12:22:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684178545; x=1686770545; 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=cISReAKOpjiQ5dFVb/50Nz3Wwf7ODReDce8Jnc0IveI=; b=egtnWPdlBueugh3XcFdj4FM3SLWv40km0VDKaUD2M2LcHSPqomJYN5Jdy8paxdlxWI wOQZPxWhIX3C1vMEfd3OelRu2QABuTh8DnjBiKAEs9VOM4W9YnspO9lGaOxAOK7CUWve /8dAv7N2s7mo9tlztipLF/3R9QDhdxGYwG3X7JYMHU6EzF3R3lRyQDSYlnUABdXYo4LO lSOQuYcnbhsSlpOEUUWMArKQjnKgg+vNMtm2U050HBvvY3ySx/oq5/JoOXGvExii8Jw/ EoCQyyH9Fwy7qeZqQpWkoGg6HyEiWRA5zzBBNDXVtsYBkQRm5AS5zfLvQCsEWoymg3i0 uAvA== X-Gm-Message-State: AC+VfDxRLuTkgenpR1RWiA1OwzQhmiGM6tWSJGQIteUx7SEnrrgAnwVA s0EjTiA2lOThxPWzv0JXvVpOGA7qPFdft1ZcLFdRDieueQnepp3iB5tSmd/T4HNwRHCOjg/VbRT cEMhwKLRmWvVSallVG5tUG97w66ymQU90vGOTzp13l2Z/MTZzpCcpFT3ZIkfdkxUDR9GioVgFI7 HS6taC7A== X-Received: by 2002:a5d:4403:0:b0:307:8800:bbdb with SMTP id z3-20020a5d4403000000b003078800bbdbmr22411468wrq.58.1684178544709; Mon, 15 May 2023 12:22:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ihmEbGyyOGKn/m6PwDSkcsufNLN2H7UgDC2a3cU/iYOCBPtzGlqOSbRRrQOsFGn/dQWNiWw== X-Received: by 2002:a5d:4403:0:b0:307:8800:bbdb with SMTP id z3-20020a5d4403000000b003078800bbdbmr22411458wrq.58.1684178544429; Mon, 15 May 2023 12:22:24 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id z1-20020a5d6401000000b003068f5cca8csm54163wru.94.2023.05.15.12.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 12:22:23 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv7 4/6] gdb/remote: avoid SIGINT after calling remote_target::stop Date: Mon, 15 May 2023 20:22:11 +0100 Message-Id: <9a5d537b06f63d95419bd2c290304b6e881dab6a.1684178293.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.6 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. --- 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 8eaa1b2c4d1..c61eeeadc52 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 = this->find_thread (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