From dfe788be256ac31e57fa4b2b47fdf2eeb7909f20 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 11 Nov 2018 12:52:36 -0600 Subject: [PATCH] arch/ all assertion functinos: up_stackdump dump the full stack if stack overflow the stack info is very useful to find the backtrace --- arch/arm/src/arm/up_assert.c | 8 ++++++-- arch/arm/src/armv6-m/up_assert.c | 11 +++++++++++ arch/arm/src/armv7-a/arm_assert.c | 15 ++++++++++++++- arch/arm/src/armv7-m/up_assert.c | 11 +++++++++++ arch/arm/src/armv7-r/arm_assert.c | 15 ++++++++++++++- arch/avr/src/avr/up_dumpstate.c | 11 +++++++++++ arch/avr/src/avr32/up_dumpstate.c | 11 +++++++++++ arch/hc/src/m9s12/m9s12_assert.c | 8 ++++++-- arch/mips/src/mips32/up_dumpstate.c | 8 ++++++-- arch/misoc/src/lm32/lm32_dumpstate.c | 8 ++++++-- arch/or1k/src/common/up_assert.c | 11 +++++++++++ arch/renesas/src/m16c/m16c_dumpstate.c | 8 ++++++-- arch/renesas/src/sh1/sh1_dumpstate.c | 8 ++++++-- arch/risc-v/src/rv32im/up_dumpstate.c | 8 ++++++-- arch/x86/src/common/up_assert.c | 8 ++++++-- arch/xtensa/src/common/xtensa_dumpstate.c | 8 ++++++-- arch/z16/src/common/up_stackdump.c | 19 ++++++++++--------- arch/z80/src/common/up_stackdump.c | 19 ++++++++++--------- 18 files changed, 157 insertions(+), 38 deletions(-) diff --git a/arch/arm/src/arm/up_assert.c b/arch/arm/src/arm/up_assert.c index 556ac4895d..441ac73135 100644 --- a/arch/arm/src/arm/up_assert.c +++ b/arch/arm/src/arm/up_assert.c @@ -245,6 +245,11 @@ static void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -270,9 +275,8 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/arm/src/armv6-m/up_assert.c b/arch/arm/src/armv6-m/up_assert.c index 3b47f3e408..66815078b0 100644 --- a/arch/arm/src/armv6-m/up_assert.c +++ b/arch/arm/src/armv6-m/up_assert.c @@ -275,6 +275,11 @@ static void up_dumpstate(void) up_stackdump(sp, istackbase); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Extract the user stack pointer if we are in an interrupt handler. * If we are not in an interrupt handler. Then sp is the user stack @@ -302,6 +307,11 @@ static void up_dumpstate(void) { up_stackdump(sp, ustackbase); } + else + { + _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); + } #else _alert("sp: %08x\n", sp); @@ -318,6 +328,7 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/arm/src/armv7-a/arm_assert.c b/arch/arm/src/armv7-a/arm_assert.c index 65722f1e19..d1e7027724 100644 --- a/arch/arm/src/armv7-a/arm_assert.c +++ b/arch/arm/src/armv7-a/arm_assert.c @@ -321,6 +321,11 @@ static void up_dumpstate(void) sp = *stackbase; _alert("User sp: %08x\n", sp); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } #endif /* Dump the user stack if the stack pointer lies within the allocated user @@ -338,12 +343,20 @@ static void up_dumpstate(void) * kernel stack memory. */ - if (sp >= (uint32_t)rtcb->xcp.kstack && sp < kstackbase) + else if (sp >= (uint32_t)rtcb->xcp.kstack && sp < kstackbase) { _alert("Kernel Stack\n", sp); up_stackdump(sp, kstackbase); } #endif + else + { + _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); +#ifdef CONFIG_ARCH_KERNEL_STACK + up_stackdump((uint32_t)rtcb->xcp.kstack, kstackbase); +#endif + } #ifdef CONFIG_SMP /* Show the CPU number */ diff --git a/arch/arm/src/armv7-m/up_assert.c b/arch/arm/src/armv7-m/up_assert.c index ce836de3bd..b25e1c4379 100644 --- a/arch/arm/src/armv7-m/up_assert.c +++ b/arch/arm/src/armv7-m/up_assert.c @@ -287,6 +287,11 @@ static void up_dumpstate(void) up_stackdump(sp, istackbase); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Extract the user stack pointer if we are in an interrupt handler. * If we are not in an interrupt handler. Then sp is the user stack @@ -314,6 +319,11 @@ static void up_dumpstate(void) { up_stackdump(sp, ustackbase); } + else + { + _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); + } #else @@ -333,6 +343,7 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/arm/src/armv7-r/arm_assert.c b/arch/arm/src/armv7-r/arm_assert.c index 01d9caee73..5eb11e5822 100644 --- a/arch/arm/src/armv7-r/arm_assert.c +++ b/arch/arm/src/armv7-r/arm_assert.c @@ -306,6 +306,11 @@ static void up_dumpstate(void) sp = g_intstackbase; _alert("User sp: %08x\n", sp); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } #endif /* Dump the user stack if the stack pointer lies within the allocated user @@ -323,12 +328,20 @@ static void up_dumpstate(void) * kernel stack memory. */ - if (sp >= (uint32_t)rtcb->xcp.kstack && sp < kstackbase) + else if (sp >= (uint32_t)rtcb->xcp.kstack && sp < kstackbase) { _alert("Kernel Stack\n", sp); up_stackdump(sp, kstackbase); } #endif + else + { + _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); +#ifdef CONFIG_ARCH_KERNEL_STACK + up_stackdump((uint32_t)rtcb->xcp.kstack, kstackbase); +#endif + } /* Then dump the registers (if available) */ diff --git a/arch/avr/src/avr/up_dumpstate.c b/arch/avr/src/avr/up_dumpstate.c index 5a1660b81b..ba7e204621 100644 --- a/arch/avr/src/avr/up_dumpstate.c +++ b/arch/avr/src/avr/up_dumpstate.c @@ -208,6 +208,11 @@ void up_dumpstate(void) up_stackdump(sp, istackbase); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Extract the user stack pointer if we are in an interrupt handler. * If we are not in an interrupt handler. Then sp is the user stack @@ -235,6 +240,11 @@ void up_dumpstate(void) { up_stackdump(sp, ustackbase); } + else + { + _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); + } #else _alert("sp: %04x\n", sp); _alert("stack base: %04x\n", ustackbase); @@ -250,6 +260,7 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/avr/src/avr32/up_dumpstate.c b/arch/avr/src/avr32/up_dumpstate.c index c15b331440..39f18ea069 100644 --- a/arch/avr/src/avr32/up_dumpstate.c +++ b/arch/avr/src/avr32/up_dumpstate.c @@ -174,6 +174,11 @@ void up_dumpstate(void) up_stackdump(sp, istackbase); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Extract the user stack pointer if we are in an interrupt handler. * If we are not in an interrupt handler. Then sp is the user stack @@ -201,6 +206,11 @@ void up_dumpstate(void) { up_stackdump(sp, ustackbase); } + else + { + _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); + } #else _alert("sp: %08x\n", sp); _alert("stack base: %08x\n", ustackbase); @@ -216,6 +226,7 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/hc/src/m9s12/m9s12_assert.c b/arch/hc/src/m9s12/m9s12_assert.c index 75733ad63b..ad2cced573 100644 --- a/arch/hc/src/m9s12/m9s12_assert.c +++ b/arch/hc/src/m9s12/m9s12_assert.c @@ -236,6 +236,11 @@ static void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %04x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -254,9 +259,8 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/mips/src/mips32/up_dumpstate.c b/arch/mips/src/mips32/up_dumpstate.c index db9fcda657..f17bc9f205 100644 --- a/arch/mips/src/mips32/up_dumpstate.c +++ b/arch/mips/src/mips32/up_dumpstate.c @@ -191,6 +191,11 @@ void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -209,9 +214,8 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/misoc/src/lm32/lm32_dumpstate.c b/arch/misoc/src/lm32/lm32_dumpstate.c index 1a26791cb1..08f30c4deb 100644 --- a/arch/misoc/src/lm32/lm32_dumpstate.c +++ b/arch/misoc/src/lm32/lm32_dumpstate.c @@ -187,6 +187,11 @@ void lm32_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -205,9 +210,8 @@ void lm32_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/or1k/src/common/up_assert.c b/arch/or1k/src/common/up_assert.c index 1100c58d8b..15f60b3257 100644 --- a/arch/or1k/src/common/up_assert.c +++ b/arch/or1k/src/common/up_assert.c @@ -280,6 +280,11 @@ static void up_dumpstate(void) up_stackdump(sp, istackbase); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Extract the user stack pointer if we are in an interrupt handler. * If we are not in an interrupt handler. Then sp is the user stack @@ -307,6 +312,11 @@ static void up_dumpstate(void) { up_stackdump(sp, ustackbase); } + else + { + _alert("ERROR: Stack pointer is not within the allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); + } #else _alert("sp: %08x\n", sp); @@ -323,6 +333,7 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { _alert("ERROR: Stack pointer is not within allocated stack\n"); + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/renesas/src/m16c/m16c_dumpstate.c b/arch/renesas/src/m16c/m16c_dumpstate.c index 50d43a7587..94be03186c 100644 --- a/arch/renesas/src/m16c/m16c_dumpstate.c +++ b/arch/renesas/src/m16c/m16c_dumpstate.c @@ -209,6 +209,11 @@ void up_dumpstate(void) sp = m16c_getusersp(); _alert("sp: %04x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + m16c_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -227,9 +232,8 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + m16c_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/renesas/src/sh1/sh1_dumpstate.c b/arch/renesas/src/sh1/sh1_dumpstate.c index 9b6b34c31f..5974aa0b9e 100644 --- a/arch/renesas/src/sh1/sh1_dumpstate.c +++ b/arch/renesas/src/sh1/sh1_dumpstate.c @@ -193,6 +193,11 @@ void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + sh1_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -211,9 +216,8 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + sh1_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/risc-v/src/rv32im/up_dumpstate.c b/arch/risc-v/src/rv32im/up_dumpstate.c index 6a27ef2915..25942413a8 100644 --- a/arch/risc-v/src/rv32im/up_dumpstate.c +++ b/arch/risc-v/src/rv32im/up_dumpstate.c @@ -196,6 +196,11 @@ void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -214,9 +219,8 @@ void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/x86/src/common/up_assert.c b/arch/x86/src/common/up_assert.c index 127ecf8831..41ec996788 100644 --- a/arch/x86/src/common/up_assert.c +++ b/arch/x86/src/common/up_assert.c @@ -187,6 +187,11 @@ static void up_dumpstate(void) sp = g_intstackbase; _alert("sp: %08x\n", sp); } + else if (g_current_regs) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + up_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -205,9 +210,8 @@ static void up_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#if !defined(CONFIG_ARCH_INTERRUPTSTACK) || CONFIG_ARCH_INTERRUPTSTACK < 4 _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + up_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/xtensa/src/common/xtensa_dumpstate.c b/arch/xtensa/src/common/xtensa_dumpstate.c index 2bf28b9b16..0cb2a8215e 100644 --- a/arch/xtensa/src/common/xtensa_dumpstate.c +++ b/arch/xtensa/src/common/xtensa_dumpstate.c @@ -255,6 +255,11 @@ void xtensa_dumpstate(void) sp = &g_instack[INTERRUPTSTACK_SIZE - sizeof(uint32_t)]; _alert("sp: %08x\n", sp); } + else if (CURRENT_REGS) + { + _alert("ERROR: Stack pointer is not within the interrupt stack\n"); + xtensa_stackdump(istackbase - istacksize, istackbase); + } /* Show user stack info */ @@ -279,9 +284,8 @@ void xtensa_dumpstate(void) if (sp > ustackbase || sp <= ustackbase - ustacksize) { -#ifdef HAVE_INTERRUPTSTACK _alert("ERROR: Stack pointer is not within allocated stack\n"); -#endif + xtensa_stackdump(ustackbase - ustacksize, ustackbase); } else { diff --git a/arch/z16/src/common/up_stackdump.c b/arch/z16/src/common/up_stackdump.c index e9eb80ef94..0802612a05 100644 --- a/arch/z16/src/common/up_stackdump.c +++ b/arch/z16/src/common/up_stackdump.c @@ -66,6 +66,7 @@ static void up_stackdump(void) chipreg_t sp = up_getsp(); chipreg_t stack_base = (chipreg_t)rtcb->adj_stack_ptr; chipreg_t stack_size = (chipreg_t)rtcb->adj_stack_size; + chipreg_t stack; _alert("stack_base: %08x\n", stack_base); _alert("stack_size: %08x\n", stack_size); @@ -74,19 +75,19 @@ static void up_stackdump(void) if (sp >= stack_base || sp < stack_base - stack_size) { _err("ERROR: Stack pointer is not within allocated stack\n"); - return; + stack = stack_base - stack_size; } else { - chipreg_t stack = sp & ~0x0f; + stack = sp; + } - for (stack = sp & ~0x0f; stack < stack_base; stack += 8*sizeof(chipreg_t)) - { - chipreg_t *ptr = (chipreg_t*)stack; - _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", - stack, ptr[0], ptr[1], ptr[2], ptr[3], - ptr[4], ptr[5], ptr[6], ptr[7]); - } + for (stack = stack & ~0x0f; stack < stack_base; stack += 8*sizeof(chipreg_t)) + { + chipreg_t *ptr = (chipreg_t*)stack; + _alert("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", + stack, ptr[0], ptr[1], ptr[2], ptr[3], + ptr[4], ptr[5], ptr[6], ptr[7]); } } diff --git a/arch/z80/src/common/up_stackdump.c b/arch/z80/src/common/up_stackdump.c index ccb8cbd8dd..a8ff40f7af 100644 --- a/arch/z80/src/common/up_stackdump.c +++ b/arch/z80/src/common/up_stackdump.c @@ -67,6 +67,7 @@ static void up_stackdump(void) uint16_t sp = up_getsp(); uint16_t stack_base = (uint16_t)rtcb->adj_stack_ptr; uint16_t stack_size = (uint16_t)rtcb->adj_stack_size; + uint16_t stack; _alert("stack_base: %04x\n", stack_base); _alert("stack_size: %04x\n", stack_size); @@ -75,19 +76,19 @@ static void up_stackdump(void) if (sp >= stack_base || sp < stack_base - stack_size) { _alert("ERROR: Stack pointer is not within allocated stack\n"); - return; + stack = stack_base - stack_size; } else { - uint16_t stack = sp & ~0x0f; + stack = sp; + } - for (stack = sp & ~0x0f; stack < stack_base; stack += 8*sizeof(uint16_t)) - { - uint16_t *ptr = (uint16_t*)stack; - _alert("%04x: %04x %04x %04x %04x %04x %04x %04x %04x\n", - stack, ptr[0], ptr[1], ptr[2], ptr[3], - ptr[4], ptr[5], ptr[6], ptr[7]); - } + for (stack = stack & ~0x0f; stack < stack_base; stack += 8*sizeof(uint16_t)) + { + uint16_t *ptr = (uint16_t*)stack; + _alert("%04x: %04x %04x %04x %04x %04x %04x %04x %04x\n", + stack, ptr[0], ptr[1], ptr[2], ptr[3], + ptr[4], ptr[5], ptr[6], ptr[7]); } }