mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-10 11:23:52 +00:00
Remove code duplication from RegisterContextPOSIX_*
Summary: This patch aims to remove multiple copies of GetByteOrder() and ConvertRegisterKindToRegisterNumber used in various versions of RegisterContextPOSIX_*. Both register implementations are move to RegisterContext class which is parent of RegisterContextPOSIX_* classes. Built and tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabihf targets. Reviewers: labath Reviewed By: labath Subscribers: wuzish, nemanjai, kristof.beyls, kbarton, atanasyan, lldb-commits Differential Revision: https://reviews.llvm.org/D80104
This commit is contained in:
parent
9d8d0646d7
commit
6c45532908
@ -39,6 +39,8 @@ public:
|
||||
|
||||
virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0;
|
||||
|
||||
virtual lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadRegister(const RegisterInfo *reg_info,
|
||||
RegisterValue ®_value) = 0;
|
||||
|
||||
@ -105,7 +107,7 @@ public:
|
||||
/// The equivalent register number in the eRegisterKindLLDB
|
||||
/// numbering scheme, if possible, else LLDB_INVALID_REGNUM.
|
||||
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) = 0;
|
||||
uint32_t num);
|
||||
|
||||
// Subclasses can override these functions if desired
|
||||
virtual uint32_t NumSupportedHardwareBreakpoints();
|
||||
|
@ -178,35 +178,6 @@ const char *RegisterContextPOSIX_arm::GetRegisterName(unsigned reg) {
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_arm::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
|
||||
lldb_private::Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_arm::IsRegisterSetAvailable(size_t set_index) {
|
||||
return set_index < k_num_register_sets;
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_arm::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < lldb::kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const lldb_private::RegisterInfo *reg_info =
|
||||
GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -44,9 +44,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
protected:
|
||||
struct RegInfo {
|
||||
uint32_t num_registers;
|
||||
@ -95,8 +92,6 @@ protected:
|
||||
|
||||
bool IsFPR(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadGPR() = 0;
|
||||
virtual bool ReadFPR() = 0;
|
||||
virtual bool WriteGPR() = 0;
|
||||
|
@ -180,6 +180,10 @@ size_t RegisterContextPOSIX_arm64::GetRegisterSetCount() {
|
||||
return sets;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_arm64::IsRegisterSetAvailable(size_t set_index) {
|
||||
return set_index < k_num_register_sets;
|
||||
}
|
||||
|
||||
const lldb_private::RegisterSet *
|
||||
RegisterContextPOSIX_arm64::GetRegisterSet(size_t set) {
|
||||
if (IsRegisterSetAvailable(set)) {
|
||||
@ -199,36 +203,3 @@ const char *RegisterContextPOSIX_arm64::GetRegisterName(unsigned reg) {
|
||||
assert(reg < m_reg_info.num_registers && "Invalid register offset.");
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_arm64::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
|
||||
lldb_private::Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_arm64::IsRegisterSetAvailable(size_t set_index) {
|
||||
return set_index < k_num_register_sets;
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_arm64::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < lldb::kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const lldb_private::RegisterInfo *reg_info =
|
||||
GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -44,9 +44,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
protected:
|
||||
struct RegInfo {
|
||||
uint32_t num_registers;
|
||||
@ -95,8 +92,6 @@ protected:
|
||||
|
||||
bool IsFPR(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadGPR() = 0;
|
||||
virtual bool ReadFPR() = 0;
|
||||
virtual bool WriteGPR() = 0;
|
||||
|
@ -149,17 +149,6 @@ const char *RegisterContextPOSIX_mips64::GetRegisterName(unsigned reg) {
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_mips64::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = eByteOrderInvalid;
|
||||
Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_mips64::IsRegisterSetAvailable(size_t set_index) {
|
||||
size_t num_sets = GetRegisterSetCount();
|
||||
|
||||
|
@ -73,8 +73,6 @@ protected:
|
||||
|
||||
bool IsFPR(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadGPR() = 0;
|
||||
virtual bool ReadFPR() = 0;
|
||||
virtual bool WriteGPR() = 0;
|
||||
|
@ -157,36 +157,8 @@ const char *RegisterContextPOSIX_powerpc::GetRegisterName(unsigned reg) {
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_powerpc::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = eByteOrderInvalid;
|
||||
Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_powerpc::IsRegisterSetAvailable(size_t set_index) {
|
||||
size_t num_sets = k_num_register_sets;
|
||||
|
||||
return (set_index < num_sets);
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_powerpc::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -165,9 +165,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
protected:
|
||||
uint64_t
|
||||
m_gpr_powerpc[k_num_gpr_registers_powerpc]; // general purpose registers.
|
||||
@ -189,8 +186,6 @@ protected:
|
||||
|
||||
bool IsVMX(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadGPR() = 0;
|
||||
virtual bool ReadFPR() = 0;
|
||||
virtual bool ReadVMX() = 0;
|
||||
|
@ -176,36 +176,8 @@ const char *RegisterContextPOSIX_ppc64le::GetRegisterName(unsigned reg) {
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_ppc64le::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = eByteOrderInvalid;
|
||||
Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContextPOSIX_ppc64le::IsRegisterSetAvailable(size_t set_index) {
|
||||
size_t num_sets = k_num_register_sets;
|
||||
|
||||
return (set_index < num_sets);
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_ppc64le::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -39,9 +39,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
protected:
|
||||
// 64-bit general purpose registers.
|
||||
uint64_t m_gpr_ppc64le[k_num_gpr_registers_ppc64le];
|
||||
@ -71,7 +68,6 @@ protected:
|
||||
|
||||
bool IsVSX(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
};
|
||||
|
||||
#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTPOSIX_PPC64LE_H
|
||||
|
@ -161,31 +161,3 @@ const RegisterSet *RegisterContextPOSIX_s390x::GetRegisterSet(size_t set) {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_s390x::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = eByteOrderInvalid;
|
||||
Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_s390x::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -43,9 +43,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
protected:
|
||||
struct RegInfo {
|
||||
uint32_t num_registers;
|
||||
@ -68,8 +65,6 @@ protected:
|
||||
|
||||
bool IsFPR(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
virtual bool ReadGPR() = 0;
|
||||
virtual bool ReadFPR() = 0;
|
||||
virtual bool WriteGPR() = 0;
|
||||
|
@ -456,17 +456,6 @@ const char *RegisterContextPOSIX_x86::GetRegisterName(unsigned reg) {
|
||||
return GetRegisterInfo()[reg].name;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContextPOSIX_x86::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = eByteOrderInvalid;
|
||||
Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
// Parse ymm registers and into xmm.bytes and ymmh.bytes.
|
||||
bool RegisterContextPOSIX_x86::CopyYMMtoXSTATE(uint32_t reg,
|
||||
lldb::ByteOrder byte_order) {
|
||||
@ -509,20 +498,3 @@ bool RegisterContextPOSIX_x86::IsRegisterSetAvailable(size_t set_index) {
|
||||
++num_sets;
|
||||
return (set_index < num_sets);
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t RegisterContextPOSIX_x86::ConvertRegisterKindToRegisterNumber(
|
||||
lldb::RegisterKind kind, uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
@ -47,9 +47,6 @@ public:
|
||||
|
||||
const char *GetRegisterName(unsigned reg);
|
||||
|
||||
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) override;
|
||||
|
||||
// Note: prefer kernel definitions over user-land
|
||||
enum FPRType {
|
||||
eNotValid = 0,
|
||||
@ -160,8 +157,6 @@ protected:
|
||||
|
||||
bool IsAVX(unsigned reg);
|
||||
|
||||
lldb::ByteOrder GetByteOrder();
|
||||
|
||||
bool CopyXSTATEtoYMM(uint32_t reg, lldb::ByteOrder byte_order);
|
||||
bool CopyYMMtoXSTATE(uint32_t reg, lldb::ByteOrder byte_order);
|
||||
bool IsFPR(unsigned reg, FPRType fpr_type);
|
||||
|
@ -274,6 +274,24 @@ uint32_t RegisterContext::SetHardwareBreakpoint(lldb::addr_t addr,
|
||||
return LLDB_INVALID_INDEX32;
|
||||
}
|
||||
|
||||
// Used when parsing DWARF and EH frame information and any other object file
|
||||
// sections that contain register numbers in them.
|
||||
uint32_t
|
||||
RegisterContext::ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind,
|
||||
uint32_t num) {
|
||||
const uint32_t num_regs = GetRegisterCount();
|
||||
|
||||
assert(kind < kNumRegisterKinds);
|
||||
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
|
||||
const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
|
||||
|
||||
if (reg_info->kinds[kind] == num)
|
||||
return reg_idx;
|
||||
}
|
||||
|
||||
return LLDB_INVALID_REGNUM;
|
||||
}
|
||||
|
||||
bool RegisterContext::ClearHardwareBreakpoint(uint32_t hw_idx) { return false; }
|
||||
|
||||
uint32_t RegisterContext::NumSupportedHardwareWatchpoints() { return 0; }
|
||||
@ -397,6 +415,17 @@ Status RegisterContext::WriteRegisterValueToMemory(
|
||||
return error;
|
||||
}
|
||||
|
||||
lldb::ByteOrder RegisterContext::GetByteOrder() {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
|
||||
lldb_private::Process *process = CalculateProcess().get();
|
||||
|
||||
if (process)
|
||||
byte_order = process->GetByteOrder();
|
||||
return byte_order;
|
||||
}
|
||||
|
||||
bool RegisterContext::ReadAllRegisterValues(
|
||||
lldb_private::RegisterCheckpoint ®_checkpoint) {
|
||||
return ReadAllRegisterValues(reg_checkpoint.GetData());
|
||||
|
Loading…
x
Reference in New Issue
Block a user