Debugger issue - apparent stack overflow

Hi,

When debugging (platformio-debug type) a simple example on nRF52 DK I get immediate error in section 2. The code seems to run fine if not being debugged. Tools fully updated as per section 1. Debug conf in section 3. Any help would be appreciated.

Section 1

$ pio system info
--------------------------  ---------------------------------------------------
PlatformIO Core             5.1.1
Python                      3.9.2-final.0
System Type                 linux_x86_64
Platform                    Linux-5.10.23-200.fc33.x86_64-x86_64-with-glibc2.32
File System Encoding        utf-8
Locale Encoding             UTF-8
PlatformIO Core Directory   /home/xpto/.platformio
PlatformIO Core Executable  /home/xpto/.platformio/penv/bin/platformio
Python Executable           /home/xpto/.platformio/penv/bin/python
Global Libraries            0
Development Platforms       1
Tools & Toolchains          59

Section 2

[00:00:00.492,858] ␛[1;31m<err> os: ***** USAGE FAULT *****␛[0m
[00:00:00.492,858] ␛[1;31m<err> os:   Illegal use of the EPSR␛[0m
[00:00:00.492,889] ␛[1;31m<err> os: r0/a1:  0x00000000  r1/a2:  0xe000ed00  r2/a3:  0x20001d54␛[0m
[00:00:00.492,889] ␛[1;31m<err> os: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0xfffffffd␛[0m
[00:00:00.492,889] ␛[1;31m<err> os:  xpsr:  0x6000000e␛[0m
[00:00:00.492,889] ␛[1;31m<err> os: Faulting instruction address (r15/pc): 0x0000be00␛[0m
[00:00:00.492,889] ␛[1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0␛[0m
[00:00:00.492,889] ␛[1;31m<err> os: Fault during interrupt handling
␛[0m
[00:00:00.492,919] ␛[1;31m<err> os: Current thread: 0x200007b0 (unknown)␛[0m
[00:00:01.545,501] ␛[1;31m<err> os: Halting system␛[0m

Section 3

{
“type”: “platformio-debug”,
“request”: “launch”,
“name”: “PIO Debug test”,
“executable”: “/home/xpto/snipped/.pio/build/nrf52_dk/firmware.elf”,
“projectEnvName”: “nrf52_dk”,
“toolchainBinDir”: “/home/xpto/.platformio/packages/toolchain-gccarmnoneeabi@1.80201.181220/bin”,
“internalConsoleOptions”: “openOnSessionStart”,
“svdPath”: “/home/xpto/.platformio/platforms/nordicnrf52/misc/svd/nrf52.svd”
}

Which Zephyr example is it exactly?

apparent stack overflow

Hm per Debugging a hard fault in ARM Cortex-M4 - Stack Overflow this could also have a different cause.

But yes per mimxrt1060_evk tests/kernel/device illegal use of the EPSR ¡ Issue #13768 ¡ zephyrproject-rtos/zephyr ¡ GitHub and mimxrt1050_evk test/crypto/rand32 meets Kernel Panic ¡ Issue #13655 ¡ zephyrproject-rtos/zephyr ¡ GitHub this might be a stack overflow issue when Zephyr is built with no optimization.

Does the bug go away when you add

debug_build_flags = -Os -ggdb3 -g3

to the platformio.ini? (per docs).

The debug experience won’t be very good because of the optimization, but it should at least not crash if it is a code optimization issue.

1 Like

Your suggestion of adding those debug_build_flags works.

JFYI, the example was this one zephyr/samples/bluetooth/beacon at main ¡ zephyrproject-rtos/zephyr ¡ GitHub

Thanks.

Then this is still something that should be reported at Issues · zephyrproject-rtos/zephyr · GitHub to the developers: If their code runs at optimization level -Os but not -Og, that’s a problem.