Fix stack trace unwinding when inside a continuation#4385
Fix stack trace unwinding when inside a continuation#4385devyte merged 4 commits intoesp8266:masterfrom
Conversation
|
Instead of creating a wrapper function, can we create a dummy stack frame at the top of the new stack? This can be done once in cont_init, I think. |
|
I tried that in a bunch of different ways but kept running into the same problem. The gdb stack unwinding code seems to abort looking at the stack for the return address if it's not able to ascertain it from the prologue code. I think it's trying to be a little too smart, so just adding a dummy frame doesn't seem to work the way I would expect it to. The reason this wrapper technique works is that it's a well-formatted case of the setting the return address to 0 in the prologue, which seems to be the only case that gdb recognizes. I think if the a0 bug I mentioned above is fixed, this won't be necessary. |
|
I have been wondering about that garbage output for the longest time. Thank you for figuring it out! |
|
Thanks for explaining @kylefleming, makes sense. Changes look good to me. I've marked the PR for 2.5.0 milestone since we are only merging fixes for critical issues before 2.4.1, which should be released soon. |
(cherry picked from commit 70f522c)
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
a0register; however, it doesn't seem to be updating thea0register 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'sa0is frame 1, so ifa0is never updated, then once it hitscont_run, it'll thinka0iscont_run's return address. It then uses the function ata0to check the stack offset ina0's prologue and then using that offset to offset the stack of thecont_runframe, 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
a0to 0 in its prologue, signaling to gdb and other stack unwinding logic that thiscont_wrapperfunction wants to be seen as the top level function. See this comment in xtensa-gdb.cont_wrapperuses a hardcoded label to return since it will always return to the same place. This allows us to clobbera0safely.Here's what it looks like after this change: