gdbstub:support gdbstub_debugpoint_add/remove smp call

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2024-05-10 19:43:44 +08:00 committed by Xiang Xiao
parent e9558a88cd
commit 3c7162338d
2 changed files with 105 additions and 7 deletions

View file

@ -26,6 +26,7 @@
****************************************************************************/
#include <stdlib.h>
#include <nuttx/arch.h>
/****************************************************************************
* 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
*

View file

@ -30,7 +30,6 @@
#include <sys/param.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/ascii.h>
#include <nuttx/gdbstub.h>
@ -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
*