[Go to site: main page, start]

LLDB mainline
SBCommunication.cpp
Go to the documentation of this file.
1//===-- SBCommunication.cpp -----------------------------------------------===//
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
13#include "lldb/Host/Host.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
21
22SBCommunication::SBCommunication(const char *broadcaster_name)
23 : m_opaque(new ThreadedCommunication(broadcaster_name)),
24 m_opaque_owned(true) {
25 LLDB_INSTRUMENT_VA(this, broadcaster_name);
26}
27
30 delete m_opaque;
31 m_opaque = nullptr;
32 m_opaque_owned = false;
33}
34
37 return this->operator bool();
38}
39SBCommunication::operator bool() const {
41
42 return m_opaque != nullptr;
43}
44
47
48 if (m_opaque)
49 return m_opaque->GetCloseOnEOF();
50 return false;
51}
52
54 LLDB_INSTRUMENT_VA(this, b);
55
56 if (m_opaque)
57 m_opaque->SetCloseOnEOF(b);
58}
59
61 LLDB_INSTRUMENT_VA(this, url);
62
63 if (m_opaque) {
64 if (!m_opaque->HasConnection())
65 m_opaque->SetConnection(Host::CreateDefaultConnection(url));
66 return m_opaque->Connect(url, nullptr);
67 }
69}
70
72 LLDB_INSTRUMENT_VA(this, fd, owns_fd);
73
75 if (m_opaque) {
76 if (m_opaque->HasConnection()) {
77 if (m_opaque->IsConnected())
78 m_opaque->Disconnect();
79 }
80 m_opaque->SetConnection(
81 std::make_unique<ConnectionFileDescriptor>(fd, owns_fd));
82 if (m_opaque->IsConnected())
84 else
86 }
87 return status;
88}
89
92
94 if (m_opaque)
95 status = m_opaque->Disconnect();
96 return status;
97}
98
100 LLDB_INSTRUMENT_VA(this);
101
102 return m_opaque ? m_opaque->IsConnected() : false;
103}
104
105size_t SBCommunication::Read(void *dst, size_t dst_len, uint32_t timeout_usec,
106 ConnectionStatus &status) {
107 LLDB_INSTRUMENT_VA(this, dst, dst_len, timeout_usec, status);
108
109 size_t bytes_read = 0;
110 Timeout<std::micro> timeout = timeout_usec == UINT32_MAX
111 ? Timeout<std::micro>(std::nullopt)
112 : std::chrono::microseconds(timeout_usec);
113 if (m_opaque)
114 bytes_read = m_opaque->Read(dst, dst_len, timeout, status, nullptr);
115 else
117
118 return bytes_read;
119}
120
121size_t SBCommunication::Write(const void *src, size_t src_len,
122 ConnectionStatus &status) {
123 LLDB_INSTRUMENT_VA(this, src, src_len, status);
124
125 size_t bytes_written = 0;
126 if (m_opaque)
127 bytes_written = m_opaque->Write(src, src_len, status, nullptr);
128 else
130
131 return bytes_written;
132}
133
135 LLDB_INSTRUMENT_VA(this);
136
137 return m_opaque ? m_opaque->StartReadThread() : false;
138}
139
141 LLDB_INSTRUMENT_VA(this);
142
143 return m_opaque ? m_opaque->StopReadThread() : false;
144}
145
147 LLDB_INSTRUMENT_VA(this);
148
149 return m_opaque ? m_opaque->ReadThreadIsRunning() : false;
150}
151
153 ReadThreadBytesReceived callback, void *callback_baton) {
154 LLDB_INSTRUMENT_VA(this, callback, callback_baton);
155
156 bool result = false;
157 if (m_opaque) {
158 m_opaque->SetReadThreadBytesReceivedCallback(callback, callback_baton);
159 result = true;
160 }
161 return result;
162}
163
165 LLDB_INSTRUMENT_VA(this);
166
167 SBBroadcaster broadcaster(m_opaque, false);
168 return broadcaster;
169}
170
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
lldb_private::ThreadedCommunication * m_opaque
static const char * GetBroadcasterClass()
void(* ReadThreadBytesReceived)(void *baton, const void *src, size_t src_len)
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status)
size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec, lldb::ConnectionStatus &status)
lldb::ConnectionStatus Disconnect()
lldb::ConnectionStatus AdoptFileDesriptor(int fd, bool owns_fd)
lldb::ConnectionStatus Connect(const char *url)
lldb::SBBroadcaster GetBroadcaster()
bool SetReadThreadBytesReceivedCallback(ReadThreadBytesReceived callback, void *callback_baton)
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
static std::unique_ptr< Connection > CreateDefaultConnection(llvm::StringRef url)
"lldb/Core/ThreadedCommunication.h" Variation of Communication that supports threaded reads.
static llvm::StringRef GetStaticBroadcasterClass()
#define UINT32_MAX
A class that represents a running process on the host machine.
ConnectionStatus
Connection Status Types.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusLostConnection
Lost connection while connected to a valid connection.
@ eConnectionStatusNoConnection
No connection.