From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qQLiGO5m8mmGNgQAWB0awg (envelope-from ) for ; Wed, 29 Apr 2026 16:15:42 -0400 Received: by simark.ca (Postfix, from userid 112) id 627AB1E0BA; Wed, 29 Apr 2026 16:15:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 C85431E093 for ; Wed, 29 Apr 2026 16:15:41 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 510FC4BB8F45 for ; Wed, 29 Apr 2026 20:15:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 510FC4BB8F45 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id E6A634BB5938 for ; Wed, 29 Apr 2026 20:15:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6A634BB5938 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 E6A634BB5938 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=1777493717; cv=none; b=tPw/WkjqLOfOtJ+7XyAkQNCW92NSCDTYVzLP3zcr5GZxw7uecJadU/6gUVNGKfAhvt/rHDo88iF6O8q7r2KeVBWsWHciltncfSkoS27duUcfpzgly1wmD0xuJu7vPFrQYWUmICQJZfFs0UMtP+auWqy4S0eM8KWUiSIEwWsJcjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777493717; c=relaxed/simple; bh=XPl/rM3DtHcBMevGKBJwEzTY5Vob8+77AliQp8F4tio=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LgolqRc2Bu6GWQoTQpU/cgcT/+8Q1IhHUH9l0yQXKWYcbVU7BFrb8ZcYmp24LiLz8keKFFciKjNP4M+Wl34g1DbWvdSME62WKZVjr6B0PdszdGCkrHE9iE6B/UciVAawh4EjYlNr/DXHxcugMKIbdI66xL8JHhCOTCtJKk6Tjqs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6A634BB5938 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-483487335c2so2021525e9.2 for ; Wed, 29 Apr 2026 13:15:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777493715; x=1778098515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/MVN7XqHVR4/mm374m9/3RiAjgTxoDm715sRD5mjBDk=; b=Bif+DioCU4u9F0efw4mnv/2knK1P6R7bHnDYk1ATnuXS6zxPwPprC8n/evmx3Aw4Fa Y8KWh4QB80oR1ZSHYZ5bXB3RfY7VaRg4z4WN7CjGO+YJVYUakuyjVYxG9GsP+6DypT7Q a1C5z9a7mQgkl9ltkIX1FCb1uTkFqm1+jAv+5G2ZxJ33lEGftJxiNPaZAa/CsZCgAZLm Z+ONFFZlUyoBxmjNDC0llGaXRWRPeevq51lrJIyTp2Eb9pcr58BF0VCxYTF4EgO24pBd iNNXZmfaHtF6/7voJFJaJowe4VJiAIK5A9lFq8N5hX4qwChzjbMm0hN+/zGAQlpl+qQw GsIw== X-Gm-Message-State: AOJu0Yw/ffAwEC3QQ9cZ6Zen39w9y9LiEY6rMZCxhIeXbTvr+HCh5I9v bFagsmS0mCFQaHw9FxrlfJIVXUih89CxQuQ6FurOAHQ8EhttozrqLw+79bv9uw== X-Gm-Gg: AeBDievAOkEVA3w3ZyWz22E/96WJCDAlupZQkfu2LQpB4+p0FRvwQUv8rHrARomlPec 3zodP8V3bvtC/5FGuYuaaJ5huhTbex5raoJD28yv3ZnHpfJeLoOqwxHrEjOXryCsJg3OJpLVgi1 y1mvHDGpmGZUVT93Lug5e1zbHdQ3/aIO38T27TPnz6bOW2awO7XSqvJDMeibnHE6Kwm0jH+br1Y uFfVhwg150htpZIHtVGlpZu/imdTJza7Ph4kaYlz8Gy5JPlHr+aaj7LsFBDwZeahcvn+8Fityr8 /8yaZhXVh3Yxne+mAhClcRIbozTV/mzcfsLIysVczFTR5oUIXINkPDxKqeTwOC5l2eRIQaDclMd IWpQILe+DvZqzUM4KFBptyUbiQluBWkzyRB/6mFN/bYByPdSr5R4L/raVmDln6gXkTSzqW2qY7b GIf9ScAZEyK9LbLNBH0qmrJFGiKs8IVQ8= X-Received: by 2002:a05:600c:4e16:b0:48a:52ce:a4b1 with SMTP id 5b1f17b1804b1-48a8451cff6mr244435e9.15.1777493715391; Wed, 29 Apr 2026 13:15:15 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:f22f:591f:e700:e91]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-48a82301b7bsm15471275e9.11.2026.04.29.13.15.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2026 13:15:14 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 02/11] linux-nat: Factor out get_detach_signal code to common code Date: Wed, 29 Apr 2026 21:14:58 +0100 Message-ID: <20260429201507.480870-3-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429201507.480870-1-pedro@palves.net> References: <20260429201507.480870-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. Approved-By: Tom Tromey Change-Id: Ifaa96b4a41bb83d868079af4d47633715c0e1940 commit-id:dac5b3f8 --- 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 0e359f0ed74..aed66bf844e 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -366,6 +366,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 f15662d5bc9..42c867ce303 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -320,6 +320,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 d7d5e010748..868f08e18fb 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1320,13 +1320,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; @@ -1356,38 +1356,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) { @@ -1517,7 +1486,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; @@ -1604,7 +1573,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.53.0