aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Target/Thread.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /lldb/source/Target/Thread.cpp
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'lldb/source/Target/Thread.cpp')
-rw-r--r--lldb/source/Target/Thread.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index f63b57fd4e62..d620f746339e 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -53,6 +53,7 @@
#include "lldb/lldb-enumerations.h"
#include <memory>
+#include <optional>
using namespace lldb;
using namespace lldb_private;
@@ -221,6 +222,7 @@ Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id)
Thread::GetStaticBroadcasterClass().AsCString()),
m_process_wp(process.shared_from_this()), m_stop_info_sp(),
m_stop_info_stop_id(0), m_stop_info_override_stop_id(0),
+ m_should_run_before_public_stop(false),
m_index_id(use_invalid_index_id ? LLDB_INVALID_INDEX32
: process.GetNextThreadIndexID(tid)),
m_reg_context_sp(), m_state(eStateUnloaded), m_state_mutex(),
@@ -369,7 +371,10 @@ void Thread::CalculatePublicStopInfo() {
SetStopInfo(GetStopInfo());
}
-lldb::StopInfoSP Thread::GetPrivateStopInfo() {
+lldb::StopInfoSP Thread::GetPrivateStopInfo(bool calculate) {
+ if (!calculate)
+ return m_stop_info_sp;
+
if (m_destroy_called)
return m_stop_info_sp;
@@ -377,9 +382,15 @@ lldb::StopInfoSP Thread::GetPrivateStopInfo() {
if (process_sp) {
const uint32_t process_stop_id = process_sp->GetStopID();
if (m_stop_info_stop_id != process_stop_id) {
+ // We preserve the old stop info for a variety of reasons:
+ // 1) Someone has already updated it by the time we get here
+ // 2) We didn't get to execute the breakpoint instruction we stopped at
+ // 3) This is a virtual step so we didn't actually run
+ // 4) If this thread wasn't allowed to run the last time round.
if (m_stop_info_sp) {
if (m_stop_info_sp->IsValid() || IsStillAtLastBreakpointHit() ||
- GetCurrentPlan()->IsVirtualStep())
+ GetCurrentPlan()->IsVirtualStep()
+ || GetTemporaryResumeState() == eStateSuspended)
SetStopInfo(m_stop_info_sp);
else
m_stop_info_sp.reset();
@@ -723,7 +734,11 @@ bool Thread::ShouldResume(StateType resume_state) {
return need_to_resume;
}
-void Thread::DidResume() { SetResumeSignal(LLDB_INVALID_SIGNAL_NUMBER); }
+void Thread::DidResume() {
+ SetResumeSignal(LLDB_INVALID_SIGNAL_NUMBER);
+ // This will get recomputed each time when we stop.
+ SetShouldRunBeforePublicStop(false);
+}
void Thread::DidStop() { SetState(eStateStopped); }
@@ -763,6 +778,9 @@ bool Thread::ShouldStop(Event *event_ptr) {
: LLDB_INVALID_ADDRESS);
return false;
}
+
+ // Clear the "must run me before stop" if it was set:
+ SetShouldRunBeforePublicStop(false);
if (log) {
LLDB_LOGF(log,
@@ -845,9 +863,14 @@ bool Thread::ShouldStop(Event *event_ptr) {
// stack below.
done_processing_current_plan =
(plan_ptr->IsControllingPlan() && !plan_ptr->OkayToDiscard());
- } else
+ } else {
+ bool should_force_run = plan_ptr->ShouldRunBeforePublicStop();
+ if (should_force_run) {
+ SetShouldRunBeforePublicStop(true);
+ should_stop = false;
+ }
done_processing_current_plan = true;
-
+ }
break;
}
}
@@ -1062,7 +1085,7 @@ ThreadPlanStack &Thread::GetPlans() const {
// queries GetDescription makes, and only assert if you try to run the thread.
if (!m_null_plan_stack_up)
m_null_plan_stack_up = std::make_unique<ThreadPlanStack>(*this, true);
- return *(m_null_plan_stack_up.get());
+ return *m_null_plan_stack_up;
}
void Thread::PushPlan(ThreadPlanSP thread_plan_sp) {
@@ -1641,6 +1664,10 @@ addr_t Thread::GetThreadLocalData(const ModuleSP module,
bool Thread::SafeToCallFunctions() {
Process *process = GetProcess().get();
if (process) {
+ DynamicLoader *loader = GetProcess()->GetDynamicLoader();
+ if (loader && loader->IsFullyInitialized() == false)
+ return false;
+
SystemRuntime *runtime = process->GetSystemRuntime();
if (runtime) {
return runtime->SafeToCallFunctionsOnThisThread(shared_from_this());
@@ -2020,10 +2047,10 @@ lldb::ValueObjectSP Thread::GetSiginfoValue() {
if (!type.IsValid())
return ValueObjectConstResult::Create(&target, Status("no siginfo_t for the platform"));
- llvm::Optional<uint64_t> type_size = type.GetByteSize(nullptr);
+ std::optional<uint64_t> type_size = type.GetByteSize(nullptr);
assert(type_size);
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> data =
- GetSiginfo(type_size.value());
+ GetSiginfo(*type_size);
if (!data)
return ValueObjectConstResult::Create(&target, Status(data.takeError()));