1 //===-- GDBRemoteCommunicationServerPlatform.h ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_GDBRemoteCommunicationServerPlatform_h_
10 #define liblldb_GDBRemoteCommunicationServerPlatform_h_
16 #include "GDBRemoteCommunicationServerCommon.h"
17 #include "lldb/Host/Socket.h"
19 namespace lldb_private {
20 namespace process_gdb_remote {
22 class GDBRemoteCommunicationServerPlatform
23 : public GDBRemoteCommunicationServerCommon {
25 typedef std::map<uint16_t, lldb::pid_t> PortMap;
27 GDBRemoteCommunicationServerPlatform(
28 const Socket::SocketProtocol socket_protocol, const char *socket_scheme);
30 ~GDBRemoteCommunicationServerPlatform() override;
32 Status LaunchProcess() override;
34 // Set both ports to zero to let the platform automatically bind to
35 // a port chosen by the OS.
36 void SetPortMap(PortMap &&port_map);
38 // If we are using a port map where we can only use certain ports,
39 // get the next available port.
41 // If we are using a port map and we are out of ports, return UINT16_MAX
43 // If we aren't using a port map, return 0 to indicate we should bind to
44 // port 0 and then figure out which port we used.
45 uint16_t GetNextAvailablePort();
47 bool AssociatePortWithProcess(uint16_t port, lldb::pid_t pid);
49 bool FreePort(uint16_t port);
51 bool FreePortForProcess(lldb::pid_t pid);
53 void SetPortOffset(uint16_t port_offset);
55 void SetInferiorArguments(const lldb_private::Args &args);
57 Status LaunchGDBServer(const lldb_private::Args &args, std::string hostname,
58 lldb::pid_t &pid, uint16_t &port,
59 std::string &socket_name);
61 void SetPendingGdbServer(lldb::pid_t pid, uint16_t port,
62 const std::string &socket_name);
65 const Socket::SocketProtocol m_socket_protocol;
66 const std::string m_socket_scheme;
67 std::recursive_mutex m_spawned_pids_mutex;
68 std::set<lldb::pid_t> m_spawned_pids;
71 uint16_t m_port_offset;
75 std::string socket_name;
76 } m_pending_gdb_server;
78 PacketResult Handle_qLaunchGDBServer(StringExtractorGDBRemote &packet);
80 PacketResult Handle_qQueryGDBServer(StringExtractorGDBRemote &packet);
82 PacketResult Handle_qKillSpawnedProcess(StringExtractorGDBRemote &packet);
84 PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);
86 PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
88 PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet);
90 PacketResult Handle_qC(StringExtractorGDBRemote &packet);
92 PacketResult Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
95 bool KillSpawnedProcess(lldb::pid_t pid);
97 bool DebugserverProcessReaped(lldb::pid_t pid);
99 static const FileSpec &GetDomainSocketDir();
101 static FileSpec GetDomainSocketPath(const char *prefix);
103 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerPlatform);
106 } // namespace process_gdb_remote
107 } // namespace lldb_private
109 #endif // liblldb_GDBRemoteCommunicationServerPlatform_h_