1 //===-- NativeRegisterContextDBReg_arm64.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_NativeRegisterContextDBReg_arm64_h
10 #define lldb_NativeRegisterContextDBReg_arm64_h
11 
12 #include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
13 
14 #include <array>
15 
16 namespace lldb_private {
17 
18 class NativeRegisterContextDBReg_arm64
19     : public virtual NativeRegisterContextRegisterInfo {
20 public:
21   uint32_t NumSupportedHardwareBreakpoints() override;
22 
23   uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
24 
25   bool ClearHardwareBreakpoint(uint32_t hw_idx) override;
26 
27   Status ClearAllHardwareBreakpoints() override;
28 
29   Status GetHardwareBreakHitIndex(uint32_t &bp_index,
30                                   lldb::addr_t trap_addr) override;
31 
32   bool BreakpointIsEnabled(uint32_t bp_index);
33 
34   uint32_t NumSupportedHardwareWatchpoints() override;
35 
36   uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
37                                  uint32_t watch_flags) override;
38 
39   bool ClearHardwareWatchpoint(uint32_t hw_index) override;
40 
41   Status ClearAllHardwareWatchpoints() override;
42 
43   Status GetWatchpointHitIndex(uint32_t &wp_index,
44                                lldb::addr_t trap_addr) override;
45 
46   lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
47 
48   lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
49 
50   uint32_t GetWatchpointSize(uint32_t wp_index);
51 
52   bool WatchpointIsEnabled(uint32_t wp_index);
53 
54   // Debug register type select
55   enum DREGType { eDREGTypeWATCH = 0, eDREGTypeBREAK };
56 
57 protected:
58   // Debug register info for hardware breakpoints and watchpoints management.
59   struct DREG {
60     lldb::addr_t address;  // Breakpoint/watchpoint address value.
61     lldb::addr_t hit_addr; // Address at which last watchpoint trigger exception
62                            // occurred.
63     lldb::addr_t real_addr; // Address value that should cause target to stop.
64     uint32_t control;       // Breakpoint/watchpoint control value.
65   };
66 
67   std::array<struct DREG, 16> m_hbp_regs; // hardware breakpoints
68   std::array<struct DREG, 16> m_hwp_regs; // hardware watchpoints
69 
70   uint32_t m_max_hbp_supported;
71   uint32_t m_max_hwp_supported;
72 
73   virtual llvm::Error ReadHardwareDebugInfo() = 0;
74   virtual llvm::Error WriteHardwareDebugRegs(DREGType hwbType) = 0;
FixWatchpointHitAddress(lldb::addr_t hit_addr)75   virtual lldb::addr_t FixWatchpointHitAddress(lldb::addr_t hit_addr) {
76     return hit_addr;
77   }
78 };
79 
80 } // namespace lldb_private
81 
82 #endif // #ifndef lldb_NativeRegisterContextDBReg_arm64_h
83