9#if defined(__aarch64__)
23#include <sys/ptrace.h>
32NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(
34 return new NativeRegisterContextFreeBSD_arm64(target_arch, native_thread);
37NativeRegisterContextFreeBSD_arm64::NativeRegisterContextFreeBSD_arm64(
41#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
46 ::memset(&m_hwp_regs, 0,
sizeof(m_hwp_regs));
47 ::memset(&m_hbp_regs, 0,
sizeof(m_hbp_regs));
51NativeRegisterContextFreeBSD_arm64::GetRegisterInfo()
const {
55uint32_t NativeRegisterContextFreeBSD_arm64::GetRegisterSetCount()
const {
60NativeRegisterContextFreeBSD_arm64::GetRegisterSet(uint32_t set_index)
const {
61 return GetRegisterInfo().GetRegisterSet(set_index);
64uint32_t NativeRegisterContextFreeBSD_arm64::GetUserRegisterCount()
const {
66 for (uint32_t set_index = 0; set_index < GetRegisterSetCount(); ++set_index)
71Status NativeRegisterContextFreeBSD_arm64::ReadRegisterSet(uint32_t set) {
74 return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),
77 return NativeProcessFreeBSD::PtraceWrapper(
78 PT_GETFPREGS, m_thread.GetID(),
81 llvm_unreachable(
"NativeRegisterContextFreeBSD_arm64::ReadRegisterSet");
84Status NativeRegisterContextFreeBSD_arm64::WriteRegisterSet(uint32_t set) {
87 return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),
90 return NativeProcessFreeBSD::PtraceWrapper(
91 PT_SETFPREGS, m_thread.GetID(),
94 llvm_unreachable(
"NativeRegisterContextFreeBSD_arm64::WriteRegisterSet");
98NativeRegisterContextFreeBSD_arm64::ReadRegister(
const RegisterInfo *reg_info,
103 error.SetErrorString(
"reg_info NULL");
110 return Status(
"no lldb regnum for %s", reg_info && reg_info->
name
112 :
"<unknown register>");
114 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
115 error = ReadRegisterSet(set);
121 reg_info->
byte_size, endian::InlHostByteOrder());
125Status NativeRegisterContextFreeBSD_arm64::WriteRegister(
130 return Status(
"reg_info NULL");
135 return Status(
"no lldb regnum for %s", reg_info && reg_info->
name
137 :
"<unknown register>");
139 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
140 error = ReadRegisterSet(set);
148 return WriteRegisterSet(set);
151Status NativeRegisterContextFreeBSD_arm64::ReadAllRegisterValues(
164 uint8_t *dst = data_sp->GetBytes();
165 ::memcpy(dst, m_reg_data.data(), m_reg_data.size());
170Status NativeRegisterContextFreeBSD_arm64::WriteAllRegisterValues(
175 error.SetErrorStringWithFormat(
176 "NativeRegisterContextFreeBSD_arm64::%s invalid data_sp provided",
181 if (data_sp->GetByteSize() != m_reg_data.size()) {
182 error.SetErrorStringWithFormat(
183 "NativeRegisterContextFreeBSD_arm64::%s data_sp contained mismatched "
184 "data size, expected %" PRIu64
", actual %" PRIu64,
185 __FUNCTION__, m_reg_data.size(), data_sp->GetByteSize());
189 const uint8_t *src = data_sp->GetBytes();
190 if (src ==
nullptr) {
191 error.SetErrorStringWithFormat(
"NativeRegisterContextFreeBSD_arm64::%s "
192 "DataBuffer::GetBytes() returned a null "
197 ::memcpy(m_reg_data.data(), src, m_reg_data.size());
206llvm::Error NativeRegisterContextFreeBSD_arm64::CopyHardwareWatchpointsFrom(
208#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
209 auto &r_source =
static_cast<NativeRegisterContextFreeBSD_arm64 &
>(source);
210 llvm::Error
error = r_source.ReadHardwareDebugInfo();
214 m_dbreg = r_source.m_dbreg;
215 m_hbp_regs = r_source.m_hbp_regs;
216 m_hwp_regs = r_source.m_hwp_regs;
217 m_max_hbp_supported = r_source.m_max_hbp_supported;
218 m_max_hwp_supported = r_source.m_max_hwp_supported;
222 return WriteHardwareDebugRegs(eDREGTypeWATCH);
224 return llvm::Error::success();
228llvm::Error NativeRegisterContextFreeBSD_arm64::ReadHardwareDebugInfo() {
229#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
234 return llvm::Error::success();
236 Status res = NativeProcessFreeBSD::PtraceWrapper(PT_GETDBREGS,
237 m_thread.GetID(), &m_dbreg);
241 LLDB_LOG(log,
"m_dbreg read: debug_ver={0}, nbkpts={1}, nwtpts={2}",
242 m_dbreg.db_debug_ver, m_dbreg.db_nbkpts, m_dbreg.db_nwtpts);
243 m_max_hbp_supported = m_dbreg.db_nbkpts;
244 m_max_hwp_supported = m_dbreg.db_nwtpts;
245 assert(m_max_hbp_supported <= m_hbp_regs.size());
246 assert(m_max_hwp_supported <= m_hwp_regs.size());
249 return llvm::Error::success();
251 return llvm::createStringError(
252 llvm::inconvertibleErrorCode(),
253 "Hardware breakpoints/watchpoints require FreeBSD 14.0");
258NativeRegisterContextFreeBSD_arm64::WriteHardwareDebugRegs(DREGType) {
259#ifdef LLDB_HAS_FREEBSD_WATCHPOINT
260 assert(m_read_dbreg &&
"dbregs must be read before writing them back");
263 for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
264 m_dbreg.db_breakregs[i].dbr_addr = m_hbp_regs[i].address;
265 m_dbreg.db_breakregs[i].dbr_ctrl = m_hbp_regs[i].control;
267 for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
268 m_dbreg.db_watchregs[i].dbw_addr = m_hwp_regs[i].address;
269 m_dbreg.db_watchregs[i].dbw_ctrl = m_hwp_regs[i].control;
272 return NativeProcessFreeBSD::PtraceWrapper(PT_SETDBREGS, m_thread.GetID(),
276 return llvm::createStringError(
277 llvm::inconvertibleErrorCode(),
278 "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.
size_t GetRegisterSetCount() const override
An architecture specification class.
A subclass of DataBuffer that stores a data buffer on the heap.
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.
#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.