2023-08-31 00:19:49 -04:00
|
|
|
/*
|
2024-01-29 20:40:10 -05:00
|
|
|
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
2023-08-31 00:19:49 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#include "esp_debug_helpers.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_private/freertos_debug.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "riscv/rvruntime-frames.h"
|
|
|
|
|
|
|
|
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
#include "esp_private/eh_frame_parser.h"
|
|
|
|
#endif // CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
|
|
|
|
#if !CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
/* Function used to print all the registers pointed by the given frame .*/
|
|
|
|
extern void panic_print_registers(const void *frame, int core);
|
|
|
|
#endif // !CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
|
|
|
|
/* Targets based on a RISC-V CPU cannot perform backtracing that easily.
|
|
|
|
* We have two options here:
|
|
|
|
* - Perform backtracing at runtime.
|
|
|
|
* - Let IDF monitor do the backtracing for us. Used during panic already.
|
|
|
|
* This could be configurable, choosing one or the other depending on
|
|
|
|
* CONFIG_ESP_SYSTEM_USE_EH_FRAME configuration option.
|
|
|
|
*
|
|
|
|
* In both cases, this takes time, and we might be in an ISR, we must
|
|
|
|
* exit this handler as fast as possible, then we will simply print
|
|
|
|
* the interruptee's registers.
|
|
|
|
*/
|
|
|
|
esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
|
|
|
|
{
|
|
|
|
(void)depth;
|
|
|
|
|
|
|
|
const int current_core = xPortGetCoreID();
|
|
|
|
|
|
|
|
TaskSnapshot_t snapshot = { 0 };
|
2023-11-02 06:19:42 -04:00
|
|
|
BaseType_t ret = vTaskGetSnapshot(xTaskGetCurrentTaskHandleForCore(current_core), &snapshot);
|
2023-08-31 00:19:49 -04:00
|
|
|
|
|
|
|
if (ret != pdTRUE) {
|
|
|
|
return ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *frame = snapshot.pxTopOfStack;
|
|
|
|
|
|
|
|
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
2024-01-29 20:40:10 -05:00
|
|
|
esp_rom_printf("Print CPU %d (current core) backtrace\n", current_core);
|
|
|
|
esp_eh_frame_print_backtrace(frame);
|
2023-08-31 00:19:49 -04:00
|
|
|
#else // CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
2024-01-29 20:40:10 -05:00
|
|
|
esp_rom_printf("Print CPU %d (current core) registers\n", current_core);
|
|
|
|
panic_print_registers(frame, current_core);
|
|
|
|
esp_rom_printf("\r\n");
|
2023-08-31 00:19:49 -04:00
|
|
|
#endif // CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|