We already set a default error reply which we can only overwrite if we
successfully follow the chain of checks. Initialise the variables as
NULL and use that to gate the construction of the filled out
stop/reply packet.
Message-ID: <20260203115201.2387721-4-alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 1f8cd118924..aeff467fdd6 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -1413,36 +1413,33 @@ static void handle_v_cont(GArray *params, void *user_ctx)
static void handle_v_attach(GArray *params, void *user_ctx)
{
- GDBProcess *process;
- CPUState *cpu;
+ GDBProcess *process = NULL;
+ CPUState *cpu = NULL;
+ /* Default error reply */
g_string_assign(gdbserver_state.str_buf, "E22");
- if (!params->len) {
- goto cleanup;
- }
-
- process = gdb_get_process(gdb_get_cmd_param(params, 0)->val_ul);
- if (!process) {
- goto cleanup;
+ if (params->len) {
+ process = gdb_get_process(gdb_get_cmd_param(params, 0)->val_ul);
}
- cpu = gdb_get_first_cpu_in_process(process);
- if (!cpu) {
- goto cleanup;
+ if (process) {
+ cpu = gdb_get_first_cpu_in_process(process);
}
- process->attached = true;
- gdbserver_state.g_cpu = cpu;
- gdbserver_state.c_cpu = cpu;
+ if (cpu) {
+ process->attached = true;
+ gdbserver_state.g_cpu = cpu;
+ 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, ';');
- gdbserver_state.allow_stop_reply = false;
-cleanup:
- gdb_put_strbuf();
+ 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, ';');
+ gdbserver_state.allow_stop_reply = false;
+ }
}
+
+ gdb_put_strbuf();
}
static void handle_v_kill(GArray *params, void *user_ctx)
--
2.47.3