I can't find a good explanation for this anywhere - I'm using a cortex-m4 device (specifically, it's a STM32L4 discovery board) and I try to write a tool that will print the call stack for me (specifically I would want to get the last 10 function calls, i.e., the corresponding program counter value). Obviously this can be done since when I'm debugging the board (using VS code with the cortex-debug extension and when I'm connected to the MCU using a J-link device) I can see the full call stack and even see the values that were passed to each function in the stack. However, I can't understand how this is done (how cortex-debug/Vs code get the backtrace).
When looking at the assembly code I don't see any frame pointer (I see the core uses R7 in some wired way but I cant backtrace using it). So I thought I might need to use the unwind tables, but when I test if the elf contains those sections (.ARM.exidx and .ARM.extbl) using arm-none-eabi-readelf --unwind test.elf
I see that there are no unwind sections.
So how does VS code unwind the stack in this case? Is there some special hardware related to the J-link that keeps that trace somehow and then the J-link gdb server can access it? Is there any good source to how those things work?
Thanks