Go to the documentation of this file.
33 llvm::StringRef ScriptedProcess::GetPluginDescriptionStatic() {
34 return "Scripted Process plug-in.";
42 llvm::ArrayRef<lldb::ScriptLanguage> supported_languages =
45 return llvm::is_contained(supported_languages, language);
48 void ScriptedProcess::CheckInterpreterAndScriptObject()
const {
49 lldbassert(m_interpreter &&
"Invalid Script Interpreter.");
50 lldbassert(m_script_object_sp &&
"Invalid Script Object.");
53 lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp,
54 lldb::ListenerSP listener_sp,
58 !IsScriptLanguageSupported(target_sp->GetDebugger().GetScriptLanguage()))
63 target_sp->GetProcessLaunchInfo());
65 auto process_sp = std::make_shared<ScriptedProcess>(
66 target_sp, listener_sp, scripted_process_info,
error);
68 if (
error.Fail() || !process_sp || !process_sp->m_script_object_sp ||
69 !process_sp->m_script_object_sp->IsValid()) {
77 bool ScriptedProcess::CanDebug(lldb::TargetSP target_sp,
78 bool plugin_specified_by_name) {
82 ScriptedProcess::ScriptedProcess(
83 lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
86 :
Process(target_sp, listener_sp),
87 m_scripted_process_info(scripted_process_info) {
90 error.SetErrorStringWithFormat(
"ScriptedProcess::%s () - ERROR: %s",
91 __FUNCTION__,
"Invalid target");
95 m_interpreter = target_sp->GetDebugger().GetScriptInterpreter();
98 error.SetErrorStringWithFormat(
"ScriptedProcess::%s () - ERROR: %s",
100 "Debugger has no Script Interpreter");
110 if (!object_sp || !object_sp->IsValid()) {
111 error.SetErrorStringWithFormat(
"ScriptedProcess::%s () - ERROR: %s",
113 "Failed to create valid script object");
130 static llvm::once_flag g_once_flag;
132 llvm::call_once(g_once_flag, []() {
145 return DoLaunch(
nullptr, launch_info);
182 LLDB_LOGF(log,
"ScriptedProcess::%s thread_resume_state = %s", __FUNCTION__,
186 assert(thread_resume_state ==
eStateRunning &&
"invalid thread resume state");
190 LLDB_LOGF(log,
"ScriptedProcess::%s sending resume", __FUNCTION__);
207 LLDB_LOGF(log,
"ScriptedProcess::%s Immediate stop", __FUNCTION__);
211 LLDB_LOGF(log,
"ScriptedProcess::%s Delayed stop", __FUNCTION__);
226 return ScriptedInterface::ErrorWithMessage<size_t>(
227 LLVM_PRETTY_FUNCTION,
"No interpreter.",
error);
229 lldb::DataExtractorSP data_extractor_sp =
232 if (!data_extractor_sp || !data_extractor_sp->GetByteSize() ||
error.Fail())
235 offset_t bytes_copied = data_extractor_sp->CopyByteOrderedData(
236 0, data_extractor_sp->GetByteSize(), buf, size,
GetByteOrder());
239 return ScriptedInterface::ErrorWithMessage<size_t>(
240 LLVM_PRETTY_FUNCTION,
"Failed to copy read memory to buffer.",
error);
254 if (
auto region_or_err =
256 region = *region_or_err;
267 while (
auto region_or_err =
275 region_list.push_back(mem_region);
297 return ScriptedInterface::ErrorWithMessage<bool>(
298 LLVM_PRETTY_FUNCTION,
299 llvm::Twine(
"ScriptInterpreter language (" +
301 llvm::Twine(
") not supported."))
308 return ScriptedInterface::ErrorWithMessage<bool>(
309 LLVM_PRETTY_FUNCTION,
310 "Couldn't fetch thread list from Scripted Process.",
error);
320 std::map<size_t, StructuredData::ObjectSP> sorted_threads;
321 auto sort_keys = [&sorted_threads,
326 llvm::StringRef key = item->GetStringValue();
330 if (!llvm::to_integer(key, idx))
333 sorted_threads[idx] = thread_info_sp->GetValueForKey(key);
337 size_t thread_count = thread_info_sp->GetSize();
339 if (!keys->ForEach(sort_keys) || sorted_threads.size() != thread_count)
341 return ScriptedInterface::ErrorWithMessage<bool>(
342 LLVM_PRETTY_FUNCTION,
"Couldn't sort thread list.",
error);
344 auto create_scripted_thread =
345 [
this, &
error, &new_thread_list](
346 const std::pair<size_t, StructuredData::ObjectSP> pair) ->
bool {
347 size_t idx = pair.first;
351 return ScriptedInterface::ErrorWithMessage<bool>(
352 LLVM_PRETTY_FUNCTION,
"Invalid thread info object",
error);
354 auto thread_or_error =
357 if (!thread_or_error)
358 return ScriptedInterface::ErrorWithMessage<bool>(
359 LLVM_PRETTY_FUNCTION,
toString(thread_or_error.takeError()),
error);
361 ThreadSP thread_sp = thread_or_error.get();
362 lldbassert(thread_sp &&
"Couldn't initialize scripted thread.");
364 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
366 return ScriptedInterface::ErrorWithMessage<bool>(
367 LLVM_PRETTY_FUNCTION,
368 llvm::Twine(
"Invalid Register Context for thread " + llvm::Twine(idx))
377 llvm::for_each(sorted_threads, create_scripted_thread);
379 return new_thread_list.
GetSize(
false) > 0;
394 const bool add_exe_file_as_first_arg =
false;
396 add_exe_file_as_first_arg);
406 auto error_with_message = [&
error](llvm::StringRef
message) {
407 return ScriptedInterface::ErrorWithMessage<bool>(LLVM_PRETTY_FUNCTION,
413 if (!loaded_images_sp || !loaded_images_sp->GetSize())
415 LLVM_PRETTY_FUNCTION,
"No loaded images.",
error);
420 auto reload_image = [&target, &module_list, &error_with_message](
425 return error_with_message(
"Couldn't cast image object into dictionary.");
428 llvm::StringRef value;
430 bool has_path = dict->
HasKey(
"path");
431 bool has_uuid = dict->
HasKey(
"uuid");
432 if (!has_path && !has_uuid)
433 return error_with_message(
"Dictionary should have key 'path' or 'uuid'");
434 if (!dict->
HasKey(
"load_addr"))
435 return error_with_message(
"Dictionary is missing key 'load_addr'");
452 return error_with_message(
"Couldn't create or get module.");
459 return error_with_message(
460 "Couldn't get valid load address or slide offset.");
465 bool changed =
false;
466 module_sp->SetLoadAddress(target, load_addr,
false ,
469 if (!changed && !module_sp->GetObjectFile())
470 return error_with_message(
"Couldn't set the load address for module.");
474 module_sp->SetFileSpecAndObjectName(objfile, objfile.
GetFilename());
476 return module_list.AppendIfNeeded(module_sp);
479 if (!loaded_images_sp->ForEach(reload_image))
481 LLVM_PRETTY_FUNCTION,
"Couldn't reload all images.",
error);
485 return loaded_images_sp;
const char * toString(AppleArm64ExceptionClass EC)
virtual StructuredData::ArraySP GetLoadedImages()
BaseType GetRangeBase() const
ScriptLanguage
Script interpreter types.
ThreadList m_thread_list
The threads for this process as the user will see them.
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
void SetArchitecture(const ArchSpec &arch)
std::shared_ptr< Generic > GenericSP
StructuredData::GenericSP CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj=nullptr) override
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
ScriptedProcessInterface & GetInterface() const
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path, bool can_connect)
Status DoDestroy() override
#define LLDB_LOGF(log,...)
Status DoLoadCore() override
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Target & GetTarget()
Get the target object pointer for this module.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
void RefreshStateAfterStop()
static llvm::StringRef GetPluginNameStatic()
void SetProcessID(lldb::pid_t pid)
void ClearThreadCache()
Clear the Thread* cache that each ThreadPlan contains.
bool DoUpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
void SetPrivateState(lldb::StateType state)
bool GetProcessInfo(ProcessInstanceInfo &info) override
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
void DidLaunch() override
Called after launching a process.
ScriptedProcessInterface & GetScriptedProcessInterface()
static llvm::StringRef GetPluginDescriptionStatic()
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, Status &error) override
Actually do the reading of memory from a process.
@ eStateStopped
Process or thread is stopped and can be examined.
lldb::ScriptLanguage GetLanguage()
static llvm::raw_ostream & error(Stream &strm)
virtual lldb::pid_t GetProcessID()
static bool UnregisterPlugin(ABICreateInstance create_callback)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
#define LLDB_INVALID_OFFSET
virtual lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size, Status &error)
virtual StructuredData::DictionarySP GetThreadsInfo()
std::shared_ptr< Object > ObjectSP
ArchSpec GetArchitecture()
virtual void Finalize()
This object is about to be destroyed, do any necessary cleanup.
lldb_private::StructuredData::ObjectSP m_script_object_sp
std::shared_ptr< Dictionary > DictionarySP
Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
lldb_private::StructuredData::ObjectSP GetLoadedDynamicLibrariesInfos() override
std::string GetClassName() const
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_caterogy=LLDBLog::Process)
const ProcessLaunchInfo & GetProcessLaunchInfo() const
const ScriptedProcessInfo m_scripted_process_info
const ArchSpec & GetArchitecture() const
static llvm::Expected< std::shared_ptr< ScriptedThread > > Create(ScriptedProcess &process, StructuredData::Generic *script_object=nullptr)
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
void ModulesDidLoad(ModuleList &module_list)
~ScriptedProcess() override
bool SetFromStringRef(llvm::StringRef str)
Dictionary * GetAsDictionary()
uint32_t GetSize(bool can_update=true)
bool HasKey(llvm::StringRef key) const
bool IsAlive() override
Check if a process is still alive.
static std::string LanguageToString(lldb::ScriptLanguage language)
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override
Launch a new process.
#define LLDB_INVALID_ADDRESS
ArchSpec & GetArchitecture()
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
ThreadPlanStackMap m_thread_plans
This is the list of thread plans for threads in m_thread_list, as well as threads we knew existed,...
Status DoResume() override
Resumes all of a process's threads as configured using the Thread run control functions.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static constexpr lldb::ScriptLanguage g_supported_script_languages[]
A class that represents a running process on the host machine.
void AddThread(const lldb::ThreadSP &thread_sp)
StructuredData::DictionarySP GetArgsSP() const
StateType
Process and Thread States.
lldb::ByteOrder GetByteOrder() const
#define LLDB_PLUGIN_DEFINE(PluginName)
std::shared_ptr< Array > ArraySP
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
Status GetMemoryRegions(lldb_private::MemoryRegionInfos ®ion_list) override
Obtain all the mapped memory regions within this process.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
void CheckInterpreterAndScriptObject() const
@ eStateRunning
Process or thread is running and can't be examined.
lldb_private::ScriptInterpreter * m_interpreter
ConstString & GetFilename()
Filename string get accessor.