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"
18#include <optional>
19
20using namespace lldb;
21using namespace lldb_private;
22
26
28 lldb::addr_t end, uint32_t permissions,
29 bool mapped, bool stack_memory)
31 LLDB_INSTRUMENT_VA(this, name, begin, end, permissions, mapped, stack_memory);
32 m_opaque_up->SetName(name);
33 m_opaque_up->GetRange().SetRangeBase(begin);
34 m_opaque_up->GetRange().SetRangeEnd(end);
35 m_opaque_up->SetLLDBPermissions(permissions);
36 m_opaque_up->SetMapped(mapped ? eLazyBoolYes : eLazyBoolNo);
37 m_opaque_up->SetIsStackMemory(stack_memory ? eLazyBoolYes : eLazyBoolNo);
38}
39
42 if (lldb_object_ptr)
43 ref() = *lldb_object_ptr;
44}
45
50
52operator=(const SBMemoryRegionInfo &rhs) {
53 LLDB_INSTRUMENT_VA(this, rhs);
54
55 if (this != &rhs)
57 return *this;
58}
59
61
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
83
86
87 return m_opaque_up->GetRange().GetRangeBase();
88}
89
92
93 return m_opaque_up->GetRange().GetRangeEnd();
94}
95
98
99 return m_opaque_up->GetReadable() == eLazyBoolYes;
100}
101
103 LLDB_INSTRUMENT_VA(this);
104
105 return m_opaque_up->GetWritable() == eLazyBoolYes;
106}
107
109 LLDB_INSTRUMENT_VA(this);
110
111 return m_opaque_up->GetExecutable() == eLazyBoolYes;
112}
113
115 LLDB_INSTRUMENT_VA(this);
116
117 return m_opaque_up->GetMapped() == eLazyBoolYes;
118}
119
121 LLDB_INSTRUMENT_VA(this);
122
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 std::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->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 std::optional<std::vector<addr_t>> &dirty_page_list =
149 m_opaque_up->GetDirtyPageList();
150 if (dirty_page_list && idx < dirty_page_list->size())
151 dirty_page_addr = (*dirty_page_list)[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.PutCString("]");
174
175 return true;
176}
#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)
writes a description of the memory region to a SBStream.
lldb_private::Stream & ref()
Definition SBStream.cpp:179
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
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
#define LLDB_INVALID_ADDRESS
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:25
uint64_t addr_t
Definition lldb-types.h:80