How does MCUXpresso debugger monitor heap and stack?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How does MCUXpresso debugger monitor heap and stack?

Jump to solution
1,775 Views
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 Kudos
Reply
1 Solution
1,748 Views
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/

View solution in original post

0 Kudos
Reply
2 Replies
1,733 Views
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,749 Views
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 Kudos
Reply