blob: 1e948d4d5c614f86e25e6c73cbc8be663b68f083 [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 Vyalov14857122015-10-28 19:49:50 +000032 GDBRemoteCommunicationServerPlatform(const Socket::SocketProtocol socket_protocol,
33 const char* socket_scheme);
Tamas Berghammere13c2732015-02-11 10:29:30 +000034
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000035 ~GDBRemoteCommunicationServerPlatform() override;
Tamas Berghammere13c2732015-02-11 10:29:30 +000036
Tamas Berghammerdb264a62015-03-31 09:52:22 +000037 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000038 LaunchProcess () override;
39
40 // Set both ports to zero to let the platform automatically bind to
41 // a port chosen by the OS.
42 void
43 SetPortMap (PortMap &&port_map);
44
45 //----------------------------------------------------------------------
46 // If we are using a port map where we can only use certain ports,
47 // get the next available port.
48 //
49 // If we are using a port map and we are out of ports, return UINT16_MAX
50 //
51 // If we aren't using a port map, return 0 to indicate we should bind to
52 // port 0 and then figure out which port we used.
53 //----------------------------------------------------------------------
54 uint16_t
55 GetNextAvailablePort ();
56
57 bool
58 AssociatePortWithProcess (uint16_t port, lldb::pid_t pid);
59
60 bool
61 FreePort (uint16_t port);
62
63 bool
64 FreePortForProcess (lldb::pid_t pid);
65
66 void
67 SetPortOffset (uint16_t port_offset);
68
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000069 void
70 SetInferiorArguments (const lldb_private::Args& args);
71
72 Error
73 LaunchGDBServer(const lldb_private::Args& args,
74 std::string hostname,
75 lldb::pid_t& pid,
76 uint16_t& port,
77 std::string& socket_name);
78
79 void
80 SetPendingGdbServer(lldb::pid_t pid, uint16_t port, const std::string& socket_name);
81
Tamas Berghammere13c2732015-02-11 10:29:30 +000082protected:
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000083 const Socket::SocketProtocol m_socket_protocol;
Oleksiy Vyalov14857122015-10-28 19:49:50 +000084 const std::string m_socket_scheme;
Pavel Labath6e4f19d2015-07-29 12:33:31 +000085 Mutex m_spawned_pids_mutex;
86 std::set<lldb::pid_t> m_spawned_pids;
Tamas Berghammere13c2732015-02-11 10:29:30 +000087 lldb::PlatformSP m_platform_sp;
88
89 PortMap m_port_map;
90 uint16_t m_port_offset;
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000091 struct { lldb::pid_t pid; uint16_t port; std::string socket_name; } m_pending_gdb_server;
Tamas Berghammere13c2732015-02-11 10:29:30 +000092
93 PacketResult
94 Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
95
96 PacketResult
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000097 Handle_qQueryGDBServer (StringExtractorGDBRemote &packet);
98
99 PacketResult
Pavel Labath6e4f19d2015-07-29 12:33:31 +0000100 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
101
102 PacketResult
Tamas Berghammere13c2732015-02-11 10:29:30 +0000103 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
104
105 PacketResult
106 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
107
108 PacketResult
109 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
110
111 PacketResult
112 Handle_qC (StringExtractorGDBRemote &packet);
113
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000114 PacketResult
115 Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
116
Tamas Berghammere13c2732015-02-11 10:29:30 +0000117private:
118 bool
Pavel Labath6e4f19d2015-07-29 12:33:31 +0000119 KillSpawnedProcess (lldb::pid_t pid);
120
121 bool
Tamas Berghammere13c2732015-02-11 10:29:30 +0000122 DebugserverProcessReaped (lldb::pid_t pid);
123
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000124 static const FileSpec&
125 GetDomainSocketDir();
126
127 static FileSpec
128 GetDomainSocketPath(const char* prefix);
129
Tamas Berghammere13c2732015-02-11 10:29:30 +0000130 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform);
131};
132
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000133} // namespace process_gdb_remote
134} // namespace lldb_private
135
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000136#endif // liblldb_GDBRemoteCommunicationServerPlatform_h_