blob: 95fa18d4b40716cbb1427312cec0d6aaed1a4ebf [file] [log] [blame]
Tamas Berghammere13c2732015-02-11 10:29:30 +00001//===-- 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
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000013// C Includes
14// C++ Includes
15#include <map>
Pavel Labath6e4f19d2015-07-29 12:33:31 +000016#include <set>
17
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000018// Other libraries and framework includes
19// Project includes
20#include "GDBRemoteCommunicationServerCommon.h"
21#include "lldb/Host/Socket.h"
22
Tamas Berghammerdb264a62015-03-31 09:52:22 +000023namespace lldb_private {
24namespace process_gdb_remote {
25
Tamas Berghammere13c2732015-02-11 10:29:30 +000026class GDBRemoteCommunicationServerPlatform :
27 public GDBRemoteCommunicationServerCommon
28{
29public:
30 typedef std::map<uint16_t, lldb::pid_t> PortMap;
31
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000032 GDBRemoteCommunicationServerPlatform(const Socket::SocketProtocol socket_protocol);
Tamas Berghammere13c2732015-02-11 10:29:30 +000033
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000034 ~GDBRemoteCommunicationServerPlatform() override;
Tamas Berghammere13c2732015-02-11 10:29:30 +000035
Tamas Berghammerdb264a62015-03-31 09:52:22 +000036 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000037 LaunchProcess () override;
38
39 // Set both ports to zero to let the platform automatically bind to
40 // a port chosen by the OS.
41 void
42 SetPortMap (PortMap &&port_map);
43
44 //----------------------------------------------------------------------
45 // If we are using a port map where we can only use certain ports,
46 // get the next available port.
47 //
48 // If we are using a port map and we are out of ports, return UINT16_MAX
49 //
50 // If we aren't using a port map, return 0 to indicate we should bind to
51 // port 0 and then figure out which port we used.
52 //----------------------------------------------------------------------
53 uint16_t
54 GetNextAvailablePort ();
55
56 bool
57 AssociatePortWithProcess (uint16_t port, lldb::pid_t pid);
58
59 bool
60 FreePort (uint16_t port);
61
62 bool
63 FreePortForProcess (lldb::pid_t pid);
64
65 void
66 SetPortOffset (uint16_t port_offset);
67
68protected:
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000069 const Socket::SocketProtocol m_socket_protocol;
Pavel Labath6e4f19d2015-07-29 12:33:31 +000070 Mutex m_spawned_pids_mutex;
71 std::set<lldb::pid_t> m_spawned_pids;
Tamas Berghammere13c2732015-02-11 10:29:30 +000072 lldb::PlatformSP m_platform_sp;
73
74 PortMap m_port_map;
75 uint16_t m_port_offset;
76
77 PacketResult
78 Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
79
80 PacketResult
Pavel Labath6e4f19d2015-07-29 12:33:31 +000081 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
82
83 PacketResult
Tamas Berghammere13c2732015-02-11 10:29:30 +000084 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
85
86 PacketResult
87 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
88
89 PacketResult
90 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
91
92 PacketResult
93 Handle_qC (StringExtractorGDBRemote &packet);
94
Chaoren Lin98d0a4b2015-07-14 01:09:28 +000095 PacketResult
96 Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
97
Tamas Berghammere13c2732015-02-11 10:29:30 +000098private:
99 bool
Pavel Labath6e4f19d2015-07-29 12:33:31 +0000100 KillSpawnedProcess (lldb::pid_t pid);
101
102 bool
Tamas Berghammere13c2732015-02-11 10:29:30 +0000103 DebugserverProcessReaped (lldb::pid_t pid);
104
105 static bool
106 ReapDebugserverProcess (void *callback_baton,
107 lldb::pid_t pid,
108 bool exited,
109 int signal,
110 int status);
111
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000112 static const FileSpec&
113 GetDomainSocketDir();
114
115 static FileSpec
116 GetDomainSocketPath(const char* prefix);
117
Tamas Berghammere13c2732015-02-11 10:29:30 +0000118 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform);
119};
120
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000121} // namespace process_gdb_remote
122} // namespace lldb_private
123
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000124#endif // liblldb_GDBRemoteCommunicationServerPlatform_h_