blob: 646d267dcb9813cc08f6142c29360d0a737b29aa [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 lldb::PlatformSP m_platform_sp;
89
90 PortMap m_port_map;
91 uint16_t m_port_offset;
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000092 struct { lldb::pid_t pid; uint16_t port; std::string socket_name; } m_pending_gdb_server;
Tamas Berghammere13c2732015-02-11 10:29:30 +000093
94 PacketResult
95 Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
96
97 PacketResult
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000098 Handle_qQueryGDBServer (StringExtractorGDBRemote &packet);
99
100 PacketResult
Pavel Labath6e4f19d2015-07-29 12:33:31 +0000101 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
102
103 PacketResult
Tamas Berghammere13c2732015-02-11 10:29:30 +0000104 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
105
106 PacketResult
107 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
108
109 PacketResult
110 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
111
112 PacketResult
113 Handle_qC (StringExtractorGDBRemote &packet);
114
Chaoren Lin98d0a4b2015-07-14 01:09:28 +0000115 PacketResult
116 Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
117
Tamas Berghammere13c2732015-02-11 10:29:30 +0000118private:
119 bool
Pavel Labath6e4f19d2015-07-29 12:33:31 +0000120 KillSpawnedProcess (lldb::pid_t pid);
121
122 bool
Tamas Berghammere13c2732015-02-11 10:29:30 +0000123 DebugserverProcessReaped (lldb::pid_t pid);
124
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000125 static const FileSpec&
126 GetDomainSocketDir();
127
128 static FileSpec
129 GetDomainSocketPath(const char* prefix);
130
Tamas Berghammere13c2732015-02-11 10:29:30 +0000131 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform);
132};
133
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000134} // namespace process_gdb_remote
135} // namespace lldb_private
136
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000137#endif // liblldb_GDBRemoteCommunicationServerPlatform_h_