From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
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 [thread overview]
Message-ID: <20260429201507.480870-3-pedro@palves.net> (raw)
In-Reply-To: <20260429201507.480870-1-pedro@palves.net>
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 <tom@tromey.com>
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
next prev parent reply other threads:[~2026-04-29 20:15 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 20:14 [PATCH v3 00/11] Windows non-stop mode Pedro Alves
2026-04-29 20:14 ` [PATCH v3 01/11] Windows gdb+gdbserver: Check whether DBG_REPLY_LATER is available Pedro Alves
2026-04-29 20:14 ` Pedro Alves [this message]
2026-04-29 20:14 ` [PATCH v3 03/11] Windows GDB: make windows_thread_info be private thread_info data Pedro Alves
2026-04-29 20:15 ` [PATCH v3 04/11] Introduce windows_nat::event_code_to_string Pedro Alves
2026-04-29 20:15 ` [PATCH v3 05/11] Windows gdb: Add non-stop support Pedro Alves
2026-04-29 20:15 ` [PATCH v3 06/11] Windows gdb: Watchpoints while running (internal vs external stops) Pedro Alves
2026-04-29 20:15 ` [PATCH v3 07/11] Windows gdb: extra thread info => show exiting Pedro Alves
2026-04-29 20:15 ` [PATCH v3 08/11] Add gdb.threads/leader-exit-schedlock.exp Pedro Alves
2026-04-29 20:15 ` [PATCH v3 09/11] infrun: with AS+NS, prefer process exit over thread exit Pedro Alves
2026-05-06 10:01 ` Bouhaouel, Mohamed
2026-05-08 21:37 ` Pedro Alves
2026-05-11 11:58 ` Bouhaouel, Mohamed
2026-04-29 20:15 ` [PATCH v3 10/11] Windows gdb: Always non-stop (default to "maint set target-non-stop on") Pedro Alves
2026-04-29 20:15 ` [PATCH v3 11/11] Mention Windows non-stop support in NEWS Pedro Alves
2026-04-30 5:55 ` [PATCH v3 00/11] Windows non-stop mode Eli Zaretskii
2026-04-30 10:13 ` Pedro Alves
2026-04-30 11:14 ` Eli Zaretskii
2026-04-30 12:01 ` Pedro Alves
2026-04-30 14:15 ` [PATCH] Clarify "maint set target-non-stop" in GDB manual (Re: [PATCH v3 00/11] Windows non-stop mode) Pedro Alves
2026-04-30 15:09 ` Eli Zaretskii
2026-04-30 16:18 ` [PATCH v2] " Pedro Alves
2026-04-30 16:27 ` Eli Zaretskii
2026-04-30 16:33 ` Pedro Alves
2026-04-30 17:45 ` [PATCH v3 00/11] Windows non-stop mode Pedro Alves
2026-05-08 18:43 ` Tom Tromey
2026-05-08 21:27 ` Pedro Alves
2026-05-22 0:22 ` Pedro Alves
2026-06-02 19:00 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260429201507.480870-3-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox