[Lldb-commits] [lldb] [lldb] Add memory region info cache to Process (PR #206208)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 26 16:54:01 PDT 2026


================
@@ -0,0 +1,53 @@
+//===-- MemoryRegionInfoCache.cpp -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/MemoryRegionInfoCache.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/Status.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+void MemoryRegionInfoCache::Clear() { m_region_infos.Clear(); }
+
+void MemoryRegionInfoCache::Erase(addr_t load_addr, addr_t size) {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  uint32_t start_idx = m_region_infos.FindEntryIndexThatContains(load_addr);
+  uint32_t end_idx =
+      m_region_infos.FindEntryIndexThatContains(load_addr + size);
+  if (start_idx == UINT32_MAX && end_idx == UINT32_MAX)
+    return;
+
+  if (start_idx == UINT32_MAX)
+    m_region_infos.Erase(end_idx, end_idx);
+  else if (end_idx == UINT32_MAX)
+    m_region_infos.Erase(start_idx, start_idx);
+  else
+    m_region_infos.Erase(start_idx, end_idx);
+  m_region_infos.Sort();
+}
----------------
JDevlieghere wrote:

I want to see a unit test for this because I think this does nothing currently. For this to actually remove entries, I think you need to call Erase(idx, idx+1) for a single index and Erase(start_idx, end_idx+1) for an inclusive range. The current branches are all no-ops because RangeDataVector::Erase rejects start>=end.

https://github.com/llvm/llvm-project/pull/206208


More information about the lldb-commits mailing list