[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,101 @@
+//===-- 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);
+
+public:
+  // These methods should be protected, but giving access to the algorithms
+  // in the unittests is not straightforward, so they're marked public.
+  // Do not call directly elsewhere.
----------------
JDevlieghere wrote:

There's a neat trick to make this `protected` and still use it in the unit tests. You create a subclass and make the functions you want to test public.  Something like this:

```
class WatchpointAlgorithmsTest : public WatchpointAlgorithms {
public:
  using WatchpointAlgorithmsTest ::PowerOf2Watchpoints;
}
```

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


More information about the lldb-commits mailing list