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 "Utils.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBError.h"
13 #include "lldb/API/SBStream.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
22  LLDB_INSTRUMENT_VA(this);
23 }
24 
26  lldb::addr_t end, uint32_t permissions,
27  bool mapped, bool stack_memory)
28  : SBMemoryRegionInfo() {
29  LLDB_INSTRUMENT_VA(this, name, begin, end, permissions, mapped, stack_memory);
30  m_opaque_up->SetName(name);
31  m_opaque_up->GetRange().SetRangeBase(begin);
32  m_opaque_up->GetRange().SetRangeEnd(end);
33  m_opaque_up->SetLLDBPermissions(permissions);
34  m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
35  : MemoryRegionInfo::eNo);
36  m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
37  : MemoryRegionInfo::eNo);
38 }
39 
41  : m_opaque_up(new MemoryRegionInfo()) {
42  if (lldb_object_ptr)
43  ref() = *lldb_object_ptr;
44 }
45 
47  LLDB_INSTRUMENT_VA(this, rhs);
49 }
50 
53  LLDB_INSTRUMENT_VA(this, rhs);
54 
55  if (this != &rhs)
57  return *this;
58 }
59 
61 
63  LLDB_INSTRUMENT_VA(this);
64 
65  m_opaque_up->Clear();
66 }
67 
69  LLDB_INSTRUMENT_VA(this, rhs);
70 
71  return ref() == rhs.ref();
72 }
73 
75  LLDB_INSTRUMENT_VA(this, rhs);
76 
77  return ref() != rhs.ref();
78 }
79 
81 
82 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
83 
85  LLDB_INSTRUMENT_VA(this);
86 
87  return m_opaque_up->GetRange().GetRangeBase();
88 }
89 
91  LLDB_INSTRUMENT_VA(this);
92 
93  return m_opaque_up->GetRange().GetRangeEnd();
94 }
95 
97  LLDB_INSTRUMENT_VA(this);
98 
99  return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
100 }
101 
103  LLDB_INSTRUMENT_VA(this);
104 
105  return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
106 }
107 
109  LLDB_INSTRUMENT_VA(this);
110 
111  return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
112 }
113 
115  LLDB_INSTRUMENT_VA(this);
116 
117  return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
118 }
119 
121  LLDB_INSTRUMENT_VA(this);
122 
123  return m_opaque_up->GetName().AsCString();
124 }
125 
127  LLDB_INSTRUMENT_VA(this);
128 
129  return m_opaque_up->GetDirtyPageList().has_value();
130 }
131 
133  LLDB_INSTRUMENT_VA(this);
134 
135  uint32_t num_dirty_pages = 0;
136  const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
137  m_opaque_up->GetDirtyPageList();
138  if (dirty_page_list)
139  num_dirty_pages = dirty_page_list.value().size();
140 
141  return num_dirty_pages;
142 }
143 
145  LLDB_INSTRUMENT_VA(this, idx);
146 
147  addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
148  const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
149  m_opaque_up->GetDirtyPageList();
150  if (dirty_page_list && idx < dirty_page_list.value().size())
151  dirty_page_addr = dirty_page_list.value()[idx];
152 
153  return dirty_page_addr;
154 }
155 
157  LLDB_INSTRUMENT_VA(this);
158 
159  return m_opaque_up->GetPageSize();
160 }
161 
163  LLDB_INSTRUMENT_VA(this, description);
164 
165  Stream &strm = description.ref();
166  const addr_t load_addr = m_opaque_up->GetRange().base;
167 
168  strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
169  load_addr + m_opaque_up->GetRange().size);
170  strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
171  strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
172  strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
173  strm.Printf("]");
174 
175  return true;
176 }
Instrumentation.h
lldb::SBMemoryRegionInfo::IsMapped
bool IsMapped()
Check if this memory address is mapped into the process address space.
Definition: SBMemoryRegionInfo.cpp:114
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBMemoryRegionInfo::~SBMemoryRegionInfo
~SBMemoryRegionInfo()
SBDefines.h
lldb::SBMemoryRegionInfo::operator==
bool operator==(const lldb::SBMemoryRegionInfo &rhs) const
Definition: SBMemoryRegionInfo.cpp:68
lldb::SBMemoryRegionInfo::Clear
void Clear()
Definition: SBMemoryRegionInfo.cpp:62
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
SBMemoryRegionInfo.h
lldb::SBMemoryRegionInfo::ref
lldb_private::MemoryRegionInfo & ref()
Definition: SBMemoryRegionInfo.cpp:80
lldb::SBMemoryRegionInfo::IsExecutable
bool IsExecutable()
Check if this memory address is marked executable to the process.
Definition: SBMemoryRegionInfo.cpp:108
SBStream.h
lldb::SBMemoryRegionInfo::operator!=
bool operator!=(const lldb::SBMemoryRegionInfo &rhs) const
Definition: SBMemoryRegionInfo.cpp:74
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:126
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:84
StreamString.h
lldb::SBMemoryRegionInfo::GetPageSize
int GetPageSize()
Returns the size of a memory page in this region.
Definition: SBMemoryRegionInfo.cpp:156
lldb::SBMemoryRegionInfo::IsWritable
bool IsWritable()
Check if this memory address is marked writable to the process.
Definition: SBMemoryRegionInfo.cpp:102
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:96
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:144
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:74
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:52
lldb::SBMemoryRegionInfo::GetName
const char * GetName()
Returns the name of the memory region mapped at the given address.
Definition: SBMemoryRegionInfo.cpp:120
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBMemoryRegionInfo::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBMemoryRegionInfo.cpp:162
lldb::SBMemoryRegionInfo::GetNumDirtyPages
uint32_t GetNumDirtyPages()
Returns the number of modified pages – dirty pages – in this memory region.
Definition: SBMemoryRegionInfo.cpp:132
lldb::SBStream
Definition: SBStream.h:18
lldb
Definition: SBAddress.h:15
SBError.h
lldb::SBMemoryRegionInfo::GetRegionEnd
lldb::addr_t GetRegionEnd()
Get the end address of this memory range.
Definition: SBMemoryRegionInfo.cpp:90