[lldb-dev] [PATCH] Handle escape characters in binary gdbserver output

Greg Clayton gclayton at apple.com
Mon Feb 24 10:43:46 PST 2014


Looks good.

On Feb 24, 2014, at 9:15 AM, Steve Pucci <spucci at google.com> wrote:

> I'm attaching a patch that fixes handling of gdbserver binary packets received.  We were not properly handling the escape character 0x7d.  https://sourceware.org/gdb/onlinedocs/gdb/Overview.html#Overview says
> 
> The binary data representation uses 7d (ascii ‘}’) as an escape character. Any escaped byte is transmitted as the escape character followed by the original character XORed with 0x20. For example, the byte 0x7d would be transmitted as the two bytes 0x7d 0x5d. The bytes 0x23 (ascii ‘#’), 0x24 (ascii ‘$’), and 0x7d (ascii ‘}’) must always be escaped. Responses sent by the stub must also escape 0x2a (ascii ‘*’), so that it is not interpreted as the start of a run-length encoded sequence (described next).
> 
> I've verified that this fixes a problem with the reading of the auxv table on 64-bit Ubuntu 12.04 via the qXfer:auxv:read packet response; prior to this fix, the fields of the auxv table were obviously wrong, and now they look reasonable (though there is another problem which is preventing the correct handling of the table).
> 
> Thanks,
>   Steve
> 
> diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> index 1ec75a4..72600d8 100644
> --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> @@ -497,6 +497,13 @@ GDBRemoteCommunication::CheckForPacket (const uint8_t *src, size_t src_len, Stri
>                      for (int i = 0; i < repeat_count; ++i)
>                          packet_str.push_back(char_to_repeat);
>                  }
> +                else if (*c == 0x7d)
> +                {
> +                    // 0x7d is the escape character.  The next character is to
> +                    // be XOR'd with 0x20.
> +                    char escapee = *++c ^ 0x20;
> +                    packet_str.push_back(escapee);
> +                }
>                  else
>                  {
>                      packet_str.push_back(*c);
> 
> <patch-escapeBinaryPackets.txt>_______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev





More information about the lldb-dev mailing list