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

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 1 06:12:12 PST 2024


================
@@ -0,0 +1,142 @@
+//===-- 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<Region> 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());
+  }
----------------
DavidSpickett wrote:

Seems like it would be simpler to write this as:
```
max_byte_size = 1;
if (supported_features &
    WatchpointHardwareFeature::eWatchpointHardwareArmMASK)
  max_byte_size = INT32_MAX;

std::vector<Region> entries = entries =
        PowerOf2Watchpoints(addr, size,
                            /*min_byte_size=*/ 1,
                            max_byte_size,
                            /*address_byte_size=*/ arch.GetAddressByteSize());
```

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


More information about the lldb-commits mailing list