GDB Stack unfolding in cortex M4F port

Hello there, 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 portTASKRETURNADDRESS I changed pxPortInitialiseStack: ~~~~~~ :::C pxTopOfStack = portINITIAL_XPSR; / xPSR / pxTopOfStack–; *pxTopOfStack = ( StackType_t ) pxCode; / PC / pxTopOfStack–; *pxTopOfStack = ( StackType_t ) portTASK_RETURN_ADDRESS; / LR */ ~~~~~~ for: ~~~~~~ :::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 portTASKRETURNADDRESS 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 portTASKRETURNADDRESS != NULL, making pxPortInitialiseStack put another fake stack level to allow both stack exit catching and stack unfolding? Or am I missing something? Best regards,

GDB Stack unfolding in cortex M4F port

FreeRTOS already has a facility that allows you change the return address exactly for this reason. Just add the following line to FreeRTOSConfig.h:
#define configTASK_RETURN_ADDRESS NULL
Regards.

GDB Stack unfolding in cortex M4F port

Yes, I know that. The problem is if you want to have a task exit catcher and debug your code normally.

GDB Stack unfolding in cortex M4F port

I believe there are some assembler directives you can use to provide GDB with information it cannot glean itself from the source code with regards to how it interprets stack frames. In this case however everything is written in .c files, albeit with naked functions and inline assembler, so I’m not sure if (even if you can interpret how to use the directives) they would necessarily work. If you work it out be sure to let us know. Regards.