Skip to contentSkip to conversation

gdbstub: reset supported features on Supported request

PATCH Superseded Pierrick Bouvier 3 participants 6 messages Oct 30 – Nov 5

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdbstub: reset supported features on Supported request

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)
gdbstub/gdbstub.c +6 -0
index 0a328b0dd48..dbb2000c817 100644
@@ -1679,6 +1679,12 @@ void gdb_extend_qsupported_features(char *qflags)
 
 static void handle_query_supported(GArray *params, void *user_ctx)
 {
+    /*
+     * Reset multiprocess support as a new gdb client may have different support
+     * than a previous one.
+     */
+    gdbserver_state.multiprocess = false;
+
     g_string_printf(gdbserver_state.str_buf, "PacketSize=%x", MAX_PACKET_LENGTH);
     if (gdb_get_core_xml_file(first_cpu)) {
         g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+");
gdbstub/user.c +1 -0
index d810f0f38c3..9b6d42d210a 100644
@@ -701,6 +701,7 @@ fail:
 
 void gdb_handle_query_supported_user(const char *gdb_supported)
 {
+    gdbserver_user_state.fork_events = false;
     if (strstr(gdb_supported, "fork-events+")) {
         gdbserver_user_state.fork_events = true;
     }
Signature · 1 line
2.47.3
#1 lore raw
Quoted 44 lines · Pierrick Bouvier

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)
gdbstub/gdbstub.c +6 -0
index 0a328b0dd48..dbb2000c817 100644
@@ -1679,6 +1679,12 @@ void gdb_extend_qsupported_features(char *qflags)
 
 static void handle_query_supported(GArray *params, void *user_ctx)
 {
+    /*
+     * Reset multiprocess support as a new gdb client may have different support
+     * than a previous one.
+     */
+    gdbserver_state.multiprocess = false;
+
     g_string_printf(gdbserver_state.str_buf, "PacketSize=%x", MAX_PACKET_LENGTH);
     if (gdb_get_core_xml_file(first_cpu)) {
         g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+");
gdbstub/user.c +0 -0
index d810f0f38c3..9b6d42d210a 100644

gdbstub/user.c fail: · line 707

Quoted 7 lines
gdbstub/user.c +1 -0
@@ -701,6 +701,7 @@ fail:
 
 void gdb_handle_query_supported_user(const char *gdb_supported)
 {
+    gdbserver_user_state.fork_events = false;
     if (strstr(gdb_supported, "fork-events+")) {
         gdbserver_user_state.fork_events = true;
     }

Ping on this patch.
@Alex: I noticed you have an 11.2 series going on, this could be nice if we had a chance to add this patch there also.

Regards,
Pierrick

Reviewed-by on v1 1/1
#2 lore raw
In reply to Pierrick Bouvier
Quoted 27 lines · Pierrick Bouvier

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)
gdbstub/gdbstub.c +0 -0
index 0a328b0dd48..dbb2000c817 100644

gdbstub/gdbstub.c void gdb_extend_qsupported_features(char *qflags) · line 1687

Quoted 9 lines
gdbstub/gdbstub.c +6 -0
@@ -1679,6 +1679,12 @@ void gdb_extend_qsupported_features(char *qflags)
 
 static void handle_query_supported(GArray *params, void *user_ctx)
 {
+    /*
+     * Reset multiprocess support as a new gdb client may have different support
+     * than a previous one.
+     */
+    gdbserver_state.multiprocess = false;
+

This looks fine to me based on the commit write-up. Although it does highlight that struct GDBState is due a clean-up to separate what is negotiated features, temporary workspace and accelerator supported features. Currently its just a random collection of stuff.

Quoted 15 lines
gdbstub/gdbstub.c +0 -0
     g_string_printf(gdbserver_state.str_buf, "PacketSize=%x", MAX_PACKET_LENGTH);
     if (gdb_get_core_xml_file(first_cpu)) {
         g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+");
gdbstub/user.c +1 -0
index d810f0f38c3..9b6d42d210a 100644
@@ -701,6 +701,7 @@ fail:
 
 void gdb_handle_query_supported_user(const char *gdb_supported)
 {
+    gdbserver_user_state.fork_events = false;
     if (strstr(gdb_supported, "fork-events+")) {
         gdbserver_user_state.fork_events = true;
     }
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#3 lore raw
In reply to Pierrick Bouvier
Quoted 15 lines · Pierrick Bouvier

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

Quoted 8 lines

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)

IIUC, in user mode a bare qSupported doesn't clear fork_events, so a previous client's fork-events+ stays active for the next client.

E.g. GDB connects with fork-events+ and disconnects, then a client sends a bare qSupported. On fork() the stub stops the parent and reports the fork to the client, but it should not report it and the parent should keep running.

#4 lore raw
Quoted 26 lines · Marco Liebel
Quoted 15 lines · Pierrick Bouvier

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

Quoted 8 lines

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)
Quoted 7 lines

IIUC, in user mode a bare qSupported doesn't clear fork_events, so a previous client's fork-events+ stays active for the next client.

E.g. GDB connects with fork-events+ and disconnects, then a client sends a bare qSupported. On fork() the stub stops the parent and reports the fork to the client, but it should not report it and the parent should keep running.

Thanks, that's a good catch Marco. I'll move the fork-events reset at beginning of handle_query_supported instead.

Regards,
Pierrick

#5 lore raw
In reply to Pierrick Bouvier
Quoted 14 lines · Pierrick Bouvier

From: Justin Sapp <[email protected]>

https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qSupported

```
Whenever the stub receives a ‘qSupported’ request, the supplied set
of GDB features should override any previous request. This allows GDB to
put the stub in a known state, even if the stub had previously been
communicating with a different version of GDB.
```

We exposed this by connecting to gdbstub using a gdb client first, and then WinDbg (EXDI) for windows kernel debugging. Since they both differ in their multiprocess support, this was confusing EXDI.

Quoted 8 lines

While we are here, fix the same for fork_events in user mode.

---
 gdbstub/gdbstub.c | 6 ++++++
 gdbstub/user.c    | 1 +
 2 files changed, 7 insertions(+)

Sent v2, fixing the rest of fork_events, and simplifying control flow. @Alex, I didn't apply your R-b, so I would appreciate if you could take a new look at it.

https://lore.kernel.org/qemu-devel/[email protected]/T/#u

Thanks,
Pierrick