<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/124269>124269</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lldb - Registers are not restored if PrepareTrivialCall fails
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DavidSpickett
      </td>
    </tr>
</table>

<pre>
    In this example I have bodged the function to return false after writing the argument registers:
```
(lldb) run
Process 3666152 launched: '/tmp/test.o' (aarch64)
Process 3666152 stopped
* thread #1, name = 'test.o', stop reason = breakpoint 1.1
    frame #0: 0x0000aaaaaaaaa72c test.o`main at test.c:4:10
   1    int bar(int a) { return a*2; }
   2
   3    int main() {
-> 4      return 0;
   5    }
(lldb) register read --all
General Purpose Registers:
        x0 = 0x0000000000000001
        x1 = 0x0000fffffffff3a8
        x2 = 0x0000fffffffff3b8
        x3 = 0x0000aaaaaaaaa72c  test.o`main at test.c:4:10
        x4 = 0x0000000000000000
        x5 = 0x209f561e2fa866d7
        x6 = 0x0000fffff7facc90  libc.so.6`initial
        x7 = 0x0000004554415649

(lldb) p bar(1)

error: Can't evaluate the expression without a running target due to: Interpreter doesn't handle one of the expression's opcodes
```
Here we should have restored the original values, but:
```
(lldb) register read --all
General Purpose Registers:
        x0 = 0x0000000000000063
        x1 = 0x0000000000000063
        x2 = 0x0000000000000063
        x3 = 0x0000000000000063
        x4 = 0x0000000000000063
        x5 = 0x0000000000000063
```
We did not.

This is 99.9% of the time not a problem as preparing a trivial call does trivial things, but in adding Arm GCS support I had to handle the failure path and found this.

For that, I'm going to handle the one case I need, but I will come back an try to make LLDB restore everything properly.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU1v2zgQ_TX0ZWCDor6sgw9Ksu4G6KHYFtjzSBxJ3FCkQFJO8u8XlOTWLtJFL0sYl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