mgorny created this revision.
mgorny added reviewers: labath, teemperor, emaste, krytarowski.
mgorny requested review of this revision.

Modify ABI::AugmentRegisterInfo() to take the whole DynamicRegisterInfo
rather than being claled per-register.


https://reviews.llvm.org/D111142

Files:
  lldb/include/lldb/Target/ABI.h
  lldb/include/lldb/Target/DynamicRegisterInfo.h
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Target/ABI.cpp
  lldb/source/Target/DynamicRegisterInfo.cpp

Index: lldb/source/Target/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -837,3 +837,11 @@
       return &reg_info;
   return nullptr;
 }
+
+lldb_private::RegisterInfo *
+DynamicRegisterInfo::GetRegisterInfo(llvm::StringRef reg_name) {
+  for (auto &reg_info : m_regs)
+    if (reg_info.name == reg_name)
+      return &reg_info;
+  return nullptr;
+}
Index: lldb/source/Target/ABI.cpp
===================================================================
--- lldb/source/Target/ABI.cpp
+++ lldb/source/Target/ABI.cpp
@@ -214,33 +214,37 @@
   return info_up;
 }
 
-void RegInfoBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
-  if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM &&
-      info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM)
-    return;
-
-  RegisterInfo abi_info;
-  if (!GetRegisterInfoByName(info.name, abi_info))
-    return;
-
-  if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame];
-  if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF];
-  if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric];
+void RegInfoBasedABI::AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) {
+  for (RegisterInfo &info : dyn_info.Registers()) {
+    if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM &&
+        info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM)
+      continue;
+
+    RegisterInfo abi_info;
+    if (!GetRegisterInfoByName(info.name, abi_info))
+      continue;
+
+    if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame];
+    if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF];
+    if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric];
+  }
 }
 
-void MCBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
+void MCBasedABI::AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) {
   uint32_t eh, dwarf;
-  std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name);
-
-  if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindEHFrame] = eh;
-  if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindDWARF] = dwarf;
-  if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
-    info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name);
+  for (RegisterInfo &info : dyn_info.Registers()) {
+    std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name);
+
+    if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindEHFrame] = eh;
+    if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindDWARF] = dwarf;
+    if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
+      info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name);
+  }
 }
 
 std::pair<uint32_t, uint32_t>
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4482,11 +4482,6 @@
 
 void ProcessGDBRemote::AddRemoteRegisters(
     std::vector<RemoteRegisterInfo> &registers, const ArchSpec &arch_to_use) {
-  // Don't use Process::GetABI, this code gets called from DidAttach, and
-  // in that context we haven't set the Target's architecture yet, so the
-  // ABI is also potentially incorrect.
-  ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
-
   std::map<uint32_t, uint32_t> remote_to_local_map;
   uint32_t remote_regnum = 0;
   for (auto it : llvm::enumerate(registers)) {
@@ -4539,12 +4534,14 @@
               : nullptr,
           remote_reg_info.dwarf_opcode_bytes.size(),
     };
-
-    if (abi_sp)
-      abi_sp->AugmentRegisterInfo(reg_info);
     m_register_info_sp->AddRegister(reg_info, remote_reg_info.set_name);
   };
 
+  // Don't use Process::GetABI, this code gets called from DidAttach, and
+  // in that context we haven't set the Target's architecture yet, so the
+  // ABI is also potentially incorrect.
+  if (ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use))
+    abi_sp->AugmentRegisterInfo(*m_register_info_sp);
   m_register_info_sp->Finalize(arch_to_use);
 }
 
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===================================================================
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -31,7 +31,8 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
-  void AugmentRegisterInfo(lldb_private::RegisterInfo &info) override;
+  void
+  AugmentRegisterInfo(lldb_private::DynamicRegisterInfo &dyn_info) override;
 
   using lldb_private::MCBasedABI::MCBasedABI;
 };
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===================================================================
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -71,10 +71,13 @@
       .Default(LLDB_INVALID_REGNUM);
 }
 
-void ABIAArch64::AugmentRegisterInfo(lldb_private::RegisterInfo &info) {
-  lldb_private::MCBasedABI::AugmentRegisterInfo(info);
+void ABIAArch64::AugmentRegisterInfo(
+    lldb_private::DynamicRegisterInfo &dyn_info) {
+  lldb_private::MCBasedABI::AugmentRegisterInfo(dyn_info);
 
-  // GDB sends x31 as "sp".  Add the "x31" alt_name for convenience.
-  if (!strcmp(info.name, "sp") && !info.alt_name)
-    info.alt_name = "x31";
+  if (lldb_private::RegisterInfo *sp = dyn_info.GetRegisterInfo("sp")) {
+    // GDB sends x31 as "sp".  Add the "x31" alt_name for convenience.
+    if (!strcmp(sp->name, "sp") && !sp->alt_name)
+      sp->alt_name = "x31";
+  }
 }
Index: lldb/include/lldb/Target/DynamicRegisterInfo.h
===================================================================
--- lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -77,6 +77,9 @@
   const lldb_private::RegisterInfo *
   GetRegisterInfo(llvm::StringRef reg_name) const;
 
+  lldb_private::RegisterInfo *
+  GetRegisterInfo(llvm::StringRef reg_name);
+
   typedef std::vector<lldb_private::RegisterInfo> reg_collection;
   llvm::iterator_range<reg_collection::iterator> Registers() {
     return llvm::iterator_range<reg_collection::iterator>(m_regs);
Index: lldb/include/lldb/Target/ABI.h
===================================================================
--- lldb/include/lldb/Target/ABI.h
+++ lldb/include/lldb/Target/ABI.h
@@ -11,6 +11,7 @@
 
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/DynamicRegisterInfo.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-private.h"
 
@@ -127,7 +128,7 @@
 
   llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
 
-  virtual void AugmentRegisterInfo(RegisterInfo &info) = 0;
+  virtual void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) = 0;
 
   virtual bool GetPointerReturnRegister(const char *&name) { return false; }
 
@@ -158,12 +159,11 @@
 };
 
 class RegInfoBasedABI : public ABI {
-public:
-  void AugmentRegisterInfo(RegisterInfo &info) override;
-
 protected:
   using ABI::ABI;
 
+  void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) override;
+
   bool GetRegisterInfoByName(llvm::StringRef name, RegisterInfo &info);
 
   virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
@@ -171,8 +171,6 @@
 
 class MCBasedABI : public ABI {
 public:
-  void AugmentRegisterInfo(RegisterInfo &info) override;
-
   /// If the register name is of the form "<from_prefix>[<number>]" then change
   /// the name to "<to_prefix>[<number>]". Otherwise, leave the name unchanged.
   static void MapRegisterName(std::string &reg, llvm::StringRef from_prefix,
@@ -180,6 +178,8 @@
 protected:
   using ABI::ABI;
 
+  void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) override;
+
   /// Return eh_frame and dwarf numbers for the given register.
   virtual std::pair<uint32_t, uint32_t> GetEHAndDWARFNums(llvm::StringRef reg);
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D11... Michał Górny via Phabricator via lldb-commits

Reply via email to