21#include "llvm/Support/Path.h"
37 return "<invalid RendezvousState>";
43 return "eTakeSnapshot";
47 return "eRemoveModules";
51 return "<invalid RendezvousAction>";
56 m_executable_interpreter(false), m_current(), m_previous(),
57 m_loaded_modules(), m_soentries(), m_added_soentries(),
58 m_removed_soentries() {
64 Log *log =
GetLog(LLDBLog::DynamicLoader);
70 LLDB_LOGF(log,
"%s null process provided", __FUNCTION__);
77 LLDB_LOGF(log,
"%s info_location = 0x%" PRIx64, __FUNCTION__, info_location);
90 "%s resolved via direct object file approach to 0x%" PRIx64,
91 __FUNCTION__, info_location);
100 "%s resolved by finding symbol '_r_debug' whose value is "
102 __FUNCTION__, info_addr);
108 "%s FAILED - direct object file approach did not yield a "
116 LLDB_LOGF(log,
"%s FAILED - invalid info address", __FUNCTION__);
120 LLDB_LOGF(log,
"%s reading pointer (%" PRIu32
" bytes) from 0x%" PRIx64,
125 LLDB_LOGF(log,
"%s FAILED - could not read from the info location: %s",
126 __FUNCTION__,
error.AsCString());
130 if (info_addr == 0) {
132 "%s FAILED - the rendezvous address contained at 0x%" PRIx64
133 " returned a null value",
134 __FUNCTION__, info_location);
143 Log *log =
GetLog(LLDBLog::DynamicLoader);
147 LLDB_LOGF(log,
"DYLDRendezvous::%s exe module executable path set: '%s'",
151 "DYLDRendezvous::%s cannot cache exe module path: null "
152 "executable module pointer",
159 LLDB_LOGF(log,
"%s Rendezvous: version = %" PRIu64
", map_addr = 0x%16.16"
160 PRIx64
", brk = 0x%16.16" PRIx64
", state = %" PRIu64
161 " (%s), ldbase = 0x%16.16" PRIx64, label ? label :
"",
version,
166 Log *log =
GetLog(LLDBLog::DynamicLoader);
178 "DYLDRendezvous::%s address size: %" PRIu64
", padding %" PRIu64,
179 __FUNCTION__, uint64_t(address_size), uint64_t(padding));
186 LLDB_LOGF(log,
"DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__,
317 Log *log =
GetLog(LLDBLog::DynamicLoader);
318 LLDB_LOG(log,
"DYLDRendezvous::GetAction() found two eAdd states in a "
319 "row, check process for multiple \"_r_debug\" symbols. "
320 "Returning eAddModules to ensure shared libraries get loaded "
334 Log *log =
GetLog(LLDBLog::DynamicLoader);
349 llvm::Expected<LoadedModuleInfoList> module_list =
352 llvm::consumeError(module_list.takeError());
367 llvm_unreachable(
"Fully covered switch above!");
374 Log *log =
GetLog(LLDBLog::DynamicLoader);
387 llvm_unreachable(
"Fully covered switch above!");
419 for (
auto const &modInfo : module_list.
m_list) {
437 for (
auto const &modInfo : module_list.
m_list) {
440 if (modInfo == existing) {
469 for (
auto const &modInfo : module_list.
m_list) {
470 if (modInfo == existing) {
536 if (!llvm::is_contained(entry_list, *I))
549 switch (triple.getOS()) {
550 case llvm::Triple::FreeBSD:
551 case llvm::Triple::NetBSD:
552 case llvm::Triple::OpenBSD:
554 case llvm::Triple::Linux:
555 if (triple.isAndroid())
586 entry_list.push_back(entry);
617 return std::string();
630 unsigned os_major = target.
GetPlatform()->GetOSVersion().getMajor();
632 (os_major == 21 || os_major == 22) &&
633 (file_path ==
"/system/bin/linker" ||
634 file_path ==
"/system/bin/linker64");
638 std::string
const &file_path) {
643 bool is_loaded =
false;
646 if (
error.Success() && is_loaded)
660 FileSpec::Style::native);
676 if ((arch.
GetTriple().getOS() == llvm::Triple::FreeBSD ||
677 arch.
GetTriple().getOS() == llvm::Triple::NetBSD) &&
682 if (mips_l_offs != 0 && mips_l_offs != entry.
base_addr)
716 Address address = list[0].symbol->GetAddress();
771 : (state ==
eAdd) ?
"add"
772 : (state ==
eDelete) ?
"delete" :
"unknown");
780 for (
int i = 1; I != E; ++I, ++i) {
781 LLDB_LOGF(log,
"\n SOEntry [%d] %s", i, I->file_spec.GetPath().c_str());
782 LLDB_LOGF(log,
" Base : %" PRIx64, I->base_addr);
783 LLDB_LOGF(log,
" Path : %" PRIx64, I->path_addr);
784 LLDB_LOGF(log,
" Dyn : %" PRIx64, I->dyn_addr);
785 LLDB_LOGF(log,
" Next : %" PRIx64, I->next);
786 LLDB_LOGF(log,
" Prev : %" PRIx64, I->prev);
static const size_t word_size
static llvm::raw_ostream & error(Stream &strm)
static bool isLoadBiasIncorrect(Target &target, const std::string &file_path)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
bool FindMetadata(const char *name, PThreadField field, uint32_t &value)
lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst)
Reads an address from the inferior's address space starting at addr.
static const char * ActionToCStr(RendezvousAction action)
std::string ReadStringFromMemory(lldb::addr_t addr)
Reads a null-terminated C string from the memory location starting at addr.
std::list< SOEntry > SOEntryList
bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
Reads an SOEntry starting at addr.
lldb::addr_t GetBreakAddress() const
A breakpoint should be set at this address and Resolve called on each hit.
lldb_private::Process * m_process
void UpdateExecutablePath()
Update the cached executable path.
bool UpdateSOEntries()
Updates the current set of SOEntries, the set of added entries, and the set of removed entries.
bool m_executable_interpreter
uint64_t GetState() const
Returns the current state of the rendezvous structure.
lldb::addr_t GetLinkMapAddress() const
DYLDRendezvous(lldb_private::Process *process)
LoadedModuleInfoList m_loaded_modules
List of currently loaded SO modules.
bool UpdateSOEntriesFromRemote()
Same as UpdateSOEntries but it gets the list of loaded modules from the remote debug server (faster w...
static const char * StateToCStr(RendezvousState state)
bool Resolve()
Update the internal snapshot of runtime linker rendezvous and recompute the currently loaded modules.
RendezvousAction GetAction() const
Returns the current action to be taken given the current and previous state.
bool AddSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList m_added_soentries
List of SOEntry's added to the link map since the last call to Resolve().
lldb::addr_t ResolveRendezvousAddress()
Locates the address of the rendezvous structure.
bool FillSOEntryFromModuleInfo(LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry)
RendezvousState
Constants describing the state of the rendezvous.
lldb::addr_t m_rendezvous_addr
Location of the r_debug structure in the inferiors address space.
iterator begin() const
Iterators over all currently loaded modules.
SOEntryList m_soentries
List of SOEntry objects corresponding to the current link map state.
void DumpToLog(lldb_private::Log *log) const
uint64_t GetVersion() const
lldb_private::FileSpec m_exe_file_spec
const ThreadInfo & GetThreadInfo()
void UpdateBaseAddrIfNecessary(SOEntry &entry, std::string const &file_path)
lldb::addr_t GetLDBase() const
bool TakeSnapshot(SOEntryList &entry_list)
Reads the current list of shared objects according to the link map supplied by the runtime linker.
void UpdateFileSpecIfNecessary(SOEntry &entry)
bool SOEntryIsMainExecutable(const SOEntry &entry)
lldb::addr_t GetRendezvousAddress() const
lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size)
Reads an unsigned integer of size bytes from the inferior's address space starting at addr.
Rendezvous m_current
Current and previous snapshots of the rendezvous structure.
bool RemoveSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList m_removed_soentries
List of SOEntry's removed from the link map since the last call to Resolve().
bool SaveSOEntriesFromRemote(const LoadedModuleInfoList &module_list)
SOEntryList::const_iterator iterator
ThreadInfo m_thread_info
Threading metadata read from the inferior.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::addr_t GetOffset() const
Get the section relative offset value.
bool IsValid() const
Check if the object state is valid.
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsMIPS() const
if MIPS architecture return true.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
bool IsEmpty() const
Test for empty string.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool get_name(std::string &out) const
bool get_link_map(lldb::addr_t &out) const
bool get_base(lldb::addr_t &out) const
bool get_dynamic(lldb::addr_t &out) const
std::vector< LoadedModuleInfo > m_list
void PutCString(const char *cstr)
ConstString GetName() const
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
A class that describes an executable image and its associated object and symbol files.
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
A plug-in interface definition class for object file parsers.
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
A plug-in interface definition class for debugging a process.
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
virtual llvm::Expected< LoadedModuleInfoList > GetLoadedModuleList()
Query remote GDBServer for a detailed loaded library list.
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
virtual lldb::addr_t GetImageInfoAddress()
Get the image information address for the current process.
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
virtual Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded, lldb::addr_t &load_addr)
Try to find the load address of a file.
uint32_t GetAddressByteSize() const
virtual bool IsLiveDebugSession() const
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Locate the memory region that contains load_addr.
Target & GetTarget()
Get the target object pointer for this module.
Defines a list of symbol context objects.
Address GetAddress() const
Module * GetExecutableModulePointer()
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
lldb::PlatformSP GetPlatform()
const ModuleList & GetImages() const
Get accessor for the images for this process.
const ArchSpec & GetArchitecture() const
uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, size_t integer_byte_size, uint64_t fail_value, Status &error, bool force_live_memory=false)
#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.
void DumpToLog(lldb_private::Log *log, const char *label)
Structure representing the shared objects currently loaded into the inferior process.
lldb::addr_t path_addr
String naming the shared object.
lldb::addr_t base_addr
Base address of the loaded object.
lldb::addr_t link_addr
Address of this link_map.
lldb_private::FileSpec file_spec
File spec of shared object.
lldb::addr_t prev
Address of previous so_entry.
lldb::addr_t next
Address of next so_entry.
lldb::addr_t dyn_addr
Dynamic section of shared object.