LLDB mainline
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
DYLDRendezvous Class Reference

Interface to the runtime linker. More...

#include <DYLDRendezvous.h>

Classes

struct  Rendezvous
 
struct  SOEntry
 Structure representing the shared objects currently loaded into the inferior process. More...
 
struct  ThreadInfo
 

Public Types

enum  RendezvousState { eConsistent , eAdd , eDelete }
 Constants describing the state of the rendezvous. More...
 
typedef SOEntryList::const_iterator iterator
 

Public Member Functions

 DYLDRendezvous (lldb_private::Process *process)
 
void UpdateExecutablePath ()
 Update the cached executable path.
 
bool Resolve ()
 Update the internal snapshot of runtime linker rendezvous and recompute the currently loaded modules.
 
bool IsValid ()
 
lldb::addr_t GetRendezvousAddress () const
 
uint64_t GetVersion () const
 
lldb::addr_t GetLinkMapAddress () const
 
lldb::addr_t GetBreakAddress () const
 A breakpoint should be set at this address and Resolve called on each hit.
 
uint64_t GetState () const
 Returns the current state of the rendezvous structure.
 
lldb::addr_t GetLDBase () const
 
const ThreadInfoGetThreadInfo ()
 
bool ModulesDidLoad () const
 
bool ModulesDidUnload () const
 
void DumpToLog (lldb_private::Log *log) const
 
iterator begin () const
 Iterators over all currently loaded modules.
 
iterator end () const
 
iterator loaded_begin () const
 Iterators over all modules loaded into the inferior since the last call to Resolve().
 
iterator loaded_end () const
 
iterator unloaded_begin () const
 Iterators over all modules unloaded from the inferior since the last call to Resolve().
 
iterator unloaded_end () const
 

Protected Types

enum  PThreadField { eSize , eNElem , eOffset }
 
enum  RendezvousAction { eNoAction , eTakeSnapshot , eAddModules , eRemoveModules }
 
typedef std::list< SOEntrySOEntryList
 

Protected Member Functions

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.
 
lldb::addr_t ReadPointer (lldb::addr_t addr, lldb::addr_t *dst)
 Reads an address from the inferior's address space starting at addr.
 
std::string ReadStringFromMemory (lldb::addr_t addr)
 Reads a null-terminated C string from the memory location starting at addr.
 
bool ReadSOEntryFromMemory (lldb::addr_t addr, SOEntry &entry)
 Reads an SOEntry starting at addr.
 
bool UpdateSOEntries ()
 Updates the current set of SOEntries, the set of added entries, and the set of removed entries.
 
bool UpdateSOEntriesFromRemote ()
 Same as UpdateSOEntries but it gets the list of loaded modules from the remote debug server (faster when supported).
 
bool FillSOEntryFromModuleInfo (LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry)
 
bool SaveSOEntriesFromRemote (const LoadedModuleInfoList &module_list)
 
bool AddSOEntriesFromRemote (const LoadedModuleInfoList &module_list)
 
bool RemoveSOEntriesFromRemote (const LoadedModuleInfoList &module_list)
 
bool AddSOEntries ()
 
bool RemoveSOEntries ()
 
void UpdateBaseAddrIfNecessary (SOEntry &entry, std::string const &file_path)
 
void UpdateFileSpecIfNecessary (SOEntry &entry)
 
bool SOEntryIsMainExecutable (const SOEntry &entry)
 
bool TakeSnapshot (SOEntryList &entry_list)
 Reads the current list of shared objects according to the link map supplied by the runtime linker.
 
bool FindMetadata (const char *name, PThreadField field, uint32_t &value)
 
bool IsCoreFile () const
 
RendezvousAction GetAction () const
 Returns the current action to be taken given the current and previous state.
 

Static Protected Member Functions

static const char * StateToCStr (RendezvousState state)
 
static const char * ActionToCStr (RendezvousAction action)
 

Protected Attributes

lldb_private::Processm_process
 
lldb_private::FileSpec m_exe_file_spec
 
lldb::addr_t m_rendezvous_addr
 Location of the r_debug structure in the inferiors address space.
 
bool m_executable_interpreter
 
Rendezvous m_current
 Current and previous snapshots of the rendezvous structure.
 
Rendezvous m_previous
 
LoadedModuleInfoList m_loaded_modules
 List of currently loaded SO modules.
 
SOEntryList m_soentries
 List of SOEntry objects corresponding to the current link map state.
 
SOEntryList m_added_soentries
 List of SOEntry's added to the link map since the last call to Resolve().
 
