Function arguments getting corrupted during debug

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

Function arguments getting corrupted during debug

2,232 Views
windam
Contributor I
Hi Everyone,

I'm debugging on a DSP56858 with CW 8.2.  My application includes an rtos.
I've noticed that function arguments become corrupted sometimes.  For example, I set 2 breakpts in the code below and hit Run.  
CW stops at breakpt #1.  I see that arg1=0 and arg2=3.  
I stepover myfunc().  
CW stops at breakpt #2.  arg1=6 and arg2=788.
Stepover at the assert indicates that arg1 and arg2 are out of range.  arg1 should be 0 and arg2 should be 3.

void caller(char arg1, char arg2)
{
   myfunc(arg1, arg2);   // <--- set breakpt #1 here, arg1=0 and arg2=3.
   // stepover
}

void myfunc(char arg1, char arg2)
{
   ASSERT (arg1 < 5);   // <--- set breakpt #2.  arg1=6 and arg2=788.
   ASSERT (arg2 < 10);  // stepover causes assert to report the error condition
}

I viewed the code in disassembly and noticed that arg1 and arg2 are placed in the Y0 and Y1 registers.  Before mfunc() is called, Y0 and Y1 are correct.  When the code executes to breakpt #2, Y0 and Y1 are 6 and 788 respectively.  So it looks like Y0 and Y1 got overwritten.  Single-stepping is disassembly did not show that Y0 and Y1 were corrupted.  Furthermore, if I ran the code without breakpts, the asserts did not report any errors with arg1 and arg2, so it seems like it is behaving as expected.  I suspect that the rtos is somehow interfering with the debugger since the code was ported from a project that does not use the rtos.
However, I could be wrong, and perhaps I need to configure the debugger differently.

Anyway, if anyone has experienced something similar and knows of a work-around/fix, please let me know.


Thanks,

-win








Labels (1)
Tags (1)
0 Kudos
3 Replies

350 Views
BlackNight
NXP Employee
NXP Employee
Here is what I would check:
make sure that the function caller() sees a prototype for the function myfunc(). From the code piece this looks like an implicit parameter declaration (the compiler does not see a prototype of the function) If so, then the compiler has to assume that the function is defined with actual arguments, returning int.

Make sure you include myfunc() prototype in a header file or declare it before using it.

You may check all the compiler warnings (and check if you have not disabled them).

The other thing is: check if you have enough RAM reserved for you stack.

BK
0 Kudos

350 Views
windam
Contributor I
I checked all your recommendations.  It turns out that registers weren't getting saved properly.  The interrupt handlers had:
#pragma interrupt alignsp
void RxSCI0_Interrupt ( void )

The above is probably ok without an RTOS.  Since we're multitasking, adding saveall seems to prevent corruption:
#pragma interrupt alignsp saveall
void RxSCI0_Interrupt ( void )

Thanks,

-win

0 Kudos

350 Views
trytohelp
NXP Employee
NXP Employee
Hi,
 
This is not easy to determine the cause of the problem.
The better way will be to log it directly in the Technical support system.
Please use Freescale on line support web page.
  - Go to following URL: http://www.freescale.com/TechSupport
  - Click on Submit a Service Request. You will come to a login page.
  - You can submit your request through the web from there.
 
Can you please provide us your example reproducing the issue ?
 
Pascal
0 Kudos