Skip to content

Commit

Permalink
Merge pull request #290 from kivancsikert/debug/core-dump
Browse files Browse the repository at this point in the history
Publish crash report
  • Loading branch information
lptr authored Dec 13, 2024
2 parents 9823b9f + 3c5a571 commit e372594
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
66 changes: 64 additions & 2 deletions main/devices/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

#include <Arduino.h>

#include "esp_netif.h"
#include "esp_wifi.h"
#include <esp_core_dump.h>
#include <esp_netif.h>
#include <esp_pm.h>
#include <esp_private/esp_clk.h>
#include <esp_wifi.h>

#include <Print.h>

Expand Down Expand Up @@ -495,6 +496,8 @@ class Device {
json["state"] = static_cast<int>(initState);
json["peripherals"].to<JsonArray>().set(peripheralsInitJson);
json["sleepWhenIdle"] = kernel.powerManager.sleepWhenIdle;

reportPreviousCrashIfAny(json);
},
Retention::NoRetain, QoS::AtLeastOnce, 5s);

Expand Down Expand Up @@ -542,6 +545,65 @@ class Device {
}
}

void reportPreviousCrashIfAny(JsonObject& json) {
esp_err_t errCheck = esp_core_dump_image_check();
if (errCheck == ESP_ERR_NOT_FOUND) {
LOGV("No core dump found");
return;
}
if (errCheck != ESP_OK) {
LOGE("Failed to check for core dump: %s", esp_err_to_name(errCheck));
return;
}

esp_core_dump_summary_t summary;
esp_err_t err = esp_core_dump_get_summary(&summary);
if (err != ESP_OK) {
LOGE("Failed to get core dump summary: %s", esp_err_to_name(err));
} else {
auto crashJson = json["crash"].to<JsonObject>();
reportPreviousCrash(crashJson, summary);
}

ESP_ERROR_CHECK_WITHOUT_ABORT(esp_core_dump_image_erase());
}

void reportPreviousCrash(JsonObject& json, const esp_core_dump_summary_t& summary) {
auto excCause =
#if __XTENSA__
summary.ex_info.exc_cause;
#else
summary.ex_info.mcause;
#endif

LOGW("Core dump found: task: %s, cause: %ld",
summary.exc_task, excCause);

json["version"] = summary.core_dump_version;
json["sha256"] = String((const char*) summary.app_elf_sha256, CONFIG_APP_RETRIEVE_LEN_ELF_SHA);
json["task"] = summary.exc_task;
json["cause"] = excCause;

static constexpr size_t PANIC_REASON_SIZE = 256;
char panicReason[PANIC_REASON_SIZE];
if (esp_core_dump_get_panic_reason(panicReason, PANIC_REASON_SIZE) == ESP_OK) {
LOGW("Panic reason: %s", panicReason);
json["panicReason"] = panicReason;
}

auto backtraceJson = json["backtrace"].to<JsonObject>();
if (summary.exc_bt_info.corrupted) {
LOGE("Backtrace corrupted, depth %lu", summary.exc_bt_info.depth);
backtraceJson["corrupted"] = true;
} else {
auto framesJson = backtraceJson["frames"].to<JsonArray>();
for (int i = 0; i < summary.exc_bt_info.depth; i++) {
auto& frame = summary.exc_bt_info.bt[i];
framesJson.add("0x" + String(frame, HEX));
}
}
}

Queue<LogRecord> logRecords { "logs", 32 };
ConfiguredKernel configuredKernel { logRecords };
Kernel<TDeviceConfiguration>& kernel = configuredKernel.kernel;
Expand Down
4 changes: 2 additions & 2 deletions partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x1E0000,
app1, app, ota_1, 0x1F0000,0x1E0000,
data, data, spiffs, 0x3D0000,0x20000,
coredump, data, coredump,0x3F0000,0x10000,
data, data, spiffs, 0x3D0000,0x18000,
coredump, data, coredump,0x3E8000,0x18000,
9 changes: 5 additions & 4 deletions sdkconfig.debug.defaults
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y

CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=n
CONFIG_ESP_COREDUMP_ENABLE_TO_UART=y
CONFIG_ESP_COREDUMP_DECODE=y
CONFIG_ESP_COREDUMP_LOGS=y
CONFIG_ESP_SYSTEM_PANIC_GDBSTUB=y
CONFIG_ESP_DEBUG_OCDAWARE=y

CONFIG_COMPILER_OPTIMIZATION_SIZE=n
CONFIG_COMPILER_OPTIMIZATION_DEBUG=y
1 change: 1 addition & 0 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ CONFIG_PM_LIGHT_SLEEP_CALLBACKS=y
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=y
CONFIG_ESP_COREDUMP_CHECKSUM_SHA256=y
CONFIG_ESP_COREDUMP_DECODE_INFO=y
CONFIG_ESP_COREDUMP_LOGS=n

0 comments on commit e372594

Please sign in to comment.