Skip to content

Commit 039cfe8

Browse files
authored
[lldb/Target] Rename ThreadPlanPython into ScriptedThreadPlan (#101931)
Following 9a9ec22, since the ThreadPlanPython class started making use of the Scripted Interface instead of calling directly into the python methods, this class can work with other scripting languages (as long as someone add the interfact for that language ;p). So it doesn't make sense anymore for it to keep this name and also we should avoid having language specific related classes outside the plugin directory. This patch renames the internal class from `ThreadPlanPython` to `ScriptedThreadPlan` as its advertised externally, and also updates the various log messages. This should hopefully make the codebase more coherent. Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent dac9042 commit 039cfe8

File tree

5 files changed

+59
-65
lines changed

5 files changed

+59
-65
lines changed

lldb/include/lldb/Target/ThreadPlanPython.h renamed to lldb/include/lldb/Target/ScriptedThreadPlan.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
//===-- ThreadPlanPython.h --------------------------------------------*- C++
2-
//-*-===//
1+
//===-- ScriptedThreadPlan.h ------------------------------------*- C++ -*-===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54
// See https://llvm.org/LICENSE.txt for license information.
65
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
76
//
87
//===----------------------------------------------------------------------===//
98

10-
#ifndef LLDB_TARGET_THREADPLANPYTHON_H
11-
#define LLDB_TARGET_THREADPLANPYTHON_H
9+
#ifndef LLDB_TARGET_SCRIPTEDTHREADPLAN_H
10+
#define LLDB_TARGET_SCRIPTEDTHREADPLAN_H
1211

1312
#include <string>
1413

@@ -27,13 +26,10 @@
2726

2827
namespace lldb_private {
2928

30-
// ThreadPlanPython:
31-
//
32-
33-
class ThreadPlanPython : public ThreadPlan {
29+
class ScriptedThreadPlan : public ThreadPlan {
3430
public:
35-
ThreadPlanPython(Thread &thread, const char *class_name,
36-
const StructuredDataImpl &args_data);
31+
ScriptedThreadPlan(Thread &thread, const char *class_name,
32+
const StructuredDataImpl &args_data);
3733

3834
void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
3935

@@ -52,15 +48,14 @@ class ThreadPlanPython : public ThreadPlan {
5248
void DidPush() override;
5349

5450
bool IsPlanStale() override;
55-
56-
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
5751

52+
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
5853

5954
protected:
6055
bool DoPlanExplainsStop(Event *event_ptr) override;
6156

6257
lldb::StateType GetPlanRunState() override;
63-
58+
6459
ScriptInterpreter *GetScriptInterpreter();
6560

6661
private:
@@ -73,10 +68,10 @@ class ThreadPlanPython : public ThreadPlan {
7368
bool m_stop_others;
7469
lldb::ScriptedThreadPlanInterfaceSP m_interface;
7570

76-
ThreadPlanPython(const ThreadPlanPython &) = delete;
77-
const ThreadPlanPython &operator=(const ThreadPlanPython &) = delete;
71+
ScriptedThreadPlan(const ScriptedThreadPlan &) = delete;
72+
const ScriptedThreadPlan &operator=(const ScriptedThreadPlan &) = delete;
7873
};
7974

8075
} // namespace lldb_private
8176

82-
#endif // LLDB_TARGET_THREADPLANPYTHON_H
77+
#endif // LLDB_TARGET_SCRIPTEDTHREADPLAN_H

lldb/source/API/SBThreadPlan.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include "lldb/Symbol/SymbolContext.h"
2222
#include "lldb/Target/Process.h"
2323
#include "lldb/Target/Queue.h"
24+
#include "lldb/Target/ScriptedThreadPlan.h"
2425
#include "lldb/Target/StopInfo.h"
2526
#include "lldb/Target/SystemRuntime.h"
2627
#include "lldb/Target/Target.h"
2728
#include "lldb/Target/Thread.h"
2829
#include "lldb/Target/ThreadPlan.h"
29-
#include "lldb/Target/ThreadPlanPython.h"
3030
#include "lldb/Target/ThreadPlanStepInRange.h"
3131
#include "lldb/Target/ThreadPlanStepInstruction.h"
3232
#include "lldb/Target/ThreadPlanStepOut.h"
@@ -66,8 +66,8 @@ SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
6666

6767
Thread *thread = sb_thread.get();
6868
if (thread)
69-
m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
70-
StructuredDataImpl());
69+
m_opaque_wp = std::make_shared<ScriptedThreadPlan>(*thread, class_name,
70+
StructuredDataImpl());
7171
}
7272

7373
SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
@@ -76,8 +76,8 @@ SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
7676

7777
Thread *thread = sb_thread.get();
7878
if (thread)
79-
m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
80-
*args_data.m_impl_up);
79+
m_opaque_wp = std::make_shared<ScriptedThreadPlan>(*thread, class_name,
80+
*args_data.m_impl_up);
8181
}
8282

