Skip to content

Commit

Permalink
Merge branch 'bugfix/eh_frame_backtrace' into 'master'
Browse files Browse the repository at this point in the history
fix(system): fixed eh-frame backtrace issue from WDT

See merge request espressif/esp-idf!33112
  • Loading branch information
ESP-Marius committed Sep 2, 2024
2 parents c68c404 + 7f5496d commit 7cf872e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/esp_system/port/arch/riscv/debug_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ esp_err_t IRAM_ATTR esp_backtrace_print(int depth)

#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) backtrace\n", current_core);
esp_eh_frame_print_backtrace(&frame);
esp_eh_frame_print_backtrace(frame);
#else // CONFIG_ESP_SYSTEM_USE_EH_FRAME
esp_rom_printf("esp_backtrace_print: Print CPU %d (current core) registers\n", current_core);
panic_prepare_frame_from_ctx(&backtrace_frame);
Expand Down
5 changes: 2 additions & 3 deletions tools/test_apps/system/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ tools/test_apps/system/cxx_no_except:

tools/test_apps/system/eh_frame:
enable:
- if: IDF_TARGET in ["esp32c2", "esp32c3"]
temporary: true
reason: the other targets are not tested yet
- if: IDF_TARGET not in ["esp32", "esp32s2", "esp32s3", "linux"]
reason: Only relevant for riscv targets

tools/test_apps/system/esp_intr_dump:

Expand Down
4 changes: 2 additions & 2 deletions tools/test_apps/system/eh_frame/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Supported Targets | ESP32-C2 | ESP32-C3 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 |
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |

# Building and running

Expand Down
2 changes: 1 addition & 1 deletion tools/test_apps/system/eh_frame/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS "eh_frame_main.c"
INCLUDE_DIRS "."
REQUIRES esp_system)
REQUIRES esp_system unity esp_timer)
26 changes: 24 additions & 2 deletions tools/test_apps/system/eh_frame/main/eh_frame_main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>

#include "unity.h"
#include "esp_timer.h"
#include "esp_debug_helpers.h"
/**
* @brief Symbols defined by the linker.
* Retrieve the addresses of both .eh_frame_hdr and .eh_frame sections.
Expand All @@ -26,6 +28,24 @@ extern char __eh_frame_end;
#define EH_FRAME_END_ADDR ((void*) (&__eh_frame_end))


void __attribute((noinline)) trigger_wdt(void)
{
const int wait_until_time = esp_timer_get_time() + (1000*1000 * (CONFIG_ESP_TASK_WDT_TIMEOUT_S + 1));
while(esp_timer_get_time() < wait_until_time) {
}
}

TEST_CASE("Test task wdt can print backtrace with eh-frame", "eh-frame")
{
trigger_wdt();
}


TEST_CASE("Test panic can print backtrace with eh-frame", "eh-frame")
{
asm("unimp");
}

void app_main(void)
{
/* As soon as this test compiles, it can be considered passed. The linker should
Expand All @@ -37,4 +57,6 @@ void app_main(void)
/* Use the symbols just to make sure they won't be optimized away */
printf(".eh_frame start: %p, end: %p\n", EH_FRAME_ADDR, EH_FRAME_END_ADDR);
printf(".eh_frame_hdr start: %p, end: %p\n", EH_FRAME_HDR_ADDR, EH_FRAME_HDR_END_ADDR);

unity_run_menu();
}
34 changes: 34 additions & 0 deletions tools/test_apps/system/eh_frame/pytest_eh_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
from pytest_embedded import Dut


@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c5
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.generic
def test_eh_frame_wdt(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.confirm_write('"Test task wdt can print backtrace with eh-frame"', expect_str=f'Running')

# Expect a backtrace which is at least 3 PC-SP pairs deep
dut.expect(r'Backtrace: (0x[a-fA-F0-9]+:0x[a-fA-F0-9]+\s*){3,}')


@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c5
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.generic
def test_eh_frame_panic(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.confirm_write('"Test panic can print backtrace with eh-frame"', expect_str=f'Running')

# Expect a backtrace which is at least 3 PC-SP pairs deep
dut.expect(r'Backtrace: (0x[a-fA-F0-9]+:0x[a-fA-F0-9]+\s*){3,}')
2 changes: 2 additions & 0 deletions tools/test_apps/system/eh_frame/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Enable eh_frame sections generation
CONFIG_ESP_SYSTEM_USE_EH_FRAME=y
# use non-rom systimer implementation, can't backtrace functions in ROM
CONFIG_HAL_SYSTIMER_USE_ROM_IMPL=n

0 comments on commit 7cf872e

Please sign in to comment.