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 <dmitrii.golovanov@intel.com>
This commit is contained in:
Dmitrii Golovanov 2023-10-03 17:55:46 +02:00 committed by Fabio Baltieri
parent 38d73a6ccf
commit f308299ca2
4 changed files with 52 additions and 1 deletions

View file

@ -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. */

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}