Stack size calculation - any tools available?

16/11/2009 - 23:20 von Gerd | Report spam
I need to allocate the stack for my system with a proper size. I don't
want do a vage estimation, so I would like to know: Is there a tool
that scans C source code, and calculates the required stack size,
based on the call graph? Only plain C, no recursion.

Any suggestions are welcome.

Thanks.
 

Lesen sie die antworten

#1 Marcel Müller
17/11/2009 - 00:23 | Warnen spam
Hi,

Gerd wrote:
I need to allocate the stack for my system with a proper size. I don't
want do a vage estimation, so I would like to know: Is there a tool
that scans C source code, and calculates the required stack size,
based on the call graph? Only plain C, no recursion.



the C language *cannot* supply an exact stack size.

This is only possible if you apply hard restrictions. E.g. your code
must be compilable without any forward declarations of functions.
Otherwise you cannot calculate the stack size for all nested function
calls. And for the same reason the program must not contain any
recursion. This has to be emulated with heap memory.
Function pointers, alloca and C99 VLA are not allowed, too.
Also any library used must meet the same constrains. Do you have the
source of all libraries you use?
And last but not least, once you managed all of the above the result is
platform dependent.

What you can do is to get a typical stack size from application runs.
E.g. you might run all test cases (including load tests!) and observe
the used stack space. The compiler or the operating system may aid you.
Compilers sometimes provide switches that initialize the stack memory to
a certain pattern. When a thread completes you can easily see how much
stack was used. The operating system might track the stack size by using
guard pages. You simply have to query the commited stack area in this case.


Marcel

Ähnliche fragen