diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h @@ -13,6 +13,7 @@ #include "Plugins/Process/Linux/NativeRegisterContextLinux.h" #include "Plugins/Process/Utility/NativeRegisterContextDBReg_x86.h" +#include "Plugins/Process/Utility/RegisterContextLinux_x86.h" #include "Plugins/Process/Utility/RegisterContext_x86.h" #include "Plugins/Process/Utility/lldb-x86-register-enums.h" #include @@ -130,6 +131,11 @@ bool IsMPX(uint32_t reg_index) const; void UpdateXSTATEforWrite(uint32_t reg_index); + + RegisterContextLinux_x86 &GetRegisterInfo() const { + return static_cast( + *m_register_info_interface_up); + } }; } // namespace process_linux diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp --- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp @@ -263,17 +263,17 @@ // NativeRegisterContextLinux_x86_64 members. -static RegisterInfoInterface * +static std::unique_ptr CreateRegisterInfoInterface(const ArchSpec &target_arch) { if (HostInfo::GetArchitecture().GetAddressByteSize() == 4) { // 32-bit hosts run with a RegisterContextLinux_i386 context. - return new RegisterContextLinux_i386(target_arch); + return std::make_unique(target_arch); } else { assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) && "Register setting path assumes this is a 64-bit host"); // X86_64 hosts know how to work with 64-bit and 32-bit EXEs using the // x86_64 register context. - return new RegisterContextLinux_x86_64(target_arch); + return std::make_unique(target_arch); } } @@ -297,7 +297,7 @@ NativeRegisterContextLinux_x86_64::NativeRegisterContextLinux_x86_64( const ArchSpec &target_arch, NativeThreadProtocol &native_thread) : NativeRegisterContextRegisterInfo( - native_thread, CreateRegisterInfoInterface(target_arch)), + native_thread, CreateRegisterInfoInterface(target_arch).release()), NativeRegisterContextLinux(native_thread), NativeRegisterContextDBReg_x86(native_thread), m_xstate_type(XStateType::Invalid), m_ymm_set(), m_mpx_set(), @@ -757,13 +757,8 @@ * **/ RegisterValue value((uint64_t)-1); - const RegisterInfo *reg_info = - GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_eax"); - if (reg_info == nullptr) - reg_info = GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_rax"); - - if (reg_info != nullptr) - return DoWriteRegisterValue(reg_info->byte_offset, reg_info->name, value); + const RegisterInfo &info = GetRegisterInfo().GetOrigAxInfo(); + return DoWriteRegisterValue(info.byte_offset, info.name, value); return error; } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h @@ -9,9 +9,10 @@ #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_I386_H #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_I386_H -#include "RegisterInfoInterface.h" +#include "Plugins/Process/Utility/RegisterContextLinux_x86.h" -class RegisterContextLinux_i386 : public lldb_private::RegisterInfoInterface { +class RegisterContextLinux_i386 + : public lldb_private::RegisterContextLinux_x86 { public: RegisterContextLinux_i386(const lldb_private::ArchSpec &target_arch); @@ -23,12 +24,6 @@ uint32_t GetRegisterCount() const override; uint32_t GetUserRegisterCount() const override; - - const std::vector * - GetDynamicRegisterInfoP() const override; - -private: - std::vector d_register_infos; }; #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp @@ -88,21 +88,18 @@ RegisterContextLinux_i386::RegisterContextLinux_i386( const ArchSpec &target_arch) - : RegisterInfoInterface(target_arch) { - RegisterInfo orig_ax = { - "orig_eax", - nullptr, - sizeof(((GPR *)nullptr)->orig_eax), - (LLVM_EXTENSION offsetof(GPR, orig_eax)), - eEncodingUint, - eFormatHex, - {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, - LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, - nullptr, - nullptr, - }; - d_register_infos.push_back(orig_ax); -} + : RegisterContextLinux_x86( + target_arch, + {"orig_eax", + nullptr, + sizeof(((GPR *)nullptr)->orig_eax), + (LLVM_EXTENSION offsetof(GPR, orig_eax)), + eEncodingUint, + eFormatHex, + {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, + LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, + nullptr, + nullptr}) {} size_t RegisterContextLinux_i386::GetGPRSizeStatic() { return sizeof(GPR); } @@ -125,8 +122,3 @@ uint32_t RegisterContextLinux_i386::GetUserRegisterCount() const { return static_cast(k_num_user_registers_i386); } - -const std::vector * -RegisterContextLinux_i386::GetDynamicRegisterInfoP() const { - return &d_register_infos; -} diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h @@ -23,14 +23,10 @@ uint32_t GetUserRegisterCount() const override; - const std::vector * - GetDynamicRegisterInfoP() const override; - private: const lldb_private::RegisterInfo *m_register_info_p; uint32_t m_register_info_count; uint32_t m_user_register_count; - std::vector d_register_infos; }; #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp @@ -54,11 +54,6 @@ m_register_info_count(GetRegisterInfoCount(target_arch)), m_user_register_count(GetUserRegisterInfoCount(target_arch)) {} -const std::vector * -RegisterContextLinux_s390x::GetDynamicRegisterInfoP() const { - return &d_register_infos; -} - const RegisterInfo *RegisterContextLinux_s390x::GetRegisterInfo() const { return m_register_info_p; } diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h copy from lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h copy to lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h @@ -6,14 +6,18 @@ // //===----------------------------------------------------------------------===// -#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_I386_H -#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_I386_H +#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_H +#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_H #include "RegisterInfoInterface.h" -class RegisterContextLinux_i386 : public lldb_private::RegisterInfoInterface { +namespace lldb_private { + +class RegisterContextLinux_x86 : public RegisterInfoInterface { public: - RegisterContextLinux_i386(const lldb_private::ArchSpec &target_arch); + RegisterContextLinux_x86(const ArchSpec &target_arch, + RegisterInfo orig_ax_info) + : RegisterInfoInterface(target_arch), m_orig_ax_info(orig_ax_info) {} static size_t GetGPRSizeStatic(); size_t GetGPRSize() const override { return GetGPRSizeStatic(); } @@ -24,11 +28,12 @@ uint32_t GetUserRegisterCount() const override; - const std::vector * - GetDynamicRegisterInfoP() const override; + const RegisterInfo &GetOrigAxInfo() const { return m_orig_ax_info; } private: - std::vector d_register_infos; + lldb_private::RegisterInfo m_orig_ax_info; }; +} // namespace lldb_private + #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h @@ -9,9 +9,10 @@ #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_64_H #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_64_H -#include "RegisterInfoInterface.h" +#include "Plugins/Process/Utility/RegisterContextLinux_x86.h" -class RegisterContextLinux_x86_64 : public lldb_private::RegisterInfoInterface { +class RegisterContextLinux_x86_64 + : public lldb_private::RegisterContextLinux_x86 { public: RegisterContextLinux_x86_64(const lldb_private::ArchSpec &target_arch); @@ -24,14 +25,11 @@ uint32_t GetUserRegisterCount() const override; - const std::vector * - GetDynamicRegisterInfoP() const override; - private: const lldb_private::RegisterInfo *m_register_info_p; uint32_t m_register_info_count; uint32_t m_user_register_count; - std::vector d_register_infos; + lldb_private::RegisterInfo m_orig_rax_info; }; #endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp @@ -152,32 +152,24 @@ RegisterContextLinux_x86_64::RegisterContextLinux_x86_64( const ArchSpec &target_arch) - : lldb_private::RegisterInfoInterface(target_arch), + : lldb_private::RegisterContextLinux_x86( + target_arch, + {"orig_rax", + nullptr, + sizeof(((GPR *)nullptr)->orig_rax), + (LLVM_EXTENSION offsetof(GPR, orig_rax)), + eEncodingUint, + eFormatHex, + {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, + LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, + nullptr, + nullptr}), m_register_info_p(GetRegisterInfoPtr(target_arch)), m_register_info_count(GetRegisterInfoCount(target_arch)), - m_user_register_count(GetUserRegisterInfoCount(target_arch)) { - RegisterInfo orig_ax = { - "orig_rax", - nullptr, - sizeof(((GPR *)nullptr)->orig_rax), - (LLVM_EXTENSION offsetof(GPR, orig_rax)), - eEncodingUint, - eFormatHex, - {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, - LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, - nullptr, - nullptr, - }; - d_register_infos.push_back(orig_ax); -} + m_user_register_count(GetUserRegisterInfoCount(target_arch)) {} size_t RegisterContextLinux_x86_64::GetGPRSizeStatic() { return sizeof(GPR); } -const std::vector * -RegisterContextLinux_x86_64::GetDynamicRegisterInfoP() const { - return &d_register_infos; -} - const RegisterInfo *RegisterContextLinux_x86_64::GetRegisterInfo() const { return m_register_info_p; } diff --git a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h --- a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h +++ b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h @@ -41,26 +41,6 @@ return m_target_arch; } - virtual const lldb_private::RegisterInfo * - GetDynamicRegisterInfo(const char *reg_name) const { - const std::vector *d_register_infos = - GetDynamicRegisterInfoP(); - if (d_register_infos != nullptr) { - std::vector::const_iterator pos = - d_register_infos->begin(); - for (; pos < d_register_infos->end(); pos++) { - if (::strcmp(reg_name, pos->name) == 0) - return (d_register_infos->data() + (pos - d_register_infos->begin())); - } - } - return nullptr; - } - - virtual const std::vector * - GetDynamicRegisterInfoP() const { - return nullptr; - } - private: lldb_private::ArchSpec m_target_arch; };