For a while now I have been developing a project for an Infineon XMC4200 and I had a problem with arm-none-eabi-gdb when it tried to examine the stack. The problem was that when I paused the debugging session gdb reported that it could not read an invalid address (0xa5a5a5b9). I experimented on using gdb commands to see where the problem was and I saw that gdb actually descended through the stack frame but tried to go one level further from the stack base and failed there (this happens in FreeRTOS tasks, not in the main stack).
At first I thought it was a problem with Eclipse/debugging plug-in (see https://sourceforge.net/p/gnuarmeclipse/bugs/111/ to view the problem in detail).
I continued working without being able to see the stack frames in Eclipse, waiting for a better moment to try and fix it. Today I have tried and compared the main function stack frame with the stack frame generated by FreeRTOS for the stacks and I think the problem is putting the return address to portTASK_RETURN_ADDRESS
I changed pxPortInitialiseStack:
:::C *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( StackType_t ) pxCode; /* PC */ pxTopOfStack--; *pxTopOfStack = ( StackType_t ) portTASK_RETURN_ADDRESS; /* LR */
:::C *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ pxTopOfStack--; *pxTopOfStack = ( StackType_t ) pxCode; /* PC */ pxTopOfStack--; *pxTopOfStack = ( StackType_t ) NULL; /* LR */
And now gdb unfolds the stack correctly (I just get another stack frame for 0x0 address).
As far as I understand, the real problem is that FreeRTOS is making the task think it has been called from portTASK_RETURN_ADDRESS but there isn’t a stack frame in the stack for that function, so it is reading garbabe that breaks stack unfolding. I am no expert on this but I am baffled at seing there is not much people with this problem. I found this bug report for the toolchain (https://answers.launchpad.net/gcc-arm-embedded/+question/247765) that is actually the problem I am describing, but I find creating veneers for tasks is not much of a solution.
Perhaps it would be good, when in debug mode or at least if portTASK_RETURN_ADDRESS != NULL, making pxPortInitialiseStack put another fake stack level to allow both stack exit catching and stack unfolding? Or am I missing something?