blob: 1f4d08c64e00946c6e2d9c6a26cfb830c67df65b [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>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000016#include <mutex>
Pavel Labath6e4f19d2015-07-29 12:33:31 +000017#include <set>
18
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000019// Other libraries and framework includes
20// Project includes
21#include "GDBRemoteCommunicationServerCommon.h"
22#include "lldb/Host/Socket.h"
23
Tamas Berghammerdb264a62015-03-31 09:52:22 +000024namespace lldb_private {
25namespace process_gdb_remote {
26
Tamas Berghammere13c2732015-02-11 10:29:30 +000027class GDBRemoteCommunicationServerPlatform :
28 public GDBRemoteCommunicationServerCommon
29{
30public:
31 typedef std::map<uint16_t, lldb::pid_t> PortMap;
32
Oleksiy Vyalov14857122015-10-28 19:49:50 +000033 GDBRemoteCommunicationServerPlatform(const Socket::SocketProtocol socket_protocol,
34 const char* socket_scheme);
Tamas Berghammere13c2732015-02-11 10:29:30 +000035
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000036 ~GDBRemoteCommunicationServerPlatform() override;
Tamas Berghammere13c2732015-02-11 10:29:30 +000037
Tamas Berghammerdb264a62015-03-31 09:52:22 +000038 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000039 LaunchProcess () override;
40
41 // Set both ports to zero to let the platform automatically bind to
42 // a port chosen by the OS.
43 void
44 SetPortMap (PortMap &&port_map);
45
46 //----------------------------------------------------------------------
47 // If we are using a port map where we can only use certain ports,
48 // get the next available port.
49 //
50 // If we are using a port map and we are out of ports, return UINT16_MAX
51 //
52 // If we aren't using a port map, return 0 to indicate we should bind to
53 // port 0 and then figure out which port we used.
54 //----------------------------------------------------------------------
55 uint16_t
56 GetNextAvailablePort ();
57
58 bool
59 AssociatePortWithProcess (uint16_t port, lldb::pid_t pid);
60
61 bool
62 FreePort (uint16_t port);
63
64 bool
65 FreePortForProcess (lldb::pid_t pid);
66
67 void
68 SetPortOffset (uint16_t port_offset);
69
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000070 void
71 SetInferiorArguments (const lldb_private::Args& args);
72
73 Error
74 LaunchGDBServer(const lldb_private::Args& args,
75 std::string hostname,
76 lldb::pid_t& pid,
77 uint16_t& port,
78 std::string& socket_name);
79
80 void
81 SetPendingGdbServer(lldb::pid_t pid, uint16_t port, const std::string& socket_name);
82
Tamas Berghammere13c2732015-02-11 10:29:30 +000083protected:
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000084 const Socket::SocketProtocol m_socket_protocol;
Oleksiy Vyalov14857122015-10-28 19:49:50 +000085 const std::string m_socket_scheme;
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000086 std::recursive_mutex m_spawned_pids_mutex;
Pavel Labath6e4f19d2015-07-29 12:33:31 +000087 std::set<lldb::pid_t> m_spawned_pids;
Tamas Berghammere13c2732015-02-11 10:29:30 +000088
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_