================
@@ -8,47 +8,183 @@
 
 #include "lldb/Target/Memory.h"
 #include "lldb/Target/Process.h"
-#include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/Utility/State.h"
 
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/MathExtras.h"
 
+#include <algorithm>
 #include <cinttypes>
 #include <memory>
+#include <utility>
 
 using namespace lldb;
 using namespace lldb_private;
 
+llvm::ArrayRef<uint8_t> LineCache::Lookup(addr_t addr) const {
+  const auto pos = m_lines.find(IndexOf(addr));
+  if (pos == m_lines.end())
+    return {};
+  const addr_t line_offset = addr % m_line_byte_size;
+  return llvm::ArrayRef(pos->second.get(), m_line_byte_size)
+      .drop_front(line_offset);
+}
+
+void LineCache::Insert(addr_t addr, llvm::ArrayRef<uint8_t> src) {
+  assert((addr % m_line_byte_size) == 0 &&
+         "whole line inserted at an unaligned address!");
+  assert(src.size() == m_line_byte_size &&
+         "whole line inserted with a partial buffer!");
+  auto line = std::make_unique<uint8_t[]>(m_line_byte_size);
+  std::copy(src.begin(), src.end(), line.get());
+  m_lines[IndexOf(addr)] = std::move(line);
+}
+
+void LineCache::EraseRange(addr_t addr, addr_t size) {
+  if (size == 0)
+    return;
+  // Clamp a range running past the end of the address space to it.
+  const addr_t end_addr = llvm::SaturatingAdd(addr, size - 1);
+  const uint64_t first_idx = IndexOf(addr);
+  const uint64_t last_idx = IndexOf(end_addr);
+  m_lines.remove_if([first_idx, last_idx](const auto &entry) {
+    return entry.getFirst() >= first_idx && entry.getFirst() <= last_idx;
+  });
+}
+
+ChunkCache::Collection::const_iterator
+ChunkCache::FindChunkContaining(addr_t addr) const {
+  if (m_chunks.empty())
+    return m_chunks.end();
+  Collection::const_iterator pos = m_chunks.upper_bound(addr);
+  if (pos == m_chunks.begin())
+    return m_chunks.end();
+  --pos;
+  // Sum pos->first + size wraps at the top of the address space.
----------------
felipepiovezan wrote:

could you elaborate what you meant with this comment?

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

Reply via email to