Corrupted pcTaskName

I’m compiling FreeRTOS V10.3.1 on a STM32F407g board, i have three tasks with the same priority that implement a simple program, with one task verifying the result of the other 2 tasks at the end of computation. If i use print ((tskTCB)pxCurrentTCB) in gdb i get somehing similar to this:

$4 = {  
   pxTopOfStack = 0x200019e8 <ucHeap+4424>,
   xStateListItem = {    
    xItemValue = 0x1,
    pxNext = 0x200080b4 <pxReadyTasksLists+8>,
    pxPrevious = 0xffffffff,
    pvOwner = 0x20000014 <xIdleTaskTCBBuffer+4>,
    pvContainer = 0x20000014 <xIdleTaskTCBBuffer+4>  
},
  xEventListItem = {    
    xItemValue = 0x2,
    pxNext = 0x200019ec <ucHeap+4428>,
    pxPrevious = 0xffffffff,
    pvOwner = 0x200019ec <ucHeap+4428>,
    pvContainer = 0x20002a54 <ucHeap+8628>  
  },
  uxPriority = 0x0,
  pxStack = 0x200080dc <pxReadyTasksLists+48>,
  pcTaskName = "\377\377\377\377܀\000 ܀\000 \000\000\000",
  uxBasePriority = 0x200080f0,
  uxMutexesHeld = 0xffffffff,
  ulNotifiedValue = 0x200080f0,
  ucNotifyState = 0xf0,
  ucStaticallyAllocated = 0x80 }

As you can see, the pcTaskName is totally corrupted but i can’t understand why. I was suspecting a stack overflow somewhere so I enabled configCHECK_FOR_STACK_OVERFLOW 2 but the function never triggers. What’s strange is that the program still reach completition verifying the right result at the end of all computations. Any idea on what i should look for?

Hi @gialbi
Welcome to the FreeRTOS Community Forums!

The issue you are facing does not seem to a memory or stack corruption, since you mention the actual program runs as expected. This is likely due to incorrect typecasting in GDB.

When you do:

print ((tskTCB)pxCurrentTCB)

you are forcing GDB to interpret pxCurrentTCB as a value of type tskTCB rather than a pointer. You should dereference the pointer ,instead of (tskTCB)pxCurrentTCB, you should use *pxCurrentTCB, which means “dereference pxCurrentTCB and treat it as a tskTCB.”

You can use either of the following

1. print ( *pxCurrentTCB )
2. print ( *(tskTCB*)pxCurrentTCB )

On using any of the methods , this is the output

-exec print *(tskTCB*)pxCurrentTCB

$7 = {
            pxTopOfStack = 0x555555629138 <ucHeap+2584>,
            xStateListItem = {
                    xItemValue = 0, pxNext = 0x555555628108 <pxReadyTasksLists+136>, pxPrevious = 0x555555628108 <pxReadyTasksLists+136>, pvOwner = 0x555555629178 <ucHeap+2648>, pvContainer = 0x5555556280f8 <pxReadyTasksLists+120>
                             },
            xEventListItem = {xItemValue = 4, pxNext = 0x0, pxPrevious = 0x0, pvOwner = 0x555555629178 <ucHeap+2648>, pvContainer = 0x0
                                    }, 
           uxPriority = 3,
           pxStack = 0x555555628e48 <ucHeap+1832>, 
           pcTaskName = "start\000\000\000\000\000\000", 
          pxEndOfStack = 0x555555629160 <ucHeap+2624>, 
          uxTCBNumber = 5,
          uxTaskNumber = 65541,
          uxBasePriority = 3,
          uxMutexesHeld = 0, 
          pxTaskTag = 0x0,
          ulRunTimeCounter = 0, 
          ulNotifiedValue = {0}, 
          ucNotifyState = "",
          ucStaticallyAllocated = 0 '\000', 
          ucDelayAborted = 0 '\000'}
1 Like

Thank you @karahulx it worked!

Thanks for reporting back !