Re: Stack Overflow Detection
- From: "Richard Phillips" <raphillips@xxxxxxxxxxxx>
- Date: Fri, 30 May 2008 18:18:03 +0100
Vladimir Vassilevsky wrote:
Richard Phillips wrote:
Hello all,
I'm thinking about implementing the above in a system I'm working
on, does anyone have a good strategy for doing this?
Look into the map file. A sensible linker will provide the call tree
with the corresponding stack usage. Depending on the system, you may
or may not need to account for the stack usage in the interrupts.
Avoid the unpredictable stack usage such as recursions and the
dynamic allocations from stack.
One possibility is having an area of RAM (beyond the stack "area")
filled with known data, if any of that data gets trashed then assume
the stack has overflowed. What are the pros and cons of this?
This is one of the common ways. The main problem with it is that you
never know for sure what is the maximum stack usage.
Another idea is to actually watch the SP, but one drawback is if I
check this at a predefined point in the code, then it's possible the
worst case scenario will occur between checks?
Check the SP in the interrupt which happens at random time instants.
This also doesn't guarantee the detection of the max. usage.
Any better ideas?
Use the CPU with MMU. Limit the stack segment size.
Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
I'll take a look at the map file and see if there is anything useful in
there, thanks.
As for maximum stack usage, it's a fair point, I guess it would have to be
determined by trial and error, which is clearly a little clumsy.
I had thought of the interrupt idea, as you say though, it still doesn't
guarantee you'll actually catch it.
Stack segment limits, I'll look into that!
Thanks,
Richard.
.
- References:
- Stack Overflow Detection
- From: Richard Phillips
- Re: Stack Overflow Detection
- From: Vladimir Vassilevsky
- Stack Overflow Detection
- Prev by Date: Re: Stack Overflow Detection
- Next by Date: Re: what is your take on evaluation boards and dev kits?
- Previous by thread: Re: Stack Overflow Detection
- Next by thread: Re: Stack Overflow Detection
- Index(es):