Skip to content

Commit d3dfd8c

Browse files
committed
Add a setting to force stepping to always run all threads.
Also allow ScriptedThreadPlans to set & get their StopOthers state. <rdar://problem/64229484> Differential Revision: https://reviews.llvm.org/D85265
1 parent 71a1f13 commit d3dfd8c

File tree

12 files changed

+136
-16
lines changed

12 files changed

+136
-16
lines changed

lldb/bindings/interface/SBThreadPlan.i

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public:
9292
bool
9393
IsPlanStale();
9494

95+
%feature("docstring", "Return whether this plan will ask to stop other threads when it runs.") GetStopOthers;
96+
bool
97+
GetStopOthers();
98+
99+
%feature("docstring", "Set whether this plan will ask to stop other threads when it runs.") GetStopOthers;
100+
void
101+
SetStopOthers(bool stop_others);
102+
95103
SBThreadPlan
96104
QueueThreadPlanForStepOverRange (SBAddress &start_address,
97105
lldb::addr_t range_size);

lldb/include/lldb/API/SBThreadPlan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class LLDB_API SBThreadPlan {
7777

7878
bool IsValid();
7979

80+
bool GetStopOthers();
81+
82+
void SetStopOthers(bool stop_others);
83+
8084
// This section allows an SBThreadPlan to push another of the common types of
8185
// plans...
8286
SBThreadPlan QueueThreadPlanForStepOverRange(SBAddress &start_address,

lldb/include/lldb/Target/Process.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ProcessProperties : public Properties {
9191
std::chrono::seconds GetUtilityExpressionTimeout() const;
9292
bool GetOSPluginReportsAllThreads() const;
9393
void SetOSPluginReportsAllThreads(bool does_report);
94+
bool GetSteppingRunsAllThreads() const;
9495

9596
protected:
9697
Process *m_process; // Can be nullptr for global ProcessProperties

lldb/include/lldb/Target/ThreadPlanPython.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class ThreadPlanPython : public ThreadPlan {
4545

4646
bool WillStop() override;
4747

48-
bool StopOthers() override;
48+
bool StopOthers() override { return m_stop_others; }
49+
50+
void SetStopOthers(bool new_value) { m_stop_others = new_value; }
4951

5052
void DidPush() override;
5153

@@ -67,6 +69,7 @@ class ThreadPlanPython : public ThreadPlan {
6769
std::string m_error_str;
6870
StructuredData::ObjectSP m_implementation_sp;
6971
bool m_did_push;
72+
bool m_stop_others;
7073

7174
ThreadPlanPython(const ThreadPlanPython &) = delete;
7275
const ThreadPlanPython &operator=(const ThreadPlanPython &) = delete;

lldb/source/API/SBThreadPlan.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ bool SBThreadPlan::IsValid() {
196196
return false;
197197
}
198198

199+
bool SBThreadPlan::GetStopOthers() {
200+
LLDB_RECORD_METHOD_NO_ARGS(bool, SBThreadPlan, GetStopOthers);
201+
202+
ThreadPlanSP thread_plan_sp(GetSP());
203+
if (thread_plan_sp)
204+
return thread_plan_sp->StopOthers();
205+
return false;
206+
}
207+
208+
void SBThreadPlan::SetStopOthers(bool stop_others) {
209+
LLDB_RECORD_METHOD(void, SBThreadPlan, SetStopOthers, (bool), stop_others);
210+
211+
ThreadPlanSP thread_plan_sp(GetSP());
212+
if (thread_plan_sp)
213+
thread_plan_sp->SetStopOthers(stop_others);
214+
}
215+
199216
// This section allows an SBThreadPlan to push another of the common types of
200217
// plans...
201218
//
@@ -463,6 +480,8 @@ void RegisterMethods<SBThreadPlan>(Registry &R) {
463480
LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanComplete, ());
464481
LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsPlanStale, ());
465482
LLDB_REGISTER_METHOD(bool, SBThreadPlan, IsValid, ());
483+
LLDB_REGISTER_METHOD(void, SBThreadPlan, SetStopOthers, (bool));
484+
LLDB_REGISTER_METHOD(bool, SBThreadPlan, GetStopOthers, ());
466485
LLDB_REGISTER_METHOD(lldb::SBThreadPlan, SBThreadPlan,
467486
QueueThreadPlanForStepOverRange,
468487
(lldb::SBAddress &, lldb::addr_t));

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,16 @@ class ThreadStepScopeOptionGroup : public OptionGroup {
482482
// Check if we are in Non-Stop mode
483483
TargetSP target_sp =
484484
execution_context ? execution_context->GetTargetSP() : TargetSP();
485-
if (target_sp && target_sp->GetNonStopModeEnabled())
485+
if (target_sp && target_sp->GetNonStopModeEnabled()) {
486+
// NonStopMode runs all threads by definition, so when it is on we don't
487+
// need to check the process setting for runs all threads.
486488
m_run_mode = eOnlyThisThread;
489+
} else {
490+
ProcessSP process_sp =
491+
execution_context ? execution_context->GetProcessSP() : ProcessSP();
492+
if (process_sp && process_sp->GetSteppingRunsAllThreads())
493+
m_run_mode = eAllThreads;
494+
}
487495

488496
m_avoid_regexp.clear();
489497
m_step_in_target.clear();
@@ -612,8 +620,7 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
612620
if (m_options.m_run_mode == eAllThreads)
613621
bool_stop_other_threads = false;
614622
else if (m_options.m_run_mode == eOnlyDuringStepping)
615-
bool_stop_other_threads =
616-
(m_step_type != eStepTypeOut && m_step_type != eStepTypeScripted);
623+
bool_stop_other_threads = (m_step_type != eStepTypeOut);
617624
else
618625
bool_stop_other_threads = true;
619626

lldb/source/Target/Process.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ std::chrono::seconds ProcessProperties::GetUtilityExpressionTimeout() const {
278278
return std::chrono::seconds(value);
279279
}
280280

281+
bool ProcessProperties::GetSteppingRunsAllThreads() const {
282+
const uint32_t idx = ePropertySteppingRunsAllThreads;
283+
return m_collection_sp->GetPropertyAtIndexAsBoolean(
284+
nullptr, idx, g_process_properties[idx].default_uint_value != 0);
285+
}
286+
281287
bool ProcessProperties::GetOSPluginReportsAllThreads() const {
282288
const bool fail_value = true;
283289
const Property *exp_property =

lldb/source/Target/TargetProperties.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ let Definition = "process" in {
217217
def UtilityExpressionTimeout: Property<"utility-expression-timeout", "UInt64">,
218218
DefaultUnsignedValue<15>,
219219
Desc<"The time in seconds to wait for LLDB-internal utility expressions.">;
220+
def SteppingRunsAllThreads: Property<"run-all-threads", "Boolean">,
221+
DefaultFalse,
222+
Desc<"If true, stepping operations will run all threads. This is equivalent to setting the run-mode option to 'all-threads'.">;
220223
}
221224

222225
let Definition = "platform" in {

lldb/source/Target/Thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ lldb::ThreadPlanSP Thread::QueueThreadPlanForStepScripted(
13801380

13811381
ThreadPlanSP thread_plan_sp(new ThreadPlanPython(*this, class_name,
13821382
extra_args_impl));
1383-
1383+
thread_plan_sp->SetStopOthers(stop_other_threads);
13841384
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
13851385
return thread_plan_sp;
13861386
}

lldb/source/Target/ThreadPlanPython.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ using namespace lldb_private;
2525

2626
// ThreadPlanPython
2727

28-
ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
28+
ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
2929
StructuredDataImpl *args_data)
3030
: ThreadPlan(ThreadPlan::eKindPython, "Python based Thread Plan", thread,
3131
eVoteNoOpinion, eVoteNoOpinion),
32-
m_class_name(class_name), m_args_data(args_data), m_did_push(false) {
32+
m_class_name(class_name), m_args_data(args_data), m_did_push(false),
33+
m_stop_others(false) {
3334
SetIsMasterPlan(true);
3435
SetOkayToDiscard(true);
3536
SetPrivate(false);
@@ -162,13 +163,6 @@ lldb::StateType ThreadPlanPython::GetPlanRunState() {
162163
}
163164

164165
// The ones below are not currently exported to Python.
165-
166-
bool ThreadPlanPython::StopOthers() {
167-
// For now Python plans run all threads, but we should add some controls for
168-
// this.
169-
return false;
170-
}
171-
172166
void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
173167
s->Printf("Python thread plan implemented by class %s.",
174168
m_class_name.c_str());

0 commit comments

Comments
 (0)