File indexing completed on 2026-05-10 08:42:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_EXPRESSION_IRMEMORYMAP_H
0010 #define LLDB_EXPRESSION_IRMEMORYMAP_H
0011
0012 #include "lldb/Utility/DataBufferHeap.h"
0013 #include "lldb/Utility/UserID.h"
0014 #include "lldb/lldb-public.h"
0015
0016 #include <map>
0017
0018 namespace lldb_private {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 class IRMemoryMap {
0035 public:
0036 IRMemoryMap(lldb::TargetSP target_sp);
0037 ~IRMemoryMap();
0038
0039 enum AllocationPolicy : uint8_t {
0040 eAllocationPolicyInvalid =
0041 0,
0042 eAllocationPolicyHostOnly,
0043
0044
0045
0046 eAllocationPolicyMirror,
0047
0048
0049 eAllocationPolicyProcessOnly
0050
0051 };
0052
0053 lldb::addr_t Malloc(size_t size, uint8_t alignment, uint32_t permissions,
0054 AllocationPolicy policy, bool zero_memory, Status &error);
0055 void Leak(lldb::addr_t process_address, Status &error);
0056 void Free(lldb::addr_t process_address, Status &error);
0057
0058 void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes,
0059 size_t size, Status &error);
0060 void WriteScalarToMemory(lldb::addr_t process_address, Scalar &scalar,
0061 size_t size, Status &error);
0062 void WritePointerToMemory(lldb::addr_t process_address, lldb::addr_t address,
0063 Status &error);
0064 void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size,
0065 Status &error);
0066 void ReadScalarFromMemory(Scalar &scalar, lldb::addr_t process_address,
0067 size_t size, Status &error);
0068 void ReadPointerFromMemory(lldb::addr_t *address,
0069 lldb::addr_t process_address, Status &error);
0070 bool GetAllocSize(lldb::addr_t address, size_t &size);
0071 void GetMemoryData(DataExtractor &extractor, lldb::addr_t process_address,
0072 size_t size, Status &error);
0073
0074 lldb::ByteOrder GetByteOrder();
0075 uint32_t GetAddressByteSize();
0076
0077
0078 ExecutionContextScope *GetBestExecutionContextScope() const;
0079
0080 lldb::TargetSP GetTarget() { return m_target_wp.lock(); }
0081
0082 protected:
0083
0084
0085
0086 lldb::ProcessWP &GetProcessWP() { return m_process_wp; }
0087
0088 private:
0089 struct Allocation {
0090 lldb::addr_t
0091 m_process_alloc;
0092 lldb::addr_t
0093 m_process_start;
0094 size_t m_size;
0095 DataBufferHeap m_data;
0096
0097
0098 AllocationPolicy m_policy;
0099 bool m_leak;
0100 uint8_t m_permissions;
0101
0102
0103 uint8_t m_alignment;
0104
0105 public:
0106 Allocation(lldb::addr_t process_alloc, lldb::addr_t process_start,
0107 size_t size, uint32_t permissions, uint8_t alignment,
0108 AllocationPolicy m_policy);
0109
0110 Allocation(const Allocation &) = delete;
0111 const Allocation &operator=(const Allocation &) = delete;
0112 };
0113
0114 static_assert(sizeof(Allocation) <=
0115 (4 * sizeof(lldb::addr_t)) + sizeof(DataBufferHeap),
0116 "IRMemoryMap::Allocation is larger than expected");
0117
0118 lldb::ProcessWP m_process_wp;
0119 lldb::TargetWP m_target_wp;
0120 typedef std::map<lldb::addr_t, Allocation> AllocationMap;
0121 AllocationMap m_allocations;
0122
0123 lldb::addr_t FindSpace(size_t size);
0124 bool ContainsHostOnlyAllocations();
0125 AllocationMap::iterator FindAllocation(lldb::addr_t addr, size_t size);
0126
0127
0128
0129 bool IntersectsAllocation(lldb::addr_t addr, size_t size) const;
0130
0131
0132 static bool AllocationsIntersect(lldb::addr_t addr1, size_t size1,
0133 lldb::addr_t addr2, size_t size2);
0134 };
0135 }
0136
0137 #endif