Author: Felipe de Azevedo Piovezan
Date: 2026-06-02T16:02:37+01:00
New Revision: 8dd51399f8a9f13cbe35fb2060f05bd30acfb6f8

URL: 
https://github.com/llvm/llvm-project/commit/8dd51399f8a9f13cbe35fb2060f05bd30acfb6f8
DIFF: 
https://github.com/llvm/llvm-project/commit/8dd51399f8a9f13cbe35fb2060f05bd30acfb6f8.diff

LOG: [lldb][NFC] Factor out helper code from MemoryCache (#201120)

This will be reused in a subsequent commit.

Added: 
    

Modified: 
    lldb/include/lldb/Target/Memory.h
    lldb/source/Target/Memory.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/Memory.h 
b/lldb/include/lldb/Target/Memory.h
index 864ef6ca00802..85584f29ec7e7 100644
--- a/lldb/include/lldb/Target/Memory.h
+++ b/lldb/include/lldb/Target/Memory.h
@@ -63,6 +63,11 @@ class MemoryCache {
   const MemoryCache &operator=(const MemoryCache &) = delete;
 
   lldb::DataBufferSP GetL2CacheLine(lldb::addr_t addr, Status &error);
+
+  // If the entire range [addr, addr+len) is covered by a single L1 entry,
+  // returns a pointer into that entry's data at the correct offset. Returns
+  // nullptr on a miss. Caller must hold m_mutex.
+  const uint8_t *FindL1CacheEntry(lldb::addr_t addr, size_t len) const;
 };
 
     

diff  --git a/lldb/source/Target/Memory.cpp b/lldb/source/Target/Memory.cpp
index d0aa67f66d20c..6c4650f1eb2d7 100644
--- a/lldb/source/Target/Memory.cpp
+++ b/lldb/source/Target/Memory.cpp
@@ -123,6 +123,20 @@ bool MemoryCache::RemoveInvalidRange(lldb::addr_t 
base_addr,
   return false;
 }
 
+const uint8_t *MemoryCache::FindL1CacheEntry(lldb::addr_t addr,
+                                             size_t len) const {
+  if (m_L1_cache.empty())
+    return nullptr;
+  AddrRange read_range(addr, len);
+  BlockMap::const_iterator pos = m_L1_cache.upper_bound(addr);
+  if (pos != m_L1_cache.begin())
+    --pos;
+  AddrRange chunk_range(pos->first, pos->second->GetByteSize());
+  if (!chunk_range.Contains(read_range))
+    return nullptr;
+  return pos->second->GetBytes() + (addr - chunk_range.GetRangeBase());
+}
+
 lldb::DataBufferSP MemoryCache::GetL2CacheLine(lldb::addr_t line_base_addr,
                                                Status &error) {
   // This function assumes that the address given is aligned correctly.
@@ -173,18 +187,9 @@ size_t MemoryCache::Read(addr_t addr, void *dst, size_t 
dst_len,
   // L1 cache contains chunks of memory that are not required to be the size of
   // an L2 cache line. We avoid trying to do partial reads from the L1 cache to
   // simplify the implementation.
-  if (!m_L1_cache.empty()) {
-    AddrRange read_range(addr, dst_len);
-    BlockMap::iterator pos = m_L1_cache.upper_bound(addr);
-    if (pos != m_L1_cache.begin()) {
-      --pos;
-    }
-    AddrRange chunk_range(pos->first, pos->second->GetByteSize());
-    if (chunk_range.Contains(read_range)) {
-      memcpy(dst, pos->second->GetBytes() + (addr - 
chunk_range.GetRangeBase()),
-             dst_len);
-      return dst_len;
-    }
+  if (const uint8_t *l1_data = FindL1CacheEntry(addr, dst_len)) {
+    memcpy(dst, l1_data, dst_len);
+    return dst_len;
   }
 
   // If the size of the read is greater than the size of an L2 cache line, 
we'll


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to