From f308299ca284ebcc2f81633ba339a4356ca5a2be Mon Sep 17 00:00:00 2001 From: Dmitrii Golovanov Date: Tue, 3 Oct 2023 17:55:46 +0200 Subject: [PATCH] debug: gdbstub: kconfig: Add GDBSTUB_TRACE config option Add GDBSTUB_TRACE config option to extend GDB backend debug logging for remote commands received and to debug the GDB stub itself. Signed-off-by: Dmitrii Golovanov --- arch/x86/core/ia32/gdbstub.c | 24 +++++++++++++++++++ subsys/debug/Kconfig | 6 +++++ subsys/debug/gdbstub.c | 16 ++++++++++++- subsys/debug/gdbstub/gdbstub_backend_serial.c | 7 ++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/arch/x86/core/ia32/gdbstub.c b/arch/x86/core/ia32/gdbstub.c index afda9b5a7e2..41b6a4500ff 100644 --- a/arch/x86/core/ia32/gdbstub.c +++ b/arch/x86/core/ia32/gdbstub.c @@ -218,17 +218,41 @@ size_t arch_gdb_reg_writeone(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen, static __used void z_gdb_debug_isr(z_arch_esf_t *esf) { +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:enter %s (IV_DEBUG)\n", __func__); +#endif + z_gdb_interrupt(IV_DEBUG, esf); + +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:exit %s (IV_DEBUG)\n", __func__); +#endif } static __used void z_gdb_break_isr(z_arch_esf_t *esf) { +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:enter %s (IV_BREAKPOINT)\n", __func__); +#endif + z_gdb_interrupt(IV_BREAKPOINT, esf); + +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:exit %s (IV_BREAKPOINT)\n", __func__); +#endif } void arch_gdb_init(void) { +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s awaits GDB connection\n", __func__); +#endif + __asm__ volatile ("int3"); + +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s GDB is connected\n", __func__); +#endif } /* Hook current IDT. */ diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 54d83f18ff6..7da4440c010 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -424,6 +424,12 @@ config GDBSTUB_BUF_SZ for GDB backend. This needs to be big enough to hold one full GDB packet at a time. +config GDBSTUB_TRACE + bool "GDB backend extra logging" + help + Enable extra debug logging for the GDB backend, including + breakpoint interrupts and remote commands it receives. + endif config SEGGER_DEBUGMON diff --git a/subsys/debug/gdbstub.c b/subsys/debug/gdbstub.c index 3cced7b0310..e632ff8abf4 100644 --- a/subsys/debug/gdbstub.c +++ b/subsys/debug/gdbstub.c @@ -559,6 +559,10 @@ static int gdb_send_exception(uint8_t *buf, size_t len, uint8_t exception) { size_t size; +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s exception=0x%x\n", __func__, exception); +#endif + *buf = 'T'; size = gdb_bin2hex(&exception, 1, buf + 1, len - 1); if (size == 0) { @@ -644,6 +648,10 @@ int z_gdb_main_loop(struct gdb_ctx *ctx) ptr = buf; +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s got '%c'(0x%x) command\n", __func__, *ptr, *ptr); +#endif + switch (*ptr++) { /** @@ -823,13 +831,19 @@ int z_gdb_main_loop(struct gdb_ctx *ctx) int gdb_init(void) { - +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s enter\n", __func__); +#endif if (z_gdb_backend_init() == -1) { LOG_ERR("Could not initialize gdbstub backend."); return -1; } arch_gdb_init(); + +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub:%s exit\n", __func__); +#endif return 0; } diff --git a/subsys/debug/gdbstub/gdbstub_backend_serial.c b/subsys/debug/gdbstub/gdbstub_backend_serial.c index e9c6c6f9152..c5806cd4e02 100644 --- a/subsys/debug/gdbstub/gdbstub_backend_serial.c +++ b/subsys/debug/gdbstub/gdbstub_backend_serial.c @@ -21,6 +21,10 @@ int z_gdb_backend_init(void) .flow_ctrl = UART_CFG_FLOW_CTRL_NONE }; +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub_serial:%s enter\n", __func__); +#endif + if (uart_dev == NULL) { uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_gdbstub_uart)); @@ -30,6 +34,9 @@ int z_gdb_backend_init(void) __ASSERT(ret == 0, "Could not configure uart device"); } +#ifdef CONFIG_GDBSTUB_TRACE + printk("gdbstub_serial:%s exit\n", __func__); +#endif return ret; }