[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- Communication.cpp -------------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Core/Communication.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
|
2017-06-27 10:33:14 +00:00
|
|
|
#include "lldb/Utility/Connection.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
|
2018-11-11 23:16:43 +00:00
|
|
|
#include <algorithm>
|
2017-04-06 21:28:29 +00:00
|
|
|
#include <cstring>
|
2018-11-11 23:16:43 +00:00
|
|
|
#include <memory>
|
2017-04-06 21:28:29 +00:00
|
|
|
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <cerrno>
|
|
|
|
|
#include <cinttypes>
|
|
|
|
|
#include <cstdio>
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2022-09-03 10:25:42 +02:00
|
|
|
Communication::Communication()
|
2023-08-11 14:55:01 -07:00
|
|
|
: m_connection_sp(), m_connection_mutex(), m_close_on_eof(true) {}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2023-08-11 14:55:01 -07:00
|
|
|
Communication::~Communication() { Disconnect(nullptr); }
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
ConnectionStatus Communication::Connect(const char *url, Status *error_ptr) {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::unique_lock guard(m_connection_mutex);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
LLDB_LOG(GetLog(LLDBLog::Communication),
|
2019-07-23 17:03:37 +00:00
|
|
|
"{0} Communication::Connect (url = {1})", this, url);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2023-08-11 14:55:01 -07:00
|
|
|
DisconnectUnlocked();
|
|
|
|
|
|
|
|
|
|
if (m_connection_sp)
|
|
|
|
|
return m_connection_sp->Connect(url, error_ptr);
|
2010-06-08 16:52:24 +00:00
|
|
|
if (error_ptr)
|
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
|
return eConnectionStatusNoConnection;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
ConnectionStatus Communication::Disconnect(Status *error_ptr) {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::unique_lock guard(m_connection_mutex);
|
|
|
|
|
return DisconnectUnlocked(error_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConnectionStatus Communication::DisconnectUnlocked(Status *error_ptr) {
|
2022-01-31 15:57:48 +01:00
|
|
|
LLDB_LOG(GetLog(LLDBLog::Communication), "{0} Communication::Disconnect ()",
|
|
|
|
|
this);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2023-08-11 14:55:01 -07:00
|
|
|
if (m_connection_sp) {
|
|
|
|
|
ConnectionStatus status = m_connection_sp->Disconnect(error_ptr);
|
2010-06-08 16:52:24 +00:00
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
return eConnectionStatusNoConnection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Communication::IsConnected() const {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::shared_lock guard(m_connection_mutex);
|
|
|
|
|
return (m_connection_sp ? m_connection_sp->IsConnected() : false);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Communication::HasConnection() const {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::shared_lock guard(m_connection_mutex);
|
2016-03-02 01:09:03 +00:00
|
|
|
return m_connection_sp.get() != nullptr;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-25 11:58:44 +00:00
|
|
|
size_t Communication::Read(void *dst, size_t dst_len,
|
|
|
|
|
const Timeout<std::micro> &timeout,
|
2017-05-12 04:51:55 +00:00
|
|
|
ConnectionStatus &status, Status *error_ptr) {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::shared_lock guard(m_connection_mutex);
|
|
|
|
|
return ReadUnlocked(dst, dst_len, timeout, status, error_ptr);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Communication::Write(const void *src, size_t src_len,
|
2017-05-12 04:51:55 +00:00
|
|
|
ConnectionStatus &status, Status *error_ptr) {
|
2023-08-11 14:55:01 -07:00
|
|
|
// We need to lock the write mutex so no concurrent writes happen, but also
|
|
|
|
|
// lock the connection mutex so it's not reset mid write. We need both mutexes
|
|
|
|
|
// because reads and writes from the connection can happen concurrently.
|
|
|
|
|
std::shared_lock guard(m_connection_mutex);
|
|
|
|
|
std::lock_guard<std::mutex> guard_write(m_write_mutex);
|
|
|
|
|
return WriteUnlocked(src, src_len, status, error_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Communication::WriteUnlocked(const void *src, size_t src_len,
|
|
|
|
|
ConnectionStatus &status,
|
|
|
|
|
Status *error_ptr) {
|
|
|
|
|
if (!m_connection_sp) {
|
|
|
|
|
if (error_ptr)
|
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-12-14 02:59:59 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
LLDB_LOG(GetLog(LLDBLog::Communication),
|
2021-09-09 17:40:12 +02:00
|
|
|
"{0} Communication::Write (src = {1}, src_len = {2}"
|
|
|
|
|
") connection = {3}",
|
2023-08-11 14:55:01 -07:00
|
|
|
this, src, (uint64_t)src_len, m_connection_sp.get());
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2023-08-11 14:55:01 -07:00
|
|
|
return m_connection_sp->Write(src, src_len, status, error_ptr);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 21:28:25 +02:00
|
|
|
size_t Communication::WriteAll(const void *src, size_t src_len,
|
|
|
|
|
ConnectionStatus &status, Status *error_ptr) {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::shared_lock guard(m_connection_mutex);
|
|
|
|
|
std::lock_guard<std::mutex> guard_write(m_write_mutex);
|
2021-10-20 21:28:25 +02:00
|
|
|
size_t total_written = 0;
|
|
|
|
|
do
|
2023-08-11 14:55:01 -07:00
|
|
|
total_written +=
|
|
|
|
|
WriteUnlocked(static_cast<const char *>(src) + total_written,
|
|
|
|
|
src_len - total_written, status, error_ptr);
|
2021-10-20 21:28:25 +02:00
|
|
|
while (status == eConnectionStatusSuccess && total_written < src_len);
|
|
|
|
|
return total_written;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 14:55:01 -07:00
|
|
|
size_t Communication::ReadUnlocked(void *dst, size_t dst_len,
|
|
|
|
|
const Timeout<std::micro> &timeout,
|
|
|
|
|
ConnectionStatus &status,
|
|
|
|
|
Status *error_ptr) {
|
|
|
|
|
Log *log = GetLog(LLDBLog::Communication);
|
|
|
|
|
LLDB_LOG(
|
|
|
|
|
log,
|
|
|
|
|
"this = {0}, dst = {1}, dst_len = {2}, timeout = {3}, connection = {4}",
|
|
|
|
|
this, dst, dst_len, timeout, m_connection_sp.get());
|
|
|
|
|
if (m_connection_sp)
|
|
|
|
|
return m_connection_sp->Read(dst, dst_len, timeout, status, error_ptr);
|
2016-11-25 11:58:44 +00:00
|
|
|
|
|
|
|
|
if (error_ptr)
|
|
|
|
|
error_ptr->SetErrorString("Invalid connection.");
|
|
|
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
|
return 0;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-02 14:40:59 +02:00
|
|
|
void Communication::SetConnection(std::unique_ptr<Connection> connection) {
|
2023-08-11 14:55:01 -07:00
|
|
|
std::unique_lock guard(m_connection_mutex);
|
|
|
|
|
DisconnectUnlocked(nullptr);
|
2020-04-02 14:40:59 +02:00
|
|
|
m_connection_sp = std::move(connection);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2010-10-26 03:11:13 +00:00
|
|
|
|
2020-07-30 11:50:53 +02:00
|
|
|
std::string
|
|
|
|
|
Communication::ConnectionStatusAsString(lldb::ConnectionStatus status) {
|
2010-10-26 03:11:13 +00:00
|
|
|
switch (status) {
|
|
|
|
|
case eConnectionStatusSuccess:
|
|
|
|
|
return "success";
|
|
|
|
|
case eConnectionStatusError:
|
|
|
|
|
return "error";
|
|
|
|
|
case eConnectionStatusTimedOut:
|
|
|
|
|
return "timed out";
|
|
|
|
|
case eConnectionStatusNoConnection:
|
|
|
|
|
return "no connection";
|
|
|
|
|
case eConnectionStatusLostConnection:
|
|
|
|
|
return "lost connection";
|
2011-03-20 04:57:14 +00:00
|
|
|
case eConnectionStatusEndOfFile:
|
|
|
|
|
return "end of file";
|
2014-05-02 00:45:31 +00:00
|
|
|
case eConnectionStatusInterrupted:
|
|
|
|
|
return "interrupted";
|
2010-10-26 03:11:13 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-07-30 11:50:53 +02:00
|
|
|
return "@" + std::to_string(status);
|
2010-10-26 03:11:13 +00:00
|
|
|
}
|