aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp')
-rw-r--r--lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 96ae305f8..e36b29d 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -170,6 +170,7 @@ Status ScriptedProcess::DoLaunch(Module *exe_module,
void ScriptedProcess::DidLaunch() {
CheckInterpreterAndScriptObject();
m_pid = GetInterface().GetProcessID();
+ GetLoadedDynamicLibrariesInfos();
}
Status ScriptedProcess::DoResume() {
@@ -378,6 +379,93 @@ bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
return true;
}
+lldb_private::StructuredData::ObjectSP
+ScriptedProcess::GetLoadedDynamicLibrariesInfos() {
+ CheckInterpreterAndScriptObject();
+
+ Status error;
+ auto error_with_message = [&error](llvm::StringRef message) {
+ return ScriptedInterface::ErrorWithMessage<bool>(LLVM_PRETTY_FUNCTION,
+ message.data(), error);
+ };
+
+ StructuredData::ArraySP loaded_images_sp = GetInterface().GetLoadedImages();
+
+ if (!loaded_images_sp || !loaded_images_sp->GetSize())
+ return GetInterface().ErrorWithMessage<StructuredData::ObjectSP>(
+ LLVM_PRETTY_FUNCTION, "No loaded images.", error);
+
+ ModuleList module_list;
+ Target &target = GetTarget();
+
+ auto reload_image = [&target, &module_list, &error_with_message](
+ StructuredData::Object *obj) -> bool {
+ StructuredData::Dictionary *dict = obj->GetAsDictionary();
+
+ if (!dict)
+ return error_with_message("Couldn't cast image object into dictionary.");
+
+ ModuleSpec module_spec;
+ llvm::StringRef value;
+
+ bool has_path = dict->HasKey("path");
+ bool has_uuid = dict->HasKey("uuid");
+ if (!has_path && !has_uuid)
+ return error_with_message("Dictionary should have key 'path' or 'uuid'");
+ if (!dict->HasKey("load_addr"))
+ return error_with_message("Dictionary is missing key 'load_addr'");
+
+ if (has_path) {
+ dict->GetValueForKeyAsString("path", value);
+ module_spec.GetFileSpec().SetPath(value);
+ }
+
+ if (has_uuid) {
+ dict->GetValueForKeyAsString("uuid", value);
+ module_spec.GetUUID().SetFromStringRef(value);
+ }
+ module_spec.GetArchitecture() = target.GetArchitecture();
+
+ ModuleSP module_sp =
+ target.GetOrCreateModule(module_spec, true /* notify */);
+
+ if (!module_sp)
+ return error_with_message("Couldn't create or get module.");
+
+ lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
+ lldb::addr_t slide = LLDB_INVALID_OFFSET;
+ dict->GetValueForKeyAsInteger("load_addr", load_addr);
+ dict->GetValueForKeyAsInteger("slide", slide);
+ if (load_addr == LLDB_INVALID_ADDRESS)
+ return error_with_message(
+ "Couldn't get valid load address or slide offset.");
+
+ if (slide != LLDB_INVALID_OFFSET)
+ load_addr += slide;
+
+ bool changed = false;
+ module_sp->SetLoadAddress(target, load_addr, false /*=value_is_offset*/,
+ changed);
+
+ if (!changed && !module_sp->GetObjectFile())
+ return error_with_message("Couldn't set the load address for module.");
+
+ dict->GetValueForKeyAsString("path", value);
+ FileSpec objfile(value);
+ module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename());
+
+ return module_list.AppendIfNeeded(module_sp);
+ };
+
+ if (!loaded_images_sp->ForEach(reload_image))
+ return GetInterface().ErrorWithMessage<StructuredData::ObjectSP>(
+ LLVM_PRETTY_FUNCTION, "Couldn't reload all images.", error);
+
+ target.ModulesDidLoad(module_list);
+
+ return loaded_images_sp;
+}
+
ScriptedProcessInterface &ScriptedProcess::GetInterface() const {
return m_interpreter->GetScriptedProcessInterface();
}