28#include "llvm/ADT/StringRef.h"
29#include "llvm/Support/Error.h"
40 llvm::StringRef plugin_name) {
42 if (!plugin_name.empty()) {
45 if (create_callback) {
46 std::unique_ptr<DynamicLoader> instance_up(
47 create_callback(process,
true));
49 return instance_up.release();
52 for (
auto create_callback :
54 std::unique_ptr<DynamicLoader> instance_up(
55 create_callback(process,
false));
57 return instance_up.release();
69 return m_process->GetStopOnSharedLibraryEvents();
73 m_process->SetStopOnSharedLibraryEvents(stop);
82 ModuleSpec module_spec(executable->GetFileSpec(),
83 executable->GetArchitecture());
84 auto module_sp = std::make_shared<Module>(module_spec);
92 if (module_sp && module_sp->GetUUID().IsValid() &&
93 executable->GetUUID().IsValid()) {
94 if (module_sp->GetUUID() != executable->GetUUID())
96 }
else if (executable->FileHasChanged()) {
115 bool base_addr_is_offset) {
121 bool base_addr_is_offset) {
123 module->SetLoadAddress(m_process->GetTarget(), base_addr, base_addr_is_offset,
135 assert(sections &&
"SectionList missing from unloaded module.");
137 const size_t num_sections = sections->
GetSize();
138 for (
size_t i = 0; i < num_sections; ++i) {
148 ObjectFile *obj_file =
module->GetObjectFile();
149 if (obj_file !=
nullptr) {
175 bool base_addr_is_offset) {
182 if (!module_sp && !
m_process->IsLiveDebugSession()) {
183 llvm::Expected<ModuleSP> memory_module_sp_or_err =
184 m_process->ReadModuleFromMemory(file, base_addr);
185 if (
auto err = memory_module_sp_or_err.takeError())
187 "Failed to read module from memory: {0}");
189 module_sp = *memory_module_sp_or_err;
190 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp,
false);
195 base_addr_is_offset);
200 llvm::StringRef name) {
203 snprintf(namebuf,
sizeof(namebuf),
"memory-image-0x%" PRIx64, addr);
206 llvm::Expected<ModuleSP> module_sp_or_err =
208 if (
auto err = module_sp_or_err.takeError()) {
210 "Failed to read module from memory: {0}");
213 return *module_sp_or_err;
219 if (!bin_spec.
name.empty())
220 desc << bin_spec.
name <<
" ";
233 msg <<
"Unable to find file";
234 if (!bin_spec.
name.empty())
235 msg <<
" " << bin_spec.
name;
240 msg.
Printf(
" with slide 0x%" PRIx64, bin_spec.
value);
242 msg.
Printf(
" at address 0x%" PRIx64, bin_spec.
value);
255 module_spec.
SetTarget(target.shared_from_this());
271 module_spec, search_paths, symbol_locator_map);
273 module_spec, symbol_locator_map);
277 bin_spec.
module_sp = std::make_shared<Module>(module_spec);
281 bin_spec.
module_sp->GetSymbolLocatorStatistics().merge(
292 bin_spec.
module_sp = std::make_shared<Module>(module_spec);
301 bin_spec.
module_sp = std::make_shared<Module>(module_spec);
313 Process *process, llvm::MutableArrayRef<BinarySpec> bin_specs) {
318 if (!bin_spec.uuid.IsValid() && !bin_spec.value_is_offset)
320 if (!bin_spec.uuid.IsValid())
327llvm::Expected<ModuleSP>
350 llvm::Error
error = llvm::createStringError(message);
352 return llvm::joinErrors(std::move(search_error), std::move(
error));
353 return std::move(
error);
362 << llvm::toString(std::move(search_error)) <<
"\n";
370 bool changed =
false;
372 if (bin_spec.
module_sp->GetObjectFile()) {
375 "DynamicLoader::LoadBinaryInTarget Loading "
376 "binary %s UUID %s at %s 0x%" PRIx64,
386 "DynamicLoader::LoadBinaryInTarget Loading "
387 "binary %s UUID %s at file address",
389 bin_spec.
module_sp->SetLoadAddress(target, 0,
true ,
395 "DynamicLoader::LoadBinaryInTarget Loading binary "
396 "%s UUID %s from memory at address 0x%" PRIx64,
399 bin_spec.
module_sp->SetLoadAddress(target, 0,
true ,
413llvm::Expected<ModuleSP>
423 m_process->ReadUnsignedIntegerFromMemory(addr, size_in_bytes, 0,
error);
427 return (int64_t)value;
442 m_process->LoadOperatingSystemPlugin(flush);
static llvm::raw_ostream & error(Stream &strm)
static ModuleSP ReadUnnamedMemoryModule(Process *process, addr_t addr, llvm::StringRef name)
static void SearchForBinary(Target &target, DynamicLoader::BinarySpec &bin_spec, const FileSpecList &search_paths)
Search for a binary with a known UUID, and create a module for it.
static void FindBinaryUUIDInMemory(Process *process, DynamicLoader::BinarySpec &bin_spec)
static std::string GetBinaryDescription(const DynamicLoader::BinarySpec &bin_spec)
static std::string GetBinaryNotFoundMessage(const DynamicLoader::BinarySpec &bin_spec)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#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.
lldb::ModuleSP FindModuleViaTarget(const ModuleSpec &module_spec)
Find a module in the target that matches the given module spec.
int64_t ReadUnsignedIntWithSizeInBytes(lldb::addr_t addr, int size_in_bytes)
static llvm::Expected< lldb::ModuleSP > LocateAndLoadBinary(Process *process, BinarySpec &bin_spec)
Find a binary and load it into a Target.
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 void LocateBinaries(Process *process, llvm::MutableArrayRef< BinarySpec > bin_specs)
Search for a batch of binaries, without mutating the Target.
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.
static llvm::Expected< lldb::ModuleSP > LoadBinaryInTarget(Process *process, BinarySpec &bin_spec)
Add a binary that LocateBinaries searched for to the Target, and set its load address.
void UnloadSectionsCommon(const lldb::ModuleSP module)
virtual void UnloadSections(const lldb::ModuleSP module)
Removes the loaded sections from the target in module.
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, bool invoke_symbol_locators=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.
void SetLoadAddress(lldb::addr_t addr)
Set the load address of a module in process memory.
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)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
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()
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.
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::Section > SectionSP
std::shared_ptr< lldb_private::Module > ModuleSP
A binary to find and load into a Target.
lldb::addr_t value
Address where the binary should be loaded, or read out of memory.
bool allow_memory_image_last_resort
If no better binary image can be found, allow reading the binary out of memory, if possible,...
UUID uuid
UUID of the binary to be loaded.
lldb::ModuleSP memory_module_sp
The binary as it was read out of the process' memory, if it had to be, so that it is not read a secon...
std::string name
Name of the binary, if available.
lldb::ModuleSP module_sp
The module found for the binary, or empty if it was not found.
Status error
What an external symbol server had to say about this binary.
bool force_symbol_search
Allow the search to do a possibly expensive external search for the ObjectFile and/or SymbolFile.
bool set_address_in_target
Whether the address of the binary should be set in the Target if it is added.
bool notify
Whether ModulesDidLoad should be called once the binary has been added to the Target.
bool value_is_offset
A flag indicating that value is an address, or an offset to be applied to the file addresses.