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  : m_opaque_up(new MemoryRegionInfo()) {
27  if (lldb_object_ptr)
28  ref() = *lldb_object_ptr;
29 }
30 
32  : m_opaque_up() {
34  (const lldb::SBMemoryRegionInfo &), rhs);
36 }
37 
42  SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &), rhs);
43 
44  if (this != &rhs)
46  return LLDB_RECORD_RESULT(*this);
47 }
48 
50 
53 
54  m_opaque_up->Clear();
55 }
56 
59  bool, SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &),
60  rhs);
61 
62  return ref() == rhs.ref();
63 }
64 
67  bool, SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &),
68  rhs);
69 
70  return ref() != rhs.ref();
71 }
72 
74 
75 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
76 
79 
80  return m_opaque_up->GetRange().GetRangeBase();
81 }
82 
85 
86  return m_opaque_up->GetRange().GetRangeEnd();
87 }
88 
91 
92  return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
93 }
94 
97 
98  return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
99 }
100 
103 
104  return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
105 }
106 
109 
110  return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
111 }
112 
115 
116  return m_opaque_up->GetName().AsCString();
117 }
118 
121 
122  return m_opaque_up->GetDirtyPageList().hasValue();
123 }
124 
127 
128  uint32_t num_dirty_pages = 0;
129  llvm::Optional<std::vector<addr_t>> dirty_page_list =
130  m_opaque_up->GetDirtyPageList();
131  if (dirty_page_list.hasValue())
132  num_dirty_pages = dirty_page_list.getValue().size();
133 
134  return num_dirty_pages;
135 }
136 
139  (uint32_t), idx);
140 
141  addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
142  const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
143  m_opaque_up->GetDirtyPageList();
144  if (dirty_page_list.hasValue() && idx < dirty_page_list.getValue().size())
145  dirty_page_addr = dirty_page_list.getValue()[idx];
146 
147  return dirty_page_addr;
148 }
149 
152  return m_opaque_up->GetPageSize();
153 }
154 
157  (lldb::SBStream &), description);
158 
159  Stream &strm = description.ref();
160  const addr_t load_addr = m_opaque_up->GetRange().base;
161 
162  strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
163  load_addr + m_opaque_up->GetRange().size);
164  strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
165  strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
166  strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
167  strm.Printf("]");
168 
169  return true;
170 }
171 
172 namespace lldb_private {
173 namespace repro {
174 
175 template <>
179  (const lldb::SBMemoryRegionInfo &));
181  const lldb::SBMemoryRegionInfo &,
182  SBMemoryRegionInfo, operator=,(const lldb::SBMemoryRegionInfo &));
183  LLDB_REGISTER_METHOD(void, SBMemoryRegionInfo, Clear, ());
185  bool,
186  SBMemoryRegionInfo, operator==,(const lldb::SBMemoryRegionInfo &));
188  bool,
189  SBMemoryRegionInfo, operator!=,(const lldb::SBMemoryRegionInfo &));
192  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsReadable, ());
193  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsWritable, ());
194  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsExecutable, ());
195  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, IsMapped, ());
196  LLDB_REGISTER_METHOD(const char *, SBMemoryRegionInfo, GetName, ());
197  LLDB_REGISTER_METHOD(bool, SBMemoryRegionInfo, GetDescription,
198  (lldb::SBStream &));
199 }
200 
201 }
202 }
lldb::SBMemoryRegionInfo::IsMapped
bool IsMapped()
Check if this memory address is mapped into the process address space.
Definition: SBMemoryRegionInfo.cpp:107
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:57
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:51
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:73
lldb::SBMemoryRegionInfo::IsExecutable
bool IsExecutable()
Check if this memory address is marked executable to the process.
Definition: SBMemoryRegionInfo.cpp:101
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:65
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:119
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:77
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:150
lldb::SBMemoryRegionInfo::IsWritable
bool IsWritable()
Check if this memory address is marked writable to the process.
Definition: SBMemoryRegionInfo.cpp:95
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:89
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:137
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:127
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:39
lldb::SBMemoryRegionInfo::GetName
const char * GetName()
Returns the name of the memory region mapped at the given address.
Definition: SBMemoryRegionInfo.cpp:113
lldb::SBMemoryRegionInfo::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBMemoryRegionInfo.cpp:155
lldb::SBMemoryRegionInfo::GetNumDirtyPages
uint32_t GetNumDirtyPages()
Returns the number of modified pages – dirty pages – in this memory region.
Definition: SBMemoryRegionInfo.cpp:125
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:176
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:83