rtos2-utils/src/debug/stack_overflow.cpp
2023-01-20 14:12:40 +01:00

36 lines
697 B
C++

#include <sta/config.hpp>
#ifdef STA_RTOS_STACK_OVERFLOW_HOOK
#include <sta/assert.hpp>
#include <sta/debug_serial.hpp>
#include <FreeRTOS.h>
#include <task.h>
extern "C" void vApplicationStackOverflowHook(xTaskHandle xTask, char * pcTaskName)
{
STA_DEBUG_PRINT("Stack overflow detected in task ");
if (pcTaskName)
{
// Manually calculate string length
// Limited to configMAX_TASK_NAME_LEN to avoid reading
// garbage values in case TCB has been corrupted
size_t len = 0;
while (len < configMAX_TASK_NAME_LEN)
{
if (pcTaskName[len] == '\0')
{
break;
}
++len;
}
STA_DEBUG_PRINTLN(pcTaskName, len);
}
STA_HALT();
}
#endif // STA_RTOS_STACK_OVERFLOW_HOOK