summaryrefslogtreecommitdiff
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.cpp121
1 files changed, 42 insertions, 79 deletions
diff --git a/source/Host/common/NativeProcessProtocol.cpp b/source/Host/common/NativeProcessProtocol.cpp
index b5b6e9d8b923..1fcb11b8b6f5 100644
--- a/source/Host/common/NativeProcessProtocol.cpp
+++ b/source/Host/common/NativeProcessProtocol.cpp
@@ -8,8 +8,6 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/common/NativeProcessProtocol.h"
-
-#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/State.h"
#include "lldb/Host/Host.h"
@@ -90,23 +88,23 @@ bool NativeProcessProtocol::SetExitStatus(WaitStatus status,
return true;
}
-NativeThreadProtocolSP NativeProcessProtocol::GetThreadAtIndex(uint32_t idx) {
+NativeThreadProtocol *NativeProcessProtocol::GetThreadAtIndex(uint32_t idx) {
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
if (idx < m_threads.size())
- return m_threads[idx];
- return NativeThreadProtocolSP();
+ return m_threads[idx].get();
+ return nullptr;
}
-NativeThreadProtocolSP
+NativeThreadProtocol *
NativeProcessProtocol::GetThreadByIDUnlocked(lldb::tid_t tid) {
- for (auto thread_sp : m_threads) {
- if (thread_sp->GetID() == tid)
- return thread_sp;
+ for (const auto &thread : m_threads) {
+ if (thread->GetID() == tid)
+ return thread.get();
}
- return NativeThreadProtocolSP();
+ return nullptr;
}
-NativeThreadProtocolSP NativeProcessProtocol::GetThreadByID(lldb::tid_t tid) {
+NativeThreadProtocol *NativeProcessProtocol::GetThreadByID(lldb::tid_t tid) {
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
return GetThreadByIDUnlocked(tid);
}
@@ -116,14 +114,6 @@ bool NativeProcessProtocol::IsAlive() const {
m_state != eStateInvalid && m_state != eStateUnloaded;
}
-bool NativeProcessProtocol::GetByteOrder(lldb::ByteOrder &byte_order) const {
- ArchSpec process_arch;
- if (!GetArchitecture(process_arch))
- return false;
- byte_order = process_arch.GetByteOrder();
- return true;
-}
-
const NativeWatchpointList::WatchpointMap &
NativeProcessProtocol::GetWatchpointMap() const {
return m_watchpoint_list.GetWatchpointMap();
@@ -134,27 +124,16 @@ NativeProcessProtocol::GetHardwareDebugSupportInfo() const {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
// get any thread
- NativeThreadProtocolSP thread_sp(
+ NativeThreadProtocol *thread(
const_cast<NativeProcessProtocol *>(this)->GetThreadAtIndex(0));
- if (!thread_sp) {
- if (log)
- log->Warning("NativeProcessProtocol::%s (): failed to find a thread to "
- "grab a NativeRegisterContext!",
- __FUNCTION__);
+ if (!thread) {
+ LLDB_LOG(log, "failed to find a thread to grab a NativeRegisterContext!");
return llvm::None;
}
- NativeRegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());
- if (!reg_ctx_sp) {
- if (log)
- log->Warning("NativeProcessProtocol::%s (): failed to get a "
- "RegisterContextNativeProcess from the first thread!",
- __FUNCTION__);
- return llvm::None;
- }
-
- return std::make_pair(reg_ctx_sp->NumSupportedHardwareBreakpoints(),
- reg_ctx_sp->NumSupportedHardwareWatchpoints());
+ NativeRegisterContext &reg_ctx = thread->GetRegisterContext();
+ return std::make_pair(reg_ctx.NumSupportedHardwareBreakpoints(),
+ reg_ctx.NumSupportedHardwareWatchpoints());
}
Status NativeProcessProtocol::SetWatchpoint(lldb::addr_t addr, size_t size,
@@ -175,7 +154,7 @@ Status NativeProcessProtocol::SetWatchpoint(lldb::addr_t addr, size_t size,
// for. If one of the thread watchpoint setting operations fails,
// back off and remove the watchpoint for all the threads that
// were successfully set so we get back to a consistent state.
- std::vector<NativeThreadProtocolSP> watchpoint_established_threads;
+ std::vector<NativeThreadProtocol *> watchpoint_established_threads;
// Tell each thread to set a watchpoint. In the event that
// hardware watchpoints are requested but the SetWatchpoint fails,
@@ -184,40 +163,33 @@ Status NativeProcessProtocol::SetWatchpoint(lldb::addr_t addr, size_t size,
// watchpoints available, some of the threads will fail to set
// hardware watchpoints while software ones may be available.
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
- for (auto thread_sp : m_threads) {
- assert(thread_sp && "thread list should not have a NULL thread!");
- if (!thread_sp)
- continue;
+ for (const auto &thread : m_threads) {
+ assert(thread && "thread list should not have a NULL thread!");
Status thread_error =
- thread_sp->SetWatchpoint(addr, size, watch_flags, hardware);
+ thread->SetWatchpoint(addr, size, watch_flags, hardware);
if (thread_error.Fail() && hardware) {
// Try software watchpoints since we failed on hardware watchpoint setting
// and we may have just run out of hardware watchpoints.
- thread_error = thread_sp->SetWatchpoint(addr, size, watch_flags, false);
- if (thread_error.Success()) {
- if (log)
- log->Warning(
- "hardware watchpoint requested but software watchpoint set");
- }
+ thread_error = thread->SetWatchpoint(addr, size, watch_flags, false);
+ if (thread_error.Success())
+ LLDB_LOG(log,
+ "hardware watchpoint requested but software watchpoint set");
}
if (thread_error.Success()) {
// Remember that we set this watchpoint successfully in
// case we need to clear it later.
- watchpoint_established_threads.push_back(thread_sp);
+ watchpoint_established_threads.push_back(thread.get());
} else {
// Unset the watchpoint for each thread we successfully
// set so that we get back to a consistent state of "not
// set" for the watchpoint.
for (auto unwatch_thread_sp : watchpoint_established_threads) {
Status remove_error = unwatch_thread_sp->RemoveWatchpoint(addr);
- if (remove_error.Fail() && log) {
- log->Warning("NativeProcessProtocol::%s (): RemoveWatchpoint failed "
- "for pid=%" PRIu64 ", tid=%" PRIu64 ": %s",
- __FUNCTION__, GetID(), unwatch_thread_sp->GetID(),
- remove_error.AsCString());
- }
+ if (remove_error.Fail())
+ LLDB_LOG(log, "RemoveWatchpoint failed for pid={0}, tid={1}: {2}",
+ GetID(), unwatch_thread_sp->GetID(), remove_error);
}
return thread_error;
@@ -233,12 +205,10 @@ Status NativeProcessProtocol::RemoveWatchpoint(lldb::addr_t addr) {
Status overall_error;
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
- for (auto thread_sp : m_threads) {
- assert(thread_sp && "thread list should not have a NULL thread!");
- if (!thread_sp)
- continue;
+ for (const auto &thread : m_threads) {
+ assert(thread && "thread list should not have a NULL thread!");
- const Status thread_error = thread_sp->RemoveWatchpoint(addr);
+ const Status thread_error = thread->RemoveWatchpoint(addr);
if (thread_error.Fail()) {
// Keep track of the first thread error if any threads
// fail. We want to try to remove the watchpoint from
@@ -277,20 +247,18 @@ Status NativeProcessProtocol::SetHardwareBreakpoint(lldb::addr_t addr,
// set this hardware breakpoint. If any of the current process threads fails
// to set this hardware breakpoint then roll back and remove this breakpoint
// for all the threads that had already set it successfully.
- std::vector<NativeThreadProtocolSP> breakpoint_established_threads;
+ std::vector<NativeThreadProtocol *> breakpoint_established_threads;
// Request to set a hardware breakpoint for each of current process threads.
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
- for (auto thread_sp : m_threads) {
- assert(thread_sp && "thread list should not have a NULL thread!");
- if (!thread_sp)
- continue;
+ for (const auto &thread : m_threads) {
+ assert(thread && "thread list should not have a NULL thread!");
- Status thread_error = thread_sp->SetHardwareBreakpoint(addr, size);
+ Status thread_error = thread->SetHardwareBreakpoint(addr, size);
if (thread_error.Success()) {
// Remember that we set this breakpoint successfully in
// case we need to clear it later.
- breakpoint_established_threads.push_back(thread_sp);
+ breakpoint_established_threads.push_back(thread.get());
} else {
// Unset the breakpoint for each thread we successfully
// set so that we get back to a consistent state of "not
@@ -298,12 +266,10 @@ Status NativeProcessProtocol::SetHardwareBreakpoint(lldb::addr_t addr,
for (auto rollback_thread_sp : breakpoint_established_threads) {
Status remove_error =
rollback_thread_sp->RemoveHardwareBreakpoint(addr);
- if (remove_error.Fail() && log) {
- log->Warning("NativeProcessProtocol::%s (): RemoveHardwareBreakpoint"
- " failed for pid=%" PRIu64 ", tid=%" PRIu64 ": %s",
- __FUNCTION__, GetID(), rollback_thread_sp->GetID(),
- remove_error.AsCString());
- }
+ if (remove_error.Fail())
+ LLDB_LOG(log,
+ "RemoveHardwareBreakpoint failed for pid={0}, tid={1}: {2}",
+ GetID(), rollback_thread_sp->GetID(), remove_error);
}
return thread_error;
@@ -324,12 +290,9 @@ Status NativeProcessProtocol::RemoveHardwareBreakpoint(lldb::addr_t addr) {
Status error;
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
- for (auto thread_sp : m_threads) {
- assert(thread_sp && "thread list should not have a NULL thread!");
- if (!thread_sp)
- continue;
-
- error = thread_sp->RemoveHardwareBreakpoint(addr);
+ for (const auto &thread : m_threads) {
+ assert(thread && "thread list should not have a NULL thread!");
+ error = thread->RemoveHardwareBreakpoint(addr);
}
// Also remove from hardware breakpoint map of current process.