LLDB  mainline
MemoryRegionInfo.h
Go to the documentation of this file.
1 //===-- MemoryRegionInfo.h ---------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_MemoryRegionInfo_h
11 #define lldb_MemoryRegionInfo_h
12 
14 #include "lldb/Utility/RangeMap.h"
15 #include "llvm/Support/FormatProviders.h"
16 
17 namespace lldb_private {
19 public:
21 
22  enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
23 
27 
29 
30  RangeType &GetRange() { return m_range; }
31 
32  void Clear() {
33  m_range.Clear();
35  }
36 
37  const RangeType &GetRange() const { return m_range; }
38 
39  OptionalBool GetReadable() const { return m_read; }
40 
41  OptionalBool GetWritable() const { return m_write; }
42 
43  OptionalBool GetExecutable() const { return m_execute; }
44 
45  OptionalBool GetMapped() const { return m_mapped; }
46 
47  ConstString GetName() const { return m_name; }
48 
49  void SetReadable(OptionalBool val) { m_read = val; }
50 
51  void SetWritable(OptionalBool val) { m_write = val; }
52 
53  void SetExecutable(OptionalBool val) { m_execute = val; }
54 
55  void SetMapped(OptionalBool val) { m_mapped = val; }
56 
57  void SetName(const char *name) { m_name = ConstString(name); }
58 
59  OptionalBool GetFlash() const { return m_flash; }
60 
61  void SetFlash(OptionalBool val) { m_flash = val; }
62 
64 
65  void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
66 
67  // Get permissions as a uint32_t that is a mask of one or more bits from the
68  // lldb::Permissions
70  uint32_t permissions = 0;
71  if (m_read)
72  permissions |= lldb::ePermissionsReadable;
73  if (m_write)
74  permissions |= lldb::ePermissionsWritable;
75  if (m_execute)
76  permissions |= lldb::ePermissionsExecutable;
77  return permissions;
78  }
79 
80  // Set permissions from a uint32_t that contains one or more bits from the
81  // lldb::Permissions
82  void SetLLDBPermissions(uint32_t permissions) {
83  m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
84  m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
85  m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
86  }
87 
88  bool operator==(const MemoryRegionInfo &rhs) const {
89  return m_range == rhs.m_range && m_read == rhs.m_read &&
90  m_write == rhs.m_write && m_execute == rhs.m_execute &&
91  m_mapped == rhs.m_mapped;
92  }
93 
94  bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
95 
96 protected:
97  RangeType m_range;
105 };
106 
107 inline bool operator<(const MemoryRegionInfo &lhs,
108  const MemoryRegionInfo &rhs) {
109  return lhs.GetRange() < rhs.GetRange();
110 }
111 
112 inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
113  return lhs.GetRange().GetRangeBase() < rhs;
114 }
115 
116 inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
117  return lhs < rhs.GetRange().GetRangeBase();
118 }
119 
120 // Forward-declarable wrapper.
121 class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
122 public:
123  using std::vector<lldb_private::MemoryRegionInfo>::vector;
124 };
125 
126 }
127 
128 namespace llvm {
129 template <>
132  raw_ostream &OS, StringRef Options) {
133  switch(B) {
135  OS << "no";
136  return;
138  OS << "yes";
139  return;
141  OS << "don't know";
142  return;
143  }
144  }
145 };
146 }
147 
148 #endif // #ifndef lldb_MemoryRegionInfo_h
OptionalBool GetMapped() const
void Clear(BaseType b=0)
Definition: RangeMap.h:40
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void SetExecutable(OptionalBool val)
Definition: Debugger.h:71
OptionalBool GetReadable() const
void SetFlash(OptionalBool val)
void SetMapped(OptionalBool val)
void SetName(const char *name)
bool operator==(const MemoryRegionInfo &rhs) const
OptionalBool GetWritable() const
Range< lldb::addr_t, lldb::addr_t > RangeType
uint64_t offset_t
Definition: lldb-types.h:87
void SetBlocksize(lldb::offset_t blocksize)
lldb::offset_t GetBlocksize() const
uint64_t addr_t
Definition: lldb-types.h:83
void SetReadable(OptionalBool val)
A uniqued constant string class.
Definition: ConstString.h:38
bool operator!=(const MemoryRegionInfo &rhs) const
void SetLLDBPermissions(uint32_t permissions)
void SetWritable(OptionalBool val)
OptionalBool GetFlash() const
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:942
const RangeType & GetRange() const
static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B, raw_ostream &OS, StringRef Options)
OptionalBool GetExecutable() const
BaseType GetRangeBase() const
Definition: RangeMap.h:46