Instead of having to guess the PC where the SP was sampled, always take
both. This allows "seamless" stack decoding for both serial and xflash
dumps, since we don't have to guess which function generated the dump.
Make the core functions (doing the sampling) be ``noinline`` as well,
so that they always have valid frame.
Save SP which is closest to the crash location, which simplifies
debugging. For serial_dump, write SP just before the dump.
For xfdump, save SP in the dump header.
This makes xfdump_dump and xfdump_full_dump_and_reset() equivalent for
stack debugging.
Now that the stack_error function is truly minimal,
we can check for stack errors much more frequently.
Also move away stack_error from ultralcd to Marlin_main.
Rename EEPROM_CRASH_ACKNOWLEDGED to EEPROM_FW_CRASH_FLAG.
Use EEPROM_FW_CRASH_FLAG to always set the last crash reason, which
simplifies handling between the online/offline variants.
Make stack_error safe, by setting the flag and restarting immediately,
so that the error can be shown after restart.
When XFLASH is not available, allow users to request _online_ crash
dumps by using D23 (since these require active user cooperation).
Once enabled, instead of just rebooting, dump memory directly to
the serial.
As similarly done with EMERGENCY_DUMP, we have two features that can be
enabled:
EMERGENCY_SERIAL_DUMP: enables dumping on crash after being requested
MENU_SERIAL_DUMP: allow triggering the same manually through the support
menu.
Create a gap between the BSS and the stack guard.
Set this gap (STACK_GUARD_MARGIN) to 32 bytes in all variants.
The gap serves two purposes:
- Detect a stack overflow earlier (falsely triggering in overtight
situations is OK!), so that we can hopefully avoid smashing
the heap and have a clean view during the dump.
- Reserve spack space itself for the stack dumping machinery,
which is going to grow the stack even further.
Remove get_stack_guard_test_value() which was unused.
As suggested by @3d-gussner, announce to the host that a dump is
available for retrieval using an action "dump_available".
Any kind of dump is announced (even if manually triggered).
To avoid reading from xflash twice, remove some duplication and return
the crash reason directly in xfdump_check_state().
If MENU_DUMP is enabled, a new entry at the end of the "Support" menu is
added that allows to dump memory for offline use.
This allows to trigger a memory dump at any moment during regular usage
(either idling or printing) and to recover the dump later even after a
hardware reset.
If EMERGENCY_DUMP is defined, crash and dump using the new xflash dump
functionality instead of just continuing with an error message.
When an emergency crash is stored, the first restart after a crash
displays a message that debug data is available and to contact support
to submit the crash for analysis.