]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
gdbstub: extract stop reply message construction
authorAlex Bennée <alex.bennee@linaro.org>
Tue, 3 Feb 2026 11:51:54 +0000 (11:51 +0000)
committerAlex Bennée <alex.bennee@linaro.org>
Fri, 6 Feb 2026 12:43:02 +0000 (12:43 +0000)
The stop reply message we send can include a lot of extra information
and a bunch is mode dependant. Extract the construction into a helper
and add specialised versions for system and user mode.

The correct response for system mode should be of the form:

  T05core:N;

Where N is the core ID. We pass GString to gdb_build_stop_packet as
other functions we are going to clean-up work variously with their own
dynamically allocated GStrings or with the common shared buffer.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260203115201.2387721-5-alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
gdbstub/gdbstub.c
gdbstub/internals.h
gdbstub/system.c
gdbstub/user.c

index aeff467fdd6bb854713cc3619910d43ea86f961b..b45eb7c7b2bd301b4588bc225f46741388577cfa 100644 (file)
@@ -1432,9 +1432,7 @@ static void handle_v_attach(GArray *params, void *user_ctx)
         gdbserver_state.c_cpu = cpu;
 
         if (gdbserver_state.allow_stop_reply) {
-            g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP);
-            gdb_append_thread_id(cpu, gdbserver_state.str_buf);
-            g_string_append_c(gdbserver_state.str_buf, ';');
+            gdb_build_stop_packet(gdbserver_state.str_buf, cpu);
             gdbserver_state.allow_stop_reply = false;
         }
     }
@@ -2038,11 +2036,9 @@ static void handle_gen_set(GArray *params, void *user_ctx)
 static void handle_target_halt(GArray *params, void *user_ctx)
 {
     if (gdbserver_state.allow_stop_reply) {
-        g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP);
-        gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf);
-        g_string_append_c(gdbserver_state.str_buf, ';');
-        gdb_put_strbuf();
+        gdb_build_stop_packet(gdbserver_state.str_buf, gdbserver_state.c_cpu);
         gdbserver_state.allow_stop_reply = false;
+        gdb_put_strbuf();
     }
     /*
      * Remove all the breakpoints when this query is issued,
index 92466b28c187bcabf6edd6d128694a2e4c5c594e..9b25bf58b8ea9c8973978786a6f9a78ee5a2ee94 100644 (file)
@@ -237,4 +237,14 @@ void gdb_breakpoint_remove_all(CPUState *cs);
 int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr,
                                uint8_t *buf, int len, bool is_write);
 
+/**
+ * gdb_build_stop_packet() - craft the stop packet
+ * @buf: GString buffer for building the packet
+ * @cs: CPUState
+ *
+ * Craft the Stop/Reply packet when we halt.
+ */
+
+void gdb_build_stop_packet(GString *buf, CPUState *cs);
+
 #endif /* GDBSTUB_INTERNALS_H */
index 79f80256e3afa656be8511ddd52130e9cd4353f0..8ec8b7ea336b142468619c308c2db9f5196805e9 100644 (file)
@@ -662,3 +662,14 @@ void gdb_breakpoint_remove_all(CPUState *cs)
         ops->remove_all_breakpoints(cs);
     }
 }
+
+/*
+ * The minimal system-mode stop reply packet is:
+ *   T05core:{id};
+ */
+
+void gdb_build_stop_packet(GString *buf, CPUState *cs)
+{
+    g_string_printf(buf,
+                    "T%02xcore:%02x;", GDB_SIGNAL_TRAP, gdb_get_cpu_index(cs));
+}
index a2327c61352395479250de1c6a76911f5f3a7a06..14369b9ce5eb358312420febd5c877009d4deddb 100644 (file)
@@ -974,3 +974,15 @@ void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx)
     gdb_put_packet_binary(gdbserver_state.str_buf->str,
                           gdbserver_state.str_buf->len, true);
 }
+
+/*
+ * The minimal user-mode stop reply packet is:
+ *   T05thread:{id};
+ */
+
+void gdb_build_stop_packet(GString *buf, CPUState *cs)
+{
+    g_string_printf(buf, "T%02xthread:", GDB_SIGNAL_TRAP);
+    gdb_append_thread_id(cs, buf);
+    g_string_append_c(buf, ';');
+}