[Lldb-commits] [lldb] 933d3ee - [lldb] Drop RegisterInfoInterface::GetDynamicRegisterInfo

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 5 04:25:56 PDT 2023


Author: Pavel Labath
Date: 2023-04-05T13:25:43+02:00
New Revision: 933d3ee60007f5798319cad05b981cb265578ba0

URL: https://github.com/llvm/llvm-project/commit/933d3ee60007f5798319cad05b981cb265578ba0
DIFF: https://github.com/llvm/llvm-project/commit/933d3ee60007f5798319cad05b981cb265578ba0.diff

LOG: [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

Added: 
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86.h

Modified: 
    lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
    lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.h
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.cpp
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp
    lldb/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h
    lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
index 4f1d2fab50f2b..e81ef3301f1f1 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<RegisterContextLinux_x86>
 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<RegisterContextLinux_i386>(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<RegisterContextLinux_x86_64>(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 43d939da84a39..40d086e0811bb 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 <optional>
@@ -130,6 +131,11 @@ class NativeRegisterContextLinux_x86_64
   bool IsMPX(uint32_t reg_index) const;
 
   void UpdateXSTATEforWrite(uint32_t reg_index);
+
+  RegisterContextLinux_x86 &GetRegisterInfo() const {
+    return static_cast<RegisterContextLinux_x86 &>(
+        *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 0b3953e1ec2c1..d4efa75fc43f5 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<uint32_t>(k_num_user_registers_i386);
 }
-
-const std::vector<lldb_private::RegisterInfo> *
-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 e0f8114fa58f0..c10613993689b 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 @@ class RegisterContextLinux_i386 : public lldb_private::RegisterInfoInterface {
   uint32_t GetRegisterCount() const override;
 
   uint32_t GetUserRegisterCount() const override;
-
-  const std::vector<lldb_private::RegisterInfo> *
-  GetDynamicRegisterInfoP() const override;
-
-private:
-  std::vector<lldb_private::RegisterInfo> 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 7a8989cd1225e..77627cfbdefe7 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<lldb_private::RegisterInfo> *
-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 f381f38ecbf9a..6bfe34de7acf1 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextLinux_s390x.h
@@ -23,14 +23,10 @@ class RegisterContextLinux_s390x : public lldb_private::RegisterInfoInterface {
 
   uint32_t GetUserRegisterCount() const override;
 
-  const std::vector<lldb_private::RegisterInfo> *
-  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<lldb_private::RegisterInfo> 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 0000000000000..663c1d9d123d5
--- /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 85c57ca698d43..31f9975bf9859 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<lldb_private::RegisterInfo> *
-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 a09deebed23af..2918e5d5ec311 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 @@ class RegisterContextLinux_x86_64 : public lldb_private::RegisterInfoInterface {
 
   uint32_t GetUserRegisterCount() const override;
 
-  const std::vector<lldb_private::RegisterInfo> *
-  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<lldb_private::RegisterInfo> 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 d8414c594d246..a79c5cc22b24f 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h
@@ -41,26 +41,6 @@ class RegisterInfoInterface {
     return m_target_arch;
   }
 
-  virtual const lldb_private::RegisterInfo *
-  GetDynamicRegisterInfo(const char *reg_name) const {
-    const std::vector<lldb_private::RegisterInfo> *d_register_infos =
-        GetDynamicRegisterInfoP();
-    if (d_register_infos != nullptr) {
-      std::vector<lldb_private::RegisterInfo>::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<lldb_private::RegisterInfo> *
-  GetDynamicRegisterInfoP() const {
-    return nullptr;
-  }
-
 private:
   lldb_private::ArchSpec m_target_arch;
 };


        


More information about the lldb-commits mailing list