From: Markus Metzger <markus.t.metzger@intel.com>
To: gdb-patches@sourceware.org
Cc: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Subject: [PATCH 2/2] gdb, remote: fix set_thread () in start_remote ()
Date: Tue, 5 Aug 2025 07:19:14 +0000 [thread overview]
Message-ID: <20250805071914.3832823-2-markus.t.metzger@intel.com> (raw)
In-Reply-To: <20250805071914.3832823-1-markus.t.metzger@intel.com>
remote_target::start_remote_1 () calls set_continue_thread (minus_one_ptid)
with the intent to
/* Let the stub know that we want it to return the thread. */
set_continue_thread (minus_one_ptid);
I interpret it such that it expects a later get_current_thread () to
return the thread selected by the target:
/* We have thread information; select the thread the target
says should be current. If we're reconnecting to a
multi-threaded program, this will ideally be the thread
that last reported an event before GDB disconnected. */
ptid_t curr_thread = get_current_thread (wait_status);
This results in the packet sequence Hc-1, qC.
Hc simply sets cont_thread:
else if (cs.own_buf[1] == 'c')
cs.cont_thread = thread_id;
write_ok (cs.own_buf);
and qC returns the general thread. This doesn't match.
It also has some special treatment for null_ptid and minus_one_ptid:
if (cs.general_thread != null_ptid && cs.general_thread != minus_one_ptid)
ptid = cs.general_thread;
else
{
init_thread_iter ();
ptid = thread_iter->id;
}
Similarly, Hg has some special treatment for null_ptid:
if (cs.own_buf[1] == 'g')
{
if (thread_id == null_ptid)
{
/* GDB is telling us to choose any thread. Check if
the currently selected thread is still valid. If
it is not, select the first available. */
thread_info *thread = find_thread_ptid (cs.general_thread);
if (thread == NULL)
thread = get_first_thread ();
thread_id = thread->id;
}
cs.general_thread = thread_id;
The comment at Hg matches the intent of GDB for sending Hc-1.
Change the set_thread () call in remote_target::start_remote_1 () to
set_general_thread (any_thread_ptid);
This results in GDB sending Hg0 and gdbserver preserving the currently
selected thread that is later returned in response to qC.
CC: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
---
gdb/remote.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 6208a90f94a..9b76578bd80 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5293,7 +5293,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
target_update_thread_list ();
/* Let the stub know that we want it to return the thread. */
- set_continue_thread (minus_one_ptid);
+ set_general_thread (any_thread_ptid);
if (thread_count (this) == 0)
{
--
2.34.1
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2025-08-05 7:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 7:19 [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids Markus Metzger
2025-08-05 7:19 ` Markus Metzger [this message]
2025-08-14 4:29 ` [PATCH 2/2] gdb, remote: fix set_thread () in start_remote () Thiago Jung Bauermann
2025-08-14 22:28 ` Simon Marchi
2025-08-15 0:29 ` Thiago Jung Bauermann
2025-08-15 5:33 ` Simon Marchi
2025-08-18 1:43 ` Thiago Jung Bauermann
2025-09-22 13:29 ` Metzger, Markus T
2025-08-14 3:36 ` [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids Thiago Jung Bauermann
2025-08-14 20:40 ` Simon Marchi
2025-09-22 13:29 ` Metzger, Markus T
2025-09-23 18:26 ` Tom Tromey
2025-09-24 8:04 ` Metzger, Markus T
2025-09-26 6:43 ` Metzger, Markus T
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=20250805071914.3832823-2-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=thiago.bauermann@linaro.org \
/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