Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

GDB Stack unfolding in cortex M4F port

Posted by sblancodiez on September 11, 2014

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 = ( StackTypet ) portTASKRETURN_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

Posted by rtel on September 11, 2014

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

Posted by sblancodiez on September 11, 2014

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

Posted by rtel on September 11, 2014

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS