Best practices to determine stack usage in Ravenscar program

余生颓废 提交于 2021-02-07 06:26:07

问题


I am writing an Ada program using the Ravenscar subset (thus, I am aware of the number of running tasks at execution time). The code is compiled by gcc with the -fstack-check switch enabled. This should cause the program raise a STORAGE_ERROR at runtime if any of my tasks exceed their stack.

Ada allows to set the upper limit for those (task-specific) stacks during the specification of the respective task like so:

pragma Storage_Size (Some_Value);

Now I was wondering what options I have to determine Some_Value. What I have heard of so far:

  1. Do wild guesses until no STORAGE_ERROR is raised anymore. This is more or less what the OP suggests here.
  2. Feed the output of -fstack-usage in there.
  3. Use some gnat specific extensions as outlined here (how does this technically differ from item #2?).
  4. Get a stack analyzer like gnatstack and let it do the work for you.

If I understand this correctly all the above techniques are dynamic (i.e. they require the program to run in order to work). Are static approaches also conceivable? E.g. by restricting myself further through some of Ada's high integrity options (such as No_Recursion, what else?).

Perhaps any of you can name some best practices to tackle this problem and/or extend/comment on my (surely incomplete) list.

Bonus question: What is the default size of a task's stack when the above pragma is not specified? GCC's docs only state this value depends on the runtime, without giving any concrete numbers.


回答1:


You can generally check the stack space required by individual types with the 'Storage_Size attribute (which counts in bits).

Once you have tabulated this (you may need to round it up to whole words/double words), you can add up how much stack space is used by each declarative region, and then walk through your calls to find the maximum stack usage.



来源:https://stackoverflow.com/questions/34765528/best-practices-to-determine-stack-usage-in-ravenscar-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!