Skip to content

Commit c752dc4

Browse files
Merge pull request #10077 from felipepiovezan/felipe/cherry-pick-customization-removal
[lldb][NFC] Remove downstream changes related to ThreadPlan migration
2 parents 1c93ab8 + a941305 commit c752dc4

File tree

6 files changed

+14
-178
lines changed

6 files changed

+14
-178
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,18 +2368,6 @@ bool PruneThreadPlansForTID(lldb::tid_t tid);
23682368
/// Prune ThreadPlanStacks for all unreported threads.
23692369
void PruneThreadPlans();
23702370

2371-
void SynchronizeThreadPlans();
2372-
2373-
/// From the detached thread plan stacks, find the first stack that explains
2374-
/// the stop represented by the thread and the event.
2375-
lldb::ThreadPlanSP FindDetachedPlanExplainingStop(Thread &thread, Event *event_ptr);
2376-
2377-
/// Helper function for FindDetachedPlanExplainingStop. Exists only to be
2378-
/// marked as a C++ friend of `ThreadPlan`.
2379-
lldb::ThreadPlanSP DoesStackExplainStopNoLock(ThreadPlanStack &stack,
2380-
Thread &thread,
2381-
Event *event_ptr);
2382-
23832371
/// Find the thread plan stack associated with thread with \a tid.
23842372
///
23852373
/// \param[in] tid

lldb/include/lldb/Target/ThreadPlan.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -498,25 +498,6 @@ class ThreadPlan : public std::enable_shared_from_this<ThreadPlan>,
498498
return m_takes_iteration_count;
499499
}
500500

501-
bool IsTID(lldb::tid_t tid) { return tid == m_tid; }
502-
bool HasTID() { return m_tid != LLDB_INVALID_THREAD_ID; }
503-
lldb::tid_t GetTID() { return m_tid; }
504-
505-
void SetTID(lldb::tid_t tid) {
506-
if (m_tid != tid) {
507-
m_tid = tid;
508-
ClearThreadCache();
509-
}
510-
}
511-
512-
void ClearTID() {
513-
m_tid = LLDB_INVALID_THREAD_ID;
514-
ClearThreadCache();
515-
}
516-
517-
friend lldb::ThreadPlanSP
518-
Process::DoesStackExplainStopNoLock(ThreadPlanStack &stack, Thread &thread,
519-
Event *event_ptr);
520501
virtual lldb::StateType GetPlanRunState() = 0;
521502

522503
protected:

lldb/include/lldb/Target/ThreadPlanStack.h

