Stack frames MC9S12XD

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

Stack frames MC9S12XD

601 Views
jaymoskowitz
Contributor I

Where can I find information regarding the format of stack frames generated by Code Warrior for a S12XD processor? I have an application in the field that runs into an issue occasionally and need to determine where a particular function is being called from. I would like to be able to write some software that can provide a callback trace and provide the return addresses of the call sequence on the stack. I need to be able to locate the return address in each frame as it executes Function A() --> Function B() --> Function C(). While inside Function C() I wish to call "callbackTrace()" which would provide the address where callbackTrace() was called, the address in Function B() that called C() and the address in Function A() that called B().

Labels (1)
0 Kudos
2 Replies

503 Views
jaymoskowitz
Contributor I

Jennie -

You did not understand the question asked. The question does not concern stack utilization at all or consumption of the stack region. The question concerns the call back sequences generated by Code Warrior when functions call other functions. Each called function has the return address of the function that called it somewhere on the stack. Each functions use of the stack is normally called a frame and the sequence of calls from function to function essentially are frame after frame after frame. If we are 5 levels deep into calls, there are 5 frames of return addresses and local variable data on the stack.

I wish to be able to view the list of return addresses on the stack so that I can tell the call sequence that got me into a particular function. So let's say Function C in my original example has some validation code in it and it finds that data handed to the function is invalid. I may not know who called Function C with the invalid data since 10 other functions potentially call function C. So if I insert a call into Function C called "ShowMeCallbacks()" then that functions could start from knowing the current location of the Stack Pointer, and could potentially display each of the return addresses on the stack that reached function C. So it would return the address of Function B and the address of Function A. Then looking at a link map we can then determine that Function B was one of the 10 functions that possibly calls C and we can also tell who called that Function B. This call sequence makes it clear how we reached a particular set of code.

But we need to know the format of stack frames to be able to write code to interpret callback sequences. In fact I would be surprised if no one has already written this code already since it serves a good purpose. We have implemented this for other compilers and processors but the code depends on how the frames are constructed by the generated code and if it provides an easy way to link back from one frame to that of the prior caller.

0 Kudos

503 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

You can use stack consumption feature to check maximal stack usage.

There are two steps to do it:

    1. Linker Option to be enabled: -StackConsumption

pastedImage_1.png

    2. Stack Consumption directives included in PRM.

I captured the related from help manual:

pastedImage_0.png

You can also find more information in help manual, search the doc with key word “STACK_CONSUMPTION”

Can this help you?


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos