28#include "llvm/ADT/StringRef.h"
38 llvm::StringRef plugin_name) {
40 if (!plugin_name.empty()) {
43 if (create_callback) {
44 std::unique_ptr<DynamicLoader> instance_up(
45 create_callback(process,
true));
47 return instance_up.release();
50 for (
auto create_callback :
52 std::unique_ptr<DynamicLoader> instance_up(
53 create_callback(process,
false));
55 return instance_up.release();
67 return m_process->GetStopOnSharedLibraryEvents();
71 m_process->SetStopOnSharedLibraryEvents(stop);
80 ModuleSpec module_spec(executable->GetFileSpec(),
81 executable->GetArchitecture());
82 auto module_sp = std::make_shared<Module>(module_spec);
90 if (module_sp && module_sp->GetUUID().IsValid() &&
91 executable->GetUUID().IsValid()) {
92 if (module_sp->GetUUID() != executable->GetUUID())
94 }
else if (executable->FileHasChanged()) {
113 bool base_addr_is_offset) {
119 bool base_addr_is_offset) {
121 module->SetLoadAddress(m_process->GetTarget(), base_addr, base_addr_is_offset,
133 assert(sections &&
"SectionList missing from unloaded module.");
135 const size_t num_sections = sections->
GetSize();
136 for (
size_t i = 0; i < num_sections; ++i) {
146 ObjectFile *obj_file =
module->GetObjectFile();
147 if (obj_file !=
nullptr) {
175 bool base_addr_is_offset) {
179 if (!module_sp && !
m_process->IsLiveDebugSession()) {
180 llvm::Expected<ModuleSP> memory_module_sp_or_err =
181 m_process->ReadModuleFromMemory(file, base_addr);
182 if (
auto err = memory_module_sp_or_err.takeError())
184 "Failed to read module from memory: {0}");
186 module_sp = *memory_module_sp_or_err;
187 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp,
false);
192 base_addr_is_offset);
197 llvm::StringRef name) {
200 snprintf(namebuf,
sizeof(namebuf),
"memory-image-0x%" PRIx64, addr);
203 llvm::Expected<ModuleSP> module_sp_or_err =
205 if (
auto err = module_sp_or_err.takeError()) {
207 "Failed to read module from memory: {0}");
210 return *module_sp_or_err;
215 bool value_is_offset,
bool force_symbol_search,
bool notify,
216 bool set_address_in_target,
bool allow_memory_image_last_resort) {
225 prog_str << name.str() <<
" ";
230 prog_str <<
" at 0x";
234 if (!uuid.
IsValid() && !value_is_offset) {
237 if (memory_module_sp) {
238 uuid = memory_module_sp->GetUUID();
246 module_spec.
SetTarget(target.shared_from_this());
275 module_sp = std::make_shared<Module>(module_spec);
279 module_sp->GetSymbolLocatorStatistics().merge(symbol_locator_map);
285 if (!module_sp || !module_sp->GetSymbolFileFileSpec()) {
287 force_symbol_search);
289 module_sp = std::make_shared<Module>(module_spec);
290 }
else if (force_symbol_search &&
error.AsCString(
"") &&
291 error.AsCString(
"")[0] !=
'\0') {
298 module_sp = std::make_shared<Module>(module_spec);
303 if (allow_memory_image_last_resort && !module_sp.get() &&
305 if (!memory_module_sp)
307 if (memory_module_sp)
308 module_sp = memory_module_sp;
312 if (module_sp.get()) {
319 bool changed =
false;
320 if (set_address_in_target) {
321 if (module_sp->GetObjectFile()) {
324 "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
325 "binary %s UUID %s at %s 0x%" PRIx64,
327 value_is_offset ?
"offset" :
"address", value);
328 module_sp->SetLoadAddress(target, value, value_is_offset, changed);
333 "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
334 "binary %s UUID %s at file address",
336 module_sp->SetLoadAddress(target, 0,
true ,
342 "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading binary "
343 "%s UUID %s from memory at address 0x%" PRIx64,
344 name.str().c_str(), uuid.
GetAsString().c_str(), value);
345 module_sp->SetLoadAddress(target, 0,
true ,
352 added_module.
Append(module_sp,
false);
356 if (force_symbol_search) {
358 s->Printf(
"Unable to find file");
360 s->Printf(
" %s", name.str().c_str());
362 s->Printf(
" with UUID %s", uuid.
GetAsString().c_str());
365 s->Printf(
" with slide 0x%" PRIx64, value);
367 s->Printf(
" at address 0x%" PRIx64, value);
372 "Unable to find binary %s with UUID %s and load it at "
375 value_is_offset ?
"offset" :
"address", value);
385 m_process->ReadUnsignedIntegerFromMemory(addr, size_in_bytes, 0,
error);
389 return (int64_t)value;
404 m_process->LoadOperatingSystemPlugin(flush);
static llvm::raw_ostream & error(Stream &strm)
static ModuleSP ReadUnnamedMemoryModule(Process *process, addr_t addr, llvm::StringRef name)
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
bool IsValid() const
Tests if this ArchSpec is valid.
lldb::StreamUP GetAsyncErrorStream()
void LoadOperatingSystemPlugin(bool flush)
void SetStopWhenImagesChange(bool stop)
Set whether the process should stop when images change.
int64_t ReadUnsignedIntWithSizeInBytes(lldb::addr_t addr, int size_in_bytes)
lldb::addr_t ReadPointer(lldb::addr_t addr)
Process * m_process
The process that this dynamic loader plug-in is tracking.
void UpdateLoadedSectionsCommon(lldb::ModuleSP module, lldb::addr_t base_addr, bool base_addr_is_offset)
lldb::ModuleSP GetTargetExecutable()
Checks to see if the target module has changed, updates the target accordingly and returns the target...
bool GetStopWhenImagesChange() const
Get whether the process should stop when images change.
static lldb::ModuleSP LoadBinaryWithUUIDAndAddress(Process *process, llvm::StringRef name, UUID uuid, lldb::addr_t value, bool value_is_offset, bool force_symbol_search, bool notify, bool set_address_in_target, bool allow_memory_image_last_resort)
Find/load a binary into lldb given a UUID and the address where it is loaded in memory,...
virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset)
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
virtual void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset)
Updates the load address of every allocatable section in module.
DynamicLoader(Process *process)
Construct with a process.
const lldb_private::SectionList * GetSectionListFromModule(const lldb::ModuleSP module) const
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
void UnloadSectionsCommon(const lldb::ModuleSP module)
lldb::ModuleSP FindModuleViaTarget(const FileSpec &file)
Find a module in the target that matches the given file.
virtual void UnloadSections(const lldb::ModuleSP module)
Removes the loaded sections from the target in module.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
A collection class for Module objects.
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true)
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Finds the first module whose file specification matches module_spec.
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
FileSpec & GetSymbolFileSpec()
void SetTarget(lldb::TargetSP target)
Set the target to be used when resolving a module.
A plug-in interface definition class for object file parsers.
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, Status &error, bool force_lookup=true, bool copy_executable=true)
static FileSpec LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths, StatisticsMap &map)
static DynamicLoaderCreateInstance GetDynamicLoaderCreateCallbackForPluginName(llvm::StringRef name)
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec, StatisticsMap &map)
static llvm::SmallVector< DynamicLoaderCreateInstance > GetDynamicLoaderCreateCallbacks()
A plug-in interface definition class for debugging a process.
llvm::Expected< lldb::ModuleSP > ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Creates and populates a module using an in-memory object file.
Target & GetTarget()
Get the target object pointer for this module.
A Progress indicator helper class.
lldb::SectionSP GetSectionAtIndex(size_t idx) const
A class to count time for plugins.
llvm::StringRef GetString() const
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Module * GetExecutableModulePointer()
Debugger & GetDebugger() const
bool SetSectionUnloaded(const lldb::SectionSP §ion_sp)
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...
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
static FileSpecList GetDefaultDebugFileSearchPaths()
lldb::PlatformSP GetPlatform()
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Represents UUID's of various sizes.
std::string GetAsString(llvm::StringRef separator="-") const
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
DynamicLoader *(* DynamicLoaderCreateInstance)(Process *process, bool force)
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Section > SectionSP
std::unique_ptr< lldb_private::Stream > StreamUP
std::shared_ptr< lldb_private::Module > ModuleSP