You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/07/27 12:48:45 UTC

[incubator-nuttx] 06/06: arch: limit output maximum size stackdump when sp is not within stack

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

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

commit 9d4549d48bfcfb17d635bad95a5808e47abb0e67
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Mon Jul 25 07:03:07 2022 +0000

    arch: limit output maximum size stackdump when sp is not within stack
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 arch/Kconfig                              | 5 +++++
 arch/arm/src/common/arm_assert.c          | 7 +++++++
 arch/risc-v/src/common/riscv_assert.c     | 7 +++++++
 arch/xtensa/src/common/xtensa_dumpstate.c | 7 +++++++
 4 files changed, 26 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index e4461c0323..52a3ccffff 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -837,6 +837,11 @@ config ARCH_STACKDUMP
 	---help---
 		Enable to do stack dumps after assertions
 
+config ARCH_STACKDUMP_MAX_LENGTH
+	int "The maximum length for dump stack on assertions"
+	depends on ARCH_STACKDUMP
+	default 0
+
 config DUMP_ON_EXIT
 	bool "Dump all tasks state on exit"
 	default n
diff --git a/arch/arm/src/common/arm_assert.c b/arch/arm/src/common/arm_assert.c
index 93bce4be33..6f5059fe1a 100644
--- a/arch/arm/src/common/arm_assert.c
+++ b/arch/arm/src/common/arm_assert.c
@@ -362,6 +362,13 @@ static void arm_dump_stack(const char *tag, uint32_t sp,
           size  -= remain;
 #endif
 
+#if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
+          if (size > CONFIG_ARCH_STACKDUMP_MAX_LENGTH)
+            {
+              size = CONFIG_ARCH_STACKDUMP_MAX_LENGTH;
+            }
+#endif
+
           arm_stackdump(base, base + size);
         }
     }
diff --git a/arch/risc-v/src/common/riscv_assert.c b/arch/risc-v/src/common/riscv_assert.c
index c04225447b..488bc88f33 100644
--- a/arch/risc-v/src/common/riscv_assert.c
+++ b/arch/risc-v/src/common/riscv_assert.c
@@ -339,6 +339,13 @@ static void riscv_dump_stack(const char *tag, uintptr_t sp,
           size  -= remain;
 #endif
 
+#if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
+          if (size > CONFIG_ARCH_STACKDUMP_MAX_LENGTH)
+            {
+              size = CONFIG_ARCH_STACKDUMP_MAX_LENGTH;
+            }
+#endif
+
           riscv_stackdump(base, base + size);
         }
     }
diff --git a/arch/xtensa/src/common/xtensa_dumpstate.c b/arch/xtensa/src/common/xtensa_dumpstate.c
index 140b5903e3..366f99a37d 100644
--- a/arch/xtensa/src/common/xtensa_dumpstate.c
+++ b/arch/xtensa/src/common/xtensa_dumpstate.c
@@ -308,6 +308,13 @@ static void xtensa_dump_stack(const char *tag, uint32_t sp,
           size = used;
 #endif
 
+#if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
+          if (size > CONFIG_ARCH_STACKDUMP_MAX_LENGTH)
+            {
+              size = CONFIG_ARCH_STACKDUMP_MAX_LENGTH;
+            }
+#endif
+
           xtensa_stackdump(base, base + size);
         }
     }