Tuesday, December 12, 2006
Monday, December 11, 2006
Stack Overflow
I read following tricks for tackling stack overflow problem on latest newsletter of The Embedded Muse
I recently wrote an article about stack management
(http://embedded.com/showArticle.jhtml?articleID=193501793 ). Ben
Jackson had an interesting take on the subject:
"I just saw your article about catching stack overflow. One trick I
used last year is to use GCC's '-finstrument-functions' flag which
brackets every compiled function with enter/exit function calls. You
can write an enter function which tests the amount of stack space
left. It's not ideal, but it can save a lot of time. After I did
this for the kernel to track down a problem, one of the application
engineers applied the idea to a thread-intensive application and
found several potential problems.
"Another trick is to look for functions where people have mistakenly
put large structures or arrays on the stack. Use a tool like
'objdump' to disassemble your program and then a one-line awk or perl
script to find the first 'sub...esp' in each function and sort them
by size. If you find an irq with 'struct huge', it's just waiting to
blow your stack."