Author: Emre Kultursay
Date: 2022-07-01T13:45:42+08:00
New Revision: c0702ac07b8e206f424930ff0331151954fb821c
URL:
https://github.com/llvm/llvm-project/commit/c0702ac07b8e206f424930ff0331151954fb821c
DIFF:
https://github.com/llvm/llvm-project/commit/c0702ac07b8e206f424930ff0331151954fb821c.diff
LOG: [PATCH] [lldb-server] Skip shared regions for memory allocation
Differential Revision: https://reviews.llvm.org/D128832
Added:
Modified:
lldb/include/lldb/Target/MemoryRegionInfo.h
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp
lldb/unittests/Process/Utility/LinuxProcMapsTest.cpp
lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
lldb/unittests/Process/minidump/MinidumpParserTest.cpp
Removed:
diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 4e978d33b05d..3ef66b403e14 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -26,12 +26,14 @@ class MemoryRegionInfo {
MemoryRegionInfo() = default;
MemoryRegionInfo(RangeType range, OptionalBool read, OptionalBool write,
- OptionalBool execute, OptionalBool mapped, ConstString name,
+ OptionalBool execute, OptionalBool shared,
+ OptionalBool mapped, ConstString name,
OptionalBool flash, lldb::offset_t blocksize,
OptionalBool memory_tagged, OptionalBool stack_memory)
: m_range(range), m_read(read), m_write(write), m_execute(execute),
-m_mapped(mapped), m_name(name), m_flash(flash), m_blocksize(blocksize),
-m_memory_tagged(memory_tagged), m_is_stack_memory(stack_memory) {}
+m_shared(shared), m_mapped(mapped), m_name(name), m_flash(flash),
+m_blocksize(blocksize), m_memory_tagged(memory_tagged),
+m_is_stack_memory(stack_memory) {}
RangeType &GetRange() { return m_range; }
@@ -45,6 +47,8 @@ class MemoryRegionInfo {
OptionalBool GetExecutable() const { return m_execute; }
+ OptionalBool GetShared() const { return m_shared; }
+
OptionalBool GetMapped() const { return m_mapped; }
ConstString GetName() const { return m_name; }
@@ -57,6 +61,8 @@ class MemoryRegionInfo {
void SetExecutable(OptionalBool val) { m_execute = val; }
+ void SetShared(OptionalBool val) { m_shared = val; }
+
void SetMapped(OptionalBool val) { m_mapped = val; }
void SetName(const char *name) { m_name = ConstString(name); }
@@ -95,6 +101,7 @@ class MemoryRegionInfo {
bool operator==(const MemoryRegionInfo &rhs) const {
return m_range == rhs.m_range && m_read == rhs.m_read &&
m_write == rhs.m_write && m_execute == rhs.m_execute &&
+ m_shared == rhs.m_shared &&
m_mapped == rhs.m_mapped && m_name == rhs.m_name &&
m_flash == rhs.m_flash && m_blocksize == rhs.m_blocksize &&
m_memory_tagged == rhs.m_memory_tagged &&
@@ -134,6 +141,7 @@ class MemoryRegionInfo {
OptionalBool m_read = eDontKnow;
OptionalBool m_write = eDontKnow;
OptionalBool m_execute = eDontKnow;
+ OptionalBool m_shared = eDontKnow;
OptionalBool m_mapped = eDontKnow;
ConstString m_name;
OptionalBool m_flash = eDontKnow;
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 0fb4c691118b..90118f9386da 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1227,7 +1227,8 @@ llvm::Expected
NativeProcessLinux::Syscall(llvm::ArrayRef args) {
PopulateMemoryRegionCache();
auto region_it = llvm::find_if(m_mem_region_cache, [](const auto &pair) {
-return pair.first.GetExecutable() == MemoryRegionInfo::eYes;
+return pair.first.GetExecutable() == MemoryRegionInfo::eYes &&
+pair.first.GetShared() != MemoryRegionInfo::eYes;
});
if (region_it == m_mem_region_cache.end())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
diff --git a/lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp
b/lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp
index 947b970edf6c..2a15f9813749 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxProcMaps.cpp
@@ -94,7 +94,15 @@ ParseMemoryRegionInfoFromProcMapsLine(llvm::StringRef
maps_line,
return ProcMapError("unexpected /proc/{pid}/%s exec permission char",
maps_kind);
- line_extractor.GetChar(); // Read the private bit
+ // Handle sharing status (private/shared).
+ const char sharing_char = line_extractor.GetChar();
+ if (sharing_char == 's')
+region.SetShared(MemoryRegionInfo::OptionalBool::eYes);
+ else if (sharing