From 3c7162338d62e44496146eee67dd07ae38c177a4 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Fri, 10 May 2024 19:43:44 +0800 Subject: [PATCH] gdbstub:support gdbstub_debugpoint_add/remove smp call Signed-off-by: anjiahao --- include/nuttx/gdbstub.h | 14 +++++ libs/libc/gdbstub/lib_gdbstub.c | 98 ++++++++++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/include/nuttx/gdbstub.h b/include/nuttx/gdbstub.h index 068f4c817f..769ce53136 100644 --- a/include/nuttx/gdbstub.h +++ b/include/nuttx/gdbstub.h @@ -26,6 +26,7 @@ ****************************************************************************/ #include +#include /**************************************************************************** * Pre-processor Definitions @@ -52,6 +53,19 @@ typedef CODE ssize_t (*gdb_recv_func_t)(FAR void *priv, FAR void *buf, typedef CODE int (*gdb_monitor_func_t)(FAR struct gdb_state_s *state, FAR const char *cmd); +/**************************************************************************** + * Name: gdbstub_debugpoint_add + ****************************************************************************/ + +int gdb_debugpoint_add(int type, void *addr, size_t size, + debug_callback_t callback, void *arg); + +/**************************************************************************** + * Name: gdbstub_debugpoint_remove + ****************************************************************************/ + +int gdb_debugpoint_remove(int type, void *addr, size_t size); + /**************************************************************************** * Name: gdb_state_init * diff --git a/libs/libc/gdbstub/lib_gdbstub.c b/libs/libc/gdbstub/lib_gdbstub.c index 68cfe5874b..2f1c7e2154 100644 --- a/libs/libc/gdbstub/lib_gdbstub.c +++ b/libs/libc/gdbstub/lib_gdbstub.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -70,6 +69,15 @@ struct gdb_state_s uintptr_t registers[0]; /* Registers of other threads */ }; +struct gdb_debugpoint_s +{ + int type; + FAR void *addr; + size_t size; + debug_callback_t callback; + FAR void *arg; +}; + typedef CODE ssize_t (*gdb_format_func_t)(FAR void *buf, size_t buf_len, FAR const void *data, size_t data_len); @@ -1463,16 +1471,48 @@ retry: #ifdef CONFIG_ARCH_HAVE_DEBUG +#ifdef CONFIG_SMP + /**************************************************************************** - * Name: gdbstub_debugpoint_callback + * Name: gdb_smp_debugpoint_add + * + * Description: + * Add debug point to all cpu. + * + ****************************************************************************/ + +static int gdb_smp_debugpoint_add(FAR void *arg) +{ + FAR struct gdb_debugpoint_s *point = arg; + return up_debugpoint_add(point->type, point->addr, point->size, + point->callback, point->arg); +} + +/**************************************************************************** + * Name: gdb_smp_debugpoint_remove + * + * Description: + * Remove debug point to all cpu. + * + ****************************************************************************/ + +static int gdb_smp_debugpoint_remove(FAR void *arg) +{ + FAR struct gdb_debugpoint_s *point = arg; + return up_debugpoint_remove(point->type, point->addr, point->size); +} +#endif + +/**************************************************************************** + * Name: gdb_debugpoint_callback * * Description: * The debugpoint callback is used by GDB to request. * ****************************************************************************/ -static void gdbstub_debugpoint_callback(int type, FAR void *addr, - size_t size, FAR void *arg) +static void gdb_debugpoint_callback(int type, FAR void *addr, + size_t size, FAR void *arg) { int stopreason; @@ -1588,12 +1628,12 @@ static int gdb_debugpoint(FAR struct gdb_state_s *state, bool enable) if (enable) { - ret = up_debugpoint_add(type, (FAR void *)addr, size, - gdbstub_debugpoint_callback, state); + ret = gdbstub_debugpoint_add(type, (FAR void *)addr, size, + gdbstub_debugpoint_callback, state); } else { - ret = up_debugpoint_remove(type, (FAR void *)addr, size); + ret = gdbstub_debugpoint_remove(type, (FAR void *)addr, size); } if (ret < 0) @@ -1670,6 +1710,50 @@ extern const struct tcbinfo_s g_tcbinfo; * Public Functions ****************************************************************************/ +#ifdef CONFIG_ARCH_HAVE_DEBUG + +/**************************************************************************** + * Name: gdbstub_debugpoint_add + ****************************************************************************/ + +int gdb_debugpoint_add(int type, FAR void *addr, size_t size, + debug_callback_t callback, FAR void *arg) +{ +#ifdef CONFIG_SMP + struct gdb_debugpoint_s point; + point.type = type; + point.addr = addr; + point.size = size; + point.callback = callback; + point.arg = arg; + retrun nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1, + gdb_smp_debugpoint_add, &point, true); +#else + return up_debugpoint_add(type, addr, size, callback, arg); +#endif +} + +/**************************************************************************** + * Name: gdb_debugpoint_remove + ****************************************************************************/ + +int gdb_debugpoint_remove(int type, FAR void *addr, size_t size) +{ +#ifdef CONFIG_SMP + struct gdb_debugpoint_s point; + point.type = type; + point.addr = addr; + point.size = size; + + retrun nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1, + gdb_smp_debugpoint_remove, &point, true); +#else + return up_debugpoint_remove(type, addr, size); +#endif +} + +#endif + /**************************************************************************** * Name: gdb_state_init *