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
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 ? eLazyBoolYes : eLazyBoolNo);
36 m_opaque_up->SetIsStackMemory(stack_memory ? eLazyBoolYes : eLazyBoolNo);
37}
38
41 if (lldb_object_ptr)
42 ref() = *lldb_object_ptr;
43}
44
49
51operator=(const SBMemoryRegionInfo &rhs) {
52 LLDB_INSTRUMENT_VA(this, rhs);
53
54 if (this != &rhs)
56 return *this;
57}
58
60
63
64 m_opaque_up->Clear();
65}
66
68 LLDB_INSTRUMENT_VA(this, rhs);
69
70 return ref() == rhs.ref();
71}
72
74 LLDB_INSTRUMENT_VA(this, rhs);
75
76 return ref() != rhs.ref();
77}
78
80
82
85
86 return m_opaque_up->GetRange().GetRangeBase();
87}
88
91
92 return m_opaque_up->GetRange().GetRangeEnd();
93}
94
97
98 return m_opaque_up->GetReadable() == eLazyBoolYes;
99}
100
102 LLDB_INSTRUMENT_VA(this);
103
104 return m_opaque_up->GetWritable() == eLazyBoolYes;
105}
106
108 LLDB_INSTRUMENT_VA(this);
109
110 return m_opaque_up->GetExecutable() == eLazyBoolYes;
111}
112
114 LLDB_INSTRUMENT_VA(this);
115
116 return m_opaque_up->GetMapped() == eLazyBoolYes;
117}
118
120 LLDB_INSTRUMENT_VA(this);
121
122 return m_opaque_up->GetName().AsCString();
123}
124
126 LLDB_INSTRUMENT_VA(this);
127
128 return m_opaque_up->GetDirtyPageList().has_value();
129}
130
132 LLDB_INSTRUMENT_VA(this);
133
134 uint32_t num_dirty_pages = 0;
135 const std::optional<std::vector<addr_t>> &dirty_page_list =
136 m_opaque_up->GetDirtyPageList();
137 if (dirty_page_list)
138 num_dirty_pages = dirty_page_list->size();
139
140 return num_dirty_pages;
141}
142
144 LLDB_INSTRUMENT_VA(this, idx);
145
146 addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
147 const std::optional<std::vector<addr_t>> &dirty_page_list =
148 m_opaque_up->GetDirtyPageList();
149 if (dirty_page_list && idx < dirty_page_list->size())
150 dirty_page_addr = (*dirty_page_list)[idx];
151
152 return dirty_page_addr;
153}
154
156 LLDB_INSTRUMENT_VA(this);
157
158 return m_opaque_up->GetPageSize();
159}
160
162 LLDB_INSTRUMENT_VA(this, description);
163
164 Stream &strm = description.ref();
165 const addr_t load_addr = m_opaque_up->GetRange().base;
166
167 strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
168 load_addr + m_opaque_up->GetRange().size);
169 strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
170 strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
171 strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
172 strm.Printf("]");
173
174 return true;
175}
#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:178
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
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
uint64_t addr_t
Definition lldb-types.h:80