Skip to content

Commit 766f1f2

Browse files
committed
Merge branch 'bugfix/riscv_task_wdt_cleanup' into 'master'
fix(wdt): changed register dump on task WDT to be more descriptive Closes IDFGH-13506 See merge request espressif/esp-idf!32947
2 parents f71f0fc + 6e51c05 commit 766f1f2

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed
Lines changed: 30 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ void panic_set_address(void *frame, uint32_t addr);
8686

8787
uint32_t panic_get_cause(const void* frame);
8888

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

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include "esp_debug_helpers.h"
7+
#include "esp_private/panic_reason.h"
8+
#include "esp_private/panic_internal.h"
79
#include "sdkconfig.h"
810
#include "freertos/FreeRTOS.h"
911
#include "freertos/task.h"
1012
#include "esp_private/freertos_debug.h"
1113
#include "esp_err.h"
1214
#include "esp_attr.h"
13-
#include "riscv/rvruntime-frames.h"
15+
#include "esp_private/esp_cpu_internal.h"
16+
#include <string.h>
1417

1518
#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
1619
#include "esp_private/eh_frame_parser.h"
@@ -47,12 +50,17 @@ esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
4750

4851
void *frame = snapshot.pxTopOfStack;
4952

53+
esp_cpu_frame_t backtrace_frame = {};
54+
memcpy(&backtrace_frame, frame, sizeof(esp_cpu_frame_t));
55+
5056
#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);
57+
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) backtrace\n", current_core);
58+
esp_eh_frame_print_backtrace(&frame);
5359
#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);
60+
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) registers\n", current_core);
61+
panic_prepare_frame_from_ctx(&backtrace_frame);
62+
63+
panic_print_registers(&backtrace_frame, current_core);
5664
esp_rom_printf("\r\n");
5765
#endif // CONFIG_ESP_SYSTEM_USE_EH_FRAME
5866

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,17 @@ void panic_set_address(void *f, uint32_t addr)
350350
{
351351
((RvExcFrame *)f)->mepc = addr;
352352
}
353+
354+
void panic_prepare_frame_from_ctx(void* frame)
355+
{
356+
/* Cleanup the frame, status registers are not saved during context switches, so these will contain garbage
357+
values from the stack.
358+
*/
359+
((RvExcFrame *)frame)->mstatus = RV_READ_CSR(mstatus);
360+
((RvExcFrame *)frame)->mtvec = RV_READ_CSR(mtvec);
361+
362+
((RvExcFrame *)frame)->mcause = MCAUSE_INVALID_VALUE;
363+
((RvExcFrame *)frame)->mtval = MCAUSE_INVALID_VALUE;
364+
365+
((RvExcFrame *)frame)->mhartid = RV_READ_CSR(mhartid);
366+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,9 @@ void panic_print_backtrace(const void *f, int core)
479479
esp_backtrace_frame_t frame = {.pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0, .exc_frame = xt_frame};
480480
esp_backtrace_print_from_frame(100, &frame, true);
481481
}
482+
483+
void panic_prepare_frame_from_ctx(void* frame)
484+
{
485+
/* Nothing to cleanup on xtensa */
486+
(void)frame;
487+
}

components/riscv/include/esp_private/panic_reason.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
#define MCAUSE_ILLIGAL_INSTRUCTION_ACCESS 1
2323
#define MCAUSE_ILLEGAL_INSTRUCTION 2
2424
#define MCAUSE_LOAD_ACCESS_FAULT 5
25+
#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

0 commit comments

Comments
 (0)