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> |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 16 | #include <mutex> |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 17 | #include <set> |
| 18 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 19 | // Other libraries and framework includes |
| 20 | // Project includes |
| 21 | #include "GDBRemoteCommunicationServerCommon.h" |
| 22 | #include "lldb/Host/Socket.h" |
| 23 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 24 | namespace lldb_private { |
| 25 | namespace process_gdb_remote { |
| 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | class GDBRemoteCommunicationServerPlatform |
| 28 | : public GDBRemoteCommunicationServerCommon { |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 29 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | typedef std::map<uint16_t, lldb::pid_t> PortMap; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 31 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | GDBRemoteCommunicationServerPlatform( |
| 33 | const Socket::SocketProtocol socket_protocol, const char *socket_scheme); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | ~GDBRemoteCommunicationServerPlatform() override; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 36 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame^] | 37 | Status LaunchProcess() override; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 38 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | //---------------------------------------------------------------------- |
| 44 | // If we are using a port map where we can only use certain ports, |
| 45 | // get the next available port. |
| 46 | // |
| 47 | // If we are using a port map and we are out of ports, return UINT16_MAX |
| 48 | // |
| 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(); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | bool AssociatePortWithProcess(uint16_t port, lldb::pid_t pid); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | bool FreePort(uint16_t port); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | bool FreePortForProcess(lldb::pid_t pid); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | void SetPortOffset(uint16_t port_offset); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | void SetInferiorArguments(const lldb_private::Args &args); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 63 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame^] | 64 | Status LaunchGDBServer(const lldb_private::Args &args, std::string hostname, |
| 65 | lldb::pid_t &pid, uint16_t &port, |
| 66 | std::string &socket_name); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 67 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | void SetPendingGdbServer(lldb::pid_t pid, uint16_t port, |
| 69 | const std::string &socket_name); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 70 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 71 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | PortMap m_port_map; |
| 78 | uint16_t m_port_offset; |
| 79 | struct { |
| 80 | lldb::pid_t pid; |
| 81 | uint16_t port; |
| 82 | std::string socket_name; |
| 83 | } m_pending_gdb_server; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | PacketResult Handle_qLaunchGDBServer(StringExtractorGDBRemote &packet); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 86 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 87 | PacketResult Handle_qQueryGDBServer(StringExtractorGDBRemote &packet); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | PacketResult Handle_qKillSpawnedProcess(StringExtractorGDBRemote &packet); |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 90 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 92 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 96 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | PacketResult Handle_qC(StringExtractorGDBRemote &packet); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | PacketResult Handle_jSignalsInfo(StringExtractorGDBRemote &packet); |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 100 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 101 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | bool KillSpawnedProcess(lldb::pid_t pid); |
Pavel Labath | 6e4f19d | 2015-07-29 12:33:31 +0000 | [diff] [blame] | 103 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | bool DebugserverProcessReaped(lldb::pid_t pid); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 105 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | static const FileSpec &GetDomainSocketDir(); |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | static FileSpec GetDomainSocketPath(const char *prefix); |
Oleksiy Vyalov | 9fe526c | 2015-10-21 19:34:26 +0000 | [diff] [blame] | 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerPlatform); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 113 | } // namespace process_gdb_remote |
| 114 | } // namespace lldb_private |
| 115 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 116 | #endif // liblldb_GDBRemoteCommunicationServerPlatform_h_ |