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/11/01 13:42:32 UTC
[incubator-nuttx] branch master updated: arm: Added breakpoint in stack overflow trap.
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
The following commit(s) were added to refs/heads/master by this push:
new 189aa0292f arm: Added breakpoint in stack overflow trap.
189aa0292f is described below
commit 189aa0292f82d099830ab8c20bfa65f2628427d6
Author: Fotis Panagiotopoulos <f....@gmail.com>
AuthorDate: Wed Oct 26 14:28:58 2022 +0300
arm: Added breakpoint in stack overflow trap.
---
arch/arm/src/armv7-m/Kconfig | 10 ++++++++++
arch/arm/src/armv7-m/arm_stackcheck.c | 8 ++++++++
arch/arm/src/armv8-m/Kconfig | 10 ++++++++++
arch/arm/src/armv8-m/arm_stackcheck.c | 8 ++++++++
4 files changed, 36 insertions(+)
diff --git a/arch/arm/src/armv7-m/Kconfig b/arch/arm/src/armv7-m/Kconfig
index 5dc99f3e00..b1ca99f116 100644
--- a/arch/arm/src/armv7-m/Kconfig
+++ b/arch/arm/src/armv7-m/Kconfig
@@ -116,6 +116,16 @@ config ARMV7M_STACKCHECK
CFLAGS when you compile. This addition to your CFLAGS should probably
be added to the definition of the CFFLAGS in your board Make.defs file.
+config ARMV7M_STACKCHECK_BREAKPOINT
+ bool "Breakpoint on stack overflow"
+ default n
+ depends on ARMV7M_STACKCHECK
+ ---help---
+ If enabled, a hard-coded breakpoint will be inserted to the stack
+ overflow trap. This is useful to stop the execution of the program
+ and diagnose the issue before the hardfault handler is called (and
+ context information is lost).
+
config ARMV7M_ITMSYSLOG
bool "ITM SYSLOG support"
default n
diff --git a/arch/arm/src/armv7-m/arm_stackcheck.c b/arch/arm/src/armv7-m/arm_stackcheck.c
index 968a190c26..d7167a9c55 100644
--- a/arch/arm/src/armv7-m/arm_stackcheck.c
+++ b/arch/arm/src/armv7-m/arm_stackcheck.c
@@ -69,6 +69,14 @@ void __stack_overflow_trap(void)
uint32_t regval;
+#ifdef CONFIG_ARMV7M_STACKCHECK_BREAKPOINT
+ regval = getreg32(NVIC_DHCSR);
+ if (regval & NVIC_DHCSR_C_DEBUGEN)
+ {
+ __asm("bkpt 1");
+ }
+#endif
+
/* force hard fault */
regval = getreg32(NVIC_INTCTRL);
diff --git a/arch/arm/src/armv8-m/Kconfig b/arch/arm/src/armv8-m/Kconfig
index c6c77cfc2a..550509281c 100644
--- a/arch/arm/src/armv8-m/Kconfig
+++ b/arch/arm/src/armv8-m/Kconfig
@@ -115,6 +115,16 @@ config ARMV8M_STACKCHECK_HARDWARE
endchoice
+config ARMV8M_STACKCHECK_BREAKPOINT
+ bool "Breakpoint on stack overflow"
+ default n
+ depends on ARMV8M_STACKCHECK
+ ---help---
+ If enabled, a hard-coded breakpoint will be inserted to the stack
+ overflow trap. This is useful to stop the execution of the program
+ and diagnose the issue before the hardfault handler is called (and
+ context information is lost).
+
config ARMV8M_ITMSYSLOG
bool "ITM SYSLOG support"
default n
diff --git a/arch/arm/src/armv8-m/arm_stackcheck.c b/arch/arm/src/armv8-m/arm_stackcheck.c
index ddc85e26ee..cbe107ca00 100644
--- a/arch/arm/src/armv8-m/arm_stackcheck.c
+++ b/arch/arm/src/armv8-m/arm_stackcheck.c
@@ -69,6 +69,14 @@ void __stack_overflow_trap(void)
uint32_t regval;
+#ifdef CONFIG_ARMV8M_STACKCHECK_BREAKPOINT
+ regval = getreg32(NVIC_DHCSR);
+ if (regval & NVIC_DHCSR_C_DEBUGEN)
+ {
+ __asm("bkpt 1");
+ }
+#endif
+
/* force hard fault */
regval = getreg32(NVIC_INTCTRL);