This article shares a method to measure stack size in AndeSight, the core idea is that we fill the stack region with specific value 0xff after loading the elf file to target,then check the stack region after running to the end. OK we take the hello-world project as the example to show how to implement this idea.
Step1: Check the initial stack top. In normal project, we get the stack initial value from the sag file or linker script.In this demo we get the value from the sag file:
Attachment:
stack_init.png [ 4.6 KiB | Viewed 17822 times ]
Step2: Set the breakpoint as the early beginning (AndeSight will take main() function as the default breakpoint, keep the default setting is OK for measuring stack size, but change breakpoint to _start can show the stack consumption more clearly):
Attachment:
debugsetting.png [ 39.61 KiB | Viewed 17827 times ]
Step3: Debug the hello-world project, open Memory View and set a appropriate monitor.(In hello -world the SP = 0x750000, and it's a small project so we watch memory after 0x74ff00 )
Attachment:
memory.png [ 32.69 KiB | Viewed 17827 times ]
Step4: Fill the memory with specific value 0xff. AndeSight gets a "import" bar to do this, it's like gdb command "restore". It can import three kinds format, we suggest use "Plain Text". As:
Attachment:
import.png [ 46.28 KiB | Viewed 17827 times ]
Step5: Continue to run (to the last line of the project). Then check the stack region:
Attachment:
memoryview.png [ 18.14 KiB | Viewed 17822 times ]
We can get the used stack size is:0x750000 - 0x74ffb0 = 0x50 Byte.
The import plain text file can find here:
Attachment:
test.txt [1.22 KiB]
Downloaded 1330 times