gdb/riscv: support c.ldsp and c.lwsp in prologue scanner
Add support to the RISC-V prologue scanner for c.ldsp and c.lwsp
instructions.
This fixes some of the failures in gdb.base/unwind-on-each-insn.exp,
though there are further failures that are not fixed by this commit.
This change started as a wider fix that would address all the failures
in gdb.base/unwind-on-each-insn.exp, however, that wider fix needed
support for the two additional compressed instructions.
When I added support for those two compressed instructions I noticed
that some of the failures in gdb.base/unwind-on-each-insn.exp resolved
themselves!
Here's what's going on:
The reason for the failures is that GDB is trying to build the
frame-id during the last few instructions of the function. These are
the instructions that restore the frame and stack pointers just prior
to the return instruction itself.
By the time we reach the function epilogue the stack offset that we
calculated during the prologue scan is no longer valid, and so we
calculate the wrong frame-id.
However, in the particular case of interest here, the test function
'foo', the function is so simple and short (the empty function) that
GDB's prologue scan could, in theory, scan every instruction of the
function.
I say "could, in theory," because currently GDB stops the prologue
scan early when it hits an unknown instruction. The unknown
instruction happens to be one of the compressed instructions that I'm
adding support for in this commit.
Now that GDB understands the compressed instructions the prologue scan
really does go from the start of the function right up to the current
program counter. As such, GDB sees that the stack frame has been
allocated, and then deallocated, and so builds the correct frame-id.
Of course, most real functions are not as simple as the test function
'foo'. As such, we can't usually rely on scanning right up to the end
of the function -- there are some instructions we always need to stop
at because GDB can't reason about how they change the inferior
state (e.g. a function call). The test function 'bar' is just such an
example.
After this commit, we can now build the frame-id correctly for every
instruction in 'foo', but there are some tests still failing in 'bar'.