80 likes | 168 Views
Passing variable argument to function on C66. environment. CCS 5.1.1.00031 CG tool: 7.3.1 Big endian, ELF format Crashed when calling vsprintf Move vsprintf.c from run time lib zip file into build Add __TI_EABI__ and _BIG_ENDIAN to the whole project. st_dpf ( char *fmt, ...) {
E N D
environment • CCS 5.1.1.00031 • CG tool: 7.3.1 • Big endian, ELF format • Crashed when calling vsprintf • Move vsprintf.c from run time lib zip file into build • Add __TI_EABI__ and _BIG_ENDIAN to the whole project
st_dpf(char *fmt, ...) { va_list ap; int result; char buffer[256]; va_start(ap, fmt); //result = st_svdpff(stream, buffer, fmt, ap); vsprintf(buffer, fmt, ap); va_end(ap); printf(buffer); return result; } inttest_dsp_logger(int i) { #if 1 char str1[]="debug with input 1\n"; st_dpf("st_dpf test: \n"); //st_dpf("st_dpf test: %d\n",i); #endif } Lib function retrieved from rts /*****************************************************************************/ /* VSPRINTF - Copy formatted output to a string */ /* */ /* This function passes a format string and an argument list to */ /* _PRINTFI, and writes the result string to the string _STRING. */ /* */ /*****************************************************************************/ _CODE_ACCESS intvsprintf(char *_string, constchar *_format, va_list _ap) { int rval; char *fptr = (char *)_format; char *out_end = _string; rval = _printfi(&fptr, _ap, (void *)&out_end, _outc, _outs); *out_end = '\0'; return rval; } Function call
A4 contains 0x811314c4, point to proper argument fmt When test_dsp_logger calls st_dpf()
When st_dpf just reaches vsprintf1) A4 contains 0x81983178, the right address for buffer2) 0x81083298, incorrect string addr, not the expected 0x811314c4
there were several delay at callP.S2 vsprintB4 moves to 1 during the loop
In functin vsprintf1) A4 has the right addr for buffer/string (0x81083178)2) B4 has value of 1, wrong value for format string – This causes to CRASH accessing invalid Ptr (0x00000001)