aboutsummaryrefslogtreecommitdiffstats
path: root/source/Host/common/NativeProcessProtocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Host/common/NativeProcessProtocol.cpp')
-rw-r--r--source/Host/common/NativeProcessProtocol.cpp75
1 files changed, 66 insertions, 9 deletions
diff --git a/source/Host/common/NativeProcessProtocol.cpp b/source/Host/common/NativeProcessProtocol.cpp
index 90272cb8d0bc..fd349cc2915b 100644
--- a/source/Host/common/NativeProcessProtocol.cpp
+++ b/source/Host/common/NativeProcessProtocol.cpp
@@ -16,6 +16,8 @@
#include "lldb/Utility/State.h"
#include "lldb/lldb-enumerations.h"
+#include "llvm/Support/Process.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -329,22 +331,23 @@ void NativeProcessProtocol::SynchronouslyNotifyProcessStateChanged(
if (log) {
if (!m_delegates.empty()) {
- log->Printf("NativeProcessProtocol::%s: sent state notification [%s] "
- "from process %" PRIu64,
- __FUNCTION__, lldb_private::StateAsCString(state), GetID());
+ LLDB_LOGF(log,
+ "NativeProcessProtocol::%s: sent state notification [%s] "
+ "from process %" PRIu64,
+ __FUNCTION__, lldb_private::StateAsCString(state), GetID());
} else {
- log->Printf("NativeProcessProtocol::%s: would send state notification "
- "[%s] from process %" PRIu64 ", but no delegates",
- __FUNCTION__, lldb_private::StateAsCString(state), GetID());
+ LLDB_LOGF(log,
+ "NativeProcessProtocol::%s: would send state notification "
+ "[%s] from process %" PRIu64 ", but no delegates",
+ __FUNCTION__, lldb_private::StateAsCString(state), GetID());
}
}
}
void NativeProcessProtocol::NotifyDidExec() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf("NativeProcessProtocol::%s - preparing to call delegates",
- __FUNCTION__);
+ LLDB_LOGF(log, "NativeProcessProtocol::%s - preparing to call delegates",
+ __FUNCTION__);
{
std::lock_guard<std::recursive_mutex> guard(m_delegates_mutex);
@@ -524,6 +527,7 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
switch (GetArchitecture().GetMachine()) {
case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64_32:
return llvm::makeArrayRef(g_aarch64_opcode);
case llvm::Triple::x86:
@@ -560,6 +564,7 @@ size_t NativeProcessProtocol::GetSoftwareBreakpointPCOffset() {
case llvm::Triple::arm:
case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64_32:
case llvm::Triple::mips64:
case llvm::Triple::mips64el:
case llvm::Triple::mips:
@@ -659,6 +664,58 @@ Status NativeProcessProtocol::ReadMemoryWithoutTrap(lldb::addr_t addr,
return Status();
}
+llvm::Expected<llvm::StringRef>
+NativeProcessProtocol::ReadCStringFromMemory(lldb::addr_t addr, char *buffer,
+ size_t max_size,
+ size_t &total_bytes_read) {
+ static const size_t cache_line_size =
+ llvm::sys::Process::getPageSizeEstimate();
+ size_t bytes_read = 0;
+ size_t bytes_left = max_size;
+ addr_t curr_addr = addr;
+ size_t string_size;
+ char *curr_buffer = buffer;
+ total_bytes_read = 0;
+ Status status;
+
+ while (bytes_left > 0 && status.Success()) {
+ addr_t cache_line_bytes_left =
+ cache_line_size - (curr_addr % cache_line_size);
+ addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
+ status = ReadMemory(curr_addr, reinterpret_cast<void *>(curr_buffer),
+ bytes_to_read, bytes_read);
+
+ if (bytes_read == 0)
+ break;
+
+ void *str_end = std::memchr(curr_buffer, '\0', bytes_read);
+ if (str_end != nullptr) {
+ total_bytes_read =
+ (size_t)(reinterpret_cast<char *>(str_end) - buffer + 1);
+ status.Clear();
+ break;
+ }
+
+ total_bytes_read += bytes_read;
+ curr_buffer += bytes_read;
+ curr_addr += bytes_read;
+ bytes_left -= bytes_read;
+ }
+
+ string_size = total_bytes_read - 1;
+
+ // Make sure we return a null terminated string.
+ if (bytes_left == 0 && max_size > 0 && buffer[max_size - 1] != '\0') {
+ buffer[max_size - 1] = '\0';
+ total_bytes_read--;
+ }
+
+ if (!status.Success())
+ return status.ToError();
+
+ return llvm::StringRef(buffer, string_size);
+}
+
lldb::StateType NativeProcessProtocol::GetState() const {
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
return m_state;