How does MCUXpresso debugger monitor heap and stack?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How does MCUXpresso debugger monitor heap and stack?

跳至解决方案
1,781 次查看
kackle123
Contributor IV

I'm looking for the details of how the debugger monitors the heap and stack. 

Normally when using a memory-fill pattern/"high water" monitoring, code fills a memory space with a repeated byte (or series of bytes).  I see that occur in memory when creating a new task when using FreeRTOS, but can't find where this is done to the standard stack and heap at start-up (such as when working with bare metal).  That memory looks untouched, so how does the debugger know that X% of stack is used up?

0 项奖励
回复
1 解答
1,754 次查看
ErichStyger
Specialist I

The linker provides special symbols for the heap and stack. For example it knows the base of the heap, and queries the 'top of heap' variable from the library, that way it knows the current heap usage (at least the level where it is up to).

Similar to the MSP: from the linker symbols it knows the stack start and end, and it can query the MSP register, and knows that way the current stack usage.

Note that this is the actual value, and not the 'max during runtime' you would get if you would use a stack fill pattern.

I hope this helps,

Erich

 

PS: https://mcuoneclipse.com/2023/02/19/avoiding-stack-overflows-application-monitoring-the-stack-usage/

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,739 次查看
kackle123
Contributor IV

Ah, so the heap and main stack monitors don't use a memory-fill pattern, which is why I couldn't find that mechanism anywhere in the code.  Thank you, Erich, for the umpteenth time.

1,755 次查看
ErichStyger
Specialist I

The linker provides special symbols for the heap and stack. For example it knows the base of the heap, and queries the 'top of heap' variable from the library, that way it knows the current heap usage (at least the level where it is up to).

Similar to the MSP: from the linker symbols it knows the stack start and end, and it can query the MSP register, and knows that way the current stack usage.

Note that this is the actual value, and not the 'max during runtime' you would get if you would use a stack fill pattern.

I hope this helps,

Erich

 

PS: https://mcuoneclipse.com/2023/02/19/avoiding-stack-overflows-application-monitoring-the-stack-usage/

0 项奖励
回复