确定Ravenscar程序中堆栈使用情况的最佳做法 [英] Best practices to determine stack usage in Ravenscar program

查看:67
本文介绍了确定Ravenscar程序中堆栈使用情况的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ravenscar子集编写Ada程序(因此,我知道执行时正在运行的任务数量).该代码由gcc使用 -fstack-check 开关已启用.这应该导致程序在运行时引发 STORAGE_ERROR 如果我有任何任务超出其堆栈范围.

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允许在相应任务的指定过程中为那些(特定于任务的)堆栈设置上限,如下所示:

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);

现在,我想知道必须使用哪些选项来确定 Some_Value .到目前为止,我所听到的是:

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

  1. 进行疯狂的猜测,直到不再引发STORAGE_ERROR为止.此处.
  2. 输入 -fstack-usage的输出 .
  3. 请使用此处所概述的特定于gnat的扩展名(这与项目2在技术上有何不同?).
  4. 获取类似 gnatstack 的堆栈分析器,然后让它为您完成工作.
  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.

如果我正确理解了上述所有技术,那么它们都是动态的(即它们需要程序才能运行).静态方法也可以想象吗?例如.通过Ada的一些高度完整性选项(例如

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.

奖金问题:未指定上述编译指示时,任务堆栈的默认大小是多少?GCC的 docs 仅声明此值取决于运行时,而没有给出任何具体数字.

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.

推荐答案

通常,您可以使用'Storage_Size 属性(以位为单位)检查各个类型所需的堆栈空间.

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.

这篇关于确定Ravenscar程序中堆栈使用情况的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