aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Core/Communication.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Core/Communication.cpp')
-rw-r--r--lldb/source/Core/Communication.cpp64
1 files changed, 29 insertions, 35 deletions
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index 0ad2751f24f0..f41ce46ede88 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -13,9 +13,9 @@
#include "lldb/Utility/Connection.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Listener.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/Logging.h"
#include "lldb/Utility/Status.h"
#include "llvm/ADT/None.h"
@@ -47,8 +47,7 @@ Communication::Communication(const char *name)
{
- LLDB_LOG(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT |
- LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Object | LLDBLog::Communication),
"{0} Communication::Communication (name = {1})", this, name);
SetEventName(eBroadcastBitDisconnected, "disconnected");
@@ -62,8 +61,7 @@ Communication::Communication(const char *name)
}
Communication::~Communication() {
- LLDB_LOG(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT |
- LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Object | LLDBLog::Communication),
"{0} Communication::~Communication (name = {1})", this,
GetBroadcasterName().AsCString());
Clear();
@@ -78,7 +76,7 @@ void Communication::Clear() {
ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
Clear();
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::Connect (url = {1})", this, url);
lldb::ConnectionSP connection_sp(m_connection_sp);
@@ -90,8 +88,8 @@ ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
}
ConnectionStatus Communication::Disconnect(Status *error_ptr) {
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
- "{0} Communication::Disconnect ()", this);
+ LLDB_LOG(GetLog(LLDBLog::Communication), "{0} Communication::Disconnect ()",
+ this);
assert((!m_read_thread_enabled || m_read_thread_did_exit) &&
"Disconnecting while the read thread is running is racy!");
@@ -125,7 +123,7 @@ bool Communication::HasConnection() const {
size_t Communication::Read(void *dst, size_t dst_len,
const Timeout<std::micro> &timeout,
ConnectionStatus &status, Status *error_ptr) {
- Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION);
+ Log *log = GetLog(LLDBLog::Communication);
LLDB_LOG(
log,
"this = {0}, dst = {1}, dst_len = {2}, timeout = {3}, connection = {4}",
@@ -175,7 +173,7 @@ size_t Communication::Write(const void *src, size_t src_len,
lldb::ConnectionSP connection_sp(m_connection_sp);
std::lock_guard<std::mutex> guard(m_write_mutex);
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::Write (src = {1}, src_len = {2}"
") connection = {3}",
this, src, (uint64_t)src_len, connection_sp.get());
@@ -206,7 +204,7 @@ bool Communication::StartReadThread(Status *error_ptr) {
if (m_read_thread.IsJoinable())
return true;
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::StartReadThread ()", this);
const std::string thread_name =
@@ -215,15 +213,14 @@ bool Communication::StartReadThread(Status *error_ptr) {
m_read_thread_enabled = true;
m_read_thread_did_exit = false;
auto maybe_thread = ThreadLauncher::LaunchThread(
- thread_name, Communication::ReadThread, this);
+ thread_name, [this] { return ReadThread(); });
if (maybe_thread) {
m_read_thread = *maybe_thread;
} else {
if (error_ptr)
*error_ptr = Status(maybe_thread.takeError());
else {
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
- "failed to launch host thread: {}",
+ LLDB_LOG(GetLog(LLDBLog::Host), "failed to launch host thread: {}",
llvm::toString(maybe_thread.takeError()));
}
}
@@ -238,7 +235,7 @@ bool Communication::StopReadThread(Status *error_ptr) {
if (!m_read_thread.IsJoinable())
return true;
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::StopReadThread ()", this);
m_read_thread_enabled = false;
@@ -280,7 +277,7 @@ size_t Communication::GetCachedBytes(void *dst, size_t dst_len) {
void Communication::AppendBytesToCache(const uint8_t *bytes, size_t len,
bool broadcast,
ConnectionStatus status) {
- LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION),
+ LLDB_LOG(GetLog(LLDBLog::Communication),
"{0} Communication::AppendBytesToCache (src = {1}, src_len = {2}, "
"broadcast = {3})",
this, bytes, (uint64_t)len, broadcast);
@@ -314,12 +311,10 @@ size_t Communication::ReadFromConnection(void *dst, size_t dst_len,
bool Communication::ReadThreadIsRunning() { return m_read_thread_enabled; }
-lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
- Communication *comm = (Communication *)p;
+lldb::thread_result_t Communication::ReadThread() {
+ Log *log = GetLog(LLDBLog::Communication);
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION));
-
- LLDB_LOGF(log, "%p Communication::ReadThread () thread starting...", p);
+ LLDB_LOG(log, "Communication({0}) thread starting...", this);
uint8_t buf[1024];
@@ -327,11 +322,11 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
ConnectionStatus status = eConnectionStatusSuccess;
bool done = false;
bool disconnect = false;
- while (!done && comm->m_read_thread_enabled) {
- size_t bytes_read = comm->ReadFromConnection(
+ while (!done && m_read_thread_enabled) {
+ size_t bytes_read = ReadFromConnection(
buf, sizeof(buf), std::chrono::seconds(5), status, &error);
if (bytes_read > 0 || status == eConnectionStatusEndOfFile)
- comm->AppendBytesToCache(buf, bytes_read, true, status);
+ AppendBytesToCache(buf, bytes_read, true, status);
switch (status) {
case eConnectionStatusSuccess:
@@ -339,12 +334,12 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
case eConnectionStatusEndOfFile:
done = true;
- disconnect = comm->GetCloseOnEOF();
+ disconnect = GetCloseOnEOF();
break;
case eConnectionStatusError: // Check GetError() for details
if (error.GetType() == eErrorTypePOSIX && error.GetError() == EIO) {
// EIO on a pipe is usually caused by remote shutdown
- disconnect = comm->GetCloseOnEOF();
+ disconnect = GetCloseOnEOF();
done = true;
}
if (error.Fail())
@@ -355,7 +350,7 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
// SynchronizeWithReadThread()
// The connection returns eConnectionStatusInterrupted only when there is
// no input pending to be read, so we can signal that.
- comm->BroadcastEvent(eBroadcastBitNoMorePendingInput);
+ BroadcastEvent(eBroadcastBitNoMorePendingInput);
break;
case eConnectionStatusNoConnection: // No connection
case eConnectionStatusLostConnection: // Lost connection while connected to
@@ -369,27 +364,26 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
break;
}
}
- log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMUNICATION);
- if (log)
- LLDB_LOGF(log, "%p Communication::ReadThread () thread exiting...", p);
+ log = GetLog(LLDBLog::Communication);
+ LLDB_LOG(log, "Communication({0}) thread exiting...", this);
// Handle threads wishing to synchronize with us.
{
// Prevent new ones from showing up.
- comm->m_read_thread_did_exit = true;
+ m_read_thread_did_exit = true;
// Unblock any existing thread waiting for the synchronization signal.
- comm->BroadcastEvent(eBroadcastBitNoMorePendingInput);
+ BroadcastEvent(eBroadcastBitNoMorePendingInput);
// Wait for the thread to finish...
- std::lock_guard<std::mutex> guard(comm->m_synchronize_mutex);
+ std::lock_guard<std::mutex> guard(m_synchronize_mutex);
// ... and disconnect.
if (disconnect)
- comm->Disconnect();
+ Disconnect();
}
// Let clients know that this thread is exiting
- comm->BroadcastEvent(eBroadcastBitReadThreadDidExit);
+ BroadcastEvent(eBroadcastBitReadThreadDidExit);
return {};
}