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