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_TARGET_MEMORYREGIONINFO_H
11 #define LLDB_TARGET_MEMORYREGIONINFO_H
12 
13 #include <vector>
14 
16 #include "lldb/Utility/RangeMap.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/Support/FormatProviders.h"
19 
20 namespace lldb_private {
22 public:
24 
25  enum OptionalBool { eDontKnow = -1, eNo = 0, eYes = 1 };
26 
27  MemoryRegionInfo() = default;
29  OptionalBool execute, OptionalBool mapped, ConstString name,
30  OptionalBool flash, lldb::offset_t blocksize,
31  OptionalBool memory_tagged, OptionalBool stack_memory)
32  : m_range(range), m_read(read), m_write(write), m_execute(execute),
33  m_mapped(mapped), m_name(name), m_flash(flash), m_blocksize(blocksize),
34  m_memory_tagged(memory_tagged), m_is_stack_memory(stack_memory) {}
35 
36  RangeType &GetRange() { return m_range; }
37 
38  void Clear() { *this = MemoryRegionInfo(); }
39 
40  const RangeType &GetRange() const { return m_range; }
41 
42  OptionalBool GetReadable() const { return m_read; }
43 
44  OptionalBool GetWritable() const { return m_write; }
45 
46  OptionalBool GetExecutable() const { return m_execute; }
47 
48  OptionalBool GetMapped() const { return m_mapped; }
49 
50  ConstString GetName() const { return m_name; }
51 
53 
54  void SetReadable(OptionalBool val) { m_read = val; }
55 
56  void SetWritable(OptionalBool val) { m_write = val; }
57 
58  void SetExecutable(OptionalBool val) { m_execute = val; }
59 
60  void SetMapped(OptionalBool val) { m_mapped = val; }
61 
62  void SetName(const char *name) { m_name = ConstString(name); }
63 
64  OptionalBool GetFlash() const { return m_flash; }
65 
66  void SetFlash(OptionalBool val) { m_flash = val; }
67 
69 
70  void SetBlocksize(lldb::offset_t blocksize) { m_blocksize = blocksize; }
71 
73 
74  // Get permissions as a uint32_t that is a mask of one or more bits from the
75  // lldb::Permissions
77  uint32_t permissions = 0;
78  if (m_read)
79  permissions |= lldb::ePermissionsReadable;
80  if (m_write)
81  permissions |= lldb::ePermissionsWritable;
82  if (m_execute)
83  permissions |= lldb::ePermissionsExecutable;
84  return permissions;
85  }
86 
87  // Set permissions from a uint32_t that contains one or more bits from the
88  // lldb::Permissions
89  void SetLLDBPermissions(uint32_t permissions) {
90  m_read = (permissions & lldb::ePermissionsReadable) ? eYes : eNo;
91  m_write = (permissions & lldb::ePermissionsWritable) ? eYes : eNo;
92  m_execute = (permissions & lldb::ePermissionsExecutable) ? eYes : eNo;
93  }
94 
95  bool operator==(const MemoryRegionInfo &rhs) const {
96  return m_range == rhs.m_range && m_read == rhs.m_read &&
97  m_write == rhs.m_write && m_execute == rhs.m_execute &&
98  m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
99  m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
101  m_pagesize == rhs.m_pagesize &&
103  }
104 
105  bool operator!=(const MemoryRegionInfo &rhs) const { return !(*this == rhs); }
106 
107  /// Get the target system's VM page size in bytes.
108  /// \return
109  /// 0 is returned if this information is unavailable.
110  int GetPageSize() { return m_pagesize; }
111 
112  /// Get a vector of target VM pages that are dirty -- that have been
113  /// modified -- within this memory region. This is an Optional return
114  /// value; it will only be available if the remote stub was able to
115  /// detail this.
116  llvm::Optional<std::vector<lldb::addr_t>> &GetDirtyPageList() {
117  return m_dirty_pages;
118  }
119 
121 
123 
124  void SetPageSize(int pagesize) { m_pagesize = pagesize; }
125 
126  void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
127  if (m_dirty_pages.hasValue())
128  m_dirty_pages.getValue().clear();
129  m_dirty_pages = std::move(pagelist);
130  }
131 
132 protected:
143  int m_pagesize = 0;
144  llvm::Optional<std::vector<lldb::addr_t>> m_dirty_pages;
145 };
146 
147 inline bool operator<(const MemoryRegionInfo &lhs,
148  const MemoryRegionInfo &rhs) {
149  return lhs.GetRange() < rhs.GetRange();
150 }
151 
152 inline bool operator<(const MemoryRegionInfo &lhs, lldb::addr_t rhs) {
153  return lhs.GetRange().GetRangeBase() < rhs;
154 }
155 
156 inline bool operator<(lldb::addr_t lhs, const MemoryRegionInfo &rhs) {
157  return lhs < rhs.GetRange().GetRangeBase();
158 }
159 
160 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
161  const MemoryRegionInfo &Info);
162 
163 // Forward-declarable wrapper.
164 class MemoryRegionInfos : public std::vector<lldb_private::MemoryRegionInfo> {
165 public:
166  using std::vector<lldb_private::MemoryRegionInfo>::vector;
167 };
168 
169 }
170 
171 namespace llvm {
172 template <>
173 /// If Options is empty, prints a textual representation of the value. If
174 /// Options is a single character, it uses that character for the "yes" value,
175 /// while "no" is printed as "-", and "don't know" as "?". This can be used to
176 /// print the permissions in the traditional "rwx" form.
177 struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
178  static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
179  raw_ostream &OS, StringRef Options);
180 };
181 }
182 
183 #endif // LLDB_TARGET_MEMORYREGIONINFO_H
lldb_private::MemoryRegionInfo::m_range
RangeType m_range
Definition: MemoryRegionInfo.h:133
lldb_private::MemoryRegionInfo::GetPageSize
int GetPageSize()
Get the target system's VM page size in bytes.
Definition: MemoryRegionInfo.h:110
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
llvm
Definition: Debugger.h:49
lldb_private::MemoryRegionInfo::GetDirtyPageList
llvm::Optional< std::vector< lldb::addr_t > > & GetDirtyPageList()
Get a vector of target VM pages that are dirty – that have been modified – within this memory region.
Definition: MemoryRegionInfo.h:116
lldb_private::MemoryRegionInfo::m_dirty_pages
llvm::Optional< std::vector< lldb::addr_t > > m_dirty_pages
Definition: MemoryRegionInfo.h:144
lldb_private::MemoryRegionInfo::m_name
ConstString m_name
Definition: MemoryRegionInfo.h:138
lldb_private::MemoryRegionInfo::SetBlocksize
void SetBlocksize(lldb::offset_t blocksize)
Definition: MemoryRegionInfo.h:70
lldb_private::MemoryRegionInfo::SetName
void SetName(const char *name)
Definition: MemoryRegionInfo.h:62
lldb_private::MemoryRegionInfo::m_blocksize
lldb::offset_t m_blocksize
Definition: MemoryRegionInfo.h:140
lldb_private::MemoryRegionInfo::Clear
void Clear()
Definition: MemoryRegionInfo.h:38
lldb_private::MemoryRegionInfo::GetLLDBPermissions
uint32_t GetLLDBPermissions() const
Definition: MemoryRegionInfo.h:76
lldb_private::MemoryRegionInfo::m_memory_tagged
OptionalBool m_memory_tagged
Definition: MemoryRegionInfo.h:141
lldb_private::MemoryRegionInfo::SetMemoryTagged
void SetMemoryTagged(OptionalBool val)
Definition: MemoryRegionInfo.h:72
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::MemoryRegionInfo::SetReadable
void SetReadable(OptionalBool val)
Definition: MemoryRegionInfo.h:54
RangeMap.h
lldb_private::MemoryRegionInfo::m_mapped
OptionalBool m_mapped
Definition: MemoryRegionInfo.h:137
lldb_private::MemoryRegionInfo::GetMemoryTagged
OptionalBool GetMemoryTagged() const
Definition: MemoryRegionInfo.h:52
lldb_private::MemoryRegionInfo::operator!=
bool operator!=(const MemoryRegionInfo &rhs) const
Definition: MemoryRegionInfo.h:105
lldb_private::MemoryRegionInfo::operator==
bool operator==(const MemoryRegionInfo &rhs) const
Definition: MemoryRegionInfo.h:95
lldb_private::MemoryRegionInfo::m_read
OptionalBool m_read
Definition: MemoryRegionInfo.h:134
lldb_private::MemoryRegionInfo::GetWritable
OptionalBool GetWritable() const
Definition: MemoryRegionInfo.h:44
lldb_private::MemoryRegionInfo::m_is_stack_memory
OptionalBool m_is_stack_memory
Definition: MemoryRegionInfo.h:142
lldb_private::MemoryRegionInfo::OptionalBool
OptionalBool
Definition: MemoryRegionInfo.h:25
lldb_private::MemoryRegionInfo::m_flash
OptionalBool m_flash
Definition: MemoryRegionInfo.h:139
lldb_private::MemoryRegionInfo::RangeType
Range< lldb::addr_t, lldb::addr_t > RangeType
Definition: MemoryRegionInfo.h:23
lldb_private::MemoryRegionInfo::GetExecutable
OptionalBool GetExecutable() const
Definition: MemoryRegionInfo.h:46
lldb_private::MemoryRegionInfo::SetDirtyPageList
void SetDirtyPageList(std::vector< lldb::addr_t > pagelist)
Definition: MemoryRegionInfo.h:126
lldb_private::MemoryRegionInfo::SetExecutable
void SetExecutable(OptionalBool val)
Definition: MemoryRegionInfo.h:58
lldb_private::MemoryRegionInfo::m_pagesize
int m_pagesize
Definition: MemoryRegionInfo.h:143
lldb_private::MemoryRegionInfo::eYes
@ eYes
Definition: MemoryRegionInfo.h:25
lldb_private::MemoryRegionInfos
Definition: MemoryRegionInfo.h:164
lldb_private::MemoryRegionInfo::m_execute
OptionalBool m_execute
Definition: MemoryRegionInfo.h:136
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::Range< lldb::addr_t, lldb::addr_t >
lldb_private::MemoryRegionInfo::GetName
ConstString GetName() const
Definition: MemoryRegionInfo.h:50
lldb_private::MemoryRegionInfo::SetPageSize
void SetPageSize(int pagesize)
Definition: MemoryRegionInfo.h:124
lldb_private::MemoryRegionInfo::eNo
@ eNo
Definition: MemoryRegionInfo.h:25
lldb_private::MemoryRegionInfo::SetFlash
void SetFlash(OptionalBool val)
Definition: MemoryRegionInfo.h:66
lldb_private::MemoryRegionInfo::SetLLDBPermissions
void SetLLDBPermissions(uint32_t permissions)
Definition: MemoryRegionInfo.h:89
lldb_private::MemoryRegionInfo::SetWritable
void SetWritable(OptionalBool val)
Definition: MemoryRegionInfo.h:56
lldb_private::MemoryRegionInfo::GetFlash
OptionalBool GetFlash() const
Definition: MemoryRegionInfo.h:64
lldb_private::MemoryRegionInfo::GetBlocksize
lldb::offset_t GetBlocksize() const
Definition: MemoryRegionInfo.h:68
uint32_t
lldb_private::operator<<
Stream & operator<<(Stream &s, const SourceLocationSpec &loc)
Dump a SourceLocationSpec object to a stream.
Definition: SourceLocationSpec.cpp:40
lldb_private::MemoryRegionInfo::MemoryRegionInfo
MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write, OptionalBool execute, OptionalBool mapped, ConstString name, OptionalBool flash, lldb::offset_t blocksize, OptionalBool memory_tagged, OptionalBool stack_memory)
Definition: MemoryRegionInfo.h:28
lldb_private::MemoryRegionInfo::eDontKnow
@ eDontKnow
Definition: MemoryRegionInfo.h:25
lldb_private::MemoryRegionInfo::SetMapped
void SetMapped(OptionalBool val)
Definition: MemoryRegionInfo.h:60
lldb_private::MemoryRegionInfo::GetRange
const RangeType & GetRange() const
Definition: MemoryRegionInfo.h:40
lldb_private::operator<
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:968
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:36
lldb_private::MemoryRegionInfo::IsStackMemory
OptionalBool IsStackMemory() const
Definition: MemoryRegionInfo.h:120
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::MemoryRegionInfo::MemoryRegionInfo
MemoryRegionInfo()=default
ConstString.h
lldb_private::MemoryRegionInfo::m_write
OptionalBool m_write
Definition: MemoryRegionInfo.h:135
lldb_private::MemoryRegionInfo::GetMapped
OptionalBool GetMapped() const
Definition: MemoryRegionInfo.h:48
lldb_private::MemoryRegionInfo::SetIsStackMemory
void SetIsStackMemory(OptionalBool val)
Definition: MemoryRegionInfo.h:122
lldb_private::MemoryRegionInfo::GetReadable
OptionalBool GetReadable() const
Definition: MemoryRegionInfo.h:42