<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88744>88744</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
GDB will not accept Target XML produced by lldb-server on AArch64
</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>
This is on AArch64 but I bet this applies broadly. If you connect gdb to an lldb-server you'll see:
```
Sending packet: $Hg0#df...Packet received: Eff
Sending packet: $qXfer:features:read:target.xml:0,1000#0c...Packet received: m<?xml version="1.0"?>\n<target version="1.0">\n <architecture>aarch64</architecture>\n <feature>\n <reg name="x0" bitsize="64" regnum="0" encoding="uint" format="hex" group="General Purpose Registers" ehframe_regnum="0" dwarf_regnum="0" generic="arg1" />\n <reg name="x1" bitsize="64" regnum="1" encoding="uint" format="hex" group="General Purpose Registers" ehframe_regnum="1" dwarf_regnum="1" generic="arg2" />\n <reg name="x2" bitsize="64" regnum="2" encoding="uint" format="hex" group="General Purpose [3585 bytes omitted]
<...>
warning: while parsing target description (at line 4): Required attribute "name" of <feature> not specified
warning: Could not load XML target description; ignoring
```
This is with GDB 9.2.
We can fix the warning by adding a name to the `<feature` element, however when I tried this, GDB still rejected the XML.
```
gdbarch_find_by_info: info.bfd_arch_info aarch64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0xaaaadc307e80
gdbarch_find_by_info: info.tdep_info 0x0
gdbarch_find_by_info: Target rejected architecture
gdbarch_update_p: Architecture not found
warning: Architecture rejected target-supplied description
```
I think this is because it did not find the expected feature name. Even copying `org.gnu.gdb.aarch64.core`, which is what GDB uses, didn't help here (see `GDBRemoteCommunicationServerLLGS::BuildTargetXml`). Perhaps it is looking for a set of features.
With GDB 9.2 you can still use the debugger though I suspect anything above the CPSR register is going to be corrupted because since https://github.com/llvm/llvm-project/commit/b8985ba0adb5fd881bb301fbc79370b86396e658 we have 32 bits of padding between CPSR and V0.
This isn't a problem inside of lldb-server but when we make the `g` packet response we pack the data according to this struct size and this leaves the gap. When GDB falls back to the default target config when the XML parsing fails, it assumes all the registers in that packet will be packed without padding.
Another issue is that lldb includes `tpidr` in the `g` response (see `GetUserRegisterCount`) and this means when you try to read `fpcr`, `v0`, any floating point register, you get this error:
```
Remote 'g' packet reply is too long (expected 788 bytes, got 800 bytes)
```
It's likely that lldb-16 is the last version that would have worked with gdb's fallbacks.
The usual advice is to make XML work properly and then we won't need these fallbacks and hardcoded register contexts. Indeed, I don't see anywhere in lldb that actually makes use of the `g` packet, we are just able to respond to one.
If we do want this to work I think we ignore the `g` packet issue and focus on making XML work. Adding feature names to all registers is hopefully a refactoring job as they are already split into groups inside lldb-server. I do wonder if lldb is able to cope with multiple feature elements in the XML, but it connects to gdb-server and qemu fine so I assume it is.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WN9v2zgS_muYl0EFWfIP-cEPjtP0AnQPRbt727eAIkcSW4pU-cOO768_DCUl8da3mwMOCxS1PSI5nG---WYU7r1qDeKOrW7Z6u6Gx9BZt7vjRyW_DEp8xxBuaivPu1875UF5sAb2eye69RLqGOABagwQ6CEfBq3QQ-0sl_qcwUMDZxtBWGNQBGhlDcECN6C1rN95dEd0tIIVG63BI7Jyz_I7lu_ZOp_-pZ9f0EhlWhg4XYiVe2DF8h9tzopSNlmWfUp2cChQHVHSgvdN8yd7f3xt0LFy3yAP0aFn5d4hp42BuxZD9tRrVu5zVhwWeU5-cnHdT8_KAyvvn3oNR3ReWcPKO1YUiyxnRcHKe1a-Z6uDYeVhPPr6srQGWHngTnQqoKBrsfI95wlqclLc_-FZ2kJ7piieTcnosAXDexz9PJEbqFXw6t-Tab0kk8PWxH60pDVohCXARlNUJpC1sa7nYbR1-ESm1tk4jJYPaNBxDZ-iG6xH-Iyt8gG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