打印
[STM32F1]

MDK 怎么查看堆栈使用情况

[复制链接]
12344|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
21ID|  楼主 | 2014-9-9 15:36 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
使用MDK时,怎么查看堆栈的使用情况。比如用了多少,还有多少。
沙发
香水城| | 2014-9-9 17:46 | 只看该作者
预先从RAM中分配的用作STACK的区域是知道的。

那么随时查看堆栈指针SP?

使用特权

评论回复
板凳
mmuuss586| | 2014-9-9 18:43 | 只看该作者

这个不知道;

使用特权

评论回复
地板
zh113214| | 2014-9-9 22:44 | 只看该作者
虽然我也不知道,不过还是给你顶一个!!

使用特权

评论回复
5
21ID|  楼主 | 2014-9-10 09:47 | 只看该作者
香水城 发表于 2014-9-9 17:46
预先从RAM中分配的用作STACK的区域是知道的。

那么随时查看堆栈指针SP?

谢谢版主!这个我知道,只是这样比较麻烦:)

使用特权

评论回复
6
21ID|  楼主 | 2014-9-10 09:48 | 只看该作者
zh113214 发表于 2014-9-9 22:44
虽然我也不知道,不过还是给你顶一个!!

谢谢!

使用特权

评论回复
7
z00| | 2014-9-10 13:41 | 只看该作者
在MDK的帮助文件中 搜索"Stack use in C and C++" 这篇**里面有介绍 看看是不是想要的

使用特权

评论回复
8
lnhjsdf| | 2014-9-10 14:10 | 只看该作者
顶起

使用特权

评论回复
9
HORSE7812| | 2014-9-10 15:19 | 只看该作者
顶起

使用特权

评论回复
10
21ID|  楼主 | 2014-9-10 16:18 | 只看该作者
z00 发表于 2014-9-10 13:41
在MDK的帮助文件中 搜索"Stack use in C and C++" 这篇**里面有介绍 看看是不是想要的 ...


我没找到

使用特权

评论回复
11
z00| | 2014-9-10 21:22 | 只看该作者
use is difficult to estimate because it is code dependent, and can vary between runs depending on the code path that the program takes on execution. However, it is possible to manually estimate the extent of stack utilization using the following methods:

Link with --callgraph to produce a static callgraph. This shows information on all functions, including stack use.

Link with --info=stack or --info=summarystack to list the stack usage of all global symbols.

Use the debugger to set a watchpoint on the last available location in the stack and see if the watchpoint is ever hit.

Note
µVision uses ULINK debug adaptors, with the CoreSight interface, which have no performance penalties.

Use the debugger, and:

Allocate space in memory for the stack that is much larger than you expect to require.

Fill the stack space with copies of a known value, for example, 0xDEADDEAD.

Run your application, or a fixed portion of it. Aim to use as much of the stack space as possible in the test run. For example, try to execute the most deeply nested function calls and the worst case path found by the static analysis. Try to generate interrupts where appropriate, so that they are included in the stack trace.

After your application has finished executing, examine the stack space of memory to see how many of the known values have been overwritten. The space has garbage in the used part and the known values in the remainder.

Count the number of garbage values and multiply by sizeof(value), to give their size, in bytes.

The result of the calculation shows how the size of the stack has grown, in bytes.

Use RTSM, and define a region of memory where access is not allowed directly below your stack in memory, with a map file. If the stack overflows into the forbidden region, a data abort occurs, which can be trapped by the debugger.

Methods of reducing stack usage
In general, you can lower the stack requirements of your program by:

writing small functions that only require a small number of variables

avoiding the use of large local structures or arrays

avoiding recursion, for example, by using an alternative algorithm

minimizing the number of variables that are in use at any given time at each point in a function

using C block scope and declaring variables only where they are needed, so overlapping the memory used by distinct scopes.

使用特权

评论回复
12
fanxsd| | 2015-8-10 10:38 | 只看该作者
楼主找到好的办法用 MDK 查看堆栈的使用了吗?

使用特权

评论回复
13
sfd123| | 2019-3-7 14:23 | 只看该作者
楼主找到简单好用的办法了吗?我也想知道啊!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

157

主题

912

帖子

5

粉丝