From 933d3ee60007f5798319cad05b981cb265578ba0 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 28 Mar 2023 14:50:16 +0200 Subject: [PATCH] [lldb] Drop RegisterInfoInterface::GetDynamicRegisterInfo "Dynamic register info" is a very overloaded term, and this particular instance of it was only used for passing the information about the "orig_[re]ax" pseudo-register on x86 through some generic code. Since both sides of the code are x86-specific, I have replaced this with a more direct route. Differential Revision: https://reviews.llvm.org/D147045 --- .../Linux/NativeRegisterContextLinux_x86_64.cpp | 17 ++++------ .../Linux/NativeRegisterContextLinux_x86_64.h | 6 ++++ .../Process/Utility/RegisterContextLinux_i386.cpp | 32 +++++++----------- .../Process/Utility/RegisterContextLinux_i386.h | 11 ++---- .../Process/Utility/RegisterContextLinux_s390x.cpp | 5 --- .../Process/Utility/RegisterContextLinux_s390x.h | 4 --- .../Process/Utility/RegisterContextLinux_x86.h | 39 ++++++++++++++++++++++ .../Utility/RegisterContextLinux_x86_64.cpp | 34 ++++++++----------- .../Process/Utility/RegisterContextLinux_x86_64.h | 10 +++--- .../Process/Utility/RegisterInfoInterface.h | 20 ----------- 10 files changed, 83 insertions(+), 95 deletions(-) create mode 100644 lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp index 4f1d2fa..e81ef33 100644 --- 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::DetermineArchitecture(lldb::tid_t tid) { // 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 @@ static std::size_t GetXSTATESize() { 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 @@ Status NativeRegisterContextLinux_x86_64::ReadAllRegisterValues( * **/ 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/Linux/NativeRegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h index 43d939d..40d086e 100644 --- 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 @@ private: 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/Utility/RegisterContextLinux_i386.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp index 0b3953e..d4efa75 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp @@ -88,21 +88,18 @@ struct UserArea { 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::GetRegisterCount() const { 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_i386.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h index e0f8114..c106139 100644 --- 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 @@ public: 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_s390x.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp index 7a8989c..77627cf 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp @@ -54,11 +54,6 @@ RegisterContextLinux_s390x::RegisterContextLinux_s390x( 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_s390x.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h index f381f38..6bfe34d 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h @@ -23,14 +23,10 @@ public: 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_x86.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h new file mode 100644 index 0000000..663c1d9 --- /dev/null +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h @@ -0,0 +1,39 @@ +//===-- RegisterContextLinux_i386.h -----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_H +#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERCONTEXTLINUX_X86_H + +#include "RegisterInfoInterface.h" + +namespace lldb_private { + +class RegisterContextLinux_x86 : public RegisterInfoInterface { +public: + 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(); } + + const lldb_private::RegisterInfo *GetRegisterInfo() const override; + + uint32_t GetRegisterCount() const override; + + uint32_t GetUserRegisterCount() const override; + + const RegisterInfo &GetOrigAxInfo() const { return m_orig_ax_info; } + +private: + lldb_private::RegisterInfo m_orig_ax_info; +}; + +} // namespace lldb_private + +#endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp index 85c57ca..31f9975 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp @@ -152,32 +152,24 @@ static uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch) { 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/RegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h index a09deeb..2918e5d 100644 --- 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 @@ public: 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/RegisterInfoInterface.h b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h index d8414c5..a79c5cc 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h +++ b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h @@ -41,26 +41,6 @@ public: 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; }; -- 2.7.4