1 //===-- MemoryRegionInfo.h ---------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef lldb_MemoryRegionInfo_h
12 #define lldb_MemoryRegionInfo_h
14 #include "lldb/Core/RangeMap.h"
15 #include "llvm/Support/FormatProviders.h"
16 #include "lldb/Utility/ConstString.h"
18 namespace lldb_private {
19 class MemoryRegionInfo {
21 typedef Range<lldb::addr_t, lldb::addr_t> RangeType;
23 enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
26 : m_range(), m_read(eDontKnow), m_write(eDontKnow), m_execute(eDontKnow),
27 m_mapped(eDontKnow), m_flash(eDontKnow), m_blocksize(0) {}
29 ~MemoryRegionInfo() {}
31 RangeType &GetRange() { return m_range; }
35 m_read = m_write = m_execute = eDontKnow;
38 const RangeType &GetRange() const { return m_range; }
40 OptionalBool GetReadable() const { return m_read; }
42 OptionalBool GetWritable() const { return m_write; }
44 OptionalBool GetExecutable() const { return m_execute; }
46 OptionalBool GetMapped() const { return m_mapped; }
48 const ConstString &GetName() const { return m_name; }
50 void SetReadable(OptionalBool val) { m_read = val; }
52 void SetWritable(OptionalBool val) { m_write = val; }
54 void SetExecutable(OptionalBool val) { m_execute = val; }
56 void SetMapped(OptionalBool val) { m_mapped = val; }
58 void SetName(const char *name) { m_name = ConstString(name); }
60 OptionalBool GetFlash() const { return m_flash; }
62 void SetFlash(OptionalBool val) { m_flash = val; }
64 lldb::offset_t GetBlocksize() const { return m_blocksize; }
66 void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
68 //----------------------------------------------------------------------
69 // Get permissions as a uint32_t that is a mask of one or more bits from the
71 //----------------------------------------------------------------------
72 uint32_t GetLLDBPermissions() const {
73 uint32_t permissions = 0;
75 permissions |= lldb::ePermissionsReadable;
77 permissions |= lldb::ePermissionsWritable;
79 permissions |= lldb::ePermissionsExecutable;
83 //----------------------------------------------------------------------
84 // Set permissions from a uint32_t that contains one or more bits from the
86 //----------------------------------------------------------------------
87 void SetLLDBPermissions(uint32_t permissions) {
88 m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
89 m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
90 m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
93 bool operator==(const MemoryRegionInfo &rhs) const {
94 return m_range == rhs.m_range && m_read == rhs.m_read &&
95 m_write == rhs.m_write && m_execute == rhs.m_execute &&
96 m_mapped == rhs.m_mapped;
99 bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
104 OptionalBool m_write;
105 OptionalBool m_execute;
106 OptionalBool m_mapped;
108 OptionalBool m_flash;
109 lldb::offset_t m_blocksize;
112 inline bool operator<(const MemoryRegionInfo &lhs,
113 const MemoryRegionInfo &rhs) {
114 return lhs.GetRange() < rhs.GetRange();
117 inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
118 return lhs.GetRange().GetRangeBase() < rhs;
121 inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
122 return lhs < rhs.GetRange().GetRangeBase();
125 // Forward-declarable wrapper.
126 class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
128 //using std::vector<lldb_private::MemoryRegionInfo>::vector;
135 struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
136 static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
137 raw_ostream &OS, StringRef Options) {
139 case lldb_private::MemoryRegionInfo::eNo:
142 case lldb_private::MemoryRegionInfo::eYes:
145 case lldb_private::MemoryRegionInfo::eDontKnow:
153 #endif // #ifndef lldb_MemoryRegionInfo_h