@@ -47,11 +47,6 @@ bool ScriptedProcess::IsScriptLanguageSupported(lldb::ScriptLanguage language) {
47
47
return llvm::is_contained (supported_languages, language);
48
48
}
49
49
50
- void ScriptedProcess::CheckInterpreterAndScriptObject () const {
51
- lldbassert (m_interpreter && " Invalid Script Interpreter." );
52
- lldbassert (m_script_object_sp && " Invalid Script Object." );
53
- }
54
-
55
50
lldb::ProcessSP ScriptedProcess::CreateInstance (lldb::TargetSP target_sp,
56
51
lldb::ListenerSP listener_sp,
57
52
const FileSpec *file,
@@ -66,8 +61,7 @@ lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp,
66
61
auto process_sp = std::shared_ptr<ScriptedProcess>(
67
62
new ScriptedProcess (target_sp, listener_sp, scripted_metadata, error));
68
63
69
- if (error.Fail () || !process_sp || !process_sp->m_script_object_sp ||
70
- !process_sp->m_script_object_sp ->IsValid ()) {
64
+ if (error.Fail () || !process_sp || !process_sp->m_interface_up ) {
71
65
LLDB_LOGF (GetLog (LLDBLog::Process), " %s" , error.AsCString ());
72
66
return nullptr ;
73
67
}
@@ -92,17 +86,28 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
92
86
return ;
93
87
}
94
88
95
- m_interpreter = target_sp->GetDebugger ().GetScriptInterpreter ();
89
+ ScriptInterpreter *interpreter =
90
+ target_sp->GetDebugger ().GetScriptInterpreter ();
96
91
97
- if (!m_interpreter ) {
92
+ if (!interpreter ) {
98
93
error.SetErrorStringWithFormat (" ScriptedProcess::%s () - ERROR: %s" ,
99
94
__FUNCTION__,
100
95
" Debugger has no Script Interpreter" );
101
96
return ;
102
97
}
103
98
99
+ // Create process instance interface
100
+ m_interface_up = interpreter->CreateScriptedProcessInterface ();
101
+ if (!m_interface_up) {
102
+ error.SetErrorStringWithFormat (
103
+ " ScriptedProcess::%s () - ERROR: %s" , __FUNCTION__,
104
+ " Script interpreter couldn't create Scripted Process Interface" );
105
+ return ;
106
+ }
107
+
104
108
ExecutionContext exe_ctx (target_sp, /* get_process=*/ false );
105
109
110
+ // Create process script object
106
111
StructuredData::GenericSP object_sp = GetInterface ().CreatePluginObject (
107
112
m_scripted_metadata.GetClassName (), exe_ctx,
108
113
m_scripted_metadata.GetArgsSP ());
@@ -113,8 +118,6 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
113
118
" Failed to create valid script object" );
114
119
return ;
115
120
}
116
-
117
- m_script_object_sp = object_sp;
118
121
}
119
122
120
123
ScriptedProcess::~ScriptedProcess () {
@@ -147,8 +150,6 @@ Status ScriptedProcess::DoLoadCore() {
147
150
148
151
Status ScriptedProcess::DoLaunch (Module *exe_module,
149
152
ProcessLaunchInfo &launch_info) {
150
- CheckInterpreterAndScriptObject ();
151
-
152
153
/* FIXME: This doesn't reflect how lldb actually launches a process.
153
154
In reality, it attaches to debugserver, then resume the process. */
154
155
Status error = GetInterface ().Launch ();
@@ -168,14 +169,11 @@ Status ScriptedProcess::DoLaunch(Module *exe_module,
168
169
}
169
170
170
171
void ScriptedProcess::DidLaunch () {
171
- CheckInterpreterAndScriptObject ();
172
172
m_pid = GetInterface ().GetProcessID ();
173
173
GetLoadedDynamicLibrariesInfos ();
174
174
}
175
175
176
176
Status ScriptedProcess::DoResume () {
177
- CheckInterpreterAndScriptObject ();
178
-
179
177
Log *log = GetLog (LLDBLog::Process);
180
178
// FIXME: Fetch data from thread.
181
179
const StateType thread_resume_state = eStateRunning;
@@ -198,8 +196,6 @@ Status ScriptedProcess::DoResume() {
198
196
}
199
197
200
198
Status ScriptedProcess::DoStop () {
201
- CheckInterpreterAndScriptObject ();
202
-
203
199
Log *log = GetLog (LLDBLog::Process);
204
200
205
201
if (GetInterface ().ShouldStop ()) {
@@ -214,18 +210,10 @@ Status ScriptedProcess::DoStop() {
214
210
215
211
Status ScriptedProcess::DoDestroy () { return Status (); }
216
212
217
- bool ScriptedProcess::IsAlive () {
218
- if (m_interpreter && m_script_object_sp)
219
- return GetInterface ().IsAlive ();
220
- return false ;
221
- }
213
+ bool ScriptedProcess::IsAlive () { return GetInterface ().IsAlive (); }
222
214
223
215
size_t ScriptedProcess::DoReadMemory (lldb::addr_t addr, void *buf, size_t size,
224
216
Status &error) {
225
- if (!m_interpreter)
226
- return ScriptedInterface::ErrorWithMessage<size_t >(
227
- LLVM_PRETTY_FUNCTION, " No interpreter." , error);
228
-
229
217
lldb::DataExtractorSP data_extractor_sp =
230
218
GetInterface ().ReadMemoryAtAddress (addr, size, error);
231
219
@@ -248,8 +236,6 @@ ArchSpec ScriptedProcess::GetArchitecture() {
248
236
249
237
Status ScriptedProcess::DoGetMemoryRegionInfo (lldb::addr_t load_addr,
250
238
MemoryRegionInfo ®ion) {
251
- CheckInterpreterAndScriptObject ();
252
-
253
239
Status error;
254
240
if (auto region_or_err =
255
241
GetInterface ().GetMemoryRegionContainingAddress (load_addr, error))
@@ -259,8 +245,6 @@ Status ScriptedProcess::DoGetMemoryRegionInfo(lldb::addr_t load_addr,
259
245
}
260
246
261
247
Status ScriptedProcess::GetMemoryRegions (MemoryRegionInfos ®ion_list) {
262
- CheckInterpreterAndScriptObject ();
263
-
264
248
Status error;
265
249
lldb::addr_t address = 0 ;
266
250
@@ -286,22 +270,9 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList &old_thread_list,
286
270
// This is supposed to get the current set of threads, if any of them are in
287
271
// old_thread_list then they get copied to new_thread_list, and then any
288
272
// actually new threads will get added to new_thread_list.
289
-
290
- CheckInterpreterAndScriptObject ();
291
273
m_thread_plans.ClearThreadCache ();
292
274
293
275
Status error;
294
- ScriptLanguage language = m_interpreter->GetLanguage ();
295
-
296
- if (language != eScriptLanguagePython)
297
- return ScriptedInterface::ErrorWithMessage<bool >(
298
- LLVM_PRETTY_FUNCTION,
299
- llvm::Twine (" ScriptInterpreter language (" +
300
- llvm::Twine (m_interpreter->LanguageToString (language)) +
301
- llvm::Twine (" ) not supported." ))
302
- .str (),
303
- error);
304
-
305
276
StructuredData::DictionarySP thread_info_sp = GetInterface ().GetThreadsInfo ();
306
277
307
278
if (!thread_info_sp)
@@ -400,8 +371,6 @@ bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
400
371
401
372
lldb_private::StructuredData::ObjectSP
402
373
ScriptedProcess::GetLoadedDynamicLibrariesInfos () {
403
- CheckInterpreterAndScriptObject ();
404
-
405
374
Status error;
406
375
auto error_with_message = [&error](llvm::StringRef message) {
407
376
return ScriptedInterface::ErrorWithMessage<bool >(LLVM_PRETTY_FUNCTION,
@@ -486,8 +455,6 @@ ScriptedProcess::GetLoadedDynamicLibrariesInfos() {
486
455
}
487
456
488
457
lldb_private::StructuredData::DictionarySP ScriptedProcess::GetMetadata () {
489
- CheckInterpreterAndScriptObject ();
490
-
491
458
StructuredData::DictionarySP metadata_sp = GetInterface ().GetMetadata ();
492
459
493
460
Status error;
@@ -499,7 +466,7 @@ lldb_private::StructuredData::DictionarySP ScriptedProcess::GetMetadata() {
499
466
}
500
467
501
468
void ScriptedProcess::UpdateQueueListIfNeeded () {
502
- CheckInterpreterAndScriptObject ();
469
+ CheckScriptedInterface ();
503
470
for (ThreadSP thread_sp : Threads ()) {
504
471
if (const char *queue_name = thread_sp->GetQueueName ()) {
505
472
QueueSP queue_sp = std::make_shared<Queue>(
@@ -510,12 +477,15 @@ void ScriptedProcess::UpdateQueueListIfNeeded() {
510
477
}
511
478
512
479
ScriptedProcessInterface &ScriptedProcess::GetInterface () const {
513
- return m_interpreter->GetScriptedProcessInterface ();
480
+ CheckScriptedInterface ();
481
+ return *m_interface_up;
514
482
}
515
483
516
484
void *ScriptedProcess::GetImplementation () {
517
- if (m_script_object_sp &&
518
- m_script_object_sp->GetType () == eStructuredDataTypeGeneric)
519
- return m_script_object_sp->GetAsGeneric ()->GetValue ();
485
+ StructuredData::GenericSP object_instance_sp =
486
+ GetInterface ().GetScriptObjectInstance ();
487
+ if (object_instance_sp &&
488
+ object_instance_sp->GetType () == eStructuredDataTypeGeneric)
489
+ return object_instance_sp->GetAsGeneric ()->GetValue ();
520
490
return nullptr ;
521
491
}
0 commit comments