[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,109 @@
+//===-- WatchpointAlgorithms.h ----------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
+#define LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
+
+#include "lldb/Breakpoint/WatchpointResource.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/lldb-public.h"
+
+#include <vector>
+
+namespace lldb_private {
+
+class WatchpointAlgorithms {
+
+public:
+  /// Convert a user's watchpoint request into an array of memory
+  /// regions that can be watched by one hardware watchpoint register
+  /// on the current target.
+  ///
+  /// \param[in] addr
+  ///     The start address specified by the user.
+  ///
+  /// \param[in] size
+  ///     The number of bytes the user wants to watch.
+  ///
+  /// \param[in] read
+  ///     True if we are watching for read accesses.
+  ///
+  /// \param[in] write
+  ///     True if we are watching for write accesses.
+  ///     \a read and \a write may both be true.
+  ///     There is no "modify" style for WatchpointResources -
+  ///     WatchpointResources are akin to the hardware watchpoint
+  ///     registers which are either in terms of read or write.
+  ///     "modify" distinction is done at the Watchpoint layer, where
+  ///     we check the actual range of bytes the user requested.
+  ///
+  /// \param[in] supported_features
+  ///     The bit flags in this parameter are set depending on which
+  ///     WatchpointHardwareFeature enum values the current target supports.
+  ///     The eWatchpointHardwareFeatureUnknown bit may be set if we
+  ///     don't have specific information about what the remote stub
+  ///     can support, and a reasonablec default will be used.
+  ///
+  /// \param[in] arch
+  ///     The ArchSpec of the current Target.
+  ///
+  /// \return
+  ///     A vector of WatchpointResourceSP's, one per hardware watchpoint
+  ///     register needed.  We may return more WatchpointResources than the
+  ///     target can watch at once; if all resources cannot be set, the
+  ///     watchpoint cannot be set.
+  static std::vector<lldb::WatchpointResourceSP> AtomizeWatchpointRequest(
+      lldb::addr_t addr, size_t size, bool read, bool write,
+      lldb::WatchpointHardwareFeature supported_features, ArchSpec &arch);
+
+  struct Region {
+    lldb::addr_t addr;
+    size_t size;
+  };
+
+protected:
+  /// Convert a user's watchpoint request into an array of addr+size that
+  /// can be watched with power-of-2 style hardware watchpoints.
+  ///
+  /// This is the default algorithm if we have no further information;
+  /// most watchpoint implementations can be assumed to be able to watch up
+  /// to pointer-size regions of memory in power-of-2 sizes and alingments.
+  ///
+  /// \param[in] user_addr
+  ///     The user's start address.
+  ///
+  /// \param[in] user_size
+  ///     The user's specified byte length.
+  ///
+  /// \param[in] min_byte_size
+  ///     The minimum byte size supported on this target.
----------------
DavidSpickett wrote:

Would be helpful to say that this is the minimum byte size *of the range of memory*.

Lest anyone think this thing supports architectures where a byte is in fact 8 bytes.

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


More information about the lldb-commits mailing list