Skip to content

Commit

Permalink
RegisterInfoPOSIX_arm64 remove unused bytes from g/G packet
Browse files Browse the repository at this point in the history
This came up while putting together our new strategy to create g/G packets
in compliance with GDB RSP protocol where register offsets are calculated in
increasing order of register numbers without any unused spacing.

RegisterInfoPOSIX_arm64::GPR size was being calculated after alignment
correction to 8 bytes which meant there was a 4 bytes unused space between
last gpr (cpsr) and first vector register V. We have put LLVM_PACKED_START
decorator on RegisterInfoPOSIX_arm64::GPR to make sure single byte
alignment is enforced. Moreover we are now doing to use arm64 user_pt_regs
struct defined in ptrace.h for accessing ptrace user registers.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92063
  • Loading branch information
omjavaid committed Dec 1, 2020
1 parent 1b8ed1d commit 26b8ea2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Expand Up @@ -936,9 +936,9 @@ Status NativeRegisterContextLinux_arm64::ReadGPR() {

struct iovec ioVec;
ioVec.iov_base = GetGPRBuffer();
ioVec.iov_len = GetGPRSize();
ioVec.iov_len = GetGPRBufferSize();

error = ReadRegisterSet(&ioVec, GetGPRSize(), NT_PRSTATUS);
error = ReadRegisterSet(&ioVec, GetGPRBufferSize(), NT_PRSTATUS);

if (error.Success())
m_gpr_is_valid = true;
Expand All @@ -953,11 +953,11 @@ Status NativeRegisterContextLinux_arm64::WriteGPR() {

struct iovec ioVec;
ioVec.iov_base = GetGPRBuffer();
ioVec.iov_len = GetGPRSize();
ioVec.iov_len = GetGPRBufferSize();

m_gpr_is_valid = false;

return WriteRegisterSet(&ioVec, GetGPRSize(), NT_PRSTATUS);
return WriteRegisterSet(&ioVec, GetGPRBufferSize(), NT_PRSTATUS);
}

Status NativeRegisterContextLinux_arm64::ReadFPR() {
Expand Down
Expand Up @@ -95,6 +95,10 @@ class NativeRegisterContextLinux_arm64 : public NativeRegisterContextLinux {

void *GetGPRBuffer() override { return &m_gpr_arm64; }

// GetGPRBufferSize returns sizeof arm64 GPR ptrace buffer, it is different
// from GetGPRSize which returns sizeof RegisterInfoPOSIX_arm64::GPR.
size_t GetGPRBufferSize() { return sizeof(m_gpr_arm64); }

void *GetFPRBuffer() override { return &m_fpr; }

size_t GetFPRSize() override { return sizeof(m_fpr); }
Expand All @@ -106,7 +110,7 @@ class NativeRegisterContextLinux_arm64 : public NativeRegisterContextLinux {

bool m_sve_header_is_valid;

RegisterInfoPOSIX_arm64::GPR m_gpr_arm64; // 64-bit general purpose registers.
struct user_pt_regs m_gpr_arm64; // 64-bit general purpose registers.

RegisterInfoPOSIX_arm64::FPU
m_fpr; // floating-point registers including extended register sets.
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
Expand Up @@ -29,6 +29,7 @@ class RegisterInfoPOSIX_arm64
};

// based on RegisterContextDarwin_arm64.h
LLVM_PACKED_START
struct GPR {
uint64_t x[29]; // x0-x28
uint64_t fp; // x29
Expand All @@ -37,6 +38,7 @@ class RegisterInfoPOSIX_arm64
uint64_t pc; // pc
uint32_t cpsr; // cpsr
};
LLVM_PACKED_END

// based on RegisterContextDarwin_arm64.h
struct VReg {
Expand Down

0 comments on commit 26b8ea2

Please sign in to comment.