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#include <optional>
18
19using namespace lldb;
20using namespace lldb_private;
21
24}
25
27 lldb::addr_t end, uint32_t permissions,
28 bool mapped, bool stack_memory)
30 LLDB_INSTRUMENT_VA(this, name, begin, end, permissions, mapped, stack_memory);
31 m_opaque_up->SetName(name);
32 m_opaque_up->GetRange().SetRangeBase(begin);
33 m_opaque_up->GetRange().SetRangeEnd(end);
34 m_opaque_up->SetLLDBPermissions(permissions);
35 m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
37 m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
39}
40
42 : m_opaque_up(new MemoryRegionInfo()) {
43 if (lldb_object_ptr)
44 ref() = *lldb_object_ptr;
45}
46
48 LLDB_INSTRUMENT_VA(this, rhs);
50}
51
53operator=(const SBMemoryRegionInfo &rhs) {
54 LLDB_INSTRUMENT_VA(this, rhs);
55
56 if (this != &rhs)
58 return *this;
59}
60
62
65
66 m_opaque_up->Clear();
67}
68
70 LLDB_INSTRUMENT_VA(this, rhs);
71
72 return ref() == rhs.ref();
73}
74
76 LLDB_INSTRUMENT_VA(this, rhs);
77
78 return ref() != rhs.ref();
79}
80
82
84
87
88 return m_opaque_up->GetRange().GetRangeBase();
89}
90
93
94 return m_opaque_up->GetRange().GetRangeEnd();
95}
96
99
100 return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
101}
102
104 LLDB_INSTRUMENT_VA(this);
105
106 return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
107}
108
110 LLDB_INSTRUMENT_VA(this);
111
112 return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
113}
114
116 LLDB_INSTRUMENT_VA(this);
117
118 return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
119}
120
122 LLDB_INSTRUMENT_VA(this);
123
124 return m_opaque_up->GetName().AsCString();
125}
126
128 LLDB_INSTRUMENT_VA(this);
129
130 return m_opaque_up->GetDirtyPageList().has_value();
131}
132
134 LLDB_INSTRUMENT_VA(this);
135
136 uint32_t num_dirty_pages = 0;
137 const std::optional<std::vector<addr_t>> &dirty_page_list =
138 m_opaque_up->GetDirtyPageList();
139 if (dirty_page_list)
140 num_dirty_pages = dirty_page_list->size();
141
142 return num_dirty_pages;
143}
144
146 LLDB_INSTRUMENT_VA(this, idx);
147
148 addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
149 const std::optional<std::vector<addr_t>> &dirty_page_list =
150 m_opaque_up->GetDirtyPageList();
151 if (dirty_page_list && idx < dirty_page_list->size())
152 dirty_page_addr = (*dirty_page_list)[idx];
153
154 return dirty_page_addr;
155}
156
158 LLDB_INSTRUMENT_VA(this);
159
160 return m_opaque_up->GetPageSize();
161}
162
164 LLDB_INSTRUMENT_VA(this, description);
165
166 Stream &strm = description.ref();
167 const addr_t load_addr = m_opaque_up->GetRange().base;
168
169 strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
170 load_addr + m_opaque_up->GetRange().size);
171 strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
172 strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
173 strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
174 strm.Printf("]");
175
176 return true;
177}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::MemoryRegionInfo & ref()
bool IsMapped()
Check if this memory address is mapped into the process address space.
bool IsReadable()
Check if this memory address is marked readable to the process.
int GetPageSize()
Returns the size of a memory page in this region.
bool operator==(const lldb::SBMemoryRegionInfo &rhs) const
addr_t GetDirtyPageAddressAtIndex(uint32_t idx)
Returns the address of a memory page that has been modified in this region.
lldb::addr_t GetRegionBase()
Get the base address of this memory range.
bool operator!=(const lldb::SBMemoryRegionInfo &rhs) const
bool HasDirtyMemoryPageList()
Returns whether this memory region has a list of memory pages that have been modified – that are dirt...
const lldb::SBMemoryRegionInfo & operator=(const lldb::SBMemoryRegionInfo &rhs)
bool IsWritable()
Check if this memory address is marked writable to the process.
lldb::addr_t GetRegionEnd()
Get the end address of this memory range.
lldb::MemoryRegionInfoUP m_opaque_up
const char * GetName()
Returns the name of the memory region mapped at the given address.
bool IsExecutable()
Check if this memory address is marked executable to the process.
uint32_t GetNumDirtyPages()
Returns the number of modified pages – dirty pages – in this memory region.
bool GetDescription(lldb::SBStream &description)
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
uint64_t addr_t
Definition: lldb-types.h:80