This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit be5a916cdbf301fd29fcbaff0320183da927c93e
Author: yangao1 <[email protected]>
AuthorDate: Tue Nov 25 16:58:52 2025 +0800

    assert.c: limit stack print length
    
    CONFIG_ARCH_STACKDUMP_MAX_LENGTH limited the stack dump only when the
    stack pointer is unknown and the whole used stack is printed.  With a
    known stack pointer the dump still ran from sp to the top of the stack,
    which can be many kilobytes for a large stack.
    
    Apply the limit to that case as well: dump at most
    CONFIG_ARCH_STACKDUMP_MAX_LENGTH bytes from sp, and change the default
    of CONFIG_ARCH_STACKDUMP_MAX_LENGTH from 0 (no limit) to 4096.
    
    Signed-off-by: yangao1 <[email protected]>
---
 arch/Kconfig        |  2 +-
 sched/misc/assert.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index b23706fcaa4..8d3c5543c6f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -1288,7 +1288,7 @@ config ARCH_HAVE_REGCPY
 config ARCH_STACKDUMP_MAX_LENGTH
        int "The maximum length for dump stack on assertions"
        depends on ARCH_STACKDUMP
-       default 0
+       default 4096
 
 config ARCH_USBDUMP
        bool "Dump USB trace data"
diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index e2285be3e7e..b4818b24274 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -226,6 +226,7 @@ static void dump_stackinfo(FAR const char *tag, uintptr_t 
sp,
   if (sp != 0)
     {
       uintptr_t top = base + size;
+      uintptr_t dump_end = top;
 
       _emerg("    sp: %p\n", (FAR void *)sp);
 
@@ -236,7 +237,14 @@ static void dump_stackinfo(FAR const char *tag, uintptr_t 
sp,
           sp -= DUMP_STRIDE;
         }
 
-      stack_dump(sp, top);
+#if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
+      if (top - sp > CONFIG_ARCH_STACKDUMP_MAX_LENGTH)
+        {
+          dump_end = sp + CONFIG_ARCH_STACKDUMP_MAX_LENGTH;
+        }
+#endif
+
+      stack_dump(sp, dump_end);
     }
   else
     {

Reply via email to