SOEntryList m_removed_soentries
 List of SOEntry's removed from the link map since the last call to Resolve().
 
ThreadInfo m_thread_info
 Threading metadata read from the inferior.
 

Private Member Functions

lldb::addr_t ResolveRendezvousAddress ()
 Locates the address of the rendezvous structure.
 

Detailed Description

Interface to the runtime linker.

A structure is present in a processes memory space which is updated by the dynamic linker each time a module is loaded or unloaded. This class provides an interface to this structure and maintains a consistent snapshot of the currently loaded modules.

In the dynamic loader sources, this structure has a type of "r_debug" and the name of the structure us "_r_debug". The structure looks like:

struct r_debug { // Version number for this protocol. int r_version; // Head of the chain of loaded objects. struct link_map *r_map; // The address the debugger should set a breakpoint at in order to get // notified when shared libraries are added or removed uintptr_t r_brk; // This state value describes the mapping change taking place when the // 'r_brk' address is called. enum { RT_CONSISTENT, // Mapping change is complete. RT_ADD, // Beginning to add a new object. RT_DELETE, // Beginning to remove an object mapping. } r_state; // Base address the linker is loaded at. uintptr_t r_ldbase; };

The dynamic linker then defines a global variable using this type named "_r_debug":

r_debug _r_debug;

The DYLDRendezvous class defines a local version of this structure named DYLDRendezvous::Rendezvous. See the definition inside the class definition for DYLDRendezvous.

This structure can be located by looking through the .dynamic section in the main executable and finding the DT_DEBUG tag entry. This value starts out with a value of zero when the program first is initially loaded, but the address of the "_r_debug" structure from ld.so is filled in by the dynamic loader during program initialization code in ld.so prior to loading or unloading and shared libraries.

The dynamic loader will update this structure as shared libraries are loaded and will call a specific function that LLDB knows to set a breakpoint on (from _r_debug.r_brk) so LLDB will find out when shared libraries are loaded or unloaded. Each time this breakpoint is hit, LLDB looks at the contents of this structure and the contents tell LLDB what needs to be done.

Currently we expect the "state" in this structure to change as things happen.

When any shared libraries are loaded the following happens:

When any shared libraries are unloaded the following happens:

Definition at line 107 of file DYLDRendezvous.h.

Member Typedef Documentation

◆ iterator

typedef SOEntryList::const_iterator DYLDRendezvous::iterator

Definition at line 249 of file DYLDRendezvous.h.

◆ SOEntryList

typedef std::list<SOEntry> DYLDRendezvous::SOEntryList
protected

Definition at line 246 of file DYLDRendezvous.h.

Member Enumeration Documentation

◆ PThreadField

Enumerator
eSize 
eNElem 
eOffset 

Definition at line 348 of file DYLDRendezvous.h.

◆ RendezvousAction

Enumerator
eNoAction 
eTakeSnapshot 
eAddModules 
eRemoveModules 

Definition at line 354 of file DYLDRendezvous.h.

◆ RendezvousState

Constants describing the state of the rendezvous.

These values are defined to match the r_debug.r_state enum from the actual dynamic loader sources.

See also
GetState().
Enumerator
eConsistent 
eAdd 
eDelete 

Definition at line 208 of file DYLDRendezvous.h.

Constructor & Destructor Documentation

◆ DYLDRendezvous()

DYLDRendezvous::DYLDRendezvous ( lldb_private::Process process)

Member Function Documentation

◆ ActionToCStr()

const char * DYLDRendezvous::ActionToCStr ( RendezvousAction  action)
staticprotected

Definition at line 40 of file DYLDRendezvous.cpp.

References eAddModules, eNoAction, eRemoveModules, and eTakeSnapshot.

Referenced by UpdateSOEntries(), and UpdateSOEntriesFromRemote().

◆ AddSOEntries()

bool DYLDRendezvous::AddSOEntries ( )
protected

◆ AddSOEntriesFromRemote()

bool DYLDRendezvous::AddSOEntriesFromRemote ( const LoadedModuleInfoList module_list)
protected

◆ begin()

iterator DYLDRendezvous::begin ( ) const
inline

Iterators over all currently loaded modules.

Definition at line 252 of file DYLDRendezvous.h.

References m_soentries.

Referenced by DumpToLog(), DynamicLoaderPOSIXDYLD::LoadAllCurrentModules(), DynamicLoaderPOSIXDYLD::RefreshModules(), and RemoveSOEntries().

◆ DumpToLog()

void DYLDRendezvous::DumpToLog ( lldb_private::Log log) const

◆ end()

iterator DYLDRendezvous::end ( ) const
inline

◆ FillSOEntryFromModuleInfo()

bool DYLDRendezvous::FillSOEntryFromModuleInfo ( LoadedModuleInfoList::LoadedModuleInfo const &  modInfo,
SOEntry entry 
)
protected

◆ FindMetadata()

bool DYLDRendezvous::FindMetadata ( const char *  name,
PThreadField  field,
uint32_t &  value 
)
protected

◆ GetAction()

DYLDRendezvous::RendezvousAction DYLDRendezvous::GetAction ( ) const
protected

Returns the current action to be taken given the current and previous state.

Definition at line 228 of file DYLDRendezvous.cpp.

References eAdd, eAddModules, eConsistent, eDelete, eNoAction, eRemoveModules, eTakeSnapshot, lldb_private::GetLog(), IsCoreFile(), LLDB_LOG, m_current, m_previous, and DYLDRendezvous::Rendezvous::state.

Referenced by UpdateSOEntries(), and UpdateSOEntriesFromRemote().

◆ GetBreakAddress()

lldb::addr_t DYLDRendezvous::GetBreakAddress ( ) const
inline

A breakpoint should be set at this address and Resolve called on each hit.

Returns
the address of a function called by the runtime linker each time a module is loaded/unloaded, or about to be loaded/unloaded.
See also
Resolve()

Definition at line 180 of file DYLDRendezvous.h.

References DYLDRendezvous::Rendezvous::brk, and m_current.

Referenced by DumpToLog(), and DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint().

◆ GetLDBase()

lldb::addr_t DYLDRendezvous::GetLDBase ( ) const
inline
Returns
the base address of the runtime linker in the inferiors address space.

Definition at line 187 of file DYLDRendezvous.h.

References DYLDRendezvous::Rendezvous::ldbase, and m_current.

Referenced by DumpToLog().

◆ GetLinkMapAddress()

lldb::addr_t DYLDRendezvous::GetLinkMapAddress ( ) const
inline
Returns
address in the inferiors address space containing the linked list of shared object descriptors.

Definition at line 171 of file DYLDRendezvous.h.

References m_current, and DYLDRendezvous::Rendezvous::map_addr.

Referenced by DumpToLog(), DynamicLoaderPOSIXDYLD::LoadAllCurrentModules(), and DynamicLoaderPOSIXDYLD::RefreshModules().

◆ GetRendezvousAddress()

lldb::addr_t DYLDRendezvous::GetRendezvousAddress ( ) const
inline
Returns
the address of the rendezvous structure in the inferiors address space.

Definition at line 164 of file DYLDRendezvous.h.

References m_rendezvous_addr.

Referenced by DumpToLog().

◆ GetState()

uint64_t DYLDRendezvous::GetState ( ) const
inline

Returns the current state of the rendezvous structure.

Definition at line 183 of file DYLDRendezvous.h.

References m_current, and DYLDRendezvous::Rendezvous::state.

Referenced by DumpToLog().

◆ GetThreadInfo()

const DYLDRendezvous::ThreadInfo & DYLDRendezvous::GetThreadInfo ( )

◆ GetVersion()

uint64_t DYLDRendezvous::GetVersion ( ) const
inline
Returns
the version of the rendezvous protocol being used.

Definition at line 167 of file DYLDRendezvous.h.

References m_current, and DYLDRendezvous::Rendezvous::version.

Referenced by DumpToLog().

◆ IsCoreFile()

bool DYLDRendezvous::IsCoreFile ( ) const
protected

Definition at line 790 of file DYLDRendezvous.cpp.

References lldb_private::Process::IsLiveDebugSession(), and m_process.

Referenced by GetAction().

◆ IsValid()

bool DYLDRendezvous::IsValid ( )
Returns
true if this rendezvous has been located in the inferiors address space and false otherwise.

Definition at line 224 of file DYLDRendezvous.cpp.

References LLDB_INVALID_ADDRESS, and m_rendezvous_addr.

Referenced by DynamicLoaderPOSIXDYLD::SetRendezvousBreakpoint().

◆ loaded_begin()

iterator DYLDRendezvous::loaded_begin ( ) const
inline

Iterators over all modules loaded into the inferior since the last call to Resolve().

Definition at line 257 of file DYLDRendezvous.h.

References m_added_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ loaded_end()

iterator DYLDRendezvous::loaded_end ( ) const
inline

Definition at line 258 of file DYLDRendezvous.h.

References m_added_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ ModulesDidLoad()

bool DYLDRendezvous::ModulesDidLoad ( ) const
inline
Returns
true if modules have been loaded into the inferior since the last call to Resolve().

Definition at line 194 of file DYLDRendezvous.h.

References m_added_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ ModulesDidUnload()

bool DYLDRendezvous::ModulesDidUnload ( ) const
inline
Returns
true if modules have been unloaded from the inferior since the last call to Resolve().

Definition at line 198 of file DYLDRendezvous.h.

References m_removed_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ ReadPointer()

addr_t DYLDRendezvous::ReadPointer ( lldb::addr_t  addr,
lldb::addr_t dst 
)
protected

Reads an address from the inferior's address space starting at addr.

Returns
addr + target address size if the read was successful and 0 otherwise.

Definition at line 602 of file DYLDRendezvous.cpp.

References error(), lldb_private::Process::GetAddressByteSize(), m_process, and lldb_private::Process::ReadPointerFromMemory().

Referenced by ReadSOEntryFromMemory(), and Resolve().

◆ ReadSOEntryFromMemory()

bool DYLDRendezvous::ReadSOEntryFromMemory ( lldb::addr_t  addr,
SOEntry entry 
)
protected

◆ ReadStringFromMemory()

std::string DYLDRendezvous::ReadStringFromMemory ( lldb::addr_t  addr)
protected

Reads a null-terminated C string from the memory location starting at addr.

Definition at line 612 of file DYLDRendezvous.cpp.

References error(), LLDB_INVALID_ADDRESS, m_process, and lldb_private::Process::ReadCStringFromMemory().

Referenced by ReadSOEntryFromMemory().

◆ ReadWord()

addr_t DYLDRendezvous::ReadWord ( lldb::addr_t  addr,
uint64_t *  dst,
size_t  size 
)
protected

Reads an unsigned integer of size bytes from the inferior's address space starting at addr.

Returns
addr + size if the read was successful and false otherwise.

Definition at line 592 of file DYLDRendezvous.cpp.

References error(), m_process, and lldb_private::Process::ReadUnsignedIntegerFromMemory().

Referenced by Resolve().

◆ RemoveSOEntries()

bool DYLDRendezvous::RemoveSOEntries ( )
protected

◆ RemoveSOEntriesFromRemote()

bool DYLDRendezvous::RemoveSOEntriesFromRemote ( const LoadedModuleInfoList module_list)
protected

◆ Resolve()

bool DYLDRendezvous::Resolve ( )

◆ ResolveRendezvousAddress()

addr_t DYLDRendezvous::ResolveRendezvousAddress ( )
private

◆ SaveSOEntriesFromRemote()

bool DYLDRendezvous::SaveSOEntriesFromRemote ( const LoadedModuleInfoList module_list)
protected

◆ SOEntryIsMainExecutable()

bool DYLDRendezvous::SOEntryIsMainExecutable ( const SOEntry entry)
protected

◆ StateToCStr()

const char * DYLDRendezvous::StateToCStr ( RendezvousState  state)
staticprotected

Definition at line 28 of file DYLDRendezvous.cpp.

References eAdd, eConsistent, and eDelete.

Referenced by DYLDRendezvous::Rendezvous::DumpToLog().

◆ TakeSnapshot()

bool DYLDRendezvous::TakeSnapshot ( SOEntryList entry_list)
protected

Reads the current list of shared objects according to the link map supplied by the runtime linker.

Definition at line 567 of file DYLDRendezvous.cpp.

References DYLDRendezvous::SOEntry::clear(), m_current, DYLDRendezvous::Rendezvous::map_addr, DYLDRendezvous::SOEntry::next, ReadSOEntryFromMemory(), SOEntryIsMainExecutable(), and UpdateFileSpecIfNecessary().

Referenced by RemoveSOEntries(), and UpdateSOEntries().

◆ unloaded_begin()

iterator DYLDRendezvous::unloaded_begin ( ) const
inline

Iterators over all modules unloaded from the inferior since the last call to Resolve().

Definition at line 262 of file DYLDRendezvous.h.

References m_removed_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ unloaded_end()

iterator DYLDRendezvous::unloaded_end ( ) const
inline

Definition at line 263 of file DYLDRendezvous.h.

References m_removed_soentries.

Referenced by DynamicLoaderPOSIXDYLD::RefreshModules().

◆ UpdateBaseAddrIfNecessary()

void DYLDRendezvous::UpdateBaseAddrIfNecessary ( SOEntry entry,
std::string const &  file_path 
)
protected

◆ UpdateExecutablePath()

void DYLDRendezvous::UpdateExecutablePath ( )

◆ UpdateFileSpecIfNecessary()

void DYLDRendezvous::UpdateFileSpecIfNecessary ( SOEntry entry)
protected

◆ UpdateSOEntries()

bool DYLDRendezvous::UpdateSOEntries ( )
protected

Updates the current set of SOEntries, the set of added entries, and the set of removed entries.

Definition at line 370 of file DYLDRendezvous.cpp.

References ActionToCStr(), AddSOEntries(), eAddModules, eNoAction, eRemoveModules, eTakeSnapshot, GetAction(), lldb_private::GetLog(), LLDB_LOG, m_added_soentries, m_removed_soentries, m_soentries, RemoveSOEntries(), and TakeSnapshot().

Referenced by Resolve().

◆ UpdateSOEntriesFromRemote()

bool DYLDRendezvous::UpdateSOEntriesFromRemote ( )
protected

Member Data Documentation

◆ m_added_soentries

SOEntryList DYLDRendezvous::m_added_soentries
protected

List of SOEntry's added to the link map since the last call to Resolve().

Definition at line 289 of file DYLDRendezvous.h.

Referenced by AddSOEntries(), AddSOEntriesFromRemote(), loaded_begin(), loaded_end(), ModulesDidLoad(), UpdateSOEntries(), and UpdateSOEntriesFromRemote().

◆ m_current

Rendezvous DYLDRendezvous::m_current
protected

Current and previous snapshots of the rendezvous structure.

Definition at line 278 of file DYLDRendezvous.h.

Referenced by AddSOEntries(), GetAction(), GetBreakAddress(), GetLDBase(), GetLinkMapAddress(), GetState(), GetVersion(), Resolve(), and TakeSnapshot().

◆ m_exe_file_spec

lldb_private::FileSpec DYLDRendezvous::m_exe_file_spec
protected

Definition at line 269 of file DYLDRendezvous.h.

Referenced by SOEntryIsMainExecutable(), and UpdateExecutablePath().

◆ m_executable_interpreter

bool DYLDRendezvous::m_executable_interpreter
protected

Definition at line 275 of file DYLDRendezvous.h.

Referenced by ResolveRendezvousAddress(), and SOEntryIsMainExecutable().

◆ m_loaded_modules

LoadedModuleInfoList DYLDRendezvous::m_loaded_modules
protected

List of currently loaded SO modules.

Definition at line 282 of file DYLDRendezvous.h.

Referenced by AddSOEntriesFromRemote(), RemoveSOEntriesFromRemote(), SaveSOEntriesFromRemote(), and UpdateSOEntriesFromRemote().

◆ m_previous

Rendezvous DYLDRendezvous::m_previous
protected

Definition at line 279 of file DYLDRendezvous.h.

Referenced by AddSOEntries(), GetAction(), RemoveSOEntries(), and Resolve().

◆ m_process

lldb_private::Process* DYLDRendezvous::m_process
protected

◆ m_removed_soentries

SOEntryList DYLDRendezvous::m_removed_soentries
protected

List of SOEntry's removed from the link map since the last call to Resolve().

Definition at line 293 of file DYLDRendezvous.h.

Referenced by ModulesDidUnload(), RemoveSOEntries(), RemoveSOEntriesFromRemote(), unloaded_begin(), unloaded_end(), UpdateSOEntries(), and UpdateSOEntriesFromRemote().

◆ m_rendezvous_addr

lldb::addr_t DYLDRendezvous::m_rendezvous_addr
protected

Location of the r_debug structure in the inferiors address space.

Definition at line 272 of file DYLDRendezvous.h.

Referenced by GetRendezvousAddress(), IsValid(), and Resolve().

◆ m_soentries

SOEntryList DYLDRendezvous::m_soentries
protected

List of SOEntry objects corresponding to the current link map state.

Definition at line 285 of file DYLDRendezvous.h.

Referenced by AddSOEntries(), AddSOEntriesFromRemote(), begin(), end(), RemoveSOEntries(), RemoveSOEntriesFromRemote(), SaveSOEntriesFromRemote(), UpdateSOEntries(), and UpdateSOEntriesFromRemote().

◆ m_thread_info

ThreadInfo DYLDRendezvous::m_thread_info
protected

Threading metadata read from the inferior.

Definition at line 296 of file DYLDRendezvous.h.

Referenced by DYLDRendezvous(), and GetThreadInfo().


The documentation for this class was generated from the following files: