From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GDSEIPkzK2hiOCoAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:36:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 82DD41E11C; Mon, 19 May 2025 09:36:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 054A31E102 for ; Mon, 19 May 2025 09:36:57 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B393D3858435 for ; Mon, 19 May 2025 13:36:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B393D3858435 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id 876033858D20 for ; Mon, 19 May 2025 13:25:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 876033858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 876033858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661104; cv=none; b=uO6TulIvw7tylyuNaYZeuCPrTjjcphsR58m4Ztd2HegVzpQnXUmeO4H9IqYuHzE/y0MlfLLD9RHcc5YqhvyJq9ifesvyMskp6jJ3LNRoir48aK9VBb6sIZjEDwHNAO2j3EN2eyfxWEi5vK1Cx0Fh1oBta3z257D/b7YAUO1/WRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661104; c=relaxed/simple; bh=rqiEyToiujHbl15xSw87AJ+qxUgSkOhf44L+LXSXI64=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Wm686gwF7psCwak9eW6ppRNj97rW1T/mZiolEdOtAIRgGxhCgjfJNylsILtYBYVa/UUcW8/WfZu2jd9ZOev1fhaLtrpUtm4OrHjol2TRglgE5CZJEvGrus6l5cEIKIgT9ugWzpoofVgklsxPgjH/e5FAZNM84tCEg2Ddw++XMEQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 876033858D20 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43d04dc73b7so47969315e9.3 for ; Mon, 19 May 2025 06:25:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661103; x=1748265903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ErMULwSM8Wxcrh8pIo6S3cva0c6ga0xvTYuYam6N3Xs=; b=Qafo2bf74L72qKgXy1G/vn9HdSQHhDXkkdtUgQTyi9+BowzPK8A87ZqccqgBLmPibY S2yZPhBiZQxY9XPE/V8nPlYpclK8J8blgTyQ+ABwBkzn4CInbpKpT/MDf5dH8NjQ43T5 i6mC6UUmr/6NX8yK0+OoED2epMjE1lfG4qVqaC966dg0hH0JtDEHerOYqCYq8nP1TZG3 htOvQkdjfHCprkdfmNAOGBDUSDtij5LZ2p6v3pFe54ECJw2Mht/AqJH6uUuXVEe0SVyJ tadpAUHxAnf7gSz2w5hLq6HvC3BNiIyDiLZKBUrQ0J06gB4haHD92c7MGc/qEvyZ7hxV OArw== X-Gm-Message-State: AOJu0YxL3WreUHqx2QByjyS0q0FozNPijQwuHHj+tDcEAWsjHedfeluC JXngtZuxcE0jEdcYsk5+skv6mGpXFAPHK914r0iVC90cWeH5Xjh71YWJI03iI9zC X-Gm-Gg: ASbGnctafEvF/S0kdqIOBG1zbRFI47+WzG5sb0GIazw37Iz/TVDG/lhhk0k3N5khSV0 e8ZGh+GKtRLRW3fKE6zm4bO6Pdb8PvigaX7eBYV3geabEOBc4fYsxV5GOJyFod806Zd7/p2/nWY C2uOPTaQO5ACQAXX3XuOD8Fufbdj8R+N77rUzDgaoLVW+35kTRn4c9JfJ+E0zWvtClum44fCXj6 Nnl/b6HRb0bSlDIrU+oYrQL+K0aMMleD+A0dL35W2E1oHabJnfwWYAH7BTWYdN65rbzDqmwNdoi nKpbM4uXhbnfJdEEEiCbMW8KEhtX1nEL6QjelX3yJ6Eu+pvVTNL0UgSn/faYuw== X-Google-Smtp-Source: AGHT+IEo5JB2CBNg5g7B85cgzOGufEIhq7bh6zYh/rQjBbBfzh5DLS69f0IUCYq5BTiM3Uh+yycJrA== X-Received: by 2002:a05:600c:45c3:b0:43e:a7c9:8d2b with SMTP id 5b1f17b1804b1-442fd664965mr112252145e9.24.1747661103073; Mon, 19 May 2025 06:25:03 -0700 (PDT) Received: from localhost ([2001:8a0:4fe9:b400:8d90:6f0d:36bf:32df]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a35ca8d258sm12751621f8f.100.2025.05.19.06.25.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:25:02 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 36/47] linux-nat: Factor out get_detach_signal code to common code Date: Mon, 19 May 2025 14:22:57 +0100 Message-ID: <20250519132308.3553663-37-pedro@palves.net> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250519132308.3553663-1-pedro@palves.net> References: <20250519132308.3553663-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The Windows target backend will want to do most of what the get_detach_signal function in gdb/linux-nat.c does, except for the Linux-specific bits. This commit moves the code that is shareable to infrun.c, so that other targets can use it too. Change-Id: Ifaa96b4a41bb83d868079af4d47633715c0e1940 --- gdb/infrun.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/infrun.h | 6 ++++++ gdb/linux-nat.c | 41 +++++------------------------------------ 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 20649ace942..826093f79f9 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -367,6 +367,43 @@ update_signals_program_target (void) target_program_signals (signal_program); } +/* See infrun.h. */ + +gdb_signal +get_detach_signal (process_stratum_target *proc_target, ptid_t ptid) +{ + thread_info *tp = proc_target->find_thread (ptid); + gdb_signal signo = GDB_SIGNAL_0; + + if (target_is_non_stop_p () + && tp->internal_state () != THREAD_INT_RUNNING) + { + if (tp->has_pending_waitstatus ()) + { + /* If the thread has a pending event, and it was stopped + with a signal, use that signal to resume it. If it has a + pending event of another kind, it was not stopped with a + signal, so resume it without a signal. */ + if (tp->pending_waitstatus ().kind () == TARGET_WAITKIND_STOPPED) + signo = tp->pending_waitstatus ().sig (); + } + else + signo = tp->stop_signal (); + } + else if (!target_is_non_stop_p ()) + { + ptid_t last_ptid; + process_stratum_target *last_target; + + get_last_target_status (&last_target, &last_ptid, nullptr); + + if (last_target == proc_target && ptid == last_ptid) + signo = tp->stop_signal (); + } + + return signo; +} + /* Value to pass to target_resume() to cause all threads to resume. */ #define RESUME_ALL minus_one_ptid diff --git a/gdb/infrun.h b/gdb/infrun.h index b09e7c1df8a..869ae2a67a9 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -319,6 +319,12 @@ extern void all_uis_on_sync_execution_starting (void); detach. */ extern void restart_after_all_stop_detach (process_stratum_target *proc_target); +/* While detaching, return the signal PTID was supposed to be resumed + with, if it were resumed, so we can pass it down to PTID while + detaching. */ +extern gdb_signal get_detach_signal (process_stratum_target *proc_target, + ptid_t ptid); + /* RAII object to temporarily disable the requirement for target stacks to commit their resumed threads. diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 4de4cc83cfa..94f3f6c7075 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1292,13 +1292,13 @@ detach_one_pid (int pid, int signo) pid, strsignal (signo)); } -/* Get pending signal of THREAD as a host signal number, for detaching +/* Get pending signal of LP as a host signal number, for detaching purposes. This is the signal the thread last stopped for, which we need to deliver to the thread when detaching, otherwise, it'd be suppressed/lost. */ static int -get_detach_signal (struct lwp_info *lp) +get_lwp_detach_signal (struct lwp_info *lp) { enum gdb_signal signo = GDB_SIGNAL_0; @@ -1328,38 +1328,7 @@ get_detach_signal (struct lwp_info *lp) else if (lp->status) signo = gdb_signal_from_host (WSTOPSIG (lp->status)); else - { - thread_info *tp = linux_target->find_thread (lp->ptid); - - if (target_is_non_stop_p () - && tp->internal_state () != THREAD_INT_RUNNING) - { - if (tp->has_pending_waitstatus ()) - { - /* If the thread has a pending event, and it was stopped with a - signal, use that signal to resume it. If it has a pending - event of another kind, it was not stopped with a signal, so - resume it without a signal. */ - if (tp->pending_waitstatus ().kind () == TARGET_WAITKIND_STOPPED) - signo = tp->pending_waitstatus ().sig (); - else - signo = GDB_SIGNAL_0; - } - else - signo = tp->stop_signal (); - } - else if (!target_is_non_stop_p ()) - { - ptid_t last_ptid; - process_stratum_target *last_target; - - get_last_target_status (&last_target, &last_ptid, nullptr); - - if (last_target == linux_target - && lp->ptid.lwp () == last_ptid.lwp ()) - signo = tp->stop_signal (); - } - } + signo = get_detach_signal (linux_target, lp->ptid); if (signo == GDB_SIGNAL_0) { @@ -1489,7 +1458,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p) if (signo_p == NULL) { /* Pass on any pending signal for this LWP. */ - signo = get_detach_signal (lp); + signo = get_lwp_detach_signal (lp); } else signo = *signo_p; @@ -1577,7 +1546,7 @@ linux_nat_target::detach (inferior *inf, int from_tty) if (main_lwp != nullptr) { /* Pass on any pending signal for the last LWP. */ - int signo = get_detach_signal (main_lwp); + int signo = get_lwp_detach_signal (main_lwp); detach_one_lwp (main_lwp, &signo); } -- 2.49.0