summaryrefslogtreecommitdiff
path: root/lldb/source/Host/posix
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/posix')
-rw-r--r--lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp78
-rw-r--r--lldb/source/Host/posix/DomainSocket.cpp10
-rw-r--r--lldb/source/Host/posix/FileSystemPosix.cpp6
-rw-r--r--lldb/source/Host/posix/HostInfoPosix.cpp2
-rw-r--r--lldb/source/Host/posix/HostProcessPosix.cpp2
-rw-r--r--lldb/source/Host/posix/HostThreadPosix.cpp2
-rw-r--r--lldb/source/Host/posix/LockFilePosix.cpp2
-rw-r--r--lldb/source/Host/posix/PipePosix.cpp2
-rw-r--r--lldb/source/Host/posix/ProcessLauncherPosixFork.cpp2
9 files changed, 61 insertions, 45 deletions
diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
index 2223e1625b19..3a547ce128d8 100644
--- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -1,4 +1,4 @@
-//===-- ConnectionFileDescriptorPosix.cpp -----------------------*- C++ -*-===//
+//===-- ConnectionFileDescriptorPosix.cpp ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -42,6 +42,7 @@
#include "lldb/Host/Host.h"
#include "lldb/Host/Socket.h"
#include "lldb/Host/common/TCPSocket.h"
+#include "lldb/Host/common/UDPSocket.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timer.h"
@@ -208,7 +209,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
// this. For now, we assume we must assume we don't own it.
std::unique_ptr<TCPSocket> tcp_socket;
- tcp_socket.reset(new TCPSocket(fd, false, false));
+ tcp_socket = std::make_unique<TCPSocket>(fd, false, false);
// Try and get a socket option from this file descriptor to see if
// this is a socket and set m_is_socket accordingly.
int resuse;
@@ -223,7 +224,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
m_write_sp =
std::make_shared<NativeFile>(fd, File::eOpenOptionWrite, false);
}
- m_uri = *addr;
+ m_uri = std::string(*addr);
return eConnectionStatusSuccess;
}
}
@@ -652,7 +653,7 @@ ConnectionFileDescriptor::NamedSocketAccept(llvm::StringRef socket_name,
if (error.Fail()) {
return eConnectionStatusError;
}
- m_uri.assign(socket_name);
+ m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
@@ -669,7 +670,7 @@ ConnectionFileDescriptor::NamedSocketConnect(llvm::StringRef socket_name,
if (error.Fail()) {
return eConnectionStatusError;
}
- m_uri.assign(socket_name);
+ m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
@@ -686,66 +687,79 @@ ConnectionFileDescriptor::UnixAbstractSocketConnect(llvm::StringRef socket_name,
if (error.Fail()) {
return eConnectionStatusError;
}
- m_uri.assign(socket_name);
+ m_uri.assign(std::string(socket_name));
return eConnectionStatusSuccess;
}
ConnectionStatus
ConnectionFileDescriptor::SocketListenAndAccept(llvm::StringRef s,
Status *error_ptr) {
+ if (error_ptr)
+ *error_ptr = Status();
m_port_predicate.SetValue(0, eBroadcastNever);
- Socket *socket = nullptr;
m_waiting_for_accept = true;
- Status error = Socket::TcpListen(s, m_child_processes_inherit, socket,
- &m_port_predicate);
- if (error_ptr)
- *error_ptr = error;
- if (error.Fail())
+ llvm::Expected<std::unique_ptr<TCPSocket>> listening_socket =
+ Socket::TcpListen(s, m_child_processes_inherit, &m_port_predicate);
+ if (!listening_socket) {
+ if (error_ptr)
+ *error_ptr = listening_socket.takeError();
+ else
+ LLDB_LOG_ERROR(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION),
+ listening_socket.takeError(), "tcp listen failed: {0}");
return eConnectionStatusError;
+ }
- std::unique_ptr<Socket> listening_socket_up;
- listening_socket_up.reset(socket);
- socket = nullptr;
- error = listening_socket_up->Accept(socket);
- listening_socket_up.reset();
+ Socket *accepted_socket;
+ Status error = listening_socket.get()->Accept(accepted_socket);
if (error_ptr)
*error_ptr = error;
if (error.Fail())
return eConnectionStatusError;
- InitializeSocket(socket);
+ InitializeSocket(accepted_socket);
return eConnectionStatusSuccess;
}
ConnectionStatus ConnectionFileDescriptor::ConnectTCP(llvm::StringRef s,
Status *error_ptr) {
- Socket *socket = nullptr;
- Status error = Socket::TcpConnect(s, m_child_processes_inherit, socket);
if (error_ptr)
- *error_ptr = error;
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
- if (error.Fail()) {
+ *error_ptr = Status();
+
+ llvm::Expected<std::unique_ptr<Socket>> socket =
+ Socket::TcpConnect(s, m_child_processes_inherit);
+ if (!socket) {
+ if (error_ptr)
+ *error_ptr = socket.takeError();
+ else
+ LLDB_LOG_ERROR(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION),
+ socket.takeError(), "tcp connect failed: {0}");
return eConnectionStatusError;
}
- m_uri.assign(s);
+ m_write_sp = std::move(*socket);
+ m_read_sp = m_write_sp;
+ m_uri.assign(std::string(s));
return eConnectionStatusSuccess;
}
ConnectionStatus ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
Status *error_ptr) {
- Socket *socket = nullptr;
- Status error = Socket::UdpConnect(s, m_child_processes_inherit, socket);
if (error_ptr)
- *error_ptr = error;
- m_write_sp.reset(socket);
- m_read_sp = m_write_sp;
- if (error.Fail()) {
+ *error_ptr = Status();
+ llvm::Expected<std::unique_ptr<UDPSocket>> socket =
+ Socket::UdpConnect(s, m_child_processes_inherit);
+ if (!socket) {
+ if (error_ptr)
+ *error_ptr = socket.takeError();
+ else
+ LLDB_LOG_ERROR(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION),
+ socket.takeError(), "tcp connect failed: {0}");
return eConnectionStatusError;
}
- m_uri.assign(s);
+ m_write_sp = std::move(*socket);
+ m_read_sp = m_write_sp;
+ m_uri.assign(std::string(s));
return eConnectionStatusSuccess;
}
diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp
index 27872f48129c..5a396906fdf6 100644
--- a/lldb/source/Host/posix/DomainSocket.cpp
+++ b/lldb/source/Host/posix/DomainSocket.cpp
@@ -1,4 +1,4 @@
-//===-- DomainSocket.cpp ----------------------------------------*- C++ -*-===//
+//===-- DomainSocket.cpp --------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -146,10 +146,10 @@ std::string DomainSocket::GetSocketName() const {
std::string DomainSocket::GetRemoteConnectionURI() const {
if (m_socket != kInvalidSocketValue) {
- return llvm::formatv("{0}://{1}",
- GetNameOffset() == 0 ? "unix-connect"
- : "unix-abstract-connect",
- GetSocketName());
+ return std::string(llvm::formatv(
+ "{0}://{1}",
+ GetNameOffset() == 0 ? "unix-connect" : "unix-abstract-connect",
+ GetSocketName()));
}
return "";
}
diff --git a/lldb/source/Host/posix/FileSystemPosix.cpp b/lldb/source/Host/posix/FileSystemPosix.cpp
index 32fae68abb4d..0aa34bc59435 100644
--- a/lldb/source/Host/posix/FileSystemPosix.cpp
+++ b/lldb/source/Host/posix/FileSystemPosix.cpp
@@ -1,4 +1,4 @@
-//===-- FileSystem.cpp ------------------------------------------*- C++ -*-===//
+//===-- FileSystemPosix.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -43,7 +43,7 @@ Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
Status error;
char buf[PATH_MAX];
- ssize_t count = ::readlink(src.GetCString(), buf, sizeof(buf) - 1);
+ ssize_t count = ::readlink(src.GetPath().c_str(), buf, sizeof(buf) - 1);
if (count < 0)
error.SetErrorToErrno();
else {
@@ -72,9 +72,11 @@ Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
}
FILE *FileSystem::Fopen(const char *path, const char *mode) {
+ Collect(path);
return llvm::sys::RetryAfterSignal(nullptr, ::fopen, path, mode);
}
int FileSystem::Open(const char *path, int flags, int mode) {
+ Collect(path);
return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
}
diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp
index 63cc5dc65e00..7e110f07d7cf 100644
--- a/lldb/source/Host/posix/HostInfoPosix.cpp
+++ b/lldb/source/Host/posix/HostInfoPosix.cpp
@@ -1,4 +1,4 @@
-//===-- HostInfoPosix.cpp ---------------------------------------*- C++ -*-===//
+//===-- HostInfoPosix.cpp -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Host/posix/HostProcessPosix.cpp b/lldb/source/Host/posix/HostProcessPosix.cpp
index cc187d442468..69a049bcf7a2 100644
--- a/lldb/source/Host/posix/HostProcessPosix.cpp
+++ b/lldb/source/Host/posix/HostProcessPosix.cpp
@@ -1,4 +1,4 @@
-//===-- HostProcessPosix.cpp ------------------------------------*- C++ -*-===//
+//===-- HostProcessPosix.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Host/posix/HostThreadPosix.cpp b/lldb/source/Host/posix/HostThreadPosix.cpp
index d78bba517f69..31c7c7f8e2f3 100644
--- a/lldb/source/Host/posix/HostThreadPosix.cpp
+++ b/lldb/source/Host/posix/HostThreadPosix.cpp
@@ -1,4 +1,4 @@
-//===-- HostThreadPosix.cpp -------------------------------------*- C++ -*-===//
+//===-- HostThreadPosix.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Host/posix/LockFilePosix.cpp b/lldb/source/Host/posix/LockFilePosix.cpp
index a6eae95c333b..d197974a72a5 100644
--- a/lldb/source/Host/posix/LockFilePosix.cpp
+++ b/lldb/source/Host/posix/LockFilePosix.cpp
@@ -1,4 +1,4 @@
-//===-- LockFilePosix.cpp ---------------------------------------*- C++ -*-===//
+//===-- LockFilePosix.cpp -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Host/posix/PipePosix.cpp b/lldb/source/Host/posix/PipePosix.cpp
index ce1baf3f12a3..780222dffbf8 100644
--- a/lldb/source/Host/posix/PipePosix.cpp
+++ b/lldb/source/Host/posix/PipePosix.cpp
@@ -1,4 +1,4 @@
-//===-- PipePosix.cpp -------------------------------------------*- C++ -*-===//
+//===-- PipePosix.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
index 185c7f0fe248..35482341d3e6 100644
--- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -1,4 +1,4 @@
-//===-- ProcessLauncherPosixFork.cpp ----------------------------*- C++ -*-===//
+//===-- ProcessLauncherPosixFork.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.