xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Breakpoint/WatchpointAlgorithms.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- WatchpointAlgorithms.h ----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
10 #define LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
11 
12 #include "lldb/Breakpoint/WatchpointResource.h"
13 #include "lldb/Utility/ArchSpec.h"
14 #include "lldb/lldb-private.h"
15 
16 #include <vector>
17 
18 namespace lldb_private {
19 
20 class WatchpointAlgorithms {
21 
22 public:
23   /// Convert a user's watchpoint request into an array of memory
24   /// regions, each region watched by one hardware watchpoint register.
25   ///
26   /// \param[in] addr
27   ///     The start address specified by the user.
28   ///
29   /// \param[in] size
30   ///     The number of bytes the user wants to watch.
31   ///
32   /// \param[in] read
33   ///     True if we are watching for read accesses.
34   ///
35   /// \param[in] write
36   ///     True if we are watching for write accesses.
37   ///     \a read and \a write may both be true.
38   ///     There is no "modify" style for WatchpointResources -
39   ///     WatchpointResources are akin to the hardware watchpoint
40   ///     registers which are either in terms of read or write.
41   ///     "modify" distinction is done at the Watchpoint layer, where
42   ///     we check the actual range of bytes the user requested.
43   ///
44   /// \param[in] supported_features
45   ///     The bit flags in this parameter are set depending on which
46   ///     WatchpointHardwareFeature enum values the current target supports.
47   ///     The eWatchpointHardwareFeatureUnknown bit may be set if we
48   ///     don't have specific information about what the remote stub
49   ///     can support, and a reasonablec default will be used.
50   ///
51   /// \param[in] arch
52   ///     The ArchSpec of the current Target.
53   ///
54   /// \return
55   ///     A vector of WatchpointResourceSP's, one per hardware watchpoint
56   ///     register needed.  We may return more WatchpointResources than the
57   ///     target can watch at once; if all resources cannot be set, the
58   ///     watchpoint cannot be set.
59   static std::vector<lldb::WatchpointResourceSP> AtomizeWatchpointRequest(
60       lldb::addr_t addr, size_t size, bool read, bool write,
61       WatchpointHardwareFeature supported_features, ArchSpec &arch);
62 
63 protected:
64   struct Region {
65     lldb::addr_t addr;
66     size_t size;
67   };
68 
69   /// Convert a user's watchpoint request into an array of Regions,
70   /// each of which can be watched by a single hardware watchpoint
71   /// that can watch power-of-2 size & aligned memory regions.
72   ///
73   /// This is the default algorithm if we have no further information;
74   /// most watchpoint implementations can be assumed to be able to watch up
75   /// to sizeof(void*) regions of memory, in power-of-2 sizes and alignments.
76   /// e.g. on a 64-bit target: 1, 2, 4, 8 or bytes with a single hardware
77   /// watchpoint register.
78   ///
79   /// \param[in] user_addr
80   ///     The user's start address.
81   ///
82   /// \param[in] user_size
83   ///     The user's specified byte length.
84   ///
85   /// \param[in] min_byte_size
86   ///     The minimum byte size of the range of memory that can be watched
87   ///     with one watchpoint register.
88   ///     In most cases, this will be 1.  AArch64 MASK watchpoints can
89   ///     watch a minimum of 8 bytes (although Byte Address Select watchpoints
90   ///     can watch 1 to pointer-size bytes in a pointer-size aligned granule).
91   ///
92   /// \param[in] max_byte_size
93   ///     The maximum byte size supported for one watchpoint on this target.
94   ///
95   /// \param[in] address_byte_size
96   ///     The address byte size on this target.
97   static std::vector<Region> PowerOf2Watchpoints(lldb::addr_t user_addr,
98                                                  size_t user_size,
99                                                  size_t min_byte_size,
100                                                  size_t max_byte_size,
101                                                  uint32_t address_byte_size);
102 };
103 
104 } // namespace lldb_private
105 
106 #endif // LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
107