Skip to content

Commit

Permalink
Fix LLDB RSP client to decode '$O' packets incorrectly
Browse files Browse the repository at this point in the history
Character with ASCII code 0 is incorrectly treated by LLDB as the end of
RSP packet. The left of the debugger server output is silently ignored.

Patch from evgeny.leviant@gmail.com
Reviewed by: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D12523

llvm-svn: 247908
  • Loading branch information
Dawn Perchik committed Sep 17, 2015
1 parent 0537f41 commit 554a857
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lldb/include/lldb/Utility/StringExtractor.h
Expand Up @@ -114,6 +114,9 @@ class StringExtractor
uint8_t
GetHexU8 (uint8_t fail_value = 0, bool set_eof_on_fail = true);

bool
GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail = true);

bool
GetNameColonValue (std::string &name, std::string &value);

Expand Down
Expand Up @@ -1262,9 +1262,13 @@ GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse
got_async_packet = true;
std::string inferior_stdout;
inferior_stdout.reserve(response.GetBytesLeft () / 2);
char ch;
while ((ch = response.GetHexU8()) != '\0')
inferior_stdout.append(1, ch);

uint8_t ch;
while (response.GetHexU8Ex(ch))
{
if (ch != 0)
inferior_stdout.append(1, (char)ch);
}
process->AppendSTDOUT (inferior_stdout.c_str(), inferior_stdout.size());
}
break;
Expand Down
13 changes: 11 additions & 2 deletions lldb/source/Utility/StringExtractor.cpp
Expand Up @@ -124,15 +124,24 @@ StringExtractor::DecodeHexU8()
//----------------------------------------------------------------------
uint8_t
StringExtractor::GetHexU8 (uint8_t fail_value, bool set_eof_on_fail)
{
GetHexU8Ex(fail_value, set_eof_on_fail);
return fail_value;
}

bool
StringExtractor::GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail)
{
int byte = DecodeHexU8();
if (byte == -1)
{
if (set_eof_on_fail || m_index >= m_packet.size())
m_index = UINT64_MAX;
return fail_value;
// ch should not be changed in case of failure
return false;
}
return (uint8_t)byte;
ch = (uint8_t)byte;
return true;
}

uint32_t
Expand Down

0 comments on commit 554a857

Please sign in to comment.