LLDB mainline
|
Encapsulates memory that may exist in the process but must also be available in the host process. More...
#include "lldb/Expression/IRMemoryMap.h"
Classes | |
struct | Allocation |
Public Types | |
enum | AllocationPolicy : uint8_t { eAllocationPolicyInvalid , eAllocationPolicyHostOnly , eAllocationPolicyMirror , eAllocationPolicyProcessOnly } |
Public Member Functions | |
IRMemoryMap (lldb::TargetSP target_sp) | |
~IRMemoryMap () | |
llvm::Expected< lldb::addr_t > | Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, AllocationPolicy *used_policy=nullptr) |
void | Leak (lldb::addr_t process_address, Status &error) |
void | Free (lldb::addr_t process_address, Status &error) |
void | WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Status &error) |
void | WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Status &error) |
void | WritePointerToMemory (lldb::addr_t process_address, lldb::addr_t pointer, Status &error) |
void | ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Status &error) |
void | ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Status &error) |
void | ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Status &error) |
bool | GetAllocSize (lldb::addr_t address, size_t &size) |
void | GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Status &error) |
lldb::ByteOrder | GetByteOrder () |
uint32_t | GetAddressByteSize () |
ExecutionContextScope * | GetBestExecutionContextScope () const |
lldb::TargetSP | GetTarget () |
Protected Member Functions | |
lldb::ProcessWP & | GetProcessWP () |
Private Types | |
typedef std::map< lldb::addr_t, Allocation > | AllocationMap |
Private Member Functions | |
lldb::addr_t | FindSpace (size_t size) |
bool | ContainsHostOnlyAllocations () |
AllocationMap::iterator | FindAllocation (lldb::addr_t addr, size_t size) |
bool | IntersectsAllocation (lldb::addr_t addr, size_t size) const |
Static Private Member Functions | |
static bool | AllocationsIntersect (lldb::addr_t addr1, size_t size1, lldb::addr_t addr2, size_t size2) |
Private Attributes | |
lldb::ProcessWP | m_process_wp |
lldb::TargetWP | m_target_wp |
AllocationMap | m_allocations |
Encapsulates memory that may exist in the process but must also be available in the host process.
This class encapsulates a group of memory objects that must be readable or writable from the host process regardless of whether the process exists. This allows the IR interpreter as well as JITted code to access the same memory. All allocations made by this class are represented as disjoint intervals.
Point queries against this group of memory objects can be made by the address in the tar at which they reside. If the inferior does not exist, allocations still get made-up addresses. If an inferior appears at some point, then those addresses need to be re-mapped.
Definition at line 35 of file IRMemoryMap.h.
|
private |
Definition at line 126 of file IRMemoryMap.h.
enum lldb_private::IRMemoryMap::AllocationPolicy : uint8_t |
Definition at line 40 of file IRMemoryMap.h.
IRMemoryMap::IRMemoryMap | ( | lldb::TargetSP | target_sp | ) |
Definition at line 23 of file IRMemoryMap.cpp.
References m_process_wp, and m_target_wp.
Referenced by lldb_private::IRExecutionUnit::IRExecutionUnit().
IRMemoryMap::~IRMemoryMap | ( | ) |
Definition at line 28 of file IRMemoryMap.cpp.
References lldb_private::Status::Clear(), Free(), m_allocations, and m_process_wp.
|
staticprivate |
Definition at line 246 of file IRMemoryMap.cpp.
Referenced by IntersectsAllocation().
|
private |
|
private |
Definition at line 199 of file IRMemoryMap.cpp.
References LLDB_INVALID_ADDRESS, and m_allocations.
Referenced by GetAllocSize(), GetMemoryData(), ReadMemory(), WriteMemory(), and WritePointerToMemory().
|
private |
Definition at line 46 of file IRMemoryMap.cpp.
References lldb_private::MemoryRegionInfo::eNo, lldb_private::Status::Fail(), GetAddressByteSize(), lldb_private::MemoryRegionInfo::GetExecutable(), lldb_private::MemoryRegionInfo::GetRange(), lldb_private::Range< B, S >::GetRangeBase(), lldb_private::Range< B, S >::GetRangeEnd(), lldb_private::MemoryRegionInfo::GetReadable(), lldb_private::MemoryRegionInfo::GetWritable(), LLDB_INVALID_ADDRESS, lldbassert, m_allocations, m_process_wp, m_target_wp, lldb_private::Status::Success(), and UINT32_MAX.
Referenced by Malloc().
void IRMemoryMap::Free | ( | lldb::addr_t | process_address, |
Status & | error ) |
Definition at line 478 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, eAllocationPolicyMirror, eAllocationPolicyProcessOnly, error(), lldb_private::Expressions, lldb_private::Status::FromErrorString(), lldb_private::GetLog(), LLDB_LOGF, m_allocations, lldb_private::IRMemoryMap::Allocation::m_policy, lldb_private::IRMemoryMap::Allocation::m_process_alloc, and m_process_wp.
Referenced by lldb_private::IRExecutionUnit::CommitAllocations(), EntityResultVariable::Dematerialize(), EntityVariableBase::Dematerialize(), EntityPersistentVariable::DestroyAllocation(), lldb_private::IRExecutionUnit::FreeNow(), IRInterpreter::Interpret(), EntityResultVariable::Wipe(), EntityVariableBase::Wipe(), lldb_private::IRExecutionUnit::WriteNow(), and ~IRMemoryMap().
uint32_t IRMemoryMap::GetAddressByteSize | ( | ) |
Definition at line 275 of file IRMemoryMap.cpp.
References m_process_wp, m_target_wp, and UINT32_MAX.
Referenced by EntityResultVariable::Dematerialize(), EntityResultVariable::DumpToLog(), EntityVariableBase::DumpToLog(), FindSpace(), GetMemoryData(), EntityPersistentVariable::MakeAllocation(), EntityPersistentVariable::Materialize(), ReadPointerFromMemory(), ReadScalarFromMemory(), and WritePointerToMemory().
bool IRMemoryMap::GetAllocSize | ( | lldb::addr_t | address, |
size_t & | size ) |
Definition at line 521 of file IRMemoryMap.cpp.
References FindAllocation(), m_allocations, lldb_private::IRMemoryMap::Allocation::m_process_start, and lldb_private::IRMemoryMap::Allocation::m_size.
Referenced by IRInterpreter::Interpret().
ExecutionContextScope * IRMemoryMap::GetBestExecutionContextScope | ( | ) | const |
Definition at line 289 of file IRMemoryMap.cpp.
References m_process_wp, and m_target_wp.
Referenced by EntityPersistentVariable::Dematerialize(), EntityResultVariable::Dematerialize(), EntityVariableBase::Dematerialize(), lldb_private::IRExecutionUnit::GetAddressByteSize(), lldb_private::IRExecutionUnit::GetArchitecture(), lldb_private::IRExecutionUnit::GetByteOrder(), lldb_private::IRExecutionUnit::GetJITModule(), EntityPersistentVariable::MakeAllocation(), EntityResultVariable::Materialize(), EntitySymbol::Materialize(), EntityVariableBase::Materialize(), and lldb_private::Materializer::Materialize().
lldb::ByteOrder IRMemoryMap::GetByteOrder | ( | ) |
Definition at line 261 of file IRMemoryMap.cpp.
References lldb::eByteOrderInvalid, m_process_wp, and m_target_wp.
Referenced by EntityResultVariable::Dematerialize(), EntityResultVariable::DumpToLog(), EntityVariableBase::DumpToLog(), GetMemoryData(), EntityRegister::Materialize(), ReadScalarFromMemory(), and WriteScalarToMemory().
void IRMemoryMap::GetMemoryData | ( | DataExtractor & | extractor, |
lldb::addr_t | process_address, | ||
size_t | size, | ||
Status & | error ) |
Definition at line 804 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, eAllocationPolicyMirror, eAllocationPolicyProcessOnly, error(), FindAllocation(), lldb_private::Status::FromErrorString(), lldb_private::Status::FromErrorStringWithFormat(), GetAddressByteSize(), GetByteOrder(), lldb_private::WritableDataBuffer::GetBytes(), lldb_private::DataBufferHeap::GetByteSize(), m_allocations, lldb_private::IRMemoryMap::Allocation::m_data, lldb_private::IRMemoryMap::Allocation::m_policy, lldb_private::IRMemoryMap::Allocation::m_process_start, and m_process_wp.
Referenced by EntityRegister::Dematerialize(), and EntityVariableBase::Dematerialize().
|
inlineprotected |
Definition at line 92 of file IRMemoryMap.h.
References m_process_wp.
Referenced by lldb_private::IRExecutionUnit::GetRunnableInfo(), and WritePointerToMemory().
|
inline |
Definition at line 86 of file IRMemoryMap.h.
References m_target_wp.
|
private |
Definition at line 217 of file IRMemoryMap.cpp.
References AllocationsIntersect(), LLDB_INVALID_ADDRESS, and m_allocations.
void IRMemoryMap::Leak | ( | lldb::addr_t | process_address, |
Status & | error ) |
Definition at line 463 of file IRMemoryMap.cpp.
References error(), lldb_private::Status::FromErrorString(), m_allocations, and lldb_private::IRMemoryMap::Allocation::m_leak.
Referenced by EntityPersistentVariable::MakeAllocation().
llvm::Expected< lldb::addr_t > IRMemoryMap::Malloc | ( | size_t | size, |
uint8_t | alignment, | ||
uint32_t | permissions, | ||
AllocationPolicy | policy, | ||
bool | zero_memory, | ||
AllocationPolicy * | used_policy = nullptr ) |
Definition at line 323 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, eAllocationPolicyMirror, eAllocationPolicyProcessOnly, error(), lldb_private::Expressions, FindSpace(), lldb_private::GetLog(), LLDB_INVALID_ADDRESS, LLDB_LOGF, m_allocations, m_process_wp, and WriteMemory().
Referenced by lldb_private::IRExecutionUnit::CommitOneAllocation(), EntityPersistentVariable::MakeAllocation(), EntityResultVariable::Materialize(), EntityVariableBase::Materialize(), and lldb_private::IRExecutionUnit::WriteNow().
void IRMemoryMap::ReadMemory | ( | uint8_t * | bytes, |
lldb::addr_t | process_address, | ||
size_t | size, | ||
Status & | error ) |
Definition at line 657 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, eAllocationPolicyMirror, eAllocationPolicyProcessOnly, error(), lldb_private::Expressions, FindAllocation(), lldb_private::Status::FromErrorString(), lldb_private::WritableDataBuffer::GetBytes(), lldb_private::DataBufferHeap::GetByteSize(), lldb_private::GetLog(), LLDB_LOGF, m_allocations, lldb_private::IRMemoryMap::Allocation::m_data, lldb_private::IRMemoryMap::Allocation::m_policy, lldb_private::IRMemoryMap::Allocation::m_process_start, m_process_wp, lldb_private::IRMemoryMap::Allocation::m_size, and m_target_wp.
Referenced by EntityPersistentVariable::Dematerialize(), EntityResultVariable::Dematerialize(), EntityPersistentVariable::DumpToLog(), EntityRegister::DumpToLog(), EntityResultVariable::DumpToLog(), EntitySymbol::DumpToLog(), EntityVariableBase::DumpToLog(), lldb_private::IRExecutionUnit::GetRunnableInfo(), IRInterpreter::Interpret(), ReadScalarFromMemory(), and lldb_private::IRExecutionUnit::WriteNow().
void IRMemoryMap::ReadPointerFromMemory | ( | lldb::addr_t * | address, |
lldb::addr_t | process_address, | ||
Status & | error ) |
Definition at line 789 of file IRMemoryMap.cpp.
References error(), GetAddressByteSize(), ReadScalarFromMemory(), and lldb_private::Scalar::ULongLong().
Referenced by EntityPersistentVariable::Dematerialize(), EntityResultVariable::Dematerialize(), EntityPersistentVariable::DumpToLog(), and IRInterpreter::Interpret().
void IRMemoryMap::ReadScalarFromMemory | ( | Scalar & | scalar, |
lldb::addr_t | process_address, | ||
size_t | size, | ||
Status & | error ) |
Definition at line 749 of file IRMemoryMap.cpp.
References error(), lldb_private::Status::FromErrorString(), lldb_private::Status::FromErrorStringWithFormat(), GetAddressByteSize(), GetByteOrder(), lldb_private::WritableDataBuffer::GetBytes(), lldb_private::DataBufferHeap::GetByteSize(), lldb_private::DataExtractor::GetU16(), lldb_private::DataExtractor::GetU32(), lldb_private::DataExtractor::GetU64(), lldb_private::DataExtractor::GetU8(), and ReadMemory().
Referenced by ReadPointerFromMemory().
void IRMemoryMap::WriteMemory | ( | lldb::addr_t | process_address, |
const uint8_t * | bytes, | ||
size_t | size, | ||
Status & | error ) |
Definition at line 543 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, eAllocationPolicyMirror, eAllocationPolicyProcessOnly, error(), lldb_private::Expressions, FindAllocation(), lldb_private::Status::FromErrorString(), lldb_private::WritableDataBuffer::GetBytes(), lldb_private::DataBufferHeap::GetByteSize(), lldb_private::GetLog(), LLDB_LOGF, m_allocations, lldb_private::IRMemoryMap::Allocation::m_data, lldb_private::IRMemoryMap::Allocation::m_policy, lldb_private::IRMemoryMap::Allocation::m_process_start, m_process_wp, and lldb_private::IRMemoryMap::Allocation::m_size.
Referenced by IRInterpreter::Interpret(), EntityPersistentVariable::MakeAllocation(), Malloc(), EntityRegister::Materialize(), EntityVariableBase::Materialize(), lldb_private::IRExecutionUnit::WriteData(), lldb_private::IRExecutionUnit::WriteNow(), and WriteScalarToMemory().
void IRMemoryMap::WritePointerToMemory | ( | lldb::addr_t | process_address, |
lldb::addr_t | pointer, | ||
Status & | error ) |
Only ask the Process to fix pointer if the address belongs to the process. An address belongs to the process if the Allocation policy is not eAllocationPolicyHostOnly.
Definition at line 639 of file IRMemoryMap.cpp.
References eAllocationPolicyHostOnly, error(), FindAllocation(), GetAddressByteSize(), GetProcessWP(), m_allocations, and WriteScalarToMemory().
Referenced by IRInterpreter::Interpret(), EntityResultVariable::Materialize(), EntitySymbol::Materialize(), and EntityVariableBase::Materialize().
void IRMemoryMap::WriteScalarToMemory | ( | lldb::addr_t | process_address, |
Scalar & | scalar, | ||
size_t | size, | ||
Status & | error ) |
Definition at line 616 of file IRMemoryMap.cpp.
References error(), lldb_private::Status::FromErrorString(), lldb_private::Scalar::GetAsMemoryData(), GetByteOrder(), lldb_private::Scalar::GetByteSize(), UINT32_MAX, and WriteMemory().
Referenced by EntityPersistentVariable::Materialize(), and WritePointerToMemory().
|
private |
Definition at line 127 of file IRMemoryMap.h.
Referenced by FindAllocation(), FindSpace(), Free(), GetAllocSize(), GetMemoryData(), IntersectsAllocation(), Leak(), Malloc(), ReadMemory(), WriteMemory(), WritePointerToMemory(), and ~IRMemoryMap().
|
private |
Definition at line 124 of file IRMemoryMap.h.
Referenced by FindSpace(), Free(), GetAddressByteSize(), GetBestExecutionContextScope(), GetByteOrder(), GetMemoryData(), GetProcessWP(), IRMemoryMap(), Malloc(), ReadMemory(), WriteMemory(), and ~IRMemoryMap().
|
private |
Definition at line 125 of file IRMemoryMap.h.
Referenced by FindSpace(), GetAddressByteSize(), GetBestExecutionContextScope(), GetByteOrder(), GetTarget(), IRMemoryMap(), and ReadMemory().