21#include "llvm/Support/Error.h"
22#include "llvm/Support/Path.h"
38 return "<invalid RendezvousState>";
44 return "eTakeSnapshot";
48 return "eRemoveModules";
52 return "<invalid RendezvousAction>";
70 LLDB_LOGF(log,
"%s null process provided", __FUNCTION__);
76 info_location =
m_process->GetImageInfoAddress();
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,
121 __FUNCTION__,
m_process->GetAddressByteSize(), info_location);
123 llvm::Expected<lldb::addr_t> info_addr_or_err =
124 m_process->ReadPointerFromMemory(info_location);
125 if (!info_addr_or_err) {
127 "{1} FAILED - could not read from the info location: {0}",
131 info_addr = *info_addr_or_err;
133 if (info_addr == 0) {
135 "%s FAILED - the rendezvous address contained at 0x%" PRIx64
136 " returned a null value",
137 __FUNCTION__, info_location);
150 LLDB_LOGF(log,
"DYLDRendezvous::%s exe module executable path set: '%s'",
154 "DYLDRendezvous::%s cannot cache exe module path: null "
155 "executable module pointer",
162 LLDB_LOGF(log,
"%s Rendezvous: version = %" PRIu64
", map_addr = 0x%16.16"
163 PRIx64
", brk = 0x%16.16" PRIx64
", state = %" PRIu64
164 " (%s), ldbase = 0x%16.16" PRIx64, label ? label :
"",
version,
178 address_size =
m_process->GetAddressByteSize();
181 "DYLDRendezvous::%s address size: %" PRIu64
", padding %" PRIu64,
182 __FUNCTION__, uint64_t(address_size), uint64_t(padding));
189 LLDB_LOGF(log,
"DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__,
321 LLDB_LOG(log,
"DYLDRendezvous::GetAction() found two eAdd states in a "
322 "row, check process for multiple \"_r_debug\" symbols. "
323 "Returning eAddModules to ensure shared libraries get loaded "
352 llvm::Expected<LoadedModuleInfoList> module_list =
355 llvm::consumeError(module_list.takeError());
370 llvm_unreachable(
"Fully covered switch above!");
390 llvm_unreachable(
"Fully covered switch above!");
422 for (
auto const &modInfo : module_list.
m_list) {
440 for (
auto const &modInfo : module_list.
m_list) {
443 if (modInfo == existing) {
472 for (
auto const &modInfo : module_list.
m_list) {
473 if (modInfo == existing) {
537 if (!llvm::is_contained(entry_list, *I))
549 auto triple =
m_process->GetTarget().GetArchitecture().GetTriple();
550 switch (triple.getOS()) {
551 case llvm::Triple::FreeBSD:
552 case llvm::Triple::NetBSD:
553 case llvm::Triple::OpenBSD:
555 case llvm::Triple::Linux:
556 if (triple.isAndroid())
587 entry_list.push_back(entry);
596 *dst =
m_process->ReadUnsignedIntegerFromMemory(addr, size, 0,
error);
604 llvm::Expected<lldb::addr_t> dst_or_err =
607 llvm::consumeError(dst_or_err.takeError());
612 return addr +
m_process->GetAddressByteSize();
620 return std::string();
633 unsigned os_major = target.
GetPlatform()->GetOSVersion().getMajor();
635 (os_major == 21 || os_major == 22) &&
636 (file_path ==
"/system/bin/linker" ||
637 file_path ==
"/system/bin/linker64");
641 std::string
const &file_path) {
646 bool is_loaded =
false;
649 if (
error.Success() && is_loaded)
663 FileSpec::Style::native);
679 if ((arch.
GetTriple().getOS() == llvm::Triple::FreeBSD ||
680 arch.
GetTriple().getOS() == llvm::Triple::NetBSD) &&
685 if (mips_l_offs != 0 && mips_l_offs != entry.
base_addr)
719 Address address = list[0].symbol->GetAddress();
722 int field_num = (field ==
eStructSize) ? 0 : field;
723 address.
Slide(field_num *
sizeof(uint32_t));
779 : (state ==
eAdd) ?
"add"
780 : (state ==
eDelete) ?
"delete" :
"unknown");
788 for (
int i = 1; I != E; ++I, ++i) {
789 LLDB_LOGF(log,
"\n SOEntry [%d] %s", i, I->file_spec.GetPath().c_str());
790 LLDB_LOGF(log,
" Base : %" PRIx64, I->base_addr);
791 LLDB_LOGF(log,
" Path : %" PRIx64, I->path_addr);
792 LLDB_LOGF(log,
" Dyn : %" PRIx64, I->dyn_addr);
793 LLDB_LOGF(log,
" Next : %" PRIx64, I->next);
794 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,...)
#define LLDB_LOG_ERROR(log, error,...)
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)
PThreadField
For the definitions of the metadata entries, see <glibc>/nptl_db/(db_info.c, structs....
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.
bool Slide(int64_t offset)
bool IsValid() const
Check if the object state is valid.
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsMIPS() const
if MIPS architecture return true.
A uniqued constant string class.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
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.
Defines a list of symbol context objects.
Address GetAddress() const
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.