Skip to content

Commit 9bda207

Browse files
Copilotsofthack007
andcommitted
Add stack trace analysis and manual exception decoder instructions
Enhanced crash analysis to help diagnose the LoadStorePIFAddrError: Workflow improvements: - Extract and display backtrace addresses from crash logs - Identify crash location (PC register) - Provide detailed manual decoding instructions - Added 3 methods to decode: PlatformIO, addr2line, online tool - Explain EXCCAUSE codes and what they mean - Show crash analysis guidance for QEMU vs real bugs Documentation improvements (QEMU-ISSUES.md): - Complete list of ESP32 exception types with codes - Detailed explanation of LoadStorePIFAddrError (0x0000000f) - Why it's common in QEMU (hardware register access) - Step-by-step decoder usage for all 3 methods - Example decoded output format - How to analyze crash location (registers, addresses) - Common QEMU-specific crash patterns - Clear guidance on QEMU limitation vs real bug The LoadStorePIFAddrError at 0x401771aa is likely ethernet MAC initialization hitting unimplemented QEMU hardware features. Co-authored-by: softhack007 <[email protected]>
1 parent 3a8b123 commit 9bda207

File tree

2 files changed

+171
-9
lines changed

2 files changed

+171
-9
lines changed

.github/workflows/qemu-e2e-test.yml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,63 @@ jobs:
176176
echo "ESP32 Exception/Crash detected in QEMU output!"
177177
echo ""
178178
echo "=== Exception Context ==="
179-
grep -A 20 -B 5 -i "exception\|abort\|backtrace\|panic\|guru meditation" qemu-output.log | head -100
179+
grep -A 25 -B 5 -i "exception\|abort\|backtrace\|panic\|guru meditation" qemu-output.log | head -150
180+
echo ""
181+
echo "=== Stack Trace Analysis ==="
182+
# Extract backtrace if present
183+
if grep -i "Backtrace:" qemu-output.log > /dev/null; then
184+
BACKTRACE=$(grep -i "Backtrace:" qemu-output.log | tail -1)
185+
echo "Raw Backtrace: $BACKTRACE"
186+
echo ""
187+
echo "Analyzing crash location:"
188+
# Extract first address (PC/crash location)
189+
CRASH_ADDR=$(echo "$BACKTRACE" | grep -oP '0x[0-9a-fA-F]+' | head -1)
190+
if [ -n "$CRASH_ADDR" ]; then
191+
echo " - Crash at address: $CRASH_ADDR"
192+
echo " - This is likely in firmware code or ROM"
193+
fi
194+
fi
195+
echo ""
196+
echo "=== Manual Exception Decoder Instructions ==="
197+
echo "To decode this crash manually:"
198+
echo ""
199+
echo "1. Download the 'esp32-firmware' artifact from this GitHub Actions run"
200+
echo "2. Extract the firmware.elf file"
201+
echo "3. Install ESP-IDF or use PlatformIO's exception decoder:"
202+
echo ""
203+
echo " Method A - Using PlatformIO:"
204+
echo " pio device monitor --filter esp32_exception_decoder"
205+
echo " (Then paste the backtrace and exception info)"
206+
echo ""
207+
echo " Method B - Using ESP-IDF addr2line:"
208+
echo " ~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line \\"
209+
echo " -pfiaC -e .pio/build/esp32_16MB_V4_M_eth_debug/firmware.elf \\"
210+
echo " 0x401771aa 0x4015b4c5 0x40134813 ..."
211+
echo ""
212+
echo " Method C - Using online decoder:"
213+
echo " https://github.com/me-no-dev/EspExceptionDecoder"
214+
echo ""
215+
echo "4. The decoded output will show:"
216+
echo " - Function names where the crash occurred"
217+
echo " - Source file locations (file:line)"
218+
echo " - Call stack leading to the crash"
219+
echo ""
220+
echo "=== Crash Analysis Guidance ==="
221+
echo "Common crash causes in QEMU:"
222+
echo " - LoadStorePIFAddrError (0x0000000f): Invalid memory access"
223+
echo " * Often caused by accessing uninitialized pointers"
224+
echo " * Or accessing hardware registers not emulated by QEMU"
225+
echo " * Check if crash is in hardware/peripheral initialization code"
226+
echo ""
227+
echo " - If crash is in ethernet/network code: May be QEMU limitation"
228+
echo " - If crash is in WiFi code: Expected - WiFi not emulated"
229+
echo " - If crash is in application code: Likely real firmware bug"
180230
echo ""
181231
echo "Note: This could be a QEMU-specific issue or a real firmware bug."
182232
echo "QEMU ESP32 emulation has limitations:"
183233
echo " - Many peripherals are not fully emulated"
184234
echo " - Some hardware features may cause crashes in QEMU but work on real hardware"
185-
echo " - Network/WiFi emulation is limited"
235+
echo " - Network/ethernet emulation may have issues"
186236
else
187237
echo "No ESP32 exceptions detected in QEMU output"
188238
fi

