diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-11-01 11:16:51 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-11-01 11:16:51 -0600 |
commit | 1087c67c2acf53fbe1f549e89be6b70705b87792 (patch) | |
tree | 61f1d974a05187e9608eda2e79565654c03d308c /nuttx/arch/arm/src/common | |
parent | 9741311259ee5434987dc8c9918f29e355d22c4f (diff) | |
download | nuttx-1087c67c2acf53fbe1f549e89be6b70705b87792.tar.gz nuttx-1087c67c2acf53fbe1f549e89be6b70705b87792.tar.bz2 nuttx-1087c67c2acf53fbe1f549e89be6b70705b87792.zip |
Extend stack debug logic to include IDLE and interrupt stacks. Also color the heap as well. Based on suggestions from David Sidrane
Diffstat (limited to 'nuttx/arch/arm/src/common')
-rw-r--r-- | nuttx/arch/arm/src/common/up_checkstack.c | 5 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_createstack.c | 47 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_internal.h | 19 |
3 files changed, 48 insertions, 23 deletions
diff --git a/nuttx/arch/arm/src/common/up_checkstack.c b/nuttx/arch/arm/src/common/up_checkstack.c index 2bcd5c556..9cf4c684f 100644 --- a/nuttx/arch/arm/src/common/up_checkstack.c +++ b/nuttx/arch/arm/src/common/up_checkstack.c @@ -47,6 +47,7 @@ #include <nuttx/arch.h> #include "os_internal.h" +#include "up_internal.h" #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) @@ -90,7 +91,7 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb) */ for (ptr = (FAR uint32_t *)tcb->stack_alloc_ptr, mark = tcb->adj_stack_size/4; - *ptr == 0xDEADBEEF && mark > 0; + *ptr == STACK_COLOR && mark > 0; ptr++, mark--); /* If the stack is completely used, then this might mean that the stack @@ -114,7 +115,7 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb) for (j = 0; j < 64; j++) { int ch; - if (*ptr++ == 0xDEADBEEF) + if (*ptr++ == STACK_COLOR) { ch = '.'; } diff --git a/nuttx/arch/arm/src/common/up_createstack.c b/nuttx/arch/arm/src/common/up_createstack.c index 46bf15358..e14142700 100644 --- a/nuttx/arch/arm/src/common/up_createstack.c +++ b/nuttx/arch/arm/src/common/up_createstack.c @@ -83,23 +83,6 @@ ****************************************************************************/ /**************************************************************************** - * Name: memset32 - * - * On most larger than 8 bit archs this will need to be word aligned so - * so maybe some checks should be put in place? - * - ****************************************************************************/ - -#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) -static void *memset32(void *s, uint32_t c, size_t n) -{ - uint32_t *p = (uint32_t *)s; - while (n-- > 0) *p++ = c; - return s; -} -#endif - -/**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -159,7 +142,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) } /* Do we need to allocate a new stack? */ - + if (!tcb->stack_alloc_ptr) { /* Allocate the stack. If DEBUG is enabled (but not stack debug), @@ -240,7 +223,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) - memset32(tcb->stack_alloc_ptr, 0xdeadbeef, tcb->adj_stack_size/4); + up_stack_color(tcb->stack_alloc_ptr, tcb->adj_stack_size); #endif up_ledon(LED_STACKCREATED); @@ -249,3 +232,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) return ERROR; } + +/**************************************************************************** + * Name: up_stack_color + * + * Description: + * Write a well know value into the stack + * + ****************************************************************************/ + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) +void up_stack_color(FAR void *stackbase, size_t nbytes) +{ + /* Take extra care that we do not write outsize the stack boundaries */ + + uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3); + uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3); + size_t nwords = (stkend - (uintptr_t)stackbase) >> 2; + + /* Set the entire stack to the coloration value */ + + while (nwords-- > 0) + { + *stkptr++ = STACK_COLOR; + } +} +#endif diff --git a/nuttx/arch/arm/src/common/up_internal.h b/nuttx/arch/arm/src/common/up_internal.h index 448735e49..eb3ca896a 100644 --- a/nuttx/arch/arm/src/common/up_internal.h +++ b/nuttx/arch/arm/src/common/up_internal.h @@ -171,6 +171,14 @@ #endif +/* This is the value used to mark the stack for subsequent stack monitoring + * logic. + */ + +#define STACK_COLOR 0xdeadbeef +#define INTSTACK_COLOR 0xdeadbeef +#define HEAP_COLOR 'h' + /**************************************************************************** * Public Types ****************************************************************************/ @@ -204,9 +212,10 @@ extern const uint32_t g_idle_topstack; #if CONFIG_ARCH_INTERRUPTSTACK > 3 #if defined(CONFIG_ARCH_CORTEXM0) || defined(CONFIG_ARCH_CORTEXM3) || \ defined(CONFIG_ARCH_CORTEXM4) -extern uint32_t g_intstackbase; +extern uint32_t g_intstackalloc; /* Allocated stack base */ +extern uint32_t g_intstackbase; /* Initial top of interrupt stack */ # else -extern uint32_t g_userstack; +extern uint32_t g_intstackbase; # endif #endif @@ -484,6 +493,12 @@ void up_usbuninitialize(void); void up_rnginitialize(void); #endif +/* Debug ********************************************************************/ + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) +void up_stack_color(FAR void *stackbase, size_t nbytes); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __ARCH_ARM_SRC_COMMON_UP_INTERNAL_H */ |