1fe6060f1SDimitry Andric //===-- ScriptedProcess.cpp -----------------------------------------------===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric 9fe6060f1SDimitry Andric #include "ScriptedProcess.h" 10fe6060f1SDimitry Andric 11fe6060f1SDimitry Andric #include "lldb/Core/Debugger.h" 12fe6060f1SDimitry Andric #include "lldb/Core/Module.h" 13fe6060f1SDimitry Andric #include "lldb/Core/PluginManager.h" 14fe6060f1SDimitry Andric 15fe6060f1SDimitry Andric #include "lldb/Host/OptionParser.h" 16fe6060f1SDimitry Andric #include "lldb/Host/ThreadLauncher.h" 17fe6060f1SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h" 18fe6060f1SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h" 19fe6060f1SDimitry Andric #include "lldb/Interpreter/OptionGroupBoolean.h" 20fe6060f1SDimitry Andric #include "lldb/Interpreter/ScriptInterpreter.h" 21fe6060f1SDimitry Andric #include "lldb/Target/MemoryRegionInfo.h" 22fe6060f1SDimitry Andric #include "lldb/Target/RegisterContext.h" 23fe6060f1SDimitry Andric #include "lldb/Utility/State.h" 24fe6060f1SDimitry Andric 25fe6060f1SDimitry Andric #include <mutex> 26fe6060f1SDimitry Andric 27fe6060f1SDimitry Andric LLDB_PLUGIN_DEFINE(ScriptedProcess) 28fe6060f1SDimitry Andric 29fe6060f1SDimitry Andric using namespace lldb; 30fe6060f1SDimitry Andric using namespace lldb_private; 31fe6060f1SDimitry Andric 32349cc55cSDimitry Andric llvm::StringRef ScriptedProcess::GetPluginDescriptionStatic() { 33fe6060f1SDimitry Andric return "Scripted Process plug-in."; 34fe6060f1SDimitry Andric } 35fe6060f1SDimitry Andric 36fe6060f1SDimitry Andric static constexpr lldb::ScriptLanguage g_supported_script_languages[] = { 37fe6060f1SDimitry Andric ScriptLanguage::eScriptLanguagePython, 38fe6060f1SDimitry Andric }; 39fe6060f1SDimitry Andric 40fe6060f1SDimitry Andric bool ScriptedProcess::IsScriptLanguageSupported(lldb::ScriptLanguage language) { 41fe6060f1SDimitry Andric llvm::ArrayRef<lldb::ScriptLanguage> supported_languages = 42fe6060f1SDimitry Andric llvm::makeArrayRef(g_supported_script_languages); 43fe6060f1SDimitry Andric 44fe6060f1SDimitry Andric return llvm::is_contained(supported_languages, language); 45fe6060f1SDimitry Andric } 46fe6060f1SDimitry Andric 47fe6060f1SDimitry Andric void ScriptedProcess::CheckInterpreterAndScriptObject() const { 48fe6060f1SDimitry Andric lldbassert(m_interpreter && "Invalid Script Interpreter."); 49fe6060f1SDimitry Andric lldbassert(m_script_object_sp && "Invalid Script Object."); 50fe6060f1SDimitry Andric } 51fe6060f1SDimitry Andric 52fe6060f1SDimitry Andric lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp, 53fe6060f1SDimitry Andric lldb::ListenerSP listener_sp, 54fe6060f1SDimitry Andric const FileSpec *file, 55fe6060f1SDimitry Andric bool can_connect) { 56fe6060f1SDimitry Andric if (!target_sp || 57fe6060f1SDimitry Andric !IsScriptLanguageSupported(target_sp->GetDebugger().GetScriptLanguage())) 58fe6060f1SDimitry Andric return nullptr; 59fe6060f1SDimitry Andric 60fe6060f1SDimitry Andric Status error; 61fe6060f1SDimitry Andric ScriptedProcess::ScriptedProcessInfo scripted_process_info( 62fe6060f1SDimitry Andric target_sp->GetProcessLaunchInfo()); 63fe6060f1SDimitry Andric 64fe6060f1SDimitry Andric auto process_sp = std::make_shared<ScriptedProcess>( 65fe6060f1SDimitry Andric target_sp, listener_sp, scripted_process_info, error); 66fe6060f1SDimitry Andric 67fe6060f1SDimitry Andric if (error.Fail() || !process_sp || !process_sp->m_script_object_sp || 68fe6060f1SDimitry Andric !process_sp->m_script_object_sp->IsValid()) { 69fe6060f1SDimitry Andric LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS), "%s", 70fe6060f1SDimitry Andric error.AsCString()); 71fe6060f1SDimitry Andric return nullptr; 72fe6060f1SDimitry Andric } 73fe6060f1SDimitry Andric 74fe6060f1SDimitry Andric return process_sp; 75fe6060f1SDimitry Andric } 76fe6060f1SDimitry Andric 77fe6060f1SDimitry Andric bool ScriptedProcess::CanDebug(lldb::TargetSP target_sp, 78fe6060f1SDimitry Andric bool plugin_specified_by_name) { 79fe6060f1SDimitry Andric return true; 80fe6060f1SDimitry Andric } 81fe6060f1SDimitry Andric 82fe6060f1SDimitry Andric ScriptedProcess::ScriptedProcess( 83fe6060f1SDimitry Andric lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, 84fe6060f1SDimitry Andric const ScriptedProcess::ScriptedProcessInfo &scripted_process_info, 85fe6060f1SDimitry Andric Status &error) 86fe6060f1SDimitry Andric : Process(target_sp, listener_sp), 87fe6060f1SDimitry Andric m_scripted_process_info(scripted_process_info) { 88fe6060f1SDimitry Andric 89fe6060f1SDimitry Andric if (!target_sp) { 90fe6060f1SDimitry Andric error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s", 91fe6060f1SDimitry Andric __FUNCTION__, "Invalid target"); 92fe6060f1SDimitry Andric return; 93fe6060f1SDimitry Andric } 94fe6060f1SDimitry Andric 95fe6060f1SDimitry Andric m_interpreter = target_sp->GetDebugger().GetScriptInterpreter(); 96fe6060f1SDimitry Andric 97fe6060f1SDimitry Andric if (!m_interpreter) { 98fe6060f1SDimitry Andric error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s", 99fe6060f1SDimitry Andric __FUNCTION__, 100fe6060f1SDimitry Andric "Debugger has no Script Interpreter"); 101fe6060f1SDimitry Andric return; 102fe6060f1SDimitry Andric } 103fe6060f1SDimitry Andric 104349cc55cSDimitry Andric ExecutionContext exe_ctx(target_sp, /*get_process=*/false); 105349cc55cSDimitry Andric 106349cc55cSDimitry Andric StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject( 107349cc55cSDimitry Andric m_scripted_process_info.GetClassName().c_str(), exe_ctx, 108349cc55cSDimitry Andric m_scripted_process_info.GetArgsSP()); 109fe6060f1SDimitry Andric 110fe6060f1SDimitry Andric if (!object_sp || !object_sp->IsValid()) { 111fe6060f1SDimitry Andric error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s", 112fe6060f1SDimitry Andric __FUNCTION__, 113fe6060f1SDimitry Andric "Failed to create valid script object"); 114fe6060f1SDimitry Andric return; 115fe6060f1SDimitry Andric } 116fe6060f1SDimitry Andric 117fe6060f1SDimitry Andric m_script_object_sp = object_sp; 118fe6060f1SDimitry Andric } 119fe6060f1SDimitry Andric 120fe6060f1SDimitry Andric ScriptedProcess::~ScriptedProcess() { 121fe6060f1SDimitry Andric Clear(); 122fe6060f1SDimitry Andric // We need to call finalize on the process before destroying ourselves to 123fe6060f1SDimitry Andric // make sure all of the broadcaster cleanup goes as planned. If we destruct 124fe6060f1SDimitry Andric // this class, then Process::~Process() might have problems trying to fully 125fe6060f1SDimitry Andric // destroy the broadcaster. 126fe6060f1SDimitry Andric Finalize(); 127fe6060f1SDimitry Andric } 128fe6060f1SDimitry Andric 129fe6060f1SDimitry Andric void ScriptedProcess::Initialize() { 130fe6060f1SDimitry Andric static llvm::once_flag g_once_flag; 131fe6060f1SDimitry Andric 132fe6060f1SDimitry Andric llvm::call_once(g_once_flag, []() { 133fe6060f1SDimitry Andric PluginManager::RegisterPlugin(GetPluginNameStatic(), 134fe6060f1SDimitry Andric GetPluginDescriptionStatic(), CreateInstance); 135fe6060f1SDimitry Andric }); 136fe6060f1SDimitry Andric } 137fe6060f1SDimitry Andric 138fe6060f1SDimitry Andric void ScriptedProcess::Terminate() { 139fe6060f1SDimitry Andric PluginManager::UnregisterPlugin(ScriptedProcess::CreateInstance); 140fe6060f1SDimitry Andric } 141fe6060f1SDimitry Andric 142fe6060f1SDimitry Andric Status ScriptedProcess::DoLoadCore() { 143fe6060f1SDimitry Andric ProcessLaunchInfo launch_info = GetTarget().GetProcessLaunchInfo(); 144fe6060f1SDimitry Andric 145fe6060f1SDimitry Andric return DoLaunch(nullptr, launch_info); 146fe6060f1SDimitry Andric } 147fe6060f1SDimitry Andric 148fe6060f1SDimitry Andric Status ScriptedProcess::DoLaunch(Module *exe_module, 149fe6060f1SDimitry Andric ProcessLaunchInfo &launch_info) { 150fe6060f1SDimitry Andric CheckInterpreterAndScriptObject(); 151fe6060f1SDimitry Andric 152fe6060f1SDimitry Andric /* FIXME: This doesn't reflect how lldb actually launches a process. 153fe6060f1SDimitry Andric In reality, it attaches to debugserver, then resume the process. */ 154fe6060f1SDimitry Andric Status error = GetInterface().Launch(); 155fe6060f1SDimitry Andric SetPrivateState(eStateRunning); 156fe6060f1SDimitry Andric 157fe6060f1SDimitry Andric if (error.Fail()) 158fe6060f1SDimitry Andric return error; 159fe6060f1SDimitry Andric 160fe6060f1SDimitry Andric // TODO: Fetch next state from stopped event queue then send stop event 161fe6060f1SDimitry Andric // const StateType state = SetThreadStopInfo(response); 162fe6060f1SDimitry Andric // if (state != eStateInvalid) { 163fe6060f1SDimitry Andric // SetPrivateState(state); 164fe6060f1SDimitry Andric 165fe6060f1SDimitry Andric SetPrivateState(eStateStopped); 166fe6060f1SDimitry Andric 167fe6060f1SDimitry Andric return {}; 168fe6060f1SDimitry Andric } 169fe6060f1SDimitry Andric 170fe6060f1SDimitry Andric void ScriptedProcess::DidLaunch() { 171fe6060f1SDimitry Andric CheckInterpreterAndScriptObject(); 172fe6060f1SDimitry Andric m_pid = GetInterface().GetProcessID(); 173fe6060f1SDimitry Andric } 174fe6060f1SDimitry Andric 175fe6060f1SDimitry Andric Status ScriptedProcess::DoResume() { 176fe6060f1SDimitry Andric CheckInterpreterAndScriptObject(); 177fe6060f1SDimitry Andric 178fe6060f1SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); 179fe6060f1SDimitry Andric // FIXME: Fetch data from thread. 180fe6060f1SDimitry Andric const StateType thread_resume_state = eStateRunning; 181fe6060f1SDimitry Andric LLDB_LOGF(log, "ScriptedProcess::%s thread_resume_state = %s", __FUNCTION__, 182fe6060f1SDimitry Andric StateAsCString(thread_resume_state)); 183fe6060f1SDimitry Andric 184fe6060f1SDimitry Andric bool resume = (thread_resume_state == eStateRunning); 185fe6060f1SDimitry Andric assert(thread_resume_state == eStateRunning && "invalid thread resume state"); 186fe6060f1SDimitry Andric 187fe6060f1SDimitry Andric Status error; 188fe6060f1SDimitry Andric if (resume) { 189fe6060f1SDimitry Andric LLDB_LOGF(log, "ScriptedProcess::%s sending resume", __FUNCTION__); 190fe6060f1SDimitry Andric 191fe6060f1SDimitry Andric SetPrivateState(eStateRunning); 192fe6060f1SDimitry Andric SetPrivateState(eStateStopped); 193fe6060f1SDimitry Andric error = GetInterface().Resume(); 194fe6060f1SDimitry Andric } 195fe6060f1SDimitry Andric 196fe6060f1SDimitry Andric return error; 197fe6060f1SDimitry Andric } 198fe6060f1SDimitry Andric 199fe6060f1SDimitry Andric Status ScriptedProcess::DoStop() { 200fe6060f1SDimitry Andric CheckInterpreterAndScriptObject(); 201fe6060f1SDimitry Andric 202fe6060f1SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); 203fe6060f1SDimitry Andric 204fe6060f1SDimitry Andric if (GetInterface().ShouldStop()) { 205fe6060f1SDimitry Andric SetPrivateState(eStateStopped); 206fe6060f1SDimitry Andric LLDB_LOGF(log, "ScriptedProcess::%s Immediate stop", __FUNCTION__); 207fe6060f1SDimitry Andric return {}; 208fe6060f1SDimitry Andric } 209fe6060f1SDimitry Andric 210fe6060f1SDimitry Andric LLDB_LOGF(log, "ScriptedProcess::%s Delayed stop", __FUNCTION__); 211fe6060f1SDimitry Andric return GetInterface().Stop(); 212fe6060f1SDimitry Andric } 213fe6060f1SDimitry Andric 214fe6060f1SDimitry Andric Status ScriptedProcess::DoDestroy() { return Status(); } 215fe6060f1SDimitry Andric 216fe6060f1SDimitry Andric bool ScriptedProcess::IsAlive() { 217fe6060f1SDimitry Andric if (m_interpreter && m_script_object_sp) 218fe6060f1SDimitry Andric return GetInterface().IsAlive(); 219fe6060f1SDimitry Andric return false; 220fe6060f1SDimitry Andric } 221fe6060f1SDimitry Andric 222fe6060f1SDimitry Andric size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size, 223fe6060f1SDimitry Andric Status &error) { 224fe6060f1SDimitry Andric if (!m_interpreter) 225*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<size_t>( 226*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, "No interpreter.", error); 227fe6060f1SDimitry Andric 228fe6060f1SDimitry Andric lldb::DataExtractorSP data_extractor_sp = 229fe6060f1SDimitry Andric GetInterface().ReadMemoryAtAddress(addr, size, error); 230fe6060f1SDimitry Andric 231349cc55cSDimitry Andric if (!data_extractor_sp || !data_extractor_sp->GetByteSize() || error.Fail()) 232fe6060f1SDimitry Andric return 0; 233fe6060f1SDimitry Andric 234fe6060f1SDimitry Andric offset_t bytes_copied = data_extractor_sp->CopyByteOrderedData( 235fe6060f1SDimitry Andric 0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder()); 236fe6060f1SDimitry Andric 237fe6060f1SDimitry Andric if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET) 238*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<size_t>( 239349cc55cSDimitry Andric LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error); 240fe6060f1SDimitry Andric 241fe6060f1SDimitry Andric return size; 242fe6060f1SDimitry Andric } 243fe6060f1SDimitry Andric 244fe6060f1SDimitry Andric ArchSpec ScriptedProcess::GetArchitecture() { 245fe6060f1SDimitry Andric return GetTarget().GetArchitecture(); 246fe6060f1SDimitry Andric } 247fe6060f1SDimitry Andric 2484824e7fdSDimitry Andric Status ScriptedProcess::GetMemoryRegionInfo(lldb::addr_t load_addr, 249fe6060f1SDimitry Andric MemoryRegionInfo ®ion) { 250349cc55cSDimitry Andric CheckInterpreterAndScriptObject(); 251349cc55cSDimitry Andric 252349cc55cSDimitry Andric Status error; 253349cc55cSDimitry Andric if (auto region_or_err = 254349cc55cSDimitry Andric GetInterface().GetMemoryRegionContainingAddress(load_addr, error)) 255349cc55cSDimitry Andric region = *region_or_err; 256349cc55cSDimitry Andric 257349cc55cSDimitry Andric return error; 258fe6060f1SDimitry Andric } 259fe6060f1SDimitry Andric 260fe6060f1SDimitry Andric Status ScriptedProcess::GetMemoryRegions(MemoryRegionInfos ®ion_list) { 261fe6060f1SDimitry Andric CheckInterpreterAndScriptObject(); 262fe6060f1SDimitry Andric 263349cc55cSDimitry Andric Status error; 264fe6060f1SDimitry Andric lldb::addr_t address = 0; 265fe6060f1SDimitry Andric 266349cc55cSDimitry Andric while (auto region_or_err = 267349cc55cSDimitry Andric GetInterface().GetMemoryRegionContainingAddress(address, error)) { 268349cc55cSDimitry Andric if (error.Fail()) 269349cc55cSDimitry Andric break; 270349cc55cSDimitry Andric 271349cc55cSDimitry Andric MemoryRegionInfo &mem_region = *region_or_err; 272349cc55cSDimitry Andric auto range = mem_region.GetRange(); 273fe6060f1SDimitry Andric address += range.GetRangeBase() + range.GetByteSize(); 274349cc55cSDimitry Andric region_list.push_back(mem_region); 275fe6060f1SDimitry Andric } 276fe6060f1SDimitry Andric 277349cc55cSDimitry Andric return error; 278fe6060f1SDimitry Andric } 279fe6060f1SDimitry Andric 280fe6060f1SDimitry Andric void ScriptedProcess::Clear() { Process::m_thread_list.Clear(); } 281fe6060f1SDimitry Andric 282fe6060f1SDimitry Andric bool ScriptedProcess::DoUpdateThreadList(ThreadList &old_thread_list, 283fe6060f1SDimitry Andric ThreadList &new_thread_list) { 284fe6060f1SDimitry Andric // TODO: Implement 285fe6060f1SDimitry Andric // This is supposed to get the current set of threads, if any of them are in 286fe6060f1SDimitry Andric // old_thread_list then they get copied to new_thread_list, and then any 287fe6060f1SDimitry Andric // actually new threads will get added to new_thread_list. 288349cc55cSDimitry Andric 289349cc55cSDimitry Andric CheckInterpreterAndScriptObject(); 290349cc55cSDimitry Andric m_thread_plans.ClearThreadCache(); 291349cc55cSDimitry Andric 292349cc55cSDimitry Andric Status error; 293349cc55cSDimitry Andric ScriptLanguage language = m_interpreter->GetLanguage(); 294349cc55cSDimitry Andric 295349cc55cSDimitry Andric if (language != eScriptLanguagePython) 296*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 297349cc55cSDimitry Andric LLVM_PRETTY_FUNCTION, 298349cc55cSDimitry Andric llvm::Twine("ScriptInterpreter language (" + 299349cc55cSDimitry Andric llvm::Twine(m_interpreter->LanguageToString(language)) + 300349cc55cSDimitry Andric llvm::Twine(") not supported.")) 301349cc55cSDimitry Andric .str(), 302349cc55cSDimitry Andric error); 303349cc55cSDimitry Andric 304*04eeddc0SDimitry Andric StructuredData::DictionarySP thread_info_sp = GetInterface().GetThreadsInfo(); 305349cc55cSDimitry Andric 306*04eeddc0SDimitry Andric if (!thread_info_sp) 307*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 308*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, 309*04eeddc0SDimitry Andric "Couldn't fetch thread list from Scripted Process.", error); 310*04eeddc0SDimitry Andric 311*04eeddc0SDimitry Andric auto create_scripted_thread = 312*04eeddc0SDimitry Andric [this, &old_thread_list, &error, 313*04eeddc0SDimitry Andric &new_thread_list](ConstString key, StructuredData::Object *val) -> bool { 314*04eeddc0SDimitry Andric if (!val) 315*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 316*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, "Invalid thread info object", error); 317*04eeddc0SDimitry Andric 318*04eeddc0SDimitry Andric lldb::tid_t tid = LLDB_INVALID_THREAD_ID; 319*04eeddc0SDimitry Andric if (!llvm::to_integer(key.AsCString(), tid)) 320*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 321*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, "Invalid thread id", error); 322*04eeddc0SDimitry Andric 323*04eeddc0SDimitry Andric if (ThreadSP thread_sp = 324*04eeddc0SDimitry Andric old_thread_list.FindThreadByID(tid, false /*=can_update*/)) { 325*04eeddc0SDimitry Andric // If the thread was already in the old_thread_list, 326*04eeddc0SDimitry Andric // just add it back to the new_thread_list. 327*04eeddc0SDimitry Andric new_thread_list.AddThread(thread_sp); 328*04eeddc0SDimitry Andric return true; 329*04eeddc0SDimitry Andric } 330*04eeddc0SDimitry Andric 331*04eeddc0SDimitry Andric auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric()); 332*04eeddc0SDimitry Andric 333*04eeddc0SDimitry Andric if (!thread_or_error) 334*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 335*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error); 336*04eeddc0SDimitry Andric 337*04eeddc0SDimitry Andric ThreadSP thread_sp = thread_or_error.get(); 338*04eeddc0SDimitry Andric lldbassert(thread_sp && "Couldn't initialize scripted thread."); 339349cc55cSDimitry Andric 3400eae32dcSDimitry Andric RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext(); 3410eae32dcSDimitry Andric if (!reg_ctx_sp) 342*04eeddc0SDimitry Andric return ScriptedInterface::ErrorWithMessage<bool>( 343*04eeddc0SDimitry Andric LLVM_PRETTY_FUNCTION, 344*04eeddc0SDimitry Andric llvm::Twine("Invalid Register Context for thread " + 345*04eeddc0SDimitry Andric llvm::Twine(key.AsCString())) 346*04eeddc0SDimitry Andric .str(), 347*04eeddc0SDimitry Andric error); 3480eae32dcSDimitry Andric 349349cc55cSDimitry Andric new_thread_list.AddThread(thread_sp); 350349cc55cSDimitry Andric 351*04eeddc0SDimitry Andric return true; 352*04eeddc0SDimitry Andric }; 353*04eeddc0SDimitry Andric 354*04eeddc0SDimitry Andric thread_info_sp->ForEach(create_scripted_thread); 355*04eeddc0SDimitry Andric 356fe6060f1SDimitry Andric return new_thread_list.GetSize(false) > 0; 357fe6060f1SDimitry Andric } 358fe6060f1SDimitry Andric 359349cc55cSDimitry Andric void ScriptedProcess::RefreshStateAfterStop() { 360349cc55cSDimitry Andric // Let all threads recover from stopping and do any clean up based on the 361349cc55cSDimitry Andric // previous thread state (if any). 362349cc55cSDimitry Andric } 363349cc55cSDimitry Andric 364fe6060f1SDimitry Andric bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) { 365fe6060f1SDimitry Andric info.Clear(); 366fe6060f1SDimitry Andric info.SetProcessID(GetID()); 367fe6060f1SDimitry Andric info.SetArchitecture(GetArchitecture()); 368fe6060f1SDimitry Andric lldb::ModuleSP module_sp = GetTarget().GetExecutableModule(); 369fe6060f1SDimitry Andric if (module_sp) { 370fe6060f1SDimitry Andric const bool add_exe_file_as_first_arg = false; 371fe6060f1SDimitry Andric info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(), 372fe6060f1SDimitry Andric add_exe_file_as_first_arg); 373fe6060f1SDimitry Andric } 374fe6060f1SDimitry Andric return true; 375fe6060f1SDimitry Andric } 376fe6060f1SDimitry Andric 377fe6060f1SDimitry Andric ScriptedProcessInterface &ScriptedProcess::GetInterface() const { 378fe6060f1SDimitry Andric return m_interpreter->GetScriptedProcessInterface(); 379fe6060f1SDimitry Andric } 380