9#if defined(__aarch64__)
24#include <sys/ptrace.h>
36static std::mutex g_register_flags_detector_mutex;
40NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(
42 std::lock_guard<std::mutex> lock(g_register_flags_detector_mutex);
50 return new NativeRegisterContextFreeBSD_arm64(target_arch, native_thread);
53NativeRegisterContextFreeBSD_arm64::NativeRegisterContextFreeBSD_arm64(
57#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
63 GetRegisterInfoInterface().GetRegisterInfo(),
64 GetRegisterInfoInterface().GetRegisterCount());
66 ::memset(&m_hwp_regs, 0,
sizeof(m_hwp_regs));
67 ::memset(&m_hbp_regs, 0,
sizeof(m_hbp_regs));
71NativeRegisterContextFreeBSD_arm64::GetRegisterInfo()
const {
75uint32_t NativeRegisterContextFreeBSD_arm64::GetRegisterSetCount()
const {
80NativeRegisterContextFreeBSD_arm64::GetRegisterSet(uint32_t set_index)
const {
81 return GetRegisterInfo().GetRegisterSet(set_index);
84uint32_t NativeRegisterContextFreeBSD_arm64::GetUserRegisterCount()
const {
86 for (uint32_t set_index = 0; set_index < GetRegisterSetCount(); ++set_index)
91Status NativeRegisterContextFreeBSD_arm64::ReadRegisterSet(uint32_t set) {
94 return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),
97 return NativeProcessFreeBSD::PtraceWrapper(
98 PT_GETFPREGS, m_thread.GetID(),
101 llvm_unreachable(
"NativeRegisterContextFreeBSD_arm64::ReadRegisterSet");
104Status NativeRegisterContextFreeBSD_arm64::WriteRegisterSet(uint32_t set) {
107 return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),
110 return NativeProcessFreeBSD::PtraceWrapper(
111 PT_SETFPREGS, m_thread.GetID(),
114 llvm_unreachable(
"NativeRegisterContextFreeBSD_arm64::WriteRegisterSet");
118NativeRegisterContextFreeBSD_arm64::ReadRegister(
const RegisterInfo *reg_info,
123 error.SetErrorString(
"reg_info NULL");
130 return Status(
"no lldb regnum for %s", reg_info && reg_info->
name
132 :
"<unknown register>");
134 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
135 error = ReadRegisterSet(set);
141 reg_info->
byte_size, endian::InlHostByteOrder());
145Status NativeRegisterContextFreeBSD_arm64::WriteRegister(
150 return Status(
"reg_info NULL");
155 return Status(
"no lldb regnum for %s", reg_info && reg_info->
name
157 :
"<unknown register>");
159 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
160 error = ReadRegisterSet(set);
168 return WriteRegisterSet(set);
171Status NativeRegisterContextFreeBSD_arm64::ReadAllRegisterValues(
184 uint8_t *dst = data_sp->GetBytes();
185 ::memcpy(dst, m_reg_data.data(), m_reg_data.size());
190Status NativeRegisterContextFreeBSD_arm64::WriteAllRegisterValues(
195 error.SetErrorStringWithFormat(
196 "NativeRegisterContextFreeBSD_arm64::%s invalid data_sp provided",
201 if (data_sp->GetByteSize() != m_reg_data.size()) {
202 error.SetErrorStringWithFormat(
203 "NativeRegisterContextFreeBSD_arm64::%s data_sp contained mismatched "
204 "data size, expected %" PRIu64
", actual %" PRIu64,
205 __FUNCTION__, m_reg_data.size(), data_sp->GetByteSize());
209 const uint8_t *src = data_sp->GetBytes();
210 if (src ==
nullptr) {
211 error.SetErrorStringWithFormat(
"NativeRegisterContextFreeBSD_arm64::%s "
212 "DataBuffer::GetBytes() returned a null "
217 ::memcpy(m_reg_data.data(), src, m_reg_data.size());
226llvm::Error NativeRegisterContextFreeBSD_arm64::CopyHardwareWatchpointsFrom(
228#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
229 auto &r_source =
static_cast<NativeRegisterContextFreeBSD_arm64 &
>(source);
230 llvm::Error
error = r_source.ReadHardwareDebugInfo();
234 m_dbreg = r_source.m_dbreg;
235 m_hbp_regs = r_source.m_hbp_regs;
236 m_hwp_regs = r_source.m_hwp_regs;
237 m_max_hbp_supported = r_source.m_max_hbp_supported;
238 m_max_hwp_supported = r_source.m_max_hwp_supported;
242 return WriteHardwareDebugRegs(eDREGTypeWATCH);
244 return llvm::Error::success();
248llvm::Error NativeRegisterContextFreeBSD_arm64::ReadHardwareDebugInfo() {
249#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
254 return llvm::Error::success();
256 Status res = NativeProcessFreeBSD::PtraceWrapper(PT_GETDBREGS,
257 m_thread.GetID(), &m_dbreg);
261 LLDB_LOG(log,
"m_dbreg read: debug_ver={0}, nbkpts={1}, nwtpts={2}",
262 m_dbreg.db_debug_ver, m_dbreg.db_nbkpts, m_dbreg.db_nwtpts);
263 m_max_hbp_supported = m_dbreg.db_nbkpts;
264 m_max_hwp_supported = m_dbreg.db_nwtpts;
265 assert(m_max_hbp_supported <= m_hbp_regs.size());
266 assert(m_max_hwp_supported <= m_hwp_regs.size());
269 return llvm::Error::success();
271 return llvm::createStringError(
272 llvm::inconvertibleErrorCode(),
273 "Hardware breakpoints/watchpoints require FreeBSD 14.0");
278NativeRegisterContextFreeBSD_arm64::WriteHardwareDebugRegs(DREGType) {
279#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
280 assert(m_read_dbreg &&
"dbregs must be read before writing them back");
283 for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
284 m_dbreg.db_breakregs[i].dbr_addr = m_hbp_regs[i].address;
285 m_dbreg.db_breakregs[i].dbr_ctrl = m_hbp_regs[i].control;
287 for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
288 m_dbreg.db_watchregs[i].dbw_addr = m_hwp_regs[i].address;
289 m_dbreg.db_watchregs[i].dbw_ctrl = m_hwp_regs[i].control;
292 return NativeProcessFreeBSD::PtraceWrapper(PT_SETDBREGS, m_thread.GetID(),
296 return llvm::createStringError(
297 llvm::inconvertibleErrorCode(),
298 "Hardware breakpoints/watchpoints require FreeBSD 14.0");
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
@ AUXV_FREEBSD_AT_HWCAP
FreeBSD specific AT_HWCAP value.
@ AUXV_AT_HWCAP2
Extension of AT_HWCAP.
size_t GetRegisterSetCount() const override
An architecture specification class.
This class manages the storage and detection of register field information.
void UpdateRegisterInfo(const RegisterInfo *reg_info, uint32_t num_regs)
Add the field information of any registers named in this class, to the relevant RegisterInfo instance...
void DetectFields(uint64_t hwcap, uint64_t hwcap2)
For the registers listed in this class, detect which fields are present.
bool HasDetected() const
Returns true if field detection has been run at least once.
A subclass of DataBuffer that stores a data buffer on the heap.
std::optional< uint64_t > GetAuxValue(enum AuxVector::EntryType type)
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
const void * GetBytes() const
llvm::Error ToError() const
bool Fail() const
Test for error condition.
Manages communication with the inferior (debugee) process.
NativeProcessFreeBSD & GetProcess()
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const char * name
Name of this register, can't be NULL.
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.