summaryrefslogtreecommitdiff
path: root/source/Host/common
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/common')
-rw-r--r--source/Host/common/File.cpp1
-rw-r--r--source/Host/common/Host.cpp1
-rw-r--r--source/Host/common/MainLoop.cpp1
-rw-r--r--source/Host/common/NativeRegisterContext.cpp67
-rw-r--r--source/Host/common/NativeThreadProtocol.cpp8
-rw-r--r--source/Host/common/Socket.cpp1
-rw-r--r--source/Host/common/SocketAddress.cpp7
-rw-r--r--source/Host/common/TCPSocket.cpp1
8 files changed, 43 insertions, 44 deletions
diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp
index 90a4462c6ca92..6ee4e894756b7 100644
--- a/source/Host/common/File.cpp
+++ b/source/Host/common/File.cpp
@@ -21,6 +21,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <termios.h>
+#include <unistd.h>
#endif
#include "llvm/Support/ConvertUTF.h"
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index 29e5991d31aa3..8248aa3c5118a 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -46,6 +46,7 @@
#endif
// C++ Includes
+#include <csignal>
// Other libraries and framework includes
// Project includes
diff --git a/source/Host/common/MainLoop.cpp b/source/Host/common/MainLoop.cpp
index c0c4471e735f1..d0e0d00a31511 100644
--- a/source/Host/common/MainLoop.cpp
+++ b/source/Host/common/MainLoop.cpp
@@ -10,6 +10,7 @@
#include "llvm/Config/llvm-config.h"
#include "lldb/Host/MainLoop.h"
+#include "lldb/Host/PosixApi.h"
#include "lldb/Utility/Status.h"
#include <algorithm>
#include <cassert>
diff --git a/source/Host/common/NativeRegisterContext.cpp b/source/Host/common/NativeRegisterContext.cpp
index 2ca95d7079638..629b0247422d2 100644
--- a/source/Host/common/NativeRegisterContext.cpp
+++ b/source/Host/common/NativeRegisterContext.cpp
@@ -345,17 +345,12 @@ Status NativeRegisterContext::ReadRegisterValueFromMemory(
return error;
}
- NativeProcessProtocolSP process_sp(m_thread.GetProcess());
- if (!process_sp) {
- error.SetErrorString("invalid process");
- return error;
- }
-
+ NativeProcessProtocol &process = m_thread.GetProcess();
uint8_t src[RegisterValue::kMaxRegisterByteSize];
// Read the memory
size_t bytes_read;
- error = process_sp->ReadMemory(src_addr, src, src_len, bytes_read);
+ error = process.ReadMemory(src_addr, src, src_len, bytes_read);
if (error.Fail())
return error;
@@ -374,7 +369,7 @@ Status NativeRegisterContext::ReadRegisterValueFromMemory(
// order of the memory data doesn't match the process. For now we are assuming
// they are the same.
lldb::ByteOrder byte_order;
- if (!process_sp->GetByteOrder(byte_order)) {
+ if (process.GetByteOrder(byte_order)) {
error.SetErrorString("NativeProcessProtocol::GetByteOrder () failed");
return error;
}
@@ -392,41 +387,37 @@ Status NativeRegisterContext::WriteRegisterValueToMemory(
Status error;
- NativeProcessProtocolSP process_sp(m_thread.GetProcess());
- if (process_sp) {
+ NativeProcessProtocol &process = m_thread.GetProcess();
- // TODO: we might need to add a parameter to this function in case the byte
- // order of the memory data doesn't match the process. For now we are
- // assuming
- // they are the same.
- lldb::ByteOrder byte_order;
- if (!process_sp->GetByteOrder(byte_order))
- return Status("NativeProcessProtocol::GetByteOrder () failed");
+ // TODO: we might need to add a parameter to this function in case the byte
+ // order of the memory data doesn't match the process. For now we are
+ // assuming
+ // they are the same.
+ lldb::ByteOrder byte_order;
+ if (!process.GetByteOrder(byte_order))
+ return Status("NativeProcessProtocol::GetByteOrder () failed");
- const size_t bytes_copied =
- reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
+ const size_t bytes_copied =
+ reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
- if (error.Success()) {
- if (bytes_copied == 0) {
- error.SetErrorString("byte copy failed.");
- } else {
- size_t bytes_written;
- error =
- process_sp->WriteMemory(dst_addr, dst, bytes_copied, bytes_written);
- if (error.Fail())
- return error;
-
- if (bytes_written != bytes_copied) {
- // This might happen if we read _some_ bytes but not all
- error.SetErrorStringWithFormat("only wrote %" PRIu64 " of %" PRIu64
- " bytes",
- static_cast<uint64_t>(bytes_written),
- static_cast<uint64_t>(bytes_copied));
- }
+ if (error.Success()) {
+ if (bytes_copied == 0) {
+ error.SetErrorString("byte copy failed.");
+ } else {
+ size_t bytes_written;
+ error = process.WriteMemory(dst_addr, dst, bytes_copied, bytes_written);
+ if (error.Fail())
+ return error;
+
+ if (bytes_written != bytes_copied) {
+ // This might happen if we read _some_ bytes but not all
+ error.SetErrorStringWithFormat("only wrote %" PRIu64 " of %" PRIu64
+ " bytes",
+ static_cast<uint64_t>(bytes_written),
+ static_cast<uint64_t>(bytes_copied));
}
}
- } else
- error.SetErrorString("invalid process");
+ }
return error;
}
diff --git a/source/Host/common/NativeThreadProtocol.cpp b/source/Host/common/NativeThreadProtocol.cpp
index 29e25bbc56927..54ac96dd3c6fd 100644
--- a/source/Host/common/NativeThreadProtocol.cpp
+++ b/source/Host/common/NativeThreadProtocol.cpp
@@ -16,9 +16,9 @@
using namespace lldb;
using namespace lldb_private;
-NativeThreadProtocol::NativeThreadProtocol(NativeProcessProtocol *process,
+NativeThreadProtocol::NativeThreadProtocol(NativeProcessProtocol &process,
lldb::tid_t tid)
- : m_process_wp(process->shared_from_this()), m_tid(tid) {}
+ : m_process(process), m_tid(tid) {}
Status NativeThreadProtocol::ReadRegister(uint32_t reg,
RegisterValue &reg_value) {
@@ -62,7 +62,3 @@ Status NativeThreadProtocol::RestoreAllRegisters(lldb::DataBufferSP &data_sp) {
return Status("no register context");
return register_context_sp->ReadAllRegisterValues(data_sp);
}
-
-NativeProcessProtocolSP NativeThreadProtocol::GetProcess() {
- return m_process_wp.lock();
-}
diff --git a/source/Host/common/Socket.cpp b/source/Host/common/Socket.cpp
index 0df9dc02c70fb..5490e9b30bdaf 100644
--- a/source/Host/common/Socket.cpp
+++ b/source/Host/common/Socket.cpp
@@ -29,6 +29,7 @@
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <unistd.h>
#endif
#ifdef __linux__
diff --git a/source/Host/common/SocketAddress.cpp b/source/Host/common/SocketAddress.cpp
index 41150fa7fd74a..def3e0359f016 100644
--- a/source/Host/common/SocketAddress.cpp
+++ b/source/Host/common/SocketAddress.cpp
@@ -317,6 +317,13 @@ bool SocketAddress::IsAnyAddr() const {
: 0 == memcmp(&m_socket_addr.sa_ipv6.sin6_addr, &in6addr_any, 16);
}
+bool SocketAddress::IsLocalhost() const {
+ return (GetFamily() == AF_INET)
+ ? m_socket_addr.sa_ipv4.sin_addr.s_addr == htonl(INADDR_LOOPBACK)
+ : 0 == memcmp(&m_socket_addr.sa_ipv6.sin6_addr, &in6addr_loopback,
+ 16);
+}
+
bool SocketAddress::operator==(const SocketAddress &rhs) const {
if (GetFamily() != rhs.GetFamily())
return false;
diff --git a/source/Host/common/TCPSocket.cpp b/source/Host/common/TCPSocket.cpp
index c013334ce23af..a7af93f10a7fe 100644
--- a/source/Host/common/TCPSocket.cpp
+++ b/source/Host/common/TCPSocket.cpp
@@ -34,6 +34,7 @@
#define CLOSE_SOCKET closesocket
typedef const char *set_socket_option_arg_type;
#else
+#include <unistd.h>
#define CLOSE_SOCKET ::close
typedef const void *set_socket_option_arg_type;
#endif