1 //===-- GDBRemoteCommunicationServer.h --------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_GDBRemoteCommunicationServer_h_ 11 #define liblldb_GDBRemoteCommunicationServer_h_ 12 13 #include <functional> 14 #include <map> 15 16 #include "GDBRemoteCommunication.h" 17 #include "lldb/lldb-private-forward.h" 18 19 class StringExtractorGDBRemote; 20 21 namespace lldb_private { 22 namespace process_gdb_remote { 23 24 class ProcessGDBRemote; 25 26 class GDBRemoteCommunicationServer : public GDBRemoteCommunication { 27 public: 28 using PortMap = std::map<uint16_t, lldb::pid_t>; 29 using PacketHandler = 30 std::function<PacketResult(StringExtractorGDBRemote &packet, 31 Status &error, bool &interrupt, bool &quit)>; 32 33 GDBRemoteCommunicationServer(const char *comm_name, 34 const char *listener_name); 35 36 ~GDBRemoteCommunicationServer() override; 37 38 void 39 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, 40 PacketHandler handler); 41 42 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout, 43 Status &error, bool &interrupt, 44 bool &quit); 45 46 // After connecting, do a little handshake with the client to make sure 47 // we are at least communicating 48 bool HandshakeWithClient(); 49 50 protected: 51 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> 52 m_packet_handlers; 53 bool m_exit_now; // use in asynchronous handling to indicate process should 54 // exit. 55 56 bool m_send_error_strings = false; // If the client enables this then 57 // we will send error strings as well. 58 59 PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet); 60 61 PacketResult SendErrorResponse(const Status &error); 62 63 PacketResult SendUnimplementedResponse(const char *packet); 64 65 PacketResult SendErrorResponse(uint8_t error); 66 67 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, 68 const char *error_message); 69 70 PacketResult SendOKResponse(); 71 72 private: 73 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer); 74 }; 75 76 } // namespace process_gdb_remote 77 } // namespace lldb_private 78 79 #endif // liblldb_GDBRemoteCommunicationServer_h_ 80