LLDB  mainline
ConnectionFileDescriptorPosix.h
Go to the documentation of this file.
1 //===-- ConnectionFileDescriptorPosix.h -------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
10 #define LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
11 
12 #include <atomic>
13 #include <memory>
14 #include <mutex>
15 
16 #include "lldb/lldb-forward.h"
17 
18 #include "lldb/Host/Pipe.h"
19 #include "lldb/Host/Socket.h"
21 #include "lldb/Utility/IOObject.h"
22 
23 namespace lldb_private {
24 
25 class Status;
26 class Socket;
27 class SocketAddress;
28 
30 public:
31  typedef llvm::function_ref<void(llvm::StringRef local_socket_id)>
33 
34  ConnectionFileDescriptor(bool child_processes_inherit = false);
35 
36  ConnectionFileDescriptor(int fd, bool owns_fd);
37 
39 
40  ~ConnectionFileDescriptor() override;
41 
42  bool IsConnected() const override;
43 
44  lldb::ConnectionStatus Connect(llvm::StringRef url,
45  Status *error_ptr) override;
46 
47  lldb::ConnectionStatus Connect(llvm::StringRef url,
48  socket_id_callback_type socket_id_callback,
49  Status *error_ptr);
50 
51  lldb::ConnectionStatus Disconnect(Status *error_ptr) override;
52 
53  size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
54  lldb::ConnectionStatus &status, Status *error_ptr) override;
55 
56  size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
57  Status *error_ptr) override;
58 
59  std::string GetURI() override;
60 
62  Status *error_ptr);
63 
64  bool InterruptRead() override;
65 
66  lldb::IOObjectSP GetReadObject() override { return m_io_sp; }
67 
68  bool GetChildProcessesInherit() const;
69  void SetChildProcessesInherit(bool child_processes_inherit);
70 
71 protected:
72  void OpenCommandPipe();
73 
74  void CloseCommandPipe();
75 
77  AcceptSocket(Socket::SocketProtocol socket_protocol,
78  llvm::StringRef socket_name,
79  llvm::function_ref<void(Socket &)> post_listen_callback,
80  Status *error_ptr);
81 
83  llvm::StringRef socket_name,
84  Status *error_ptr);
85 
86  lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port,
87  socket_id_callback_type socket_id_callback,
88  Status *error_ptr);
89 
90  lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
91  socket_id_callback_type socket_id_callback,
92  Status *error_ptr);
93 
94  lldb::ConnectionStatus ConnectUDP(llvm::StringRef args,
95  socket_id_callback_type socket_id_callback,
96  Status *error_ptr);
97 
99  ConnectNamedSocket(llvm::StringRef socket_name,
100  socket_id_callback_type socket_id_callback,
101  Status *error_ptr);
102 
104  AcceptNamedSocket(llvm::StringRef socket_name,
105  socket_id_callback_type socket_id_callback,
106  Status *error_ptr);
107 
109  AcceptAbstractSocket(llvm::StringRef socket_name,
110  socket_id_callback_type socket_id_callback,
111  Status *error_ptr);
112 
114  ConnectAbstractSocket(llvm::StringRef socket_name,
115  socket_id_callback_type socket_id_callback,
116  Status *error_ptr);
117 
118  lldb::ConnectionStatus ConnectFD(llvm::StringRef args,
119  socket_id_callback_type socket_id_callback,
120  Status *error_ptr);
121 
122  lldb::ConnectionStatus ConnectFile(llvm::StringRef args,
123  socket_id_callback_type socket_id_callback,
124  Status *error_ptr);
125 
127  ConnectSerialPort(llvm::StringRef args,
128  socket_id_callback_type socket_id_callback,
129  Status *error_ptr);
130 
131  lldb::IOObjectSP m_io_sp;
132 
134  std::recursive_mutex m_mutex;
135  std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
136  // if we get woken up from
137  // BytesAvailable to disconnect, we won't try to read again.
139 
141 
142 private:
143  void InitializeSocket(Socket *socket);
144 
147  operator=(const ConnectionFileDescriptor &) = delete;
148 };
149 
150 } // namespace lldb_private
151 
152 #endif // LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
lldb_private::ConnectionFileDescriptor::GetURI
std::string GetURI() override
Returns a URI that describes this connection object.
Definition: ConnectionFileDescriptorPosix.cpp:424
lldb_private::Connection
Definition: Connection.h:41
lldb_private::Pipe
PipePosix Pipe
Definition: Pipe.h:20
lldb_private::ConnectionFileDescriptor::InitializeSocket
void InitializeSocket(Socket *socket)
Definition: ConnectionFileDescriptorPosix.cpp:811
lldb_private::Socket::SocketProtocol
SocketProtocol
Definition: Socket.h:43
lldb_private::ConnectionFileDescriptor::SetChildProcessesInherit
void SetChildProcessesInherit(bool child_processes_inherit)
Definition: ConnectionFileDescriptorPosix.cpp:806
lldb_private::ConnectionFileDescriptor::GetReadObject
lldb::IOObjectSP GetReadObject() override
Returns the underlying IOObject used by the Connection.
Definition: ConnectionFileDescriptorPosix.h:66
lldb_private::Socket
Definition: Socket.h:41
lldb_private::ConnectionFileDescriptor::operator=
const ConnectionFileDescriptor & operator=(const ConnectionFileDescriptor &)=delete
lldb_private::ConnectionFileDescriptor::BytesAvailable
lldb::ConnectionStatus BytesAvailable(const Timeout< std::micro > &timeout, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:442
lldb_private::ConnectionFileDescriptor::AcceptSocket
lldb::ConnectionStatus AcceptSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, llvm::function_ref< void(Socket &)> post_listen_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:537
lldb_private::ConnectionFileDescriptor::m_shutting_down
std::atomic< bool > m_shutting_down
Definition: ConnectionFileDescriptorPosix.h:135
lldb_private::ConnectionFileDescriptor::OpenCommandPipe
void OpenCommandPipe()
Definition: ConnectionFileDescriptorPosix.cpp:91
lldb_private::ConnectionFileDescriptor::socket_id_callback_type
llvm::function_ref< void(llvm::StringRef local_socket_id)> socket_id_callback_type
Definition: ConnectionFileDescriptorPosix.h:32
lldb_private::ConnectionFileDescriptor::m_pipe
Pipe m_pipe
Definition: ConnectionFileDescriptorPosix.h:133
lldb_private::ConnectionFileDescriptor::ConnectFile
lldb::ConnectionStatus ConnectFile(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:723
lldb_private::ConnectionFileDescriptor::ConnectNamedSocket
lldb::ConnectionStatus ConnectNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:598
lldb_private::ConnectionFileDescriptor::m_uri
std::string m_uri
Definition: ConnectionFileDescriptorPosix.h:140
lldb_private::ConnectionFileDescriptor::ConnectFD
lldb::ConnectionStatus ConnectFD(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:668
lldb_private::ConnectionFileDescriptor::m_mutex
std::recursive_mutex m_mutex
Definition: ConnectionFileDescriptorPosix.h:134
lldb_private::ConnectionFileDescriptor::ConnectSocket
lldb::ConnectionStatus ConnectSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:566
Socket.h
lldb::ConnectionStatus
ConnectionStatus
Connection Status Types.
Definition: lldb-enumerations.h:295
Pipe.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ConnectionFileDescriptor::GetChildProcessesInherit
bool GetChildProcessesInherit() const
Definition: ConnectionFileDescriptorPosix.cpp:802
lldb_private::ConnectionFileDescriptor::m_io_sp
lldb::IOObjectSP m_io_sp
Definition: ConnectionFileDescriptorPosix.h:131
lldb_private::ConnectionFileDescriptor::Connect
lldb::ConnectionStatus Connect(llvm::StringRef url, Status *error_ptr) override
Connect using the connect string url.
Definition: ConnectionFileDescriptorPosix.cpp:123
lldb_private::ConnectionFileDescriptor::ConnectAbstractSocket
lldb::ConnectionStatus ConnectAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:615
Connection.h
lldb_private::ConnectionFileDescriptor::Disconnect
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
Definition: ConnectionFileDescriptorPosix.cpp:190
lldb_private::ConnectionFileDescriptor::IsConnected
bool IsConnected() const override
Check if the connection is valid.
Definition: ConnectionFileDescriptorPosix.cpp:119
lldb_private::ConnectionFileDescriptor::ConnectTCP
lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:640
lldb_private::Status
Definition: Status.h:44
lldb_private::Timeout< std::micro >
lldb_private::ConnectionFileDescriptor::AcceptAbstractSocket
lldb::ConnectionStatus AcceptAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:604
lldb_private::ConnectionFileDescriptor::ConnectUDP
lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:647
lldb_private::ConnectionFileDescriptor::m_child_processes_inherit
bool m_child_processes_inherit
Definition: ConnectionFileDescriptorPosix.h:138
lldb-forward.h
lldb_private::ConnectionFileDescriptor::InterruptRead
bool InterruptRead() override
Interrupts an ongoing Read() operation.
Definition: ConnectionFileDescriptorPosix.cpp:184
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ConnectionFileDescriptor::ConnectionFileDescriptor
ConnectionFileDescriptor(bool child_processes_inherit=false)
Definition: ConnectionFileDescriptorPosix.cpp:54
lldb_private::ConnectionFileDescriptor::AcceptTCP
lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:622
lldb_private::ConnectionFileDescriptor::Write
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
Definition: ConnectionFileDescriptorPosix.cpp:357
lldb_private::ConnectionFileDescriptor::CloseCommandPipe
void CloseCommandPipe()
Definition: ConnectionFileDescriptorPosix.cpp:111
lldb_private::ConnectionFileDescriptor::ConnectSerialPort
lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:761
lldb_private::ConnectionFileDescriptor::AcceptNamedSocket
lldb::ConnectionStatus AcceptNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:587
IOObject.h
lldb_private::LineStatus::Status
@ Status
lldb_private::ConnectionFileDescriptor
Definition: ConnectionFileDescriptorPosix.h:29
lldb_private::ConnectionFileDescriptor::~ConnectionFileDescriptor
~ConnectionFileDescriptor() override
Definition: ConnectionFileDescriptorPosix.cpp:83
lldb_private::ConnectionFileDescriptor::Read
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
Definition: ConnectionFileDescriptorPosix.cpp:248