3 Restoring the Crash Context from a Memory Dump

3.1 Memory Dump Method

Refer to section 5.8 Memory Dump Method to dump the crash memory context.

3.2 Method for Automatically Restoring the Crash Context with Trace32

Refer to section 6.2 Restoring the Hcpu Crash Context with Trace32

3.3 Method for Manually Restoring the Crash Context with Trace32

If automatic context restoration fails, you can manually enter the register values based on the crash context to restore the crash context.
When an interrupt occurs (hardfault is also an interrupt), the interrupt function:

HardFault_Handler->rt_hw_hard_fault_exception->handle_exception

Inside the function, registers R0-R4,R12,R14(LR),PC are pushed onto the saved_stack_frame and saved_stack_pointer variables,
alt text

The stacked registers can be seen in Figure 2 below. In the crash context shown in Figure 1 below, address 0x20054998 contains R0, address 0x200549AC contains LR, and address 0x200549B0 contains PC:0x10CD6602.
Register PC: stores the program PC pointer before the crash.
Register LR: stores the program pointer to return to after program execution completes.
These registers can be used to restore the crash context.
The global variable saved_stack_pointer stores the base address of the stacked data.
The global variable saved_stack_frame stores the stacked data.

alt text

alt text