mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
The current record macros already log the function being called. This patch extends the macros to also log their input arguments and removes explicit logging from the SB API. This might degrade the amount of information in some cases (because of smarter casts or efforts to log return values). However I think this is outweighed by the increased coverage and consistency. Furthermore, using the reproducer infrastructure, diagnosing bugs in the API layer should become much easier compared to relying on log messages. Differential revision: https://reviews.llvm.org/D59101 llvm-svn: 355649
170 lines
5.1 KiB
C++
170 lines
5.1 KiB
C++
//===-- SBCommunication.cpp -------------------------------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/API/SBCommunication.h"
|
|
#include "SBReproducerPrivate.h"
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
#include "lldb/Core/Communication.h"
|
|
#include "lldb/Host/ConnectionFileDescriptor.h"
|
|
#include "lldb/Host/Host.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
SBCommunication::SBCommunication() : m_opaque(NULL), m_opaque_owned(false) {
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommunication);
|
|
}
|
|
|
|
SBCommunication::SBCommunication(const char *broadcaster_name)
|
|
: m_opaque(new Communication(broadcaster_name)), m_opaque_owned(true) {
|
|
LLDB_RECORD_CONSTRUCTOR(SBCommunication, (const char *), broadcaster_name);
|
|
}
|
|
|
|
SBCommunication::~SBCommunication() {
|
|
if (m_opaque && m_opaque_owned)
|
|
delete m_opaque;
|
|
m_opaque = NULL;
|
|
m_opaque_owned = false;
|
|
}
|
|
|
|
bool SBCommunication::IsValid() const {
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommunication, IsValid);
|
|
|
|
return m_opaque != NULL;
|
|
}
|
|
|
|
bool SBCommunication::GetCloseOnEOF() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommunication, GetCloseOnEOF);
|
|
|
|
if (m_opaque)
|
|
return m_opaque->GetCloseOnEOF();
|
|
return false;
|
|
}
|
|
|
|
void SBCommunication::SetCloseOnEOF(bool b) {
|
|
LLDB_RECORD_METHOD(void, SBCommunication, SetCloseOnEOF, (bool), b);
|
|
|
|
if (m_opaque)
|
|
m_opaque->SetCloseOnEOF(b);
|
|
}
|
|
|
|
ConnectionStatus SBCommunication::Connect(const char *url) {
|
|
LLDB_RECORD_METHOD(lldb::ConnectionStatus, SBCommunication, Connect,
|
|
(const char *), url);
|
|
|
|
if (m_opaque) {
|
|
if (!m_opaque->HasConnection())
|
|
m_opaque->SetConnection(Host::CreateDefaultConnection(url).release());
|
|
return m_opaque->Connect(url, NULL);
|
|
}
|
|
return eConnectionStatusNoConnection;
|
|
}
|
|
|
|
ConnectionStatus SBCommunication::AdoptFileDesriptor(int fd, bool owns_fd) {
|
|
LLDB_RECORD_METHOD(lldb::ConnectionStatus, SBCommunication,
|
|
AdoptFileDesriptor, (int, bool), fd, owns_fd);
|
|
|
|
ConnectionStatus status = eConnectionStatusNoConnection;
|
|
if (m_opaque) {
|
|
if (m_opaque->HasConnection()) {
|
|
if (m_opaque->IsConnected())
|
|
m_opaque->Disconnect();
|
|
}
|
|
m_opaque->SetConnection(new ConnectionFileDescriptor(fd, owns_fd));
|
|
if (m_opaque->IsConnected())
|
|
status = eConnectionStatusSuccess;
|
|
else
|
|
status = eConnectionStatusLostConnection;
|
|
}
|
|
return status;
|
|
}
|
|
|
|
ConnectionStatus SBCommunication::Disconnect() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::ConnectionStatus, SBCommunication,
|
|
Disconnect);
|
|
|
|
ConnectionStatus status = eConnectionStatusNoConnection;
|
|
if (m_opaque)
|
|
status = m_opaque->Disconnect();
|
|
return status;
|
|
}
|
|
|
|
bool SBCommunication::IsConnected() const {
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommunication, IsConnected);
|
|
|
|
return m_opaque ? m_opaque->IsConnected() : false;
|
|
}
|
|
|
|
size_t SBCommunication::Read(void *dst, size_t dst_len, uint32_t timeout_usec,
|
|
ConnectionStatus &status) {
|
|
size_t bytes_read = 0;
|
|
Timeout<std::micro> timeout = timeout_usec == UINT32_MAX
|
|
? Timeout<std::micro>(llvm::None)
|
|
: std::chrono::microseconds(timeout_usec);
|
|
if (m_opaque)
|
|
bytes_read = m_opaque->Read(dst, dst_len, timeout, status, NULL);
|
|
else
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
return bytes_read;
|
|
}
|
|
|
|
size_t SBCommunication::Write(const void *src, size_t src_len,
|
|
ConnectionStatus &status) {
|
|
size_t bytes_written = 0;
|
|
if (m_opaque)
|
|
bytes_written = m_opaque->Write(src, src_len, status, NULL);
|
|
else
|
|
status = eConnectionStatusNoConnection;
|
|
|
|
return bytes_written;
|
|
}
|
|
|
|
bool SBCommunication::ReadThreadStart() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommunication, ReadThreadStart);
|
|
|
|
return m_opaque ? m_opaque->StartReadThread() : false;
|
|
}
|
|
|
|
bool SBCommunication::ReadThreadStop() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommunication, ReadThreadStop);
|
|
|
|
return m_opaque ? m_opaque->StopReadThread() : false;
|
|
}
|
|
|
|
bool SBCommunication::ReadThreadIsRunning() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommunication, ReadThreadIsRunning);
|
|
|
|
return m_opaque ? m_opaque->ReadThreadIsRunning() : false;
|
|
}
|
|
|
|
bool SBCommunication::SetReadThreadBytesReceivedCallback(
|
|
ReadThreadBytesReceived callback, void *callback_baton) {
|
|
bool result = false;
|
|
if (m_opaque) {
|
|
m_opaque->SetReadThreadBytesReceivedCallback(callback, callback_baton);
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
SBBroadcaster SBCommunication::GetBroadcaster() {
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommunication,
|
|
GetBroadcaster);
|
|
|
|
SBBroadcaster broadcaster(m_opaque, false);
|
|
return LLDB_RECORD_RESULT(broadcaster);
|
|
}
|
|
|
|
const char *SBCommunication::GetBroadcasterClass() {
|
|
LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommunication,
|
|
GetBroadcasterClass);
|
|
|
|
return Communication::GetStaticBroadcasterClass().AsCString();
|
|
}
|