mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
61 lines
2.0 KiB
C
61 lines
2.0 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* 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 };
|
|
BaseType_t ret = vTaskGetSnapshot(xTaskGetCurrentTaskHandleForCPU(current_core), &snapshot);
|
|
|
|
if (ret != pdTRUE) {
|
|
return ESP_ERR_NOT_FOUND;
|
|
}
|
|
|
|
void *frame = snapshot.pxTopOfStack;
|
|
|
|
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
esp_rom_printf("Print CPU %d (current core) backtrace\n", current_core);
|
|
esp_eh_frame_print_backtrace(frame);
|
|
#else // CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
esp_rom_printf("Print CPU %d (current core) registers\n", current_core);
|
|
panic_print_registers(frame, current_core);
|
|
esp_rom_printf("\r\n");
|
|
#endif // CONFIG_ESP_SYSTEM_USE_EH_FRAME
|
|
|
|
return ESP_OK;
|
|
}
|