8383
// Assignment operator

lldb/source/Target/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_lldb_library(lldbTarget
3636
RegisterFlags.cpp
3737
RegisterNumber.cpp
3838
RemoteAwarePlatform.cpp
39+
ScriptedThreadPlan.cpp
3940
SectionLoadHistory.cpp
4041
SectionLoadList.cpp
4142
StackFrame.cpp
@@ -57,7 +58,6 @@ add_lldb_library(lldbTarget
5758
ThreadPlanCallFunctionUsingABI.cpp
5859
ThreadPlanCallOnFunctionExit.cpp
5960
ThreadPlanCallUserExpression.cpp
60-
ThreadPlanPython.cpp
6161
ThreadPlanRunToAddress.cpp
6262
ThreadPlanShouldStopHere.cpp
6363
ThreadPlanStepInRange.cpp

lldb/source/Target/ThreadPlanPython.cpp renamed to lldb/source/Target/ScriptedThreadPlan.cpp

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- ThreadPlanPython.cpp ----------------------------------------------===//
1+
//===-- ScriptedThreadPlan.cpp --------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -14,22 +14,20 @@
1414
#include "lldb/Interpreter/ScriptInterpreter.h"
1515
#include "lldb/Target/Process.h"
1616
#include "lldb/Target/RegisterContext.h"
17+
#include "lldb/Target/ScriptedThreadPlan.h"
1718
#include "lldb/Target/Target.h"
1819
#include "lldb/Target/Thread.h"
1920
#include "lldb/Target/ThreadPlan.h"
20-
#include "lldb/Target/ThreadPlanPython.h"
2121
#include "lldb/Utility/LLDBLog.h"
2222
#include "lldb/Utility/Log.h"
2323
#include "lldb/Utility/State.h"
2424

2525
using namespace lldb;
2626
using namespace lldb_private;
2727

28-
// ThreadPlanPython
29-
30-
ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
31-
const StructuredDataImpl &args_data)
32-
: ThreadPlan(ThreadPlan::eKindPython, "Python based Thread Plan", thread,
28+
ScriptedThreadPlan::ScriptedThreadPlan(Thread &thread, const char *class_name,
29+
const StructuredDataImpl &args_data)
30+
: ThreadPlan(ThreadPlan::eKindPython, "Script based Thread Plan", thread,
3331
eVoteNoOpinion, eVoteNoOpinion),
3432
m_class_name(class_name), m_args_data(args_data), m_did_push(false),
3533
m_stop_others(false) {
@@ -38,7 +36,7 @@ ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
3836
SetPlanComplete(false);
3937
// FIXME: error handling
4038
// error.SetErrorStringWithFormat(
41-
// "ThreadPlanPython::%s () - ERROR: %s", __FUNCTION__,
39+
// "ScriptedThreadPlan::%s () - ERROR: %s", __FUNCTION__,
4240
// "Couldn't get script interpreter");
4341
return;
4442
}
@@ -48,7 +46,7 @@ ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
4846
SetPlanComplete(false);
4947
// FIXME: error handling
5048
// error.SetErrorStringWithFormat(
51-
// "ThreadPlanPython::%s () - ERROR: %s", __FUNCTION__,
49+
// "ScriptedThreadPlan::%s () - ERROR: %s", __FUNCTION__,
5250
// "Script interpreter couldn't create Scripted Thread Plan Interface");
5351
return;
5452
}
@@ -58,26 +56,26 @@ ThreadPlanPython::ThreadPlanPython(Thread &thread, const char *class_name,
5856
SetPrivate(false);
5957
}
6058

61-
bool ThreadPlanPython::ValidatePlan(Stream *error) {
59+
bool ScriptedThreadPlan::ValidatePlan(Stream *error) {
6260
if (!m_did_push)
6361
return true;
6462

6563
if (!m_implementation_sp) {
6664
if (error)
6765
error->Printf("Error constructing Python ThreadPlan: %s",
68-
m_error_str.empty() ? "<unknown error>"
69-
: m_error_str.c_str());
66+
m_error_str.empty() ? "<unknown error>"
67+
: m_error_str.c_str());
7068
return false;
7169
}
7270

7371
return true;
7472
}
7573

76-
ScriptInterpreter *ThreadPlanPython::GetScriptInterpreter() {
74+
ScriptInterpreter *ScriptedThreadPlan::GetScriptInterpreter() {
7775
return m_process.GetTarget().GetDebugger().GetScriptInterpreter();
7876
}
7977

80-
void ThreadPlanPython::DidPush() {
78+
void ScriptedThreadPlan::DidPush() {
8179
// We set up the script side in DidPush, so that it can push other plans in
8280
// the constructor, and doesn't have to care about the details of DidPush.
8381
m_did_push = true;
@@ -92,10 +90,10 @@ void ThreadPlanPython::DidPush() {
9290
}
9391
}
9492

95-
bool ThreadPlanPython::ShouldStop(Event *event_ptr) {
93+
bool ScriptedThreadPlan::ShouldStop(Event *event_ptr) {
9694
Log *log = GetLog(LLDBLog::Thread);
97-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
98-
m_class_name.c_str());
95+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
96+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
9997

10098
bool should_stop = true;
10199
if (m_implementation_sp) {
@@ -110,10 +108,10 @@ bool ThreadPlanPython::ShouldStop(Event *event_ptr) {
110108
return should_stop;
111109
}
112110

113-
bool ThreadPlanPython::IsPlanStale() {
111+
bool ScriptedThreadPlan::IsPlanStale() {
114112
Log *log = GetLog(LLDBLog::Thread);
115-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
116-
m_class_name.c_str());
113+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
114+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
117115

118116
bool is_stale = true;
119117
if (m_implementation_sp) {
@@ -128,10 +126,10 @@ bool ThreadPlanPython::IsPlanStale() {
128126
return is_stale;
129127
}
130128

131-
bool ThreadPlanPython::DoPlanExplainsStop(Event *event_ptr) {
129+
bool ScriptedThreadPlan::DoPlanExplainsStop(Event *event_ptr) {
132130
Log *log = GetLog(LLDBLog::Thread);
133-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
134-
m_class_name.c_str());
131+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
132+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
135133

136134
bool explains_stop = true;
137135
if (m_implementation_sp) {
@@ -147,10 +145,10 @@ bool ThreadPlanPython::DoPlanExplainsStop(Event *event_ptr) {
147145
return explains_stop;
148146
}
149147

150-
bool ThreadPlanPython::MischiefManaged() {
148+
bool ScriptedThreadPlan::MischiefManaged() {
151149
Log *log = GetLog(LLDBLog::Thread);
152-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
153-
m_class_name.c_str());
150+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
151+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
154152
bool mischief_managed = true;
155153
if (m_implementation_sp) {
156154
// I don't really need mischief_managed, since it's simpler to just call
@@ -165,20 +163,21 @@ bool ThreadPlanPython::MischiefManaged() {
165163
return mischief_managed;
166164
}
167165

168-
lldb::StateType ThreadPlanPython::GetPlanRunState() {
166+
lldb::StateType ScriptedThreadPlan::GetPlanRunState() {
169167
Log *log = GetLog(LLDBLog::Thread);
170-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
171-
m_class_name.c_str());
168+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
169+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
172170
lldb::StateType run_state = eStateRunning;
173171
if (m_implementation_sp)
174172
run_state = m_interface->GetRunState();
175173
return run_state;
176174
}
177175

178-
void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
176+
void ScriptedThreadPlan::GetDescription(Stream *s,
177+
lldb::DescriptionLevel level) {
179178
Log *log = GetLog(LLDBLog::Thread);
180-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
181-
m_class_name.c_str());
179+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
180+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
182181
if (m_implementation_sp) {
183182
ScriptInterpreter *script_interp = GetScriptInterpreter();
184183
if (script_interp) {
@@ -187,8 +186,8 @@ void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
187186
if (err) {
188187
LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
189188
"Can't call ScriptedThreadPlan::GetStopDescription.");
190-
s->Printf("Python thread plan implemented by class %s.",
191-
m_class_name.c_str());
189+
s->Printf("Scripted thread plan implemented by class %s.",
190+
m_class_name.c_str());
192191
} else
193192
s->PutCString(
194193
reinterpret_cast<StreamString *>(stream.get())->GetData());
@@ -198,21 +197,21 @@ void ThreadPlanPython::GetDescription(Stream *s, lldb::DescriptionLevel level) {
198197
// It's an error not to have a description, so if we get here, we should
199198
// add something.
200199
if (m_stop_description.Empty())
201-
s->Printf("Python thread plan implemented by class %s.",
200+
s->Printf("Scripted thread plan implemented by class %s.",
202201
m_class_name.c_str());
203202
s->PutCString(m_stop_description.GetData());
204203
}
205204

206205
// The ones below are not currently exported to Python.
207-
bool ThreadPlanPython::WillStop() {
206+
bool ScriptedThreadPlan::WillStop() {
208207
Log *log = GetLog(LLDBLog::Thread);
209-
LLDB_LOGF(log, "%s called on Python Thread Plan: %s )", LLVM_PRETTY_FUNCTION,
210-
m_class_name.c_str());
208+
LLDB_LOGF(log, "%s called on Scripted Thread Plan: %s )",
209+
LLVM_PRETTY_FUNCTION, m_class_name.c_str());
211210
return true;
212211
}
213212

214-
bool ThreadPlanPython::DoWillResume(lldb::StateType resume_state,
215-
bool current_plan) {
213+
bool ScriptedThreadPlan::DoWillResume(lldb::StateType resume_state,
214+
bool current_plan) {
216215
m_stop_description.Clear();
217-
return true;
216+
return true;
218217
}

lldb/source/Target/Thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#include "lldb/Target/LanguageRuntime.h"
2626
#include "lldb/Target/Process.h"
2727
#include "lldb/Target/RegisterContext.h"
28+
#include "lldb/Target/ScriptedThreadPlan.h"
2829
#include "lldb/Target/StackFrameRecognizer.h"
2930
#include "lldb/Target/StopInfo.h"
3031
#include "lldb/Target/SystemRuntime.h"
3132
#include "lldb/Target/Target.h"
3233
#include "lldb/Target/ThreadPlan.h"
3334
#include "lldb/Target/ThreadPlanBase.h"
3435
#include "lldb/Target/ThreadPlanCallFunction.h"
35-
#include "lldb/Target/ThreadPlanPython.h"
3636
#include "lldb/Target/ThreadPlanRunToAddress.h"
3737
#include "lldb/Target/ThreadPlanStack.h"
3838
#include "lldb/Target/ThreadPlanStepInRange.h"
@@ -1378,7 +1378,7 @@ lldb::ThreadPlanSP Thread::QueueThreadPlanForStepScripted(
13781378
StructuredData::ObjectSP extra_args_sp, bool stop_other_threads,
13791379
Status &status) {
13801380

1381-
ThreadPlanSP thread_plan_sp(new ThreadPlanPython(
1381+
ThreadPlanSP thread_plan_sp(new ScriptedThreadPlan(
13821382
*this, class_name, StructuredDataImpl(extra_args_sp)));
13831383
thread_plan_sp->SetStopOthers(stop_other_threads);
13841384
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);

0 commit comments

Comments
 (0)