Re: Stack Overflow Detection
- From: Vladimir Vassilevsky <antispam_bogus@xxxxxxxxxxx>
- Date: Fri, 30 May 2008 10:37:20 -0500
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
.
- Follow-Ups:
- Re: Stack Overflow Detection
- From: Tomás Ó hÉilidhe
- Re: Stack Overflow Detection
- From: Richard Phillips
- Re: Stack Overflow Detection
- References:
- Stack Overflow Detection
- From: Richard Phillips
- Stack Overflow Detection
- Prev by Date: Cheap/free stuff
- Next by Date: Re: Driving tri-state LED matrix
- Previous by thread: Re: Stack Overflow Detection
- Next by thread: Re: Stack Overflow Detection
- Index(es):