LLDB  mainline
SBMemoryRegionInfo.cpp
Go to the documentation of this file.
1 //===-- SBMemoryRegionInfo.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBError.h"
14 #include "lldb/API/SBStream.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
23 }
24 
26  lldb::addr_t end, uint32_t permissions,
27  bool mapped, bool stack_memory)
28  : SBMemoryRegionInfo() {
31  (const char *, lldb::addr_t, lldb::addr_t, uint32_t, bool, bool), name,
32  begin, end, permissions, mapped, stack_memory);
33  m_opaque_up->SetName(name);
34  m_opaque_up->GetRange().SetRangeBase(begin);
35  m_opaque_up->GetRange().SetRangeEnd(end);
36  m_opaque_up->SetLLDBPermissions(permissions);
37  m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
38  : MemoryRegionInfo::eNo);
39  m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
40  : MemoryRegionInfo::eNo);
41 }
42 
44  : m_opaque_up(new MemoryRegionInfo()) {
45  if (lldb_object_ptr)
46  ref() = *lldb_object_ptr;
47 }
48 
50  : m_opaque_up() {
52  (const lldb::SBMemoryRegionInfo &), rhs);
54 }
55 
60  SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &), rhs);
61 
62  if (this != &rhs)
64  return LLDB_RECORD_RESULT(*this);
65 }
66 
68 
71 
72  m_opaque_up->Clear();
73 }
74 
77  bool, SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &),
78  rhs);
79 
80  return ref() == rhs.ref();
81 }
82 
85  bool, SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &),
86  rhs);
87 
88  return ref() != rhs.ref();
89 }
90 
92 
93 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
94 
97 
98  return m_opaque_up->GetRange().GetRangeBase();
99 }
100 
103 
104  return m_opaque_up->GetRange().GetRangeEnd();
105 }
106 
109 
110  return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
111 }
112 
115 
116  return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
117 }
118 
121 
122  return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
123 }
124 
127 
128  return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
129 }
130 
133 
134  return m_opaque_up->GetName().AsCString();
135 }
136 
139 
140  return m_opaque_up->GetDirtyPageList().hasValue();
141 }
142 
145 
146  uint32_t num_dirty_pages = 0;
147  llvm::Optional<std::vector<addr_t>> dirty_page_list =
148  m_opaque_up->GetDirtyPageList();
149  if (dirty_page_list.hasValue())
150  num_dirty_pages = dirty_page_list.getValue().size();
151 
152  return num_dirty_pages;
153 }
154 
158 
159  addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
160  const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
161  m_opaque_up->GetDirtyPageList();
162  if (dirty_page_list.hasValue() && idx < dirty_page_list.getValue().size())
163  dirty_page_addr = dirty_page_list.getValue()[idx];
164 
165  return dirty_page_addr;
166 }
167 
170 
171  return m_opaque_up->GetPageSize();
172 }
173 
176  (lldb::SBStream &), description);
177 
178  Stream &strm = description.ref();
179  const addr_t load_addr = m_opaque_up->GetRange().base;
180 
181  strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
182  load_addr + m_opaque_up->GetRange().size);
183  strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
184  strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
185  strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
186  strm.Printf("]");
187 
188  return true;
189 }
190 
191 namespace lldb_private {
192 namespace repro {
193 
194 template <>
198  (const lldb::SBMemoryRegionInfo &));
201  (const char *, lldb::addr_t, lldb::addr_t, uint32_t, bool, bool));
203  const lldb::SBMemoryRegionInfo &,
204  SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &));
205  LLDB_REGISTER_METHOD(void, SBMemoryRegionInfo, Clear, ());
207  bool,
208  SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &));
210  bool,
211  SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &));
214  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsReadable, ());
215  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsWritable, ());
216  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsExecutable, ());
217  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsMapped, ());
218  LLDB_REGISTER_METHOD(const char *, SBMemoryRegionInfo, GetName, ());
219  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, GetDescription,
220  (lldb::SBStream &));
221  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, HasDirtyMemoryPageList, ());
222  LLDB_REGISTER_METHOD(uint32_t, SBMemoryRegionInfo, GetNumDirtyPages, ());
223  LLDB_REGISTER_METHOD(lldb::addr_t, SBMemoryRegionInfo, GetDirtyPageAddressAtIndex, (uint32_t));
224  LLDB_REGISTER_METHOD(int, SBMemoryRegionInfo, GetPageSize, ());
225 }
226 
227 }
228 }
lldb::SBMemoryRegionInfo::IsMapped
bool IsMapped()
Check if this memory address is mapped into the process address space.
Definition: SBMemoryRegionInfo.cpp:125
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBMemoryRegionInfo::~SBMemoryRegionInfo
~SBMemoryRegionInfo()
SBDefines.h
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
lldb::SBMemoryRegionInfo::operator==
bool operator==(const lldb::SBMemoryRegionInfo &rhs) const
Definition: SBMemoryRegionInfo.cpp:75
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb::SBMemoryRegionInfo::Clear
void Clear()
Definition: SBMemoryRegionInfo.cpp:69
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
SBReproducerPrivate.h
SBMemoryRegionInfo.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBMemoryRegionInfo::ref
lldb_private::MemoryRegionInfo & ref()
Definition: SBMemoryRegionInfo.cpp:91
lldb::SBMemoryRegionInfo::IsExecutable
bool IsExecutable()
Check if this memory address is marked executable to the process.
Definition: SBMemoryRegionInfo.cpp:119
SBStream.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBMemoryRegionInfo::operator!=
bool operator!=(const lldb::SBMemoryRegionInfo &rhs) const
Definition: SBMemoryRegionInfo.cpp:83
lldb::SBMemoryRegionInfo::HasDirtyMemoryPageList
bool HasDirtyMemoryPageList()
Returns whether this memory region has a list of memory pages that have been modified – that are dirt...
Definition: SBMemoryRegionInfo.cpp:137
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
MemoryRegionInfo.h
Utils.h
lldb::SBMemoryRegionInfo::GetRegionBase
lldb::addr_t GetRegionBase()
Get the base address of this memory range.
Definition: SBMemoryRegionInfo.cpp:95
GetName
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition: XcodeSDK.cpp:21
StreamString.h
lldb::SBMemoryRegionInfo::GetPageSize
int GetPageSize()
Returns the size of a memory page in this region.
Definition: SBMemoryRegionInfo.cpp:168
lldb::SBMemoryRegionInfo::IsWritable
bool IsWritable()
Check if this memory address is marked writable to the process.
Definition: SBMemoryRegionInfo.cpp:113
lldb::SBMemoryRegionInfo::SBMemoryRegionInfo
SBMemoryRegionInfo()
Definition: SBMemoryRegionInfo.cpp:21
lldb::SBMemoryRegionInfo::IsReadable
bool IsReadable()
Check if this memory address is marked readable to the process.
Definition: SBMemoryRegionInfo.cpp:107
lldb::SBMemoryRegionInfo::GetDirtyPageAddressAtIndex
addr_t GetDirtyPageAddressAtIndex(uint32_t idx)
Returns the address of a memory page that has been modified in this region.
Definition: SBMemoryRegionInfo.cpp:155
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
uint32_t
lldb::SBMemoryRegionInfo::m_opaque_up
lldb::MemoryRegionInfoUP m_opaque_up
Definition: SBMemoryRegionInfo.h:133
lldb::SBMemoryRegionInfo
Definition: SBMemoryRegionInfo.h:17
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBMemoryRegionInfo::operator=
const lldb::SBMemoryRegionInfo & operator=(const lldb::SBMemoryRegionInfo &rhs)
Definition: SBMemoryRegionInfo.cpp:57
lldb::SBMemoryRegionInfo::GetName
const char * GetName()
Returns the name of the memory region mapped at the given address.
Definition: SBMemoryRegionInfo.cpp:131
lldb::SBMemoryRegionInfo::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBMemoryRegionInfo.cpp:174
lldb::SBMemoryRegionInfo::GetNumDirtyPages
uint32_t GetNumDirtyPages()
Returns the number of modified pages – dirty pages – in this memory region.
Definition: SBMemoryRegionInfo.cpp:143
lldb::SBStream
Definition: SBStream.h:18
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb
Definition: SBAddress.h:15
SBError.h
lldb_private::repro::RegisterMethods< SBMemoryRegionInfo >
void RegisterMethods< SBMemoryRegionInfo >(Registry &R)
Definition: SBMemoryRegionInfo.cpp:195
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93
lldb::SBMemoryRegionInfo::GetRegionEnd
lldb::addr_t GetRegionEnd()
Get the end address of this memory range.
Definition: SBMemoryRegionInfo.cpp:101