docs/QEMU-ISSUES.md

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,130 @@ ESP32 QEMU emulation is not perfect and has several known limitations:
9090

9191
## Analyzing Crashes
9292

93-
### Check Exception Type
94-
Common ESP32 exceptions:
95-
- `LoadProhibited`: Reading from invalid memory address
96-
- `StoreProhibited`: Writing to invalid memory address
97-
- `IllegalInstruction`: Executing invalid code
93+
### Common Exception Types
94+
ESP32 exceptions with EXCCAUSE codes:
95+
- `0x00000000` (IllegalInstruction): Executing invalid code
96+
- `0x00000001` (Syscall): Syscall instruction
97+
- `0x00000002` (InstructionFetchError): Cannot fetch instruction
98+
- `0x00000003` (LoadStoreError): Load/store alignment error
99+
- `0x00000005` (LoadStoreAlignmentCause): Load/store alignment error
100+
- `0x00000006` (InstructionDataError): Data error during instruction fetch
101+
- `0x00000007` (LoadStoreDataError): Data error during load/store
102+
- `0x00000009` (LoadStorePrivilegeViolation): Privilege violation
103+
- `0x0000000f` (LoadStorePIFAddrError): Invalid PIF address (common in QEMU)
104+
- `0x0000001c` (InstructionAddrError): Address error during instruction fetch
105+
- `0x0000001d` (LoadStoreAddrError): Address error during load/store
106+
- `0x0000001e` (InstructionBusError): Bus error during instruction fetch
107+
- `0x0000001f` (LoadStoreBusError): Bus error during load/store
108+
109+
### LoadStorePIFAddrError (0x0000000f)
110+
This is **very common in QEMU** and usually indicates:
111+
- Accessing hardware registers not emulated by QEMU
112+
- Accessing invalid memory-mapped peripheral addresses
113+
- Often occurs during peripheral initialization (I2C, SPI, ADC, etc.)
114+
- **May work fine on real hardware** - QEMU limitation
115+
116+
### Decoding Crash Backtraces
117+
118+
When you see a crash like:
119+
```
120+
Guru Meditation Error: Core 1 panic'ed (LoadStorePIFAddrError)
121+
Backtrace: 0x401771aa:0x3ffb2090 0x4015b4c5:0x3ffb20c0 ...
122+
```
123+
124+
#### Method 1: Using PlatformIO Exception Decoder
125+
```bash
126+
# In the WLED-MM directory
127+
pio device monitor --filter esp32_exception_decoder
128+
129+
# Then paste the exception output (registers + backtrace)
130+
# The decoder will show function names and file locations
131+
```
132+
133+
#### Method 2: Using ESP-IDF addr2line
134+
```bash
135+
# Install toolchain (if not already from PlatformIO)
136+
~/.platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-addr2line \
137+
-pfiaC -e .pio/build/esp32_16MB_V4_M_eth_debug/firmware.elf \
138+
0x401771aa 0x4015b4c5 0x40134813 0x40103cd0 0x40135d33 0x401383c6 0x4016107e
139+
```
140+
141+
Replace the addresses with those from your backtrace.
142+
143+
#### Method 3: Online Decoder
144+
1. Get firmware.elf from build artifacts
145+
2. Use https://github.com/me-no-dev/EspExceptionDecoder
146+
3. Paste exception info and upload firmware.elf
147+
4. Get decoded stack trace
148+
149+
### Example Decoded Output
150+
```
151+
0x401771aa: emac_hal_init at components/hal/esp32/emac_hal.c:45
152+
0x4015b4c5: esp_eth_mac_esp32_init at components/esp_eth/src/esp_eth_mac_esp32.c:123
153+
0x40134813: NetworkClass::begin at wled00/network.cpp:234
154+
```
155+
156+
This shows the crash occurred in ethernet MAC initialization - likely a QEMU emulation limitation.
157+
158+
### Analyzing the Crash Location
159+
160+
1. **Check the function names**: Are they in hardware/peripheral code?
161+
- `emac_`, `i2c_`, `spi_`, `adc_`, etc. → Likely QEMU limitation
162+
- Application functions → Likely real bug
163+
164+
2. **Check EXCVADDR**: The address being accessed
165+
- `0x3ff69xxx` range → Peripheral registers (QEMU issue)
166+
- `0x00000000` or very low → Null pointer (real bug)
167+
- Stack addresses → Possible stack overflow
168+
169+
3. **Check PC (Program Counter)**: Where code was executing
170+
- ROM addresses (`0x4000xxxx`) → ESP32 ROM functions
171+
- Flash addresses (`0x400dxxxx - 0x4017xxxx`) → Your firmware
172+
- RAM addresses (`0x4008xxxx`) → RAM-loaded code
173+
174+
### Common QEMU-Specific Crashes
175+
176+
#### Ethernet MAC Initialization
177+
```
178+
Backtrace: ... esp_eth_mac_esp32_init ... emac_hal_init ...
179+
```
180+
**Cause**: QEMU's ethernet emulation may not fully support all MAC features
181+
**Action**: Check if ethernet link comes up; web server may still work
182+
183+
#### I2C/SPI Peripheral Access
184+
```
185+
Backtrace: ... i2c_master_cmd_begin ...
186+
```
187+
**Cause**: I2C peripherals not emulated
188+
**Action**: Expected in QEMU; disable or mock peripheral access
189+
190+
#### WiFi Functions
191+
```
192+
Backtrace: ... esp_wifi_init ... wifi_hw_init ...
193+
```
194+
**Cause**: WiFi not emulated
195+
**Action**: Use ethernet build (already configured)
98196

99197
### Expected Behavior in QEMU
100198
For WLED testing in QEMU, we expect:
101199
- ✅ Web server to start successfully
102200
- ✅ HTTP requests to be handled
103201
- ✅ Web UI pages to load
104-
- ⚠️ WiFi operations to fail/be limited
202+
- ✅ Basic ethernet connectivity
203+
- ⚠️ WiFi operations to fail/be disabled
105204
- ⚠️ Some LED control features may not work fully
205+
- ⚠️ Peripheral access (I2C, SPI) may crash
206+
- ⚠️ Some hardware features cause QEMU-specific crashes
106207

107-
See full QEMU logs in GitHub Actions artifacts.
208+
### Investigating Crashes
209+
210+
1. **Download QEMU logs** from GitHub Actions artifacts
211+
2. **Find the exception** in qemu-output.log
212+
3. **Copy the backtrace addresses**
213+
4. **Decode using one of the methods above**
214+
5. **Analyze the decoded output**:
215+
- Hardware access? → Probably QEMU limitation
216+
- Application logic? → Likely real bug to fix
217+
- Initialization code? → May need QEMU workaround
218+
219+
See full QEMU logs in GitHub Actions artifacts (`qemu-logs`).

0 commit comments

Comments
 (0)