Handle breakpoints via postmortem when GDB is not running. by mhightower83 · Pull Request #7704 · esp8266/Arduino (original) (raw)

Objective: Add support for Debug, Kernel, and Double Exception reporting with minimum impact on IRAM usage. Additionally, improve reporting of Unhandled Exception causes for the disabled interrupt case.

Overview: In the absence of GDB, install a small breakpoint handler that clears EXCM and executes an illegal instruction. This leverages the existing exception handling code in the SDK for the ill instruction. At postmortem processing, identify the event and report. This allows for the alerting of embedded breakpoints. In the stack trace, EPC1 is updated with the value of EPC2. This helps "Exception Decoder" identify the line where the BP occurred. By using the SDK's handling for ill, we get support for handling the process of getting out of the "Cache_Read_Disable state" free, without consuming IRAM.

For breakpoints (BP), the SDK's default behavior is to loop, waiting for an interrupt, or until the HWDT kicks in. Note the current "C++" compiler will embed breakpoints when it detects a divide by zero at compile time.

Expand technique to preserve more of the current context, and report Kernel and Double exceptions through postmortem. As well as enhanced reporting for XTOS Unhandled Exceptions. This allows reporting of EXCCAUSE value 20, InstFetchProhibitedCause, this is commonly caused by calling address 0x00000000. For example, this can happen from a defined weak function definition without supplying the function, or a failure to check for NULL before calling a callback function. Without this enhancement for XTOS Unhandled Exceptions an HWDT reboot will occur.

To assist the "ESP Exception Decoder", a stack frame is created to store various special registers for inspection. The expectation is that some of these values may point to code. This can give insight into what was running at the time of the crash.

This enhancement is only built when DEBUG_ESP_PORT (Debug selection from the Arduino IDE) or DEBUG_ESP_EXCEPTIONS is defined. This enhancement by itself (built with DEBUG_ESP_EXCEPTIONS defined) adds about 620 bytes of IROM, 20 bytes of IRAM, and 0 bytes of DRAM to a sketch.

Edited: expanded description