Skip to contentSkip to conversation

gdbstub: synchronize state for individual 'p' register reads

PATCH In review Boden Randin 2 participants 2 messages Sep 20 – Sep 22

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdbstub: synchronize state for individual 'p' register reads

'p' does not call cpu_synchronize_state like 'g' does.

Accelerators may keep guest CPU state out of sync with QEMU while a vCPU is running. After a vCPU is stopped, an individual 'p' register read can therefore observe stale state until something updates the state.

---

Notes:
I found this while investigating why LLDB was showing the RIP truncated to 32 bits under WHPX. LLDB appears to use individual p register reads by default, while GDB primarily uses g, which is why I noticed the issue much more consistently with LLDB.

This is my first open-source contribution, so please let me know if I missed anything in the patch or submission process.

 gdbstub/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/gdbstub.c +1 -1
index 0a328b0dd4..31a845cfa7 100644
@@ -1246,7 +1246,7 @@ static void handle_get_reg(GArray *params, void *user_ctx)
         gdb_put_packet("E14");
         return;
     }
-
+    cpu_synchronize_state(gdbserver_state.g_cpu);
     reg_size = gdb_read_register(gdbserver_state.g_cpu,
                                  gdbserver_state.mem_buf,
                                  gdb_get_cmd_param(params, 0)->val_ull);
Signature · 1 line
2.53.0.windows.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Boden Randin

'p' does not call cpu_synchronize_state like 'g' does.

Accelerators may keep guest CPU state out of sync with QEMU while a vCPU is running. After a vCPU is stopped, an individual 'p' register read can therefore observe stale state until something updates the state.

Yeah, I mentioned that to Alex few months ago and have a similar fix but put my work on hold to avoid clash with Richard series in the same area, waiting his work to be merged:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 8 lines

---

Notes:
I found this while investigating why LLDB was showing the RIP truncated to 32 bits under WHPX. LLDB appears to use individual p register reads by default, while GDB primarily uses g, which is why I noticed the issue much more consistently with LLDB.

This is my first open-source contribution, so please let me know if I missed anything in the patch or submission process.

Well done!

Quoted 9 lines
  gdbstub/gdbstub.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
gdbstub/gdbstub.c +0 -0
index 0a328b0dd4..31a845cfa7 100644

gdbstub/gdbstub.c static void handle_get_reg(GArray *params, void *user_ctx) · line 1252

Quoted 8 lines
gdbstub/gdbstub.c +1 -1
@@ -1246,7 +1246,7 @@ static void handle_get_reg(GArray *params, void *user_ctx)
          gdb_put_packet("E14");
          return;
      }
-
+    cpu_synchronize_state(gdbserver_state.g_cpu);
      reg_size = gdb_read_register(gdbserver_state.g_cpu,
                                   gdbserver_state.mem_buf,
                                   gdb_get_cmd_param(params, 0)->val_ull);