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 // C Includes 14 // C++ Includes 15 #include <functional> 16 #include <map> 17 18 // Other libraries and framework includes 19 // Project includes 20 #include "GDBRemoteCommunication.h" 21 #include "lldb/lldb-private-forward.h" 22 23 class StringExtractorGDBRemote; 24 25 namespace lldb_private { 26 namespace process_gdb_remote { 27 28 class ProcessGDBRemote; 29 30 class GDBRemoteCommunicationServer : public GDBRemoteCommunication { 31 public: 32 using PortMap = std::map<uint16_t, lldb::pid_t>; 33 using PacketHandler = 34 std::function<PacketResult(StringExtractorGDBRemote &packet, Error &error, 35 bool &interrupt, bool &quit)>; 36 37 GDBRemoteCommunicationServer(const char *comm_name, 38 const char *listener_name); 39 40 ~GDBRemoteCommunicationServer() override; 41 42 void 43 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, 44 PacketHandler handler); 45 46 PacketResult GetPacketAndSendResponse(uint32_t timeout_usec, Error &error, 47 bool &interrupt, bool &quit); 48 49 // After connecting, do a little handshake with the client to make sure 50 // we are at least communicating 51 bool HandshakeWithClient(); 52 53 protected: 54 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> 55 m_packet_handlers; 56 bool m_exit_now; // use in asynchronous handling to indicate process should 57 // exit. 58 59 PacketResult SendUnimplementedResponse(const char *packet); 60 61 PacketResult SendErrorResponse(uint8_t error); 62 63 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, 64 const char *error_message); 65 66 PacketResult SendOKResponse(); 67 68 private: 69 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer); 70 }; 71 72 } // namespace process_gdb_remote 73 } // namespace lldb_private 74 75 #endif // liblldb_GDBRemoteCommunicationServer_h_ 76