9#if defined(__loongarch__) && __loongarch_grlen == 64
29#define REG_CONTEXT_SIZE (GetGPRSize() + GetFPRSize())
35std::unique_ptr<NativeRegisterContextLinux>
36NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
39 case llvm::Triple::loongarch64: {
41 auto register_info_up = std::make_unique<RegisterInfoPOSIX_loongarch64>(
42 target_arch, opt_regsets);
43 return std::make_unique<NativeRegisterContextLinux_loongarch64>(
44 target_arch, native_thread, std::move(register_info_up));
47 llvm_unreachable(
"have no register context for architecture");
51llvm::Expected<ArchSpec>
52NativeRegisterContextLinux::DetermineArchitecture(
lldb::tid_t tid) {
53 return HostInfo::GetArchitecture();
56NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
58 std::unique_ptr<RegisterInfoPOSIX_loongarch64> register_info_up)
60 register_info_up.release()),
62 ::memset(&m_fpr, 0,
sizeof(m_fpr));
63 ::memset(&m_gpr, 0,
sizeof(m_gpr));
65 m_gpr_is_valid =
false;
66 m_fpu_is_valid =
false;
70NativeRegisterContextLinux_loongarch64::GetRegisterInfo()
const {
72 NativeRegisterContextRegisterInfo::GetRegisterInfoInterface());
75uint32_t NativeRegisterContextLinux_loongarch64::GetRegisterSetCount()
const {
79const RegisterSet *NativeRegisterContextLinux_loongarch64::GetRegisterSet(
80 uint32_t set_index)
const {
81 return GetRegisterInfo().GetRegisterSet(set_index);
84uint32_t NativeRegisterContextLinux_loongarch64::GetUserRegisterCount()
const {
86 for (uint32_t set_index = 0; set_index < GetRegisterSetCount(); ++set_index)
91Status NativeRegisterContextLinux_loongarch64::ReadRegister(
96 error.SetErrorString(
"reg_info NULL");
103 return Status(
"no lldb regnum for %s", reg_info && reg_info->
name
105 :
"<unknown register>");
107 uint8_t *src =
nullptr;
116 assert(offset < GetGPRSize());
117 src = (uint8_t *)GetGPRBuffer() + offset;
119 }
else if (IsFPR(reg)) {
124 offset = CalculateFprOffset(reg_info);
125 assert(offset < GetFPRSize());
126 src = (uint8_t *)GetFPRBuffer() + offset;
128 return Status(
"failed - register wasn't recognized to be a GPR or an FPR, "
129 "write strategy unknown");
132 eByteOrderLittle,
error);
137Status NativeRegisterContextLinux_loongarch64::WriteRegister(
142 return Status(
"reg_info NULL");
147 return Status(
"no lldb regnum for %s", reg_info->
name !=
nullptr
149 :
"<unknown register>");
151 uint8_t *dst =
nullptr;
160 dst = (uint8_t *)GetGPRBuffer() + reg_info->
byte_offset;
164 }
else if (IsFPR(reg)) {
169 offset = CalculateFprOffset(reg_info);
170 assert(offset < GetFPRSize());
171 dst = (uint8_t *)GetFPRBuffer() + offset;
177 return Status(
"Failed to write register value");
180Status NativeRegisterContextLinux_loongarch64::ReadAllRegisterValues(
194 uint8_t *dst = data_sp->GetBytes();
195 ::memcpy(dst, GetGPRBuffer(), GetGPRSize());
197 ::memcpy(dst, GetFPRBuffer(), GetFPRSize());
202Status NativeRegisterContextLinux_loongarch64::WriteAllRegisterValues(
207 error.SetErrorStringWithFormat(
208 "NativeRegisterContextLinux_loongarch64::%s invalid data_sp provided",
214 error.SetErrorStringWithFormat(
215 "NativeRegisterContextLinux_loongarch64::%s data_sp contained "
216 "mismatched data size, expected %" PRIu64
", actual %" PRIu64,
221 const uint8_t *src = data_sp->GetBytes();
222 if (src ==
nullptr) {
223 error.SetErrorStringWithFormat(
"NativeRegisterContextLinux_loongarch64::%s "
224 "DataBuffer::GetBytes() returned a null "
229 ::memcpy(GetGPRBuffer(), src, GetRegisterInfoInterface().GetGPRSize());
235 src += GetRegisterInfoInterface().GetGPRSize();
236 ::memcpy(GetFPRBuffer(), src, GetFPRSize());
245bool NativeRegisterContextLinux_loongarch64::IsGPR(
unsigned reg)
const {
246 return GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg) ==
250bool NativeRegisterContextLinux_loongarch64::IsFPR(
unsigned reg)
const {
251 return GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg) ==
255Status NativeRegisterContextLinux_loongarch64::ReadGPR() {
262 ioVec.iov_base = GetGPRBuffer();
263 ioVec.iov_len = GetGPRSize();
265 error = ReadRegisterSet(&ioVec, GetGPRSize(), NT_PRSTATUS);
268 m_gpr_is_valid =
true;
273Status NativeRegisterContextLinux_loongarch64::WriteGPR() {
279 ioVec.iov_base = GetGPRBuffer();
280 ioVec.iov_len = GetGPRSize();
282 m_gpr_is_valid =
false;
284 return WriteRegisterSet(&ioVec, GetGPRSize(), NT_PRSTATUS);
287Status NativeRegisterContextLinux_loongarch64::ReadFPR() {
294 ioVec.iov_base = GetFPRBuffer();
295 ioVec.iov_len = GetFPRSize();
297 error = ReadRegisterSet(&ioVec, GetFPRSize(), NT_FPREGSET);
300 m_fpu_is_valid =
true;
305Status NativeRegisterContextLinux_loongarch64::WriteFPR() {
311 ioVec.iov_base = GetFPRBuffer();
312 ioVec.iov_len = GetFPRSize();
314 m_fpu_is_valid =
false;
316 return WriteRegisterSet(&ioVec, GetFPRSize(), NT_FPREGSET);
319void NativeRegisterContextLinux_loongarch64::InvalidateAllRegisters() {
320 m_gpr_is_valid =
false;
321 m_fpu_is_valid =
false;
324uint32_t NativeRegisterContextLinux_loongarch64::CalculateFprOffset(
330NativeRegisterContextLinux_loongarch64::GetExpeditedRegisters(
332 std::vector<uint32_t> expedited_reg_nums =
333 NativeRegisterContext::GetExpeditedRegisters(expType);
335 return expedited_reg_nums;
static llvm::raw_ostream & error(Stream &strm)
size_t GetRegisterSetCount() const override
An architecture specification class.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
A subclass of DataBuffer that stores a data buffer on the heap.
uint32_t SetFromMemoryData(const RegisterInfo ®_info, const void *src, uint32_t src_len, lldb::ByteOrder src_byte_order, Status &error)
const void * GetBytes() const
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
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.