From fb176c02caba0539a266b191f733862c71e5d12b Mon Sep 17 00:00:00 2001 From: anjiahao Date: Tue, 9 Apr 2024 17:37:36 +0800 Subject: [PATCH] gdb/thread.py:Remove dependence on g_current_regs Signed-off-by: anjiahao --- fs/procfs/fs_procfstcbinfo.c | 19 +++++++++++++++++-- include/nuttx/compiler.h | 6 +++++- tools/gdb/thread.py | 14 +++----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/fs/procfs/fs_procfstcbinfo.c b/fs/procfs/fs_procfstcbinfo.c index bff91f3516..7aa1f47459 100644 --- a/fs/procfs/fs_procfstcbinfo.c +++ b/fs/procfs/fs_procfstcbinfo.c @@ -176,6 +176,20 @@ static int tcbinfo_close(FAR struct file *filep) return OK; } +/**************************************************************************** + * Name: tcbinfo_current_regs + * + * Description: + * A special version of up_current_regs() that is non-optimized. + * + ****************************************************************************/ + +nooptimiziation_function +FAR static void *tcbinfo_current_regs(void) +{ + return up_current_regs(); +} + /**************************************************************************** * Name: tcbinfo_read ****************************************************************************/ @@ -198,8 +212,9 @@ static ssize_t tcbinfo_read(FAR struct file *filep, FAR char *buffer, if (filep->f_pos == 0) { linesize = procfs_snprintf(attr->line, TCBINFO_LINELEN, - "pointer %p size %zu\n", &g_tcbinfo, - sizeof(struct tcbinfo_s)); + "pointer %p size %zu current regs %p\n", + &g_tcbinfo, sizeof(struct tcbinfo_s), + tcbinfo_current_regs()); /* Save the linesize in case we are re-entered with f_pos > 0 */ diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index d09be5d1fb..9bf1a6ee51 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -264,7 +264,11 @@ /* The nooptimiziation_function attribute no optimize */ -# define nooptimiziation_function __attribute__((optimize(0))) +# if defined(__clang__) +# define nooptimiziation_function __attribute__((optnone)) +# else +# define nooptimiziation_function __attribute__((optimize("O0"))) +# endif /* The nosanitize_address attribute informs GCC don't sanitize it */ diff --git a/tools/gdb/thread.py b/tools/gdb/thread.py index 9f5aa1c19b..b822e3443a 100644 --- a/tools/gdb/thread.py +++ b/tools/gdb/thread.py @@ -82,7 +82,8 @@ class Nxsetregs(gdb.Command): super(Nxsetregs, self).__init__("nxsetregs", gdb.COMMAND_USER) def invoke(self, args, from_tty): - current_regs = gdb.parse_and_eval("g_current_regs") + gdb.execute("set $_current_regs=tcbinfo_current_regs()") + current_regs = gdb.parse_and_eval("$_current_regs") tcbinfo = gdb.parse_and_eval("g_tcbinfo") arg = args.split(" ") @@ -91,16 +92,7 @@ class Nxsetregs(gdb.Command): gdb.lookup_type("char").pointer() ) else: - if utils.is_target_smp(): - gdb.execute("set $_index=up_cpu_index()") - index = gdb.parse_and_eval("$_index") - else: - index = 0 - - if current_regs[index] == 0: - return - - regs = current_regs[index].cast(gdb.lookup_type("char").pointer()) + regs = current_regs.cast(gdb.lookup_type("char").pointer()) if regs == 0: gdb.write("regs is NULL\n")