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>
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;
}
}
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,
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 */
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));
+}
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, ';');
+}