[PATCH v2 13/47] gdb, remote, ze: fix "$Hc-1#09...Packet received: E01" during startup

Tankut Baris Aktemur
2024-12-13T16:17:08Z

From: Markus Metzger <markus.t.metzger@intel.com>

When opening a connection, the remote target does

set_continue_thread (minus_one_ptid);

which results in

$Hc-1#09

to be send to gdbserver. In remote-utils.c:read_ptid (), this is read as

{ <current inferior>, -1, 0 }

and not recognized as minus_one_ptid when handling 'H' in

ptid_t thread_id = read_ptid (&cs.own_buf[2], NULL);

if (thread_id == null_ptid || thread_id == minus_one_ptid)
thread_id = null_ptid;

Since minus_one_ptid and null_ptid are treated the same way, this is
probably what we want.

In remote_target::remote_resume_with_hc (), we do

if (ptid == minus_one_ptid)
set_continue_thread (any_thread_ptid);
else
set_continue_thread (ptid);

which amounts to the same thing as set_thread () does

*buf++ = 'H';
*buf++ = gen ? 'g' : 'c';
if (ptid == magic_null_ptid)
xsnprintf (buf, endbuf - buf, "0");
else if (ptid == any_thread_ptid)
xsnprintf (buf, endbuf - buf, "0");

so any_thread_ptid is pretty much the same as null_ptid and as
minus_one_ptid in this context.

Use any_thread_ptid to align with remote_target::remote_resume_with_hc ().
---
gdb/remote.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 281e616eb83008e75da8a18efaee7001ddbf6d0d..3aaa1614211d617e0d7683eade88f0d00e1bee8b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5284,7 +5284,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_continue_thread (any_thread_ptid);

if (thread_count (this) == 0)
{