Skip to content
Permalink
Browse files

[lldb] [Process/NetBSD] Remove unnecessary register buffer abstraction

Remove most of the abstraction over ptrace() register operations,
as it has little value and introduces more code than it saves.
Instead, leave a single ptrace() wrapper method and call it directly
from ReadRegisterSet() and WriteRegisterSet() with correct PT_* request
and buffer.

Remove the remaining direct ReadGPR() and WriteGPR() invocations
with ReadRegisterSet() and WriteRegisterSet().

Cleanup suggested by Pavel Labath in D63545.

Differential Revision: https://reviews.llvm.org/D63594

llvm-svn: 363923
  • Loading branch information...
mgorny committed Jun 20, 2019
1 parent a4d705e commit d687fa7d023ab897d2ced58555f9f480f26d72a2
@@ -24,81 +24,8 @@ NativeRegisterContextNetBSD::NativeRegisterContextNetBSD(
: NativeRegisterContextRegisterInfo(native_thread,
reg_info_interface_p) {}

Status NativeRegisterContextNetBSD::ReadGPR() {
void *buf = GetGPRBuffer();
if (!buf)
return Status("GPR buffer is NULL");

return DoReadGPR(buf);
}

Status NativeRegisterContextNetBSD::WriteGPR() {
void *buf = GetGPRBuffer();
if (!buf)
return Status("GPR buffer is NULL");

return DoWriteGPR(buf);
}

Status NativeRegisterContextNetBSD::ReadFPR() {
void *buf = GetFPRBuffer();
if (!buf)
return Status("FPR buffer is NULL");

return DoReadFPR(buf);
}

Status NativeRegisterContextNetBSD::WriteFPR() {
void *buf = GetFPRBuffer();
if (!buf)
return Status("FPR buffer is NULL");

return DoWriteFPR(buf);
}

Status NativeRegisterContextNetBSD::ReadDBR() {
void *buf = GetDBRBuffer();
if (!buf)
return Status("DBR buffer is NULL");

return DoReadDBR(buf);
}

Status NativeRegisterContextNetBSD::WriteDBR() {
void *buf = GetDBRBuffer();
if (!buf)
return Status("DBR buffer is NULL");

return DoWriteDBR(buf);
}

Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
m_thread.GetID());
}

Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
m_thread.GetID());
}

Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
m_thread.GetID());
}

Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
m_thread.GetID());
}

Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf,
m_thread.GetID());
}

Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf,
Status NativeRegisterContextNetBSD::DoRegisterSet(int ptrace_req, void *buf) {
return NativeProcessNetBSD::PtraceWrapper(ptrace_req, GetProcessPid(), buf,
m_thread.GetID());
}

@@ -32,35 +32,7 @@ class NativeRegisterContextNetBSD : public NativeRegisterContextRegisterInfo {
NativeThreadProtocol &native_thread);

protected:
virtual Status ReadGPR();
virtual Status WriteGPR();

virtual Status ReadFPR();
virtual Status WriteFPR();

virtual Status ReadDBR();
virtual Status WriteDBR();

virtual void *GetGPRBuffer() { return nullptr; }
virtual size_t GetGPRSize() {
return GetRegisterInfoInterface().GetGPRSize();
}

virtual void *GetFPRBuffer() { return nullptr; }
virtual size_t GetFPRSize() { return 0; }

virtual void *GetDBRBuffer() { return nullptr; }
virtual size_t GetDBRSize() { return 0; }

virtual Status DoReadGPR(void *buf);
virtual Status DoWriteGPR(void *buf);

virtual Status DoReadFPR(void *buf);
virtual Status DoWriteFPR(void *buf);

virtual Status DoReadDBR(void *buf);
virtual Status DoWriteDBR(void *buf);

Status DoRegisterSet(int req, void *buf);
virtual NativeProcessNetBSD &GetProcess();
virtual ::pid_t GetProcessPid();
};
@@ -20,6 +20,7 @@

// clang-format off
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/sysctl.h>
#include <x86/cpu.h>
#include <elf.h>
@@ -161,23 +162,23 @@ int NativeRegisterContextNetBSD_x86_64::GetSetForNativeRegNum(
Status NativeRegisterContextNetBSD_x86_64::ReadRegisterSet(uint32_t set) {
switch (set) {
case GPRegSet:
return ReadGPR();
return DoRegisterSet(PT_GETREGS, &m_gpr_x86_64);
case FPRegSet:
return ReadFPR();
return DoRegisterSet(PT_GETFPREGS, &m_fpr_x86_64);
case DBRegSet:
return ReadDBR();
return DoRegisterSet(PT_GETDBREGS, &m_dbr_x86_64);
}
llvm_unreachable("NativeRegisterContextNetBSD_x86_64::ReadRegisterSet");
}

Status NativeRegisterContextNetBSD_x86_64::WriteRegisterSet(uint32_t set) {
switch (set) {
case GPRegSet:
return WriteGPR();
return DoRegisterSet(PT_SETREGS, &m_gpr_x86_64);
case FPRegSet:
return WriteFPR();
return DoRegisterSet(PT_SETFPREGS, &m_fpr_x86_64);
case DBRegSet:
return WriteDBR();
return DoRegisterSet(PT_SETDBREGS, &m_dbr_x86_64);
}
llvm_unreachable("NativeRegisterContextNetBSD_x86_64::WriteRegisterSet");
}
@@ -578,7 +579,7 @@ Status NativeRegisterContextNetBSD_x86_64::ReadAllRegisterValues(
return error;
}

error = ReadGPR();
error = ReadRegisterSet(GPRegSet);
if (error.Fail())
return error;

@@ -630,7 +631,7 @@ Status NativeRegisterContextNetBSD_x86_64::WriteAllRegisterValues(
}
::memcpy(&m_gpr_x86_64, src, GetRegisterInfoInterface().GetGPRSize());

error = WriteGPR();
error = WriteRegisterSet(GPRegSet);
if (error.Fail())
return error;
src += GetRegisterInfoInterface().GetGPRSize();
@@ -66,11 +66,6 @@ class NativeRegisterContextNetBSD_x86_64 : public NativeRegisterContextNetBSD {

uint32_t NumSupportedHardwareWatchpoints() override;

protected:
void *GetGPRBuffer() override { return &m_gpr_x86_64; }
void *GetFPRBuffer() override { return &m_fpr_x86_64; }
void *GetDBRBuffer() override { return &m_dbr_x86_64; }

private:
// Private member types.
enum { GPRegSet, FPRegSet, DBRegSet };

0 comments on commit d687fa7

Please sign in to comment.
You can’t perform that action at this time.