[Lldb-commits] [lldb] [lldb] Add support for large watchpoints in lldb (PR #79962)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 30 20:01:00 PST 2024


================
@@ -0,0 +1,146 @@
+//===-- WatchpointAlgorithms.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/Breakpoint/WatchpointAlgorithms.h"
+#include "lldb/Breakpoint/WatchpointResource.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/ArchSpec.h"
+
+#include <utility>
+#include <vector>
+
+using namespace lldb;
+using namespace lldb_private;
+
+std::vector<WatchpointResourceSP>
+WatchpointAlgorithms::AtomizeWatchpointRequest(
+    addr_t addr, size_t size, bool read, bool write,
+    WatchpointHardwareFeature supported_features, ArchSpec &arch) {
+
+  std::vector<std::pair<addr_t, size_t>> entries;
+
+  if (supported_features &
+      WatchpointHardwareFeature::eWatchpointHardwareArmMASK) {
+    entries =
+        PowerOf2Watchpoints(addr, size,
+                            /* min_byte_size */ 1,
+                            /* max_byte_size */ INT32_MAX,
+                            /* address_byte_size */ arch.GetAddressByteSize());
+  } else {
+    // As a fallback, assume we can watch any power-of-2
+    // number of bytes up through the size of an address in the target.
+    entries =
+        PowerOf2Watchpoints(addr, size,
+                            /* min_byte_size */ 1,
+                            /* max_byte_size */ arch.GetAddressByteSize(),
+                            /* address_byte_size */ arch.GetAddressByteSize());
+  }
+
+  std::vector<WatchpointResourceSP> resources;
+  for (std::pair<addr_t, size_t> &ent : entries) {
+    addr_t addr = std::get<0>(ent);
+    size_t size = std::get<1>(ent);
+    WatchpointResourceSP wp_res_sp =
+        std::make_shared<WatchpointResource>(addr, size, read, write);
+    resources.push_back(wp_res_sp);
+  }
+
+  return resources;
+}
+
+/// Convert a user's watchpoint request (\a user_addr and \a user_size)
+/// into hardware watchpoints, for a target that can watch a power-of-2
+/// region of memory (1, 2, 4, 8, etc), aligned to that same power-of-2
+/// memory address.
+///
+/// If a user asks to watch 4 bytes at address 0x1002 (0x1002-0x1005
+/// inclusive) we can implement this with two 2-byte watchpoints
+/// (0x1002 and 0x1004) or with an 8-byte watchpoint at 0x1000.
+/// A 4-byte watchpoint at 0x1002 would not be properly 4 byte aligned.
+///
+/// If a user asks to watch 16 bytes at 0x1000, and this target supports
+/// 8-byte watchpoints, we can implement this with two 8-byte watchpoints
+/// at 0x1000 and 0x1008.
+
----------------
JDevlieghere wrote:

Spurious newline. 

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


More information about the lldb-commits mailing list