I am developing code with Codewarrior for the NXP DSC, the MC56F82748VLH to be precise. One function call has 7 parameters passed to it. Inside a C function the local parameters are all stored on the stack (some call it the heap). They are accessed as (SP-6), (SP-4) for example, where SP = stack pointer and brackets denote indirection. When a function is called the arguments are written to registers and SP increased to reserve room for the local variables in the function and the return address. If there are more than 6 arguments the extra ones are pushed onto the stack before the function call. Inside the called function those arguments are directly read from the stack location the were written to before the call. So if argument 7 is pushed on the stack and the function is called, SP is incremented by 2. Inside the called function SP is increased again to reserve space for local variables. If 16 is added to SP to allocate room for local variables, argument 7 would be accessed inside the called function as (SP-0x12). This is apparent from looking at the stack, the processor registers, and the disassembly of the program.
What I have seen however is that when the program is inside the called function where argument 7 is located at (SP-0x12), the IDE displays (SP) for this same parameter. I see this when the cursor hovers over the variable name or if I open up the variable window. If I modify location (SP) in a memory window I see the IDE display for argument 7 change. The program is executing the code correctly but the IDE is not adding in the stack offset for arguments that have been pushed on the stack in a function call. This only happens if 7 (or possibly more) arguments are passed in a function. I have not tried it with 8 or more. I have tried it with 6 arguments by making argument 7 a global in the function call and then assigning that value to a local inside the called function. In that case of course the IDE displays the parameter values correctly and the program runs correctly.
This is an IDE bug that most would not see, since it doesn't make the program execute incorrectly and only occurs when more than 6 arguments are passed to a function. Codewarrior doesn't have a mixed (C + asm) debug mode with JTAG or many compile options so there does not appear to be any work-around for this IDE display bug.
To investigate your problem correctly and efficiently, please provide us the follows:
1. your CW version:
- if you use classic version: Start the IDE and click on Help | About Freescale CodeWarrior. Click on Installed Products.Save all info displayed into a txt file and send it to me.
- if you use eclipse version: Start the IDE and click on Help | About CodeWarrior Development Studio. Send me the version and build id.
2. upload the entire sample code folder in zip format here thus we can test it on my side directly.
3. error screenshot.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Codewarrior version 10.6 Build ID:140329
We cannot send our code. You will have to write some functions yourself to reproduce the problem. All that is required is a function with 7 or more arguments and a call to that function from Main.
There is no error message. The IDE displays the wrong values.
Hi
I did a quick test from my side.
run code to the cursor in debugger as below. in variable window, a5-a7 shows incorrect. Is it your problem?
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
EDIT** I took another look at your example and although the processor is different your example does show the same IDE bug I saw. In your case the last 3 local variables have the wrong value. The other problem I see is that some of your local variables have the same address as the arguments of the function. That would be a compiler problem if it is not another example of the IDE display bug. If you look at the disassembly code (I am using an MC56F82748VLH. There is no guarantee the problem will occur for a different processor), the last operand, a7, is pushed on the stack. If it was copied to register A earlier then you will see this instruction: move.w A, X:(SP). Later 2+<N=number of local variables> is added to SP. The disassembly of the called function will show this but any IDE display of that parameter will access it at X:(SP) instead of X:(SP - 2 - N).
William.
Thanks! This problem is escalated as defect to development team (ENGR0085401)
Thanks for bringing the problem to our attention.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I am happy to be of help. It looks like you were able to duplicate the problem easily so the fix should be easy.