11#include "lldb/Host/Config.h"
19#include "llvm/Support/JSON.h"
52 switch (packet_type) {
58 error.SetErrorString(
"invalid packet");
71 packet_result = handler_it->second(packet,
error, interrupt, quit);
76 error.SetErrorString(
"lost connection");
79 error.SetErrorString(
"timeout");
99 int packet_len = ::snprintf(packet,
sizeof(packet),
"E%2.2x", err);
100 assert(packet_len < (
int)
sizeof(packet));
108 packet.
Printf(
"E%2.2x;",
static_cast<uint8_t
>(
error.GetError()));
118 std::unique_ptr<llvm::ErrorInfoBase> EIB;
119 std::unique_ptr<UnimplementedError> UE;
120 llvm::handleAllErrors(
122 [&](std::unique_ptr<UnimplementedError> E) { UE = std::move(E); },
123 [&](std::unique_ptr<llvm::ErrorInfoBase> E) { EIB = std::move(E); });
141 LLDB_LOGF(log,
"GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)",
143 message ? message :
"");
154 std::string json_string;
155 raw_string_ostream os(json_string);
159 escaped_response.
PutEscapedBytes(json_string.c_str(), json_string.size());
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
bool IsConnected() const
Check if the connection is valid.
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
llvm::StringRef GetString() const
size_t PutStringAsRawHex8(llvm::StringRef s)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
std::function< PacketResult(StringExtractorGDBRemote &packet, Status &error, bool &interrupt, bool &quit)> PacketHandler
void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketHandler handler)
~GDBRemoteCommunicationServer() override
std::map< StringExtractorGDBRemote::ServerPacketType, PacketHandler > m_packet_handlers
GDBRemoteCommunicationServer()
bool m_send_error_strings
PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet)
PacketResult SendErrorResponse(const Status &error)
PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, const char *error_message)
PacketResult GetPacketAndSendResponse(Timeout< std::micro > timeout, Status &error, bool &interrupt, bool &quit)
PacketResult SendJSONResponse(const llvm::json::Value &value)
Serialize and send a JSON object response.
PacketResult SendUnimplementedResponse(const char *packet)
PacketResult SendOKResponse()
PacketResult ReadPacket(StringExtractorGDBRemote &response, Timeout< std::micro > timeout, bool sync_on_timeout)
PacketResult SendPacketNoLock(llvm::StringRef payload)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.