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;
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
if (PACKET_MATCHES ("qLaunchGDBServer")) return eServerPacketType_qLaunchGDBServer;
|
|
|
|
if (PACKET_MATCHES ("qLaunchSuccess")) return eServerPacketType_qLaunchSuccess;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
if (PACKET_STARTS_WITH ("qProcessInfoPID:")) return eServerPacketType_qProcessInfoPID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|