Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 1 | //===-- 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 Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | #include <map> |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 16 | #include <set> |
| 17 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 18 | // Other libraries and framework includes |
| 19 | // Project includes |
| 20 | #include "GDBRemoteCommunicationServerCommon.h" |
| 21 | #include "lldb/Host/Socket.h" |
| 22 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 23 | namespace lldb_private { |
| 24 | namespace process_gdb_remote { |
| 25 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 26 | class GDBRemoteCommunicationServerPlatform : |
| 27 | public GDBRemoteCommunicationServerCommon |
| 28 | { |
| 29 | public: |
| 30 | typedef std::map<uint16_t, lldb::pid_t> PortMap; |
| 31 | |
Oleksiy Vyalov | 1485712 | 2015-10-28 19:49:50 +0000 | [diff] [blame] | 32 | GDBRemoteCommunicationServerPlatform(const Socket::SocketProtocol socket_protocol, |
| 33 | const char* socket_scheme); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 34 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 35 | ~GDBRemoteCommunicationServerPlatform() override; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 36 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 37 | Error |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 38 | LaunchProcess () override; |
| 39 | |
| 40 | // Set both ports to zero to let the platform automatically bind to |
| 41 | // a port chosen by the OS. |
| 42 | void |
| 43 | SetPortMap (PortMap &&port_map); |
| 44 | |
| 45 | //---------------------------------------------------------------------- |
| 46 | // If we are using a port map where we can only use certain ports, |
| 47 | // get the next available port. |
| 48 | // |
| 49 | // If we are using a port map and we are out of ports, return UINT16_MAX |
| 50 | // |
| 51 | // If we aren't using a port map, return 0 to indicate we should bind to |
| 52 | // port 0 and then figure out which port we used. |
| 53 | //---------------------------------------------------------------------- |
| 54 | uint16_t |
| 55 | GetNextAvailablePort (); |
| 56 | |
| 57 | bool |
| 58 | AssociatePortWithProcess (uint16_t port, lldb::pid_t pid); |
| 59 | |
| 60 | bool |
| 61 | FreePort (uint16_t port); |
| 62 | |
| 63 | bool |
| 64 | FreePortForProcess (lldb::pid_t pid); |
| 65 | |
| 66 | void |
| 67 | SetPortOffset (uint16_t port_offset); |
| 68 | |
| 69 | protected: |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 70 | const Socket::SocketProtocol m_socket_protocol; |
Oleksiy Vyalov | 1485712 | 2015-10-28 19:49:50 +0000 | [diff] [blame] | 71 | const std::string m_socket_scheme; |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 72 | Mutex m_spawned_pids_mutex; |
| 73 | std::set<lldb::pid_t> m_spawned_pids; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 74 | lldb::PlatformSP m_platform_sp; |
| 75 | |
| 76 | PortMap m_port_map; |
| 77 | uint16_t m_port_offset; |
| 78 | |
| 79 | PacketResult |
| 80 | Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet); |
| 81 | |
| 82 | PacketResult |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 83 | Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet); |
| 84 | |
| 85 | PacketResult |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 86 | Handle_qProcessInfo (StringExtractorGDBRemote &packet); |
| 87 | |
| 88 | PacketResult |
| 89 | Handle_qGetWorkingDir (StringExtractorGDBRemote &packet); |
| 90 | |
| 91 | PacketResult |
| 92 | Handle_QSetWorkingDir (StringExtractorGDBRemote &packet); |
| 93 | |
| 94 | PacketResult |
| 95 | Handle_qC (StringExtractorGDBRemote &packet); |
| 96 | |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 97 | PacketResult |
| 98 | Handle_jSignalsInfo(StringExtractorGDBRemote &packet); |
| 99 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 100 | private: |
| 101 | bool |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 102 | KillSpawnedProcess (lldb::pid_t pid); |
| 103 | |
| 104 | bool |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 105 | DebugserverProcessReaped (lldb::pid_t pid); |
| 106 | |
| 107 | static bool |
| 108 | ReapDebugserverProcess (void *callback_baton, |
| 109 | lldb::pid_t pid, |
| 110 | bool exited, |
| 111 | int signal, |
| 112 | int status); |
| 113 | |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 114 | static const FileSpec& |
| 115 | GetDomainSocketDir(); |
| 116 | |
| 117 | static FileSpec |
| 118 | GetDomainSocketPath(const char* prefix); |
| 119 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 120 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerPlatform); |
| 121 | }; |
| 122 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 123 | } // namespace process_gdb_remote |
| 124 | } // namespace lldb_private |
| 125 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 126 | #endif // liblldb_GDBRemoteCommunicationServerPlatform_h_ |