runtime: improve hardfault handler and stack reporting on Cortex-M#5380
Conversation
63dc7f7 to
217664b
Compare
|
The |
217664b to
3d78ac8
Compare
| // goroutine (thread mode, PSP active). The MSP-based sp above is the | ||
| // scheduler's stack and its PC is garbage in that case. | ||
| pspVal := task.GoroutineStack() | ||
| if pspVal >= 0x20000000 && pspVal < 0x20040000 { |
There was a problem hiding this comment.
Assuming 256kB of RAM seems kind of arbitrary?
I would suggest either using the range according to the Cortex-M memory map (0x2000_0000..0x3fff_ffff) or using the actual chip RAM (currently exposed as _heap_end).
There was a problem hiding this comment.
Good point. Updated.
| // reading PSP+0x18 gives the actual faulting PC. | ||
| // | ||
| //export GoroutineStack | ||
| func GoroutineStack() uintptr |
There was a problem hiding this comment.
I suspect you'll also need a declaration of this for -scheduler=cores (try tinygo build -scheduler=cores -target=pico examples/blinky1).
There was a problem hiding this comment.
No, the file has a build constraint of //go:build (scheduler.tasks || scheduler.cores) && cortexm - already including the scheduler.cores.
3d78ac8 to
30fc1b0
Compare
|
@digitalentity could you please rebase this PR against the latest |
- Add reference to the current goroutine stack (PSP) when showing the hardfault info on Cortex-M.
5cdb1f1 to
a7378b0
Compare
|
@deadprogram done |
|
Thanks for the improvements here @digitalentity now merging. |
Add reference to the current goroutine stack (PSP) when showing the hardfault info on Cortex-M. The stack where the hardfault happens is usually the scheduler's stack (MSP), which provides no information about the goroutine that actually caused the fault.
This was required to debug random crashes (#5375). The reason was stack overflow, which trigered the
udfinstruction. The MSP only pointed to the HardFault handler and the PC initially suggested stack corruption and nil dereference, while in reality the stack canary was overwritten which triggered a panic.