109 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef lldb_NativeRegisterContextDBReg_h10#define lldb_NativeRegisterContextDBReg_h11 12#include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"13 14#include <array>15#include <optional>16 17// Common utilities for hardware breakpoints and hardware watchpoints on AArch6418// and LoongArch.19 20namespace lldb_private {21 22class NativeRegisterContextDBReg23 : public virtual NativeRegisterContextRegisterInfo {24public:25 explicit NativeRegisterContextDBReg(uint32_t enable_bit)26 : m_hw_dbg_enable_bit(enable_bit) {}27 28 uint32_t NumSupportedHardwareBreakpoints() override;29 30 uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;31 32 bool ClearHardwareBreakpoint(uint32_t hw_idx) override;33 34 Status ClearAllHardwareBreakpoints() override;35 36 Status GetHardwareBreakHitIndex(uint32_t &bp_index,37 lldb::addr_t trap_addr) override;38 39 uint32_t NumSupportedHardwareWatchpoints() override;40 41 uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,42 uint32_t watch_flags) override;43 44 bool ClearHardwareWatchpoint(uint32_t hw_index) override;45 46 Status ClearAllHardwareWatchpoints() override;47 48 Status GetWatchpointHitIndex(uint32_t &wp_index,49 lldb::addr_t trap_addr) override;50 51 lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index) override;52 53 lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;54 55 // Debug register type select56 enum DREGType { eDREGTypeWATCH = 0, eDREGTypeBREAK };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 exception62 // 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 67protected:68 std::array<struct DREG, 16> m_hbp_regs; // hardware breakpoints69 std::array<struct DREG, 16> m_hwp_regs; // hardware watchpoints70 71 uint32_t m_max_hbp_supported;72 uint32_t m_max_hwp_supported;73 const uint32_t m_hw_dbg_enable_bit;74 75 bool WatchpointIsEnabled(uint32_t wp_index);76 bool BreakpointIsEnabled(uint32_t bp_index);77 78 // On AArch64 and Loongarch the hardware breakpoint length size is 4, and the79 // target address must 4-byte alignment.80 virtual bool ValidateBreakpoint(size_t size, lldb::addr_t addr) {81 return (size == 4) && !(addr & 0x3);82 }83 84 struct WatchpointDetails {85 size_t size;86 lldb::addr_t addr;87 };88 virtual std::optional<WatchpointDetails>89 AdjustWatchpoint(const WatchpointDetails &details) = 0;90 91 using BreakpointDetails = WatchpointDetails;92 virtual BreakpointDetails AdjustBreakpoint(const BreakpointDetails &details) {93 return details;94 }95 96 virtual uint32_t MakeBreakControlValue(size_t size) = 0;97 virtual uint32_t MakeWatchControlValue(size_t size, uint32_t watch_flags) = 0;98 virtual uint32_t GetWatchpointSize(uint32_t wp_index) = 0;99 virtual llvm::Error ReadHardwareDebugInfo() = 0;100 virtual llvm::Error WriteHardwareDebugRegs(DREGType hwbType) = 0;101 virtual lldb::addr_t FixWatchpointHitAddress(lldb::addr_t hit_addr) {102 return hit_addr;103 }104};105 106} // namespace lldb_private107 108#endif // #ifndef lldb_NativeRegisterContextDBReg_h109