AnsweredAssumed Answered

Codewarrior IDE doesn't track some function parameters

Question asked by William Ogilvie on Oct 24, 2016
Latest reply on Oct 28, 2016 by William Ogilvie

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.

Outcomes