diff --git a/arch/x86/core/ia32/gdbstub.c b/arch/x86/core/ia32/gdbstub.c index f40797a3bcb..9639b992adf 100644 --- a/arch/x86/core/ia32/gdbstub.c +++ b/arch/x86/core/ia32/gdbstub.c @@ -12,7 +12,6 @@ static struct gdb_ctx ctx; -static bool start; /** * Currently we just handle vectors 1 and 3 but lets keep it generic @@ -100,8 +99,7 @@ static void z_gdb_interrupt(unsigned int vector, z_arch_esf_t *esf) ctx.registers[GDB_FS] = esf->fs; ctx.registers[GDB_GS] = esf->gs; - z_gdb_main_loop(&ctx, start); - start = false; + z_gdb_main_loop(&ctx); esf->eax = ctx.registers[GDB_EAX]; esf->ecx = ctx.registers[GDB_ECX]; @@ -230,7 +228,6 @@ static __used void z_gdb_break_isr(z_arch_esf_t *esf) void arch_gdb_init(void) { - start = true; __asm__ volatile ("int3"); } diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 2612b9c2984..c8c3c8cd991 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -188,7 +188,7 @@ struct gdb_ctx; /* Should be called by the arch layer. This is the gdbstub main loop * and synchronously communicate with gdb on host. */ -extern int z_gdb_main_loop(struct gdb_ctx *ctx, bool start); +extern int z_gdb_main_loop(struct gdb_ctx *ctx); #endif #ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING diff --git a/subsys/debug/gdbstub.c b/subsys/debug/gdbstub.c index e3de190220a..b2ae55c656b 100644 --- a/subsys/debug/gdbstub.c +++ b/subsys/debug/gdbstub.c @@ -33,6 +33,8 @@ LOG_MODULE_REGISTER(gdbstub); #define GDB_ERROR_MEMORY "E14" #define GDB_ERROR_OVERFLOW "E22" +static bool not_first_start; + size_t gdb_bin2hex(const uint8_t *buf, size_t buflen, char *hex, size_t hexlen) { if ((hexlen + 1) < buflen * 2) { @@ -229,7 +231,7 @@ static int gdb_send_exception(uint8_t *buf, size_t len, uint8_t exception) /** * Synchronously communicate with gdb on the host */ -int z_gdb_main_loop(struct gdb_ctx *ctx, bool start) +int z_gdb_main_loop(struct gdb_ctx *ctx) { /* 'static' modifier is intentional so the buffer * is not declared inside running stack, which may @@ -245,8 +247,13 @@ int z_gdb_main_loop(struct gdb_ctx *ctx, bool start) state = RECEIVING; - if (start == false) { + /* Only send exception if this is not the first + * GDB break. + */ + if (not_first_start) { gdb_send_exception(buf, sizeof(buf), ctx->exception); + } else { + not_first_start = true; } #define CHECK_ERROR(condition) \