1 //===-- GDBRemoteCommunicationServerPlatform.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_GDBRemoteCommunicationServerPlatform_h_
11 #define liblldb_GDBRemoteCommunicationServerPlatform_h_
12 
13 #include "GDBRemoteCommunicationServerCommon.h"
14 
15 namespace lldb_private {
16 namespace process_gdb_remote {
17 
18 class GDBRemoteCommunicationServerPlatform :
19     public GDBRemoteCommunicationServerCommon
20 {
21 public:
22     typedef std::map<uint16_t, lldb::pid_t> PortMap;
23 
24     GDBRemoteCommunicationServerPlatform();
25 
26     virtual
27     ~GDBRemoteCommunicationServerPlatform();
28 
29     Error
30     LaunchProcess () override;
31 
32     // Set both ports to zero to let the platform automatically bind to
33     // a port chosen by the OS.
34     void
35     SetPortMap (PortMap &&port_map);
36 
37     //----------------------------------------------------------------------
38     // If we are using a port map where we can only use certain ports,
39     // get the next available port.
40     //
41     // If we are using a port map and we are out of ports, return UINT16_MAX
42     //
43     // If we aren't using a port map, return 0 to indicate we should bind to
44     // port 0 and then figure out which port we used.
45     //----------------------------------------------------------------------
46     uint16_t
47     GetNextAvailablePort ();
48 
49     bool
50     AssociatePortWithProcess (uint16_t port, lldb::pid_t pid);
51 
52     bool
53     FreePort (uint16_t port);
54 
55     bool
56     FreePortForProcess (lldb::pid_t pid);
57 
58     void
59     SetPortOffset (uint16_t port_offset);
60 
61 protected:
62     lldb::PlatformSP m_platform_sp;
63 
64     PortMap m_port_map;
65     uint16_t m_port_offset;
66 
67     PacketResult
68     Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
69 
70     PacketResult
71     Handle_qProcessInfo (StringExtractorGDBRemote &packet);
72 
73     PacketResult
74     Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
75 
76     PacketResult
77     Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
78 
79     PacketResult
80     Handle_qC (StringExtractorGDBRemote &packet);
81 
82     PacketResult
83     Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
84 
85 private:
86     bool
87     DebugserverProcessReaped (lldb::pid_t pid);
88 
89     static bool
90     ReapDebugserverProcess (void *callback_baton,
91                             lldb::pid_t pid,
92                             bool exited,
93                             int signal,
94                             int status);
95 
96     //------------------------------------------------------------------
97     // For GDBRemoteCommunicationServerPlatform only
98     //------------------------------------------------------------------
99     DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform);
100 };
101 
102 } // namespace process_gdb_remote
103 } // namespace lldb_private
104 
105 #endif  // liblldb_GDBRemoteCommunicationServerPlatform_h_
106