Dump Stack for Function calls

Print order of the functions in which they have been called. How this can be possible for FreeRTOS? because in ARM we are not saving stack at any place. So, how this gone be possible? I tried many solutions but it only works with gcc compiler on linux but not working on arm-none-eabi-gcc compiler and freeRTOS based Marvell’s WMSDK. Please help me in finding exact solution.

Dump Stack for Function calls

Each task maintains its own stack – which definitely is stored somewhere otherwise it would not run. Do you want to look at the stack frame at run time, or in a debugger? I think all debuggers I have used give you the ability to do that. If on the other hand you want to look at the stack frame at run time then you will have to access the stack pointer and unwind the stack from your C code.
I tried many solutions but it
Here it would be really helpful if you had said what solutions you had tried, for at least two reasons: 1) I would have understood what it was you were trying to do, and so not just have to reply by asking what you are trying to do (as above). 2) We would not recommend you tried things that you had already tried.

Dump Stack for Function calls

Are you aware of the relation between compiler optimisation level and the contents of the stack frames? When you want to check the the contents of stack frames, it is probably best to disable optimisations by using -O0 ( minus Oslo zero ). In circuit debuggers nowadays are pretty smart: they even show a proper call-stack when the code has been highly optimised.

Dump Stack for Function calls

Are you aware of the relation between compiler optimisation level and the contents of the stack frames? When you want to check the the contents of stack frames, it is probably best to disable optimisations by using -O0 ( minus Oslo zero ). In-circuit debuggers nowadays are pretty smart: they even show a proper call-stack when the code has been highly optimised.

Dump Stack for Function calls

I want to trace stack at runtime. I have found frame_pointer value and lr register value using register int x asm(“fp”); and register int y asm(“lr”); Now how I have to proceed to grab the previous fp for previous frame and how I can print lr value for that frame?

Dump Stack for Function calls

This is totally not FreeRTOS dependent, but is defined by the compiler and the ABI, and would be the same in FreeRTOS and without. The only part that would be at all FreeRTOS related would be finding the starting stack pointer for another task if you wanted one task to dump out the stack of another task. One thing that will give you some dificulties is that as I remember things, use of the frame pointer is optional (and the fp is just a software convention, nothing hard fixed by the hardware, like the sp and lr), and a compiler in optimizing a function can decide not to use it. A debugger when providing a stack trace looks up the metadata for a function (which it figures out from the LR) to determine how to unwind a given functions stack frame. You would either need to recreate this logic in your code, or and compiler flags to force every function (that you want to back trace) to use the standard stack frame.

Dump Stack for Function calls

But now let say I have sp for current function and if I want to find sp of previously called function, then how can I find it? I mean to say how far it may be? How much deduction of memory pointer I have to do? Please say logic if you have any with related pseudo code.

Dump Stack for Function calls

The stack frame is created by the compiler generated code. If you are using an EABI compiler on ARM (which could well be the case) then you will need to look up the EABI documentation, which will explain the stack format, from which you can deduce how to unwind it. This is very much a compiler question – rather than a FreeRTOS question. The stack frame will be the same if you are using FreeRTOS or not.

Dump Stack for Function calls

I forget which chip you are using, but if its ARM, the frame pointer, if there is one, will be in R7, not LR. LR will be the return address. What gets placed in LR when you enter a function is controlled by hardware, what gets put in the frame pointer is controlled by software. To do this you are going to have to understand both. I presume you have searched the web for examples of how to unwind a stack frame?

Dump Stack for Function calls

So as you said I started working on EABI compiler unwinding function. But, -fno-omit-frame-pointer can’t work for MW300 device, because of less memory it can’t store stack_frame info. So, can you help me out for writing out program without this compiler flag and gives me all backtrace of function? If you have any logic then drop it here in terms of pseudo code.

Dump Stack for Function calls

So, can you help me out for writing out program without this compiler flag
I’m not sure what you are asking us to do – but I’m pretty sure as per other posts in this thread it is not related to FreeRTOS but a matter of reading the EABI and compiler documentation to figure it out for yourself – if you want me to do that for you I”m afraid the answer is no.

Dump Stack for Function calls

No problem. Thank you for your kind support. This thread discussion helped me alot.