29#include "llvm/ADT/StringRef.h"
30#include "llvm/Support/Error.h"
41 llvm::StringRef plugin_name) {
43 if (!plugin_name.empty()) {
46 if (create_callback) {
47 std::unique_ptr<DynamicLoader> instance_up(
48 create_callback(process,
true));
50 return instance_up.release();
53 for (
auto create_callback :
55 std::unique_ptr<DynamicLoader> instance_up(
56 create_callback(process,
false));
58 return instance_up.release();
70 return m_process->GetStopOnSharedLibraryEvents();
74 m_process->SetStopOnSharedLibraryEvents(stop);
83 ModuleSpec module_spec(executable->GetFileSpec(),
84 executable->GetArchitecture());
85 auto module_sp = std::make_shared<Module>(module_spec);
93 if (module_sp && module_sp->GetUUID().IsValid() &&
94 executable->GetUUID().IsValid()) {
95 if (module_sp->GetUUID() != executable->GetUUID())
97 }
else if (executable->FileHasChanged()) {
116 bool base_addr_is_offset) {
122 bool base_addr_is_offset) {
124 module->SetLoadAddress(m_process->GetTarget(), base_addr, base_addr_is_offset,
136 assert(sections &&
"SectionList missing from unloaded module.");
138 const size_t num_sections = sections->
GetSize();
139 for (
size_t i = 0; i < num_sections; ++i) {
149 ObjectFile *obj_file =
module->GetObjectFile();
150 if (obj_file !=
nullptr) {
176 bool base_addr_is_offset) {
183 if (!module_sp && !
m_process->IsLiveDebugSession()) {
184 llvm::Expected<ModuleSP> memory_module_sp_or_err =
185 m_process->ReadModuleFromMemory(file, base_addr);
186 if (
auto err = memory_module_sp_or_err.takeError())
188 "Failed to read module from memory: {0}");
190 module_sp = *memory_module_sp_or_err;
191 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp,
false);
196 base_addr_is_offset);
201 llvm::StringRef name) {
204 snprintf(namebuf,
sizeof(namebuf),
"memory-image-0x%" PRIx64, addr);
207 llvm::Expected<ModuleSP> module_sp_or_err =
209 if (
auto err = module_sp_or_err.takeError()) {
211 "Failed to read module from memory: {0}");
214 return *module_sp_or_err;
220 if (!bin_spec.
name.empty())
221 desc << bin_spec.
name <<
" ";
234 msg <<
"Unable to find file";
235 if (!bin_spec.
name.empty())
236 msg <<
" " << bin_spec.
name;
241 msg.
Printf(
" with slide 0x%" PRIx64, bin_spec.
value);
243 msg.
Printf(
" at address 0x%" PRIx64, bin_spec.
value);
256 module_spec.
SetTarget(target.shared_from_this());
277 llvm::Expected<SymbolLocator::Result> located =
282 llvm::Error
error = located.takeError();
284 llvm::consumeError(std::move(
error));
292 if (located->symbol_error)
305 if (!located_module_sp)
306 located_module_sp = std::make_shared<Module>(located->module_spec);
310 bin_spec.
module_sp = std::move(located_module_sp);
311 bin_spec.
module_sp->GetSymbolLocatorStatistics().merge(located->statistics);
323 Process *process, llvm::MutableArrayRef<BinarySpec> bin_specs) {
328 if (!bin_spec.uuid.IsValid() && !bin_spec.value_is_offset)
330 if (!bin_spec.uuid.IsValid())
337llvm::Expected<ModuleSP>
360 llvm::Error
error = llvm::createStringError(message);
362 return llvm::joinErrors(std::move(search_error), std::move(
error));
363 return std::move(
error);
372 << llvm::toString(std::move(search_error)) <<
"\n";
380 bool changed =
false;
382 if (bin_spec.
module_sp->GetObjectFile()) {
385 "DynamicLoader::LoadBinaryInTarget Loading "
386 "binary %s UUID %s at %s 0x%" PRIx64,
396 "DynamicLoader::LoadBinaryInTarget Loading "
397 "binary %s UUID %s at file address",
399 bin_spec.
module_sp->SetLoadAddress(target, 0,
true ,
405 "DynamicLoader::LoadBinaryInTarget Loading binary "
406 "%s UUID %s from memory at address 0x%" PRIx64,
409 bin_spec.
module_sp->SetLoadAddress(target, 0,
true ,
423llvm::Expected<ModuleSP>
433 m_process->ReadUnsignedIntegerFromMemory(addr, size_in_bytes, 0,
error);
437 return (int64_t)value;
452 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.
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 DynamicLoaderCreateInstance GetDynamicLoaderCreateCallbackForPluginName(llvm::StringRef name)
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
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
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.
A binary was not found and nothing could say why.
static llvm::Expected< Result > Locate(const Request &request, const FileSpecList &search_paths)
Find a binary and, if possible, its symbols.
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.
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.
One binary to search for.
lldb::PlatformSP platform
A platform that may know where the binary is.
ModuleSpec module_spec
What to look for.
bool external_lookup
Allow contacting an external symbol server when the local searches come up empty.