1 //===-- GDBRemoteCommunicationServerPlatform.h ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GDBRemoteCommunicationServerPlatform_h_
11 #define liblldb_GDBRemoteCommunicationServerPlatform_h_
19 // Other libraries and framework includes
21 #include "GDBRemoteCommunicationServerCommon.h"
22 #include "lldb/Host/Socket.h"
24 namespace lldb_private {
25 namespace process_gdb_remote {
27 class GDBRemoteCommunicationServerPlatform
28 : public GDBRemoteCommunicationServerCommon {
30 typedef std::map<uint16_t, lldb::pid_t> PortMap;
32 GDBRemoteCommunicationServerPlatform(
33 const Socket::SocketProtocol socket_protocol, const char *socket_scheme);
35 ~GDBRemoteCommunicationServerPlatform() override;
37 Status LaunchProcess() override;
39 // Set both ports to zero to let the platform automatically bind to
40 // a port chosen by the OS.
41 void SetPortMap(PortMap &&port_map);
43 //----------------------------------------------------------------------
44 // If we are using a port map where we can only use certain ports,
45 // get the next available port.
47 // If we are using a port map and we are out of ports, return UINT16_MAX
49 // If we aren't using a port map, return 0 to indicate we should bind to
50 // port 0 and then figure out which port we used.
51 //----------------------------------------------------------------------
52 uint16_t GetNextAvailablePort();
54 bool AssociatePortWithProcess(uint16_t port, lldb::pid_t pid);
56 bool FreePort(uint16_t port);
58 bool FreePortForProcess(lldb::pid_t pid);
60 void SetPortOffset(uint16_t port_offset);
62 void SetInferiorArguments(const lldb_private::Args &args);
64 Status LaunchGDBServer(const lldb_private::Args &args, std::string hostname,
65 lldb::pid_t &pid, uint16_t &port,
66 std::string &socket_name);
68 void SetPendingGdbServer(lldb::pid_t pid, uint16_t port,
69 const std::string &socket_name);
72 const Socket::SocketProtocol m_socket_protocol;
73 const std::string m_socket_scheme;
74 std::recursive_mutex m_spawned_pids_mutex;
75 std::set<lldb::pid_t> m_spawned_pids;
78 uint16_t m_port_offset;
82 std::string socket_name;
83 } m_pending_gdb_server;
85 PacketResult Handle_qLaunchGDBServer(StringExtractorGDBRemote &packet);
87 PacketResult Handle_qQueryGDBServer(StringExtractorGDBRemote &packet);
89 PacketResult Handle_qKillSpawnedProcess(StringExtractorGDBRemote &packet);
91 PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);
93 PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
95 PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet);
97 PacketResult Handle_qC(StringExtractorGDBRemote &packet);
99 PacketResult Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
102 bool KillSpawnedProcess(lldb::pid_t pid);
104 bool DebugserverProcessReaped(lldb::pid_t pid);
106 static const FileSpec &GetDomainSocketDir();
108 static FileSpec GetDomainSocketPath(const char *prefix);
110 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerPlatform);
113 } // namespace process_gdb_remote
114 } // namespace lldb_private
116 #endif // liblldb_GDBRemoteCommunicationServerPlatform_h_