[Lldb-commits] [lldb] [lldb] Fix and speedup the `memory find` command (PR #104193)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 28 08:38:06 PDT 2024


================
@@ -3367,21 +3340,48 @@ lldb::addr_t Process::FindInMemory(lldb::addr_t low, lldb::addr_t high,
   if (region_size < size)
     return LLDB_INVALID_ADDRESS;
 
+  // See "Boyer-Moore string search algorithm".
   std::vector<size_t> bad_char_heuristic(256, size);
-  ProcessMemoryIterator iterator(*this, low);
-
   for (size_t idx = 0; idx < size - 1; idx++) {
     decltype(bad_char_heuristic)::size_type bcu_idx = buf[idx];
     bad_char_heuristic[bcu_idx] = size - idx - 1;
   }
-  for (size_t s = 0; s <= (region_size - size);) {
+
+  // Memory we're currently searching through.
+  llvm::SmallVector<uint8_t, 0> mem;
+  // Position of the memory buffer.
+  addr_t mem_pos = low;
+  // Maximum number of bytes read (and buffered). We need to read at least
+  // `size` bytes for a successful match.
+  const size_t max_read_size = std::max<size_t>(size, 0x10000);
+
+  for (addr_t s = low; s <= (high - size);) {
----------------
labath wrote:

How about cur_addr? :) (`s` was a leftover from the original implementation, but I've now completely changed it anyway).

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


More information about the lldb-commits mailing list