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

    <tr>
        <th>Summary</th>
        <td>
            [LLDB] [GDB server] Host byte order incorrectly used for `g`, `G`, `p`, `P` packet types
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    The [GDB server protocol specification](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets) is very clear on the topic:

> ‘g’
> Read general registers.

> Reply:

> ‘XX…’
> Each byte of register data is described by two hex digits. The bytes with the register are transmitted in **target byte order**. The size of each register and their position within the ‘g’ packet are determined by the target description (see [Target Descriptions](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Target-Descriptions.html#Target-Descriptions)); in the absence of a target description, this is done using code internal to GDB; typically this is some customary register layout for the architecture in question.

However, LLDB incorrectly uses the **debugger host byte order** (which may not be the same as the target byte order):

https://github.com/llvm/llvm-project/blob/f33821628d0e03f5389e1f4339b4d10f6a8883b5/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp#L3566-L3578
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVE9zo7gT_TTypSsuLIECBw5xHGcOOaSm5jBXIbVBvxGIkYT9Yz_9lgS2k9lctmqrqKJR06__vKcW3ut2QKxJsSfFYSOm0FlXXzod8Pck3K9NY9Vc_-gQSLF_PezBozujg9HZYKU14EeU-qSlCNoOpDgQWnYhjJ6wJ0KPhB69nZzEi3C4ta4l9NiqhtCjnJzDIRB6tIPRAyor_eLcdqE3hB7fhfyFwa-fbP0ktALt4YxuBmlQOLADhA4h2FHLmDVLD3sB8kJJmZGqbK9WtXq-o1DQ4oBOGHDYah_Q-e017vrTaOYV8H56A_35czWf-J_wL0J20MwB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