18#include "etiss/jit/types.h"
41 size_t cur = buffer.find(
c);
44 while (cur != std::string::npos)
46 if (buffer[cur - 1] !=
'}' && (cur <= 1 || buffer[cur - 2] !=
'}'))
50 cur = buffer.find(
c, cur);
57 while (buffer.length() > pos)
59 if (buffer[pos] ==
'+' || buffer[pos] ==
'-')
61 int ret = (
int)buffer[pos];
65 else if (buffer[pos] ==
'%' || buffer[pos] ==
'$')
67 std::string substr = buffer.substr(pos);
69 if (cpos == std::string::npos)
73 else if (buffer[pos] !=
' ')
79 std::cout <<
"ERROR: gdb transmission corrupted; aborting" <<
stream_code_info << std::endl;
89 if (dol == std::string::npos && per == std::string::npos)
91 return std::string::npos;
93 else if (dol == std::string::npos)
97 else if (per == std::string::npos)
103 return dol < per ? dol : per;
108 if (prefix.length() > str.length())
110 return str.substr(0, prefix.length()) == prefix;
116 if (
command ==
"QStartNoAckMode")
171 if (diamond == std::string::npos)
174 if (
buffer.length() < diamond + 1 + 2)
179 std::string tmp =
buffer.substr(1, diamond - 1);
181 for (
unsigned i = 0; i < tmp.length(); i++)
183 chksm = chksm + (
uint8_t)tmp[i];
202 if (tmp.find(
'}') == std::string::npos && tmp.find(
'*') == std::string::npos)
211 for (
unsigned i = 0; i <
command.length(); i++)
217 for (
int j = 0; j < (
int)
command[i + 1] - 29; j++)
235 for (
unsigned i = 0; i < tmp.length(); i++)
239 if (i + 1 < tmp.length())
241 command.push_back(tmp[++i] ^ 0x20);
245 std::cout <<
"ERROR: PacketProtocol::available() or its parser functions contain an error"
270 std::string pack = isnotification ?
"%" :
"$";
271 for (
unsigned i = 0; i < answer.length(); i++)
273 if (answer[i] ==
'}' || answer[i] ==
'#' || answer[i] ==
'$' || answer[i] ==
'%' || answer[i] ==
'*')
276 pack.push_back(answer[i] ^ 0x20);
280 pack.push_back(answer[i]);
285 for (
unsigned i = 1; i < pack.length() - 1; i++)
287 chksm = chksm + (
uint8_t)pack[i];
311 std::cout <<
"ERROR: gdp protocol implementation contains an error" <<
stream_code_info << std::endl;
314 std::this_thread::sleep_for(std::chrono::milliseconds(1));
size_t PacketProtocol_getPacketStart(std::string &buffer)
size_t PacketProtocol_findUE(std::string &buffer, char c)
bool PacketProtocol_startsWith(const std::string &str, const std::string &prefix)
int PacketProtocol_findResponse(std::string &buffer)
__device__ __2f16 float c
static __inline__ uint8_t
interface for gdb connections.
virtual bool isRelyable()
virtual void clearBREAK()
virtual bool pendingBREAK()
virtual std::string rcv()=0
virtual bool available()=0
virtual bool snd(std::string answer)=0
virtual PacketProtocol & getPacketProtocol()
implements gdb's packet protocol
virtual bool snd(std::string answer, bool isnotification)
virtual std::string rcv(bool &isnotification)
virtual bool available(bool block=false)
bool command_isnotification
virtual void tryReadPacket()
virtual bool _available(bool block)
PacketProtocol(Connection &connection)
uint8_t toByte(char h, char l)
converts 2 hex characters to a byte
std::string fromByte(uint8_t byte)
converts a byte to a hex string (without "0x" prefix);