Skip to content

Commit a6cce53

Browse files
committed
fix(wdt): changed register dump on non panic task WDT to be more descriptive
Closes #14400
1 parent 53fef80 commit a6cce53

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
#pragma once
9+
10+
#include "sdkconfig.h"
11+
12+
#if CONFIG_IDF_TARGET_ARCH_XTENSA
13+
#include "xtensa_context.h"
14+
#elif CONFIG_IDF_TARGET_ARCH_RISCV
15+
#include "riscv/rvruntime-frames.h"
16+
#endif
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#if CONFIG_IDF_TARGET_ARCH_XTENSA
23+
typedef XtExcFrame esp_cpu_frame_t;
24+
#elif CONFIG_IDF_TARGET_ARCH_RISCV
25+
typedef RvExcFrame esp_cpu_frame_t;
26+
#endif
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif

components/esp_system/include/esp_private/panic_internal.h

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void panic_set_address(void *frame, uint32_t addr);
8585

8686
uint32_t panic_get_cause(const void* frame);
8787

88+
void panic_prepare_frame_from_ctx(void* frame);
89+
8890
#ifdef __cplusplus
8991
}
9092
#endif

components/esp_system/port/arch/riscv/debug_helpers.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,7 +10,9 @@
1010
#include "esp_private/freertos_debug.h"
1111
#include "esp_err.h"
1212
#include "esp_attr.h"
13-
#include "riscv/rvruntime-frames.h"
13+
#include "esp_private/esp_cpu_internal.h"
14+
#include "esp_private/panic_internal.h"
15+
#include <string.h>
1416

1517
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
1618
#include "esp_private/eh_frame_parser.h"
@@ -47,13 +49,18 @@ esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
4749

4850
void *frame = snapshot.pxTopOfStack;
4951

52+
esp_cpu_frame_t backtrace_frame = {};
53+
memcpy(&backtrace_frame, frame, sizeof(esp_cpu_frame_t));
54+
5055
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
51-
esp_rom_printf("Print CPU %d (current core) backtrace\n", current_core);
52-
esp_eh_frame_print_backtrace(frame);
56+
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) backtrace\n", current_core);
57+
esp_eh_frame_print_backtrace(frame);
5358
#else // CONFIG_ESP_SYSTEM_USE_EH_FRAME
54-
esp_rom_printf("Print CPU %d (current core) registers\n", current_core);
55-
panic_print_registers(frame, current_core);
56-
esp_rom_printf("\r\n");
59+
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) registers\n", current_core);
60+
panic_prepare_frame_from_ctx(&backtrace_frame);
61+
62+
panic_print_registers(&backtrace_frame, current_core);
63+
esp_rom_printf("\r\n");
5764
#endif // CONFIG_ESP_SYSTEM_USE_EH_FRAME
5865

5966
return ESP_OK;

components/esp_system/port/arch/riscv/panic_arch.c

+14
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,17 @@ void panic_set_address(void *f, uint32_t addr)
432432
{
433433
((RvExcFrame *)f)->mepc = addr;
434434
}
435+
436+
void panic_prepare_frame_from_ctx(void* frame)
437+
{
438+
/* Cleanup the frame, status registers are not saved during context switches, so these will contain garbage
439+
values from the stack.
440+
*/
441+
((RvExcFrame *)frame)->mstatus = RV_READ_CSR(mstatus);
442+
((RvExcFrame *)frame)->mtvec = RV_READ_CSR(mtvec);
443+
444+
((RvExcFrame *)frame)->mcause = MCAUSE_INVALID_VALUE;
445+
((RvExcFrame *)frame)->mtval = MCAUSE_INVALID_VALUE;
446+
447+
((RvExcFrame *)frame)->mhartid = RV_READ_CSR(mhartid);
448+
}

components/esp_system/port/arch/xtensa/panic_arch.c

+6
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,9 @@ void panic_print_backtrace(const void *f, int core)
470470
esp_backtrace_frame_t frame = {.pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0, .exc_frame = xt_frame};
471471
esp_backtrace_print_from_frame(100, &frame, true);
472472
}
473+
474+
void panic_prepare_frame_from_ctx(void* frame)
475+
{
476+
/* Nothing to cleanup on xtensa */
477+
(void)frame;
478+
}

components/riscv/include/esp_private/panic_reason.h

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
#endif
1919

2020
#define PANIC_RSN_CACHEERR 3
21+
22+
#define MCAUSE_INVALID_VALUE 0xDEADC0DE // Frame mcause value was written by SW to indicate no useful info, e.g. during a register dump without a crash
23+

0 commit comments

Comments
 (0)