Lines changed: 6 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ class ThreadPlanStack {
9797
/// generated.
9898
void ClearThreadCache();
9999

100-
bool IsTID(lldb::tid_t tid) {
101-
return GetTID() == tid;
102-
}
103-
lldb::tid_t GetTID();
104-
void SetTID(lldb::tid_t tid);
105-
106100
private:
107101
lldb::ThreadPlanSP DiscardPlanNoLock();
108102
lldb::ThreadPlanSP GetCurrentPlanNoLock() const;
@@ -122,9 +116,6 @@ class ThreadPlanStack {
122116
// completed plan checkpoints.
123117
std::unordered_map<size_t, PlanStack> m_completed_plan_store;
124118
mutable llvm::sys::RWMutex m_stack_mutex;
125-
126-
// ThreadPlanStacks shouldn't be copied.
127-
ThreadPlanStack(ThreadPlanStack &rhs) = delete;
128119
};
129120

130121
class ThreadPlanStackMap {
@@ -139,35 +130,16 @@ class ThreadPlanStackMap {
139130
void AddThread(Thread &thread) {
140131
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
141132
lldb::tid_t tid = thread.GetID();
142-
// If we already have a ThreadPlanStack for this thread, use it.
143-
if (m_plans_list.find(tid) != m_plans_list.end())
144-
return;
145-
146-
m_plans_up_container.emplace_back(
147-
std::make_unique<ThreadPlanStack>(thread));
148-
m_plans_list.emplace(tid, m_plans_up_container.back().get());
133+
m_plans_list.emplace(tid, thread);
149134
}
150135

151136
bool RemoveTID(lldb::tid_t tid) {
152137
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
153138
auto result = m_plans_list.find(tid);
154139
if (result == m_plans_list.end())
155140
return false;
156-
ThreadPlanStack *removed_stack = result->second;
141+
result->second.ThreadDestroyed(nullptr);
157142
m_plans_list.erase(result);
158-
// Now find it in the stack storage:
159-
auto end = m_plans_up_container.end();
160-
auto iter = std::find_if(m_plans_up_container.begin(), end,
161-
[&] (std::unique_ptr<ThreadPlanStack> &stack) {
162-
return stack->IsTID(tid);
163-
});
164-
if (iter == end)
165-
return false;
166-
167-
// Then tell the stack its thread has been destroyed:
168-
removed_stack->ThreadDestroyed(nullptr);
169-
// And then remove it from the container so it goes away.
170-
m_plans_up_container.erase(iter);
171143
return true;
172144
}
173145

@@ -177,69 +149,22 @@ class ThreadPlanStackMap {
177149
if (result == m_plans_list.end())
178150
return nullptr;
179151
else
180-
return result->second;
152+
return &result->second;
181153
}
182154

183155
/// Clear the Thread* cache that each ThreadPlan contains.
184156
///
185157
/// This is useful in situations like when a new Thread list is being
186158
/// generated.
187159
void ClearThreadCache() {
188-
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
189160
for (auto &plan_list : m_plans_list)
190-
plan_list.second->ClearThreadCache();
191-
}
192-
193-
// rename to Reactivate?
194-
void Activate(ThreadPlanStack &stack) {
195-
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
196-
// Remove this from the detached plan list:
197-
auto end = m_detached_plans.end();
198-
auto iter = std::find_if(m_detached_plans.begin(), end,
199-
[&] (ThreadPlanStack *elem) {
200-
return elem == &stack; });
201-
if (iter != end)
202-
m_detached_plans.erase(iter);
203-
204-
if (m_plans_list.find(stack.GetTID()) == m_plans_list.end())
205-
m_plans_list.emplace(stack.GetTID(), &stack);
206-
else
207-
m_plans_list.at(stack.GetTID()) = &stack;
208-
}
209-
210-
void ScanForDetachedPlanStacks() {
211-
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
212-
llvm::SmallVector<lldb::tid_t, 2> invalidated_tids;
213-
for (auto &pair : m_plans_list)
214-
if (pair.second->GetTID() != pair.first)
215-
invalidated_tids.push_back(pair.first);
216-
217-
for (auto tid : invalidated_tids) {
218-
auto it = m_plans_list.find(tid);
219-
ThreadPlanStack *stack = it->second;
220-
m_plans_list.erase(it);
221-
m_detached_plans.push_back(stack);
222-
}
223-
}
224-
225-
// This gets the vector of pointers to thread plans that aren't
226-
// currently running on a thread. This is generally for thread
227-
// plans that represent asynchronous operations waiting to be
228-
// scheduled.
229-
// The vector will never have null ThreadPlanStacks in it.
230-
lldb::ThreadPlanSP FindThreadPlanInStack(
231-
llvm::function_ref<lldb::ThreadPlanSP(ThreadPlanStack &)> fn) {
232-
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
233-
for (auto *stack : m_detached_plans)
234-
if (auto plan = fn(*stack))
235-
return plan;
236-
return {};
161+
plan_list.second.ClearThreadCache();
237162
}
238163

239164
void Clear() {
240165
std::lock_guard<std::recursive_mutex> guard(m_stack_map_mutex);
241166
for (auto &plan : m_plans_list)
242-
plan.second->ThreadDestroyed(nullptr);
167+
plan.second.ThreadDestroyed(nullptr);
243168
m_plans_list.clear();
244169
}
245170

@@ -256,23 +181,8 @@ class ThreadPlanStackMap {
256181

257182
private:
258183
Process &m_process;
259-
// We don't want to make copies of these ThreadPlanStacks, there needs to be
260-
// just one of these tracking each piece of work. But we need to move the
261-
// work from "attached to a TID" state to "detached" state, which is most
262-
// conveniently done by having organizing containers for each of the two
263-
// states.
264-
// To make it easy to move these non-copyable entities in and out of the
265-
// organizing containers, we make the ThreadPlanStacks into unique_ptr's in a
266-
// storage container - m_plans_up_container. Storing unique_ptrs means we
267-
// can then use the pointer to the ThreadPlanStack in the "organizing"
268-
// containers, the TID->Stack map m_plans_list, and the detached plans
269-
// vector m_detached_plans.
270-
271-
using PlansStore = std::vector<std::unique_ptr<ThreadPlanStack>>;
272-
PlansStore m_plans_up_container;
273-
std::vector<ThreadPlanStack *> m_detached_plans;
274184
mutable std::recursive_mutex m_stack_map_mutex;
275-
using PlansList = std::unordered_map<lldb::tid_t, ThreadPlanStack *>;
185+
using PlansList = std::unordered_map<lldb::tid_t, ThreadPlanStack>;
276186
PlansList m_plans_list;
277187

278188
};

lldb/source/Target/Process.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,34 +1349,6 @@ void Process::UpdateThreadListIfNeeded() {
13491349
}
13501350
}
13511351

1352-
void Process::SynchronizeThreadPlans() {
1353-
m_thread_plans.ScanForDetachedPlanStacks();
1354-
}
1355-
1356-
ThreadPlanSP Process::FindDetachedPlanExplainingStop(Thread &thread,
1357-
Event *event_ptr) {
1358-
return m_thread_plans.FindThreadPlanInStack(
1359-
[&](ThreadPlanStack &stack) -> ThreadPlanSP {
1360-
return DoesStackExplainStopNoLock(stack, thread, event_ptr);
1361-
});
1362-
}
1363-
1364-
// This extracted function only exists so that it can be marked a friend of
1365-
// `ThreadPlan`, which is needed to call `DoPlanExplainsStop`.
1366-
ThreadPlanSP Process::DoesStackExplainStopNoLock(ThreadPlanStack &stack,
1367-
Thread &thread,
1368-
Event *event_ptr) {
1369-
ThreadPlanSP plan_sp = stack.GetCurrentPlan();
1370-
plan_sp->SetTID(thread.GetID());
1371-
if (plan_sp->DoPlanExplainsStop(event_ptr)) {
1372-
stack.SetTID(thread.GetID());
1373-
m_thread_plans.Activate(stack);
1374-
return plan_sp;
1375-
}
1376-
plan_sp->ClearTID();
1377-
return {};
1378-
}
1379-
13801352
ThreadPlanStack *Process::FindThreadPlans(lldb::tid_t tid) {
13811353
return m_thread_plans.Find(tid);
13821354
}
@@ -3851,10 +3823,8 @@ bool Process::ShouldBroadcastEvent(Event *event_ptr) {
38513823
// restarted... Asking the thread list is also not likely to go well,
38523824
// since we are running again. So in that case just report the event.
38533825

3854-
if (!was_restarted) {
3826+
if (!was_restarted)
38553827
should_resume = !m_thread_list.ShouldStop(event_ptr);
3856-
SynchronizeThreadPlans();
3857-
}
38583828

38593829
if (was_restarted || should_resume || m_resume_requested) {
38603830
Vote report_stop_vote = m_thread_list.ShouldReportStop(event_ptr);

lldb/source/Target/Thread.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ void Thread::DidResume() {
785785
void Thread::DidStop() { SetState(eStateStopped); }
786786

787787
bool Thread::ShouldStop(Event *event_ptr) {
788+
ThreadPlan *current_plan = GetCurrentPlan();
788789
bool should_stop = true;
789790

790791
Log *log = GetLog(LLDBLog::Step);
@@ -838,6 +839,9 @@ bool Thread::ShouldStop(Event *event_ptr) {
838839
LLDB_LOGF(log, "Plan stack initial state:\n%s", s.GetData());
839840
}
840841

842+
// The top most plan always gets to do the trace log...
843+
current_plan->DoTraceLog();
844+
841845
// First query the stop info's ShouldStopSynchronous. This handles
842846
// "synchronous" stop reasons, for example the breakpoint command on internal
843847
// breakpoints. If a synchronous stop reason says we should not stop, then
@@ -850,16 +854,6 @@ bool Thread::ShouldStop(Event *event_ptr) {
850854
return false;
851855
}
852856

853-
// Call this after ShouldStopSynchronous.
854-
ThreadPlan *current_plan;
855-
if (auto plan = GetProcess()->FindDetachedPlanExplainingStop(*this, event_ptr))
856-
current_plan = plan.get();
857-
else
858-
current_plan = GetCurrentPlan();
859-
860-
// The top most plan always gets to do the trace log…
861-
current_plan->DoTraceLog();
862-
863857
// If we've already been restarted, don't query the plans since the state
864858
// they would examine is not current.
865859
if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr))

lldb/source/Target/ThreadPlanStack.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,6 @@ void ThreadPlanStack::WillResume() {
408408
m_discarded_plans.clear();
409409
}
410410

411-
lldb::tid_t ThreadPlanStack::GetTID() { return GetCurrentPlan()->GetTID(); }
412-
413-
void ThreadPlanStack::SetTID(lldb::tid_t tid) {
414-
for (auto plan_sp : m_plans)
415-
plan_sp->SetTID(tid);
416-
}
417-
418411
void ThreadPlanStackMap::Update(ThreadList &current_threads,
419412
bool delete_missing,
420413
bool check_for_new) {
@@ -468,8 +461,8 @@ void ThreadPlanStackMap::DumpPlans(Stream &strm,
468461
index_id = thread_sp->GetIndexID();
469462

470463
if (condense_if_trivial) {
471-
if (!elem.second->AnyPlans() && !elem.second->AnyCompletedPlans() &&
472-
!elem.second->AnyDiscardedPlans()) {
464+
if (!elem.second.AnyPlans() && !elem.second.AnyCompletedPlans() &&
465+
!elem.second.AnyDiscardedPlans()) {
473466
strm.Printf("thread #%u: tid = 0x%4.4" PRIx64 "\n", index_id, tid);
474467
strm.IndentMore();
475468
strm.Indent();
@@ -482,7 +475,7 @@ void ThreadPlanStackMap::DumpPlans(Stream &strm,
482475
strm.Indent();
483476
strm.Printf("thread #%u: tid = 0x%4.4" PRIx64 ":\n", index_id, tid);
484477

485-
elem.second->DumpThreadPlans(strm, desc_level, internal);
478+
elem.second.DumpThreadPlans(strm, desc_level, internal);
486479
}
487480
}
488481

0 commit comments

Comments
 (0)