2010-06-09 00:52:24 +08:00
|
|
|
//===-- StringExtractorGDBRemote.cpp ----------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
2011-03-23 10:02:29 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2011-03-23 10:02:29 +08:00
|
|
|
#include "Utility/StringExtractorGDBRemote.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::ResponseType
|
|
|
|
StringExtractorGDBRemote::GetResponseType () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (m_packet.empty())
|
|
|
|
return eUnsupported;
|
|
|
|
|
|
|
|
switch (m_packet[0])
|
|
|
|
{
|
|
|
|
case 'E':
|
|
|
|
if (m_packet.size() == 3 &&
|
|
|
|
isxdigit(m_packet[1]) &&
|
|
|
|
isxdigit(m_packet[2]))
|
|
|
|
return eError;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
if (m_packet.size() == 2 && m_packet[1] == 'K')
|
|
|
|
return eOK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
if (m_packet.size() == 1)
|
|
|
|
return eAck;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
if (m_packet.size() == 1)
|
|
|
|
return eNack;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return eResponse;
|
|
|
|
}
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::ServerPacketType
|
|
|
|
StringExtractorGDBRemote::GetServerPacketType () const
|
|
|
|
{
|
2011-04-12 13:54:46 +08:00
|
|
|
#define PACKET_MATCHES(s) ((packet_size == (sizeof(s)-1)) && (strcmp((packet_cstr),(s)) == 0))
|
|
|
|
#define PACKET_STARTS_WITH(s) ((packet_size >= (sizeof(s)-1)) && ::strncmp(packet_cstr, s, (sizeof(s)-1))==0)
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
// Empty is not a supported packet...
|
|
|
|
if (m_packet.empty())
|
|
|
|
return eServerPacketType_invalid;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
const size_t packet_size = m_packet.size();
|
2011-03-22 12:00:09 +08:00
|
|
|
const char *packet_cstr = m_packet.c_str();
|
|
|
|
switch (m_packet[0])
|
|
|
|
{
|
2011-03-23 08:09:55 +08:00
|
|
|
case '\x03':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1) return eServerPacketType_interrupt;
|
2011-03-23 08:09:55 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case '-':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1) return eServerPacketType_nack;
|
2011-03-22 12:00:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
2011-04-12 13:54:46 +08:00
|
|
|
if (packet_size == 1) return eServerPacketType_ack;
|
2011-03-22 12:00:09 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'A':
|
|
|
|
return eServerPacketType_A;
|
|
|
|
|
2011-03-24 12:28:38 +08:00
|
|
|
case 'Q':
|
2011-04-12 13:54:46 +08:00
|
|
|
switch (packet_cstr[1])
|
|
|
|
{
|
|
|
|
case 'E':
|
|
|
|
if (PACKET_STARTS_WITH ("QEnvironment:")) return eServerPacketType_QEnvironment;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
if (PACKET_MATCHES ("QStartNoAckMode")) return eServerPacketType_QStartNoAckMode;
|
|
|
|
else if (PACKET_STARTS_WITH ("QSetDisableASLR:")) return eServerPacketType_QSetDisableASLR;
|
|
|
|
else if (PACKET_STARTS_WITH ("QSetSTDIN:")) return eServerPacketType_QSetSTDIN;
|
|
|
|
else if (PACKET_STARTS_WITH ("QSetSTDOUT:")) return eServerPacketType_QSetSTDOUT;
|
|
|
|
else if (PACKET_STARTS_WITH ("QSetSTDERR:")) return eServerPacketType_QSetSTDERR;
|
|
|
|
else if (PACKET_STARTS_WITH ("QSetWorkingDir:")) return eServerPacketType_QSetWorkingDir;
|
|
|
|
break;
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'L':
|
|
|
|
if (PACKET_STARTS_WITH ("QLaunchArch:")) return eServerPacketType_QLaunchArch;
|
|
|
|
break;
|
2011-04-12 13:54:46 +08:00
|
|
|
}
|
2011-03-24 12:28:38 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
case 'q':
|
2011-04-12 13:54:46 +08:00
|
|
|
switch (packet_cstr[1])
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
if (PACKET_MATCHES ("qsProcessInfo")) return eServerPacketType_qsProcessInfo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
if (PACKET_STARTS_WITH ("qfProcessInfo")) return eServerPacketType_qfProcessInfo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
if (packet_size == 2) return eServerPacketType_qC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
if (PACKET_STARTS_WITH ("qGroupName:")) return eServerPacketType_qGroupName;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
if (PACKET_MATCHES ("qHostInfo")) return eServerPacketType_qHostInfo;
|
|
|
|
break;
|
|
|
|
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'K':
|
|
|
|
if (PACKET_STARTS_WITH ("qKillSpawnedProcess")) return eServerPacketType_qKillSpawnedProcess;
|
|
|
|
break;
|
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
case 'L':
|
2013-08-27 07:57:52 +08:00
|
|
|
if (PACKET_STARTS_WITH ("qLaunchGDBServer")) return eServerPacketType_qLaunchGDBServer;
|
2011-04-12 13:54:46 +08:00
|
|
|
if (PACKET_MATCHES ("qLaunchSuccess")) return eServerPacketType_qLaunchSuccess;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
2013-08-27 07:57:52 +08:00
|
|
|
if (PACKET_STARTS_WITH ("qProcessInfoPID:")) return eServerPacketType_qProcessInfoPID;
|
|
|
|
if (PACKET_STARTS_WITH ("qPlatform_RunCommand:")) return eServerPacketType_qPlatform_RunCommand;
|
|
|
|
if (PACKET_STARTS_WITH ("qPlatform_IO_MkDir:")) return eServerPacketType_qPlatform_IO_MkDir;
|
2011-04-12 13:54:46 +08:00
|
|
|
break;
|
2013-08-27 07:57:52 +08:00
|
|
|
|
2011-04-12 13:54:46 +08:00
|
|
|
|
|
|
|
case 'S':
|
|
|
|
if (PACKET_STARTS_WITH ("qSpeedTest:")) return eServerPacketType_qSpeedTest;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
if (PACKET_STARTS_WITH ("qUserName:")) return eServerPacketType_qUserName;
|
|
|
|
break;
|
|
|
|
}
|
2011-03-22 12:00:09 +08:00
|
|
|
break;
|
2013-08-27 07:57:52 +08:00
|
|
|
case 'v':
|
|
|
|
if (PACKET_STARTS_WITH("vFile:"))
|
|
|
|
{
|
|
|
|
if (PACKET_STARTS_WITH("vFile:open:")) return eServerPacketType_vFile_Open;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:close:")) return eServerPacketType_vFile_Close;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:pread")) return eServerPacketType_vFile_pRead;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:pwrite")) return eServerPacketType_vFile_pWrite;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:size")) return eServerPacketType_vFile_Size;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:exists")) return eServerPacketType_vFile_Exists;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:stat")) return eServerPacketType_vFile_Stat;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:mode")) return eServerPacketType_vFile_Mode;
|
|
|
|
else if (PACKET_STARTS_WITH("vFile:MD5")) return eServerPacketType_vFile_MD5;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2011-03-22 12:00:09 +08:00
|
|
|
}
|
|
|
|
return eServerPacketType_unimplemented;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::IsOKResponse() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-22 12:00:09 +08:00
|
|
|
return GetResponseType () == eOK;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::IsUnsupportedResponse() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-22 12:00:09 +08:00
|
|
|
return GetResponseType () == eUnsupported;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::IsNormalResponse() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-22 12:00:09 +08:00
|
|
|
return GetResponseType () == eResponse;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-03-22 12:00:09 +08:00
|
|
|
StringExtractorGDBRemote::IsErrorResponse() const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-22 12:00:09 +08:00
|
|
|
return GetResponseType () == eError &&
|
2010-06-09 00:52:24 +08:00
|
|
|
m_packet.size() == 3 &&
|
|
|
|
isxdigit(m_packet[1]) &&
|
|
|
|
isxdigit(m_packet[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
StringExtractorGDBRemote::GetError ()
|
|
|
|
{
|
2011-03-22 12:00:09 +08:00
|
|
|
if (GetResponseType() == eError)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SetFilePos(1);
|
|
|
|
return GetHexU8(255);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-27 07:57:52 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
StringExtractorGDBRemote::GetEscapedBinaryData (std::string &str)
|
|
|
|
{
|
|
|
|
str.clear();
|
|
|
|
char ch;
|
|
|
|
while (GetBytesLeft())
|
|
|
|
{
|
|
|
|
ch = GetChar();
|
|
|
|
if (ch == 0x7d)
|
|
|
|
ch = (GetChar() ^ 0x20);
|
|
|
|
str.append(1,ch);
|
|
|
|
}
|
|
|
|
return str.size();
|
|
|
|
}
|
|
|
|
|