esp-idf: backtrace for abort / panic not available in coredump (IDFGH-4276)

Environment

  • Development Kit: ESP32-Wrover-Kit or ESP32-DevKitC
  • Kit version (for WroverKit/PicoKit/DevKitC): v4
  • Module or chip used: ESP32-WROVER-B or ESP32-WROVER-B
  • IDF version (run git describe --tags to find it): v4.1
  • Build System: CMake
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it): (crosstool-NG esp-2020r2) 8.2.0
  • Operating System: Windows
  • (Windows only) environment type: ESP Command Prompt
  • Using an IDE?: Yes Eclipse ESP-IDF Plugin
  • Power Supply: USB

Problem Description

the CoreDump component is intended to locate problems in the sources, but it cannot provide a backtrace in case of panic / assert / abort

Expected Behavior

Complete backtrace is available

Actual Behavior

Just 2 frames are available

#0  0x4008429c in invoke_abort () at D:/esp-idf/esp-idf-v4.1/components/esp32/panic.c:159
#1  0x40084698 in abort () at D:/esp-idf/esp-idf-v4.1/components/esp32/panic.c:174
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Steps to reproduce

  1. take an example (like examples / get-started / hello_world)
  2. put an assert(0); somewhere, for example in the loop, line 45 of hello_world_main.c, see below too
  3. configure coredump to flash in sdkconfig (or use attached config file)
  4. run the code
  5. read the dump via \esp-idf-v4.1\components\espcoredump\espcoredump.py -p COM15 info_corefile D:\eclipse_cpp\workspace\hello_world\build\hello-world.elf

Code to reproduce this issue

/* Hello World Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

#ifdef CONFIG_IDF_TARGET_ESP32
#define CHIP_NAME "ESP32"
#endif

#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
#define CHIP_NAME "ESP32-S2 Beta"
#endif

void app_main(void)
{
    printf("Hello world!\n");

    /* Print chip information */
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);
    printf("This is %s chip with %d CPU cores, WiFi%s%s, ",
            CHIP_NAME,
            chip_info.cores,
            (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
            (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

    printf("silicon revision %d, ", chip_info.revision);

    printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
            (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    for (int i = 10; i >= 0; i--) {
        printf("Restarting in %d seconds...\n", i);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        assert(0);
    }
    printf("Restarting now.\n");
    fflush(stdout);
    esp_restart();
}

Other items if possible

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Will there be backports? Will it make the cut for 5.0?

@KaeLL, it’s already avaliabe in 5.0 branch (06cdc0ee4f6a254f4c682e4652e345506d194e3e)

Also, it will be patched for v4.4 soon

How to get backtrace from esp_core_dump_summary_t ?

  • I have enabled coredump to flash and it is working fine. Now, i get the coredump_summary using this functions.
  • I want to save this summary to sdcard. I want to use this summary to work with EspExceptionDecoder.
  • is that possible? and How?
if (esp_core_dump_image_get(&out_addr, &out_size) == ESP_OK) {
        esp_core_dump_summary_t coredump_summary;
        ESP_ERROR_CHECK(esp_core_dump_get_summary(&coredump_summary));
        // save this coredump
    }

@igrr

Hi @ztefanjo, i’m sorry I have missed your previous comment, I was on leave. Here is the patch you can apply to release/v4.4 to prevent the issue for noreturn functions. 0001-system-add-workaround-for-interrupted-backtraces-on-.patch.txt

We had this change in review a while ago, but it wasn’t accepted because the issue may still occur for “noreturn” functions in application code. Given that we had to revert the fix in GDB, I’ll put this patch for review once again.

@KaeLL for your question, you can trigger some exception (like *((int*)1) = 0;) or use the __builtin_trap(); compiler built-in.