[Lldb-commits] [lldb] [lldb] Add 'FindInMemory()' overload for PostMortemProcess. (PR #102536)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 22:45:03 PDT 2024


================
@@ -2835,6 +2835,34 @@ void PruneThreadPlans();
                               AddressRanges &matches, size_t alignment,
                               size_t max_matches);
 
+  template <typename IT>
+  lldb::addr_t FindInMemoryGeneric(IT &&iterator, lldb::addr_t low,
+                                   lldb::addr_t high, const uint8_t *buf,
+                                   size_t size) {
+    const size_t region_size = high - low;
+
+    if (region_size < size)
+      return LLDB_INVALID_ADDRESS;
+
+    std::vector<size_t> bad_char_heuristic(256, size);
+
+    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);) {
+      int64_t j = size - 1;
+      while (j >= 0 && buf[j] == iterator[s + j])
+        j--;
+      if (j < 0)
+        return low + s;
+      else
+        s += bad_char_heuristic[iterator[s + size - 1]];
+    }
+
+    return LLDB_INVALID_ADDRESS;
+  }
+
----------------
clayborg wrote:

Does this need to be templatized? Can't we leave this in Process::FindInMemory() as the default implementation?

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


More information about the lldb-commits mailing list