Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists