[Lldb-commits] [lldb] r363923 - [lldb] [Process/NetBSD] Remove unnecessary register buffer abstraction
Michal Gorny via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 20 05:44:37 PDT 2019
Author: mgorny
Date: Thu Jun 20 05:44:37 2019
New Revision: 363923
URL: http://llvm.org/viewvc/llvm-project?rev=363923&view=rev
Log:
[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
Modified:
lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp?rev=363923&r1=363922&r2=363923&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp Thu Jun 20 05:44:37 2019
@@ -24,81 +24,8 @@ NativeRegisterContextNetBSD::NativeRegis
: 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());
}
Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h?rev=363923&r1=363922&r2=363923&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h Thu Jun 20 05:44:37 2019
@@ -32,35 +32,7 @@ public:
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();
};
Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp?rev=363923&r1=363922&r2=363923&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp Thu Jun 20 05:44:37 2019
@@ -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,11 +162,11 @@ int NativeRegisterContextNetBSD_x86_64::
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");
}
@@ -173,11 +174,11 @@ Status NativeRegisterContextNetBSD_x86_6
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_6
return error;
}
- error = ReadGPR();
+ error = ReadRegisterSet(GPRegSet);
if (error.Fail())
return error;
@@ -630,7 +631,7 @@ Status NativeRegisterContextNetBSD_x86_6
}
::memcpy(&m_gpr_x86_64, src, GetRegisterInfoInterface().GetGPRSize());
- error = WriteGPR();
+ error = WriteRegisterSet(GPRegSet);
if (error.Fail())
return error;
src += GetRegisterInfoInterface().GetGPRSize();
Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h?rev=363923&r1=363922&r2=363923&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h Thu Jun 20 05:44:37 2019
@@ -66,11 +66,6 @@ public:
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 };
More information about the lldb-commits
mailing list