Fix stack trace unwinding when inside a continuation #4385
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes stack trace unwinding with gdb when inside a continuation.
Gdb walks back through the stack finding the return address and checks the instructions in the prologue of each function to see what the function is doing with the return address. Currently, I think there is a bug in the xtensa-gdb stack trace unwinding code where if it can't determine exactly what's going on with the return address in the prologue, then it looks at the
a0
register; however, it doesn't seem to be updating thea0
register properly with each frame as it traces up the call stack. This leads to the behavior where once it hitscont_run
(or another function that is creating a virtual stack and pretending to be the top function), it shows the frame 1 function as the next one up, instead of ending atcont_run
. This is because frame 0'sa0
is frame 1, so ifa0
is never updated, then once it hitscont_run
, it'll thinka0
iscont_run
's return address. It then uses the function ata0
to check the stack offset ina0
's prologue and then using that offset to offset the stack of thecont_run
frame, leading to garbage results after that.This is an example of the current behavior:
The change in the PR is to create a dummy wrapper that sets
a0
to 0 in its prologue, signaling to gdb and other stack unwinding logic that thiscont_wrapper
function wants to be seen as the top level function. See this comment in xtensa-gdb.cont_wrapper
uses a hardcoded label to return since it will always return to the same place. This allows us to clobbera0
safely.Here's what it looks like after this change: