blob: f507a085cdb8a4dd0bc5d492fa72b73d0ed358a9 [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
13#include "GDBRemoteCommunicationServerCommon.h"
14
Pavel Labath6e4f19d2015-07-29 12:33:31 +000015#include <set>
16
Tamas Berghammerdb264a62015-03-31 09:52:22 +000017namespace lldb_private {
18namespace process_gdb_remote {
19
Tamas Berghammere13c2732015-02-11 10:29:30 +000020class GDBRemoteCommunicationServerPlatform :
21 public GDBRemoteCommunicationServerCommon
22{
23public:
24 typedef std::map<uint16_t, lldb::pid_t> PortMap;
25
26 GDBRemoteCommunicationServerPlatform();
27
28 virtual
29 ~GDBRemoteCommunicationServerPlatform();
30
Tamas Berghammerdb264a62015-03-31 09:52:22 +000031 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000032 LaunchProcess () override;
33
34 // Set both ports to zero to let the platform automatically bind to
35 // a port chosen by the OS.
36 void
37 SetPortMap (PortMap &&port_map);
38
39 //----------------------------------------------------------------------
40 // If we are using a port map where we can only use certain ports,
41 // get the next available port.
42 //
43 // If we are using a port map and we are out of ports, return UINT16_MAX
44 //
45 // If we aren't using a port map, return 0 to indicate we should bind to
46 // port 0 and then figure out which port we used.
47 //----------------------------------------------------------------------
48 uint16_t
49 GetNextAvailablePort ();
50
51 bool
52 AssociatePortWithProcess (uint16_t port, lldb::pid_t pid);
53
54 bool
55 FreePort (uint16_t port);
56
57 bool
58 FreePortForProcess (lldb::pid_t pid);
59
60 void
61 SetPortOffset (uint16_t port_offset);
62
63protected:
Pavel Labath6e4f19d2015-07-29 12:33:31 +000064 Mutex m_spawned_pids_mutex;
65 std::set<lldb::pid_t> m_spawned_pids;
Tamas Berghammere13c2732015-02-11 10:29:30 +000066 lldb::PlatformSP m_platform_sp;
67
68 PortMap m_port_map;
69 uint16_t m_port_offset;
70
71 PacketResult
72 Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
73
74 PacketResult
Pavel Labath6e4f19d2015-07-29 12:33:31 +000075 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
76
77 PacketResult
Tamas Berghammere13c2732015-02-11 10:29:30 +000078 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
79
80 PacketResult
81 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
82
83 PacketResult
84 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
85
86 PacketResult
87 Handle_qC (StringExtractorGDBRemote &packet);
88
Chaoren Lin98d0a4b2015-07-14 01:09:28 +000089 PacketResult
90 Handle_jSignalsInfo(StringExtractorGDBRemote &packet);
91
Tamas Berghammere13c2732015-02-11 10:29:30 +000092private:
93 bool
Pavel Labath6e4f19d2015-07-29 12:33:31 +000094 KillSpawnedProcess (lldb::pid_t pid);
95
96 bool
Tamas Berghammere13c2732015-02-11 10:29:30 +000097 DebugserverProcessReaped (lldb::pid_t pid);
98
99 static bool
100 ReapDebugserverProcess (void *callback_baton,
101 lldb::pid_t pid,
102 bool exited,
103 int signal,
104 int status);
105
106 //------------------------------------------------------------------
107 // For GDBRemoteCommunicationServerPlatform only
108 //------------------------------------------------------------------
109 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform);
110};
111
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000112} // namespace process_gdb_remote
113} // namespace lldb_private
114
Tamas Berghammere13c2732015-02-11 10:29:30 +0000115#endif // liblldb_GDBRemoteCommunicationServerPlatform_h_