LLDB mainline
NativeRegisterContextDBReg.h
Go to the documentation of this file.
1//===-- NativeRegisterContextDBReg.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_h
10#define lldb_NativeRegisterContextDBReg_h
11
13
14#include <array>
15
16// Common utilities for hardware breakpoints and hardware watchpoints on AArch64
17// and LoongArch.
18
19namespace lldb_private {
20
22 : public virtual NativeRegisterContextRegisterInfo {
23public:
24 explicit NativeRegisterContextDBReg(uint32_t enable_bit)
25 : m_hw_dbg_enable_bit(enable_bit) {}
26
27 uint32_t NumSupportedHardwareBreakpoints() override;
28
29 uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
30
31 bool ClearHardwareBreakpoint(uint32_t hw_idx) override;
32
34
35 Status GetHardwareBreakHitIndex(uint32_t &bp_index,
36 lldb::addr_t trap_addr) override;
37
38 uint32_t NumSupportedHardwareWatchpoints() override;
39
40 uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
41 uint32_t watch_flags) override;
42
43 bool ClearHardwareWatchpoint(uint32_t hw_index) override;
44
46
47 Status GetWatchpointHitIndex(uint32_t &wp_index,
48 lldb::addr_t trap_addr) override;
49
50 lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;
51
52 lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
53
54protected:
55 // Debug register type select
57
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
72 const uint32_t m_hw_dbg_enable_bit;
73
74 bool WatchpointIsEnabled(uint32_t wp_index);
75 bool BreakpointIsEnabled(uint32_t bp_index);
76
77 // On AArch64 and Loongarch the hardware breakpoint length size is 4, and the
78 // target address must 4-byte alignment.
79 bool ValidateBreakpoint(size_t size, lldb::addr_t addr) {
80 return (size == 4) && !(addr & 0x3);
81 }
83 size_t size;
85 };
86 virtual std::optional<WatchpointDetails>
88 virtual uint32_t MakeBreakControlValue(size_t size) = 0;
89 virtual uint32_t MakeWatchControlValue(size_t size, uint32_t watch_flags) = 0;
90 virtual uint32_t GetWatchpointSize(uint32_t wp_index) = 0;
91
92 virtual llvm::Error ReadHardwareDebugInfo() = 0;
93 virtual llvm::Error WriteHardwareDebugRegs(DREGType hwbType) = 0;
95 return hit_addr;
96 }
97};
98
99} // namespace lldb_private
100
101#endif // #ifndef lldb_NativeRegisterContextDBReg_h
virtual lldb::addr_t FixWatchpointHitAddress(lldb::addr_t hit_addr)
bool ClearHardwareWatchpoint(uint32_t hw_index) override
virtual llvm::Error WriteHardwareDebugRegs(DREGType hwbType)=0
Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr) override
virtual llvm::Error ReadHardwareDebugInfo()=0
lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override
bool ValidateBreakpoint(size_t size, lldb::addr_t addr)
virtual uint32_t MakeWatchControlValue(size_t size, uint32_t watch_flags)=0
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags) override
virtual std::optional< WatchpointDetails > AdjustWatchpoint(const WatchpointDetails &details)=0
virtual uint32_t MakeBreakControlValue(size_t size)=0
virtual uint32_t GetWatchpointSize(uint32_t wp_index)=0
bool ClearHardwareBreakpoint(uint32_t hw_idx) override
uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override
Status GetHardwareBreakHitIndex(uint32_t &bp_index, lldb::addr_t trap_addr) override
lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override
An error handling class.
Definition: Status.h:118
A class that represents a running process on the host machine.
uint64_t addr_t
Definition: lldb-types.h:80
Debug register info for hardware breakpoints and watchpoints management.