mgorny updated this revision to Diff 373452.
mgorny added a comment.

Rebase. Clang-format. Eliminate remote regnums entirely.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109876/new/

https://reviews.llvm.org/D109876

Files:
  lldb/include/lldb/Target/ABI.h
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
  lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py

Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
@@ -380,6 +380,7 @@
                 return "".join(reg_data)
 
             def writeRegisters(self, reg_hex):
+                reg_data[:] = [reg_hex]
                 return "OK"
 
             def haltReason(self):
@@ -429,3 +430,43 @@
                    ["v0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
         self.match("register read v31",
                    ["v31 = {0xa1 0xa2 0xa3 0xa4 0xa5 0xa6 0xa7 0xa8 0xa9 0xaa 0xab 0xac 0xad 0xae 0xaf 0xb0}"])
+
+        # test partial registers
+        self.match("register read w0",
+                   ["w0 = 0x04030201"])
+        self.runCmd("register write w0 0xfffefdfc")
+        self.match("register read x0",
+                   ["x0 = 0x08070605fffefdfc"])
+
+        self.match("register read w1",
+                   ["w1 = 0x14131211"])
+        self.runCmd("register write w1 0xefeeedec")
+        self.match("register read x1",
+                   ["x1 = 0x18171615efeeedec"])
+
+        self.match("register read w30",
+                   ["w30 = 0x44434241"])
+        self.runCmd("register write w30 0xdfdedddc")
+        self.match("register read x30",
+                   ["x30 = 0x48474645dfdedddc"])
+
+        self.match("register read w31",
+                   ["w31 = 0x54535251"])
+        self.runCmd("register write w31 0xcfcecdcc")
+        self.match("register read x31",
+                   ["sp = 0x58575655cfcecdcc"])
+
+        # test FPU registers (overlapping with vector registers)
+        self.runCmd("register write d0 16")
+        self.match("register read v0",
+                   ["v0 = {0x00 0x00 0x00 0x00 0x00 0x00 0x30 0x40 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+        self.runCmd("register write v31 '{0x00 0x00 0x00 0x00 0x00 0x00 0x50 0x40 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff}'")
+        self.match("register read d31",
+                   ["d31 = 64"])
+
+        self.runCmd("register write s0 32")
+        self.match("register read v0",
+                   ["v0 = {0x00 0x00 0x00 0x42 0x00 0x00 0x30 0x40 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+        self.runCmd("register write v31 '{0x00 0x00 0x00 0x43 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff}'")
+        self.match("register read s31",
+                   ["s31 = 128"])
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
@@ -453,6 +453,10 @@
   if (GetGDBServerRegisterInfo(arch_to_use))
     return;
 
+  // We have to make a temporary ABI here, and not use the GetABI because
+  // this code gets called in DidAttach, when the target architecture
+  // (and consequently the ABI we'll get from the process) may be wrong.
+  ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
   char packet[128];
   uint32_t reg_offset = LLDB_INVALID_INDEX32;
   uint32_t reg_num = 0;
@@ -579,10 +583,7 @@
 
         reg_info.name = reg_name.AsCString();
         reg_info.alt_name = alt_name.AsCString();
-        // We have to make a temporary ABI here, and not use the GetABI because
-        // this code gets called in DidAttach, when the target architecture
-        // (and consequently the ABI we'll get from the process) may be wrong.
-        if (ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use))
+        if (abi_sp)
           abi_sp->AugmentRegisterInfo(reg_info);
 
         m_register_info_sp->AddRegister(reg_info, set_name);
@@ -595,6 +596,8 @@
   }
 
   if (m_register_info_sp->GetNumRegisters() > 0) {
+    if (abi_sp)
+      abi_sp->PreFinalizeDynamicRegisterInfo(*m_register_info_sp);
     m_register_info_sp->Finalize(GetTarget().GetArchitecture());
     return;
   }
@@ -618,6 +621,8 @@
   }
 
   // At this point, we can finalize our register info.
+  if (abi_sp)
+    abi_sp->PreFinalizeDynamicRegisterInfo(*m_register_info_sp);
   m_register_info_sp->Finalize(GetTarget().GetArchitecture());
 }
 
@@ -4730,6 +4735,8 @@
       m_register_info_sp->AddRegister(reg_info, remote_reg_info.set_name);
     };
 
+    if (abi_sp)
+      abi_sp->PreFinalizeDynamicRegisterInfo(*m_register_info_sp);
     m_register_info_sp->Finalize(arch_to_use);
   }
 
Index: lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -843,7 +843,8 @@
 const lldb_private::RegisterInfo *
 DynamicRegisterInfo::GetRegisterInfo(llvm::StringRef reg_name) const {
   for (auto &reg_info : m_regs)
-    if (reg_info.name == reg_name)
+    if (reg_info.name == reg_name ||
+        (reg_info.alt_name && reg_info.alt_name == reg_name))
       return &reg_info;
   return nullptr;
 }
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===================================================================
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -32,6 +32,7 @@
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
   void AugmentRegisterInfo(lldb_private::RegisterInfo &info) override;
+  void PreFinalizeDynamicRegisterInfo(DynamicRegisterInfo &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
@@ -13,6 +13,8 @@
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Target/Process.h"
 
+#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
+
 LLDB_PLUGIN_DEFINE(ABIAArch64)
 
 void ABIAArch64::Initialize() {
@@ -78,3 +80,59 @@
   if (!strcmp(info.name, "sp") && !info.alt_name)
     info.alt_name = "x31";
 }
+
+static void AddPartialRegister(DynamicRegisterInfo &info,
+                               const lldb_private::RegisterInfo *full_reg,
+                               uint32_t full_reg_size,
+                               const std::string &partial_reg_name,
+                               uint32_t partial_reg_size,
+                               lldb::Encoding encoding, lldb::Format format,
+                               uint32_t &next_regnum_lldb) {
+  if (!full_reg || full_reg->byte_size != full_reg_size)
+    return;
+  if (info.GetRegisterInfo(partial_reg_name))
+    return;
+
+  lldb_private::ConstString group{"partial registers"};
+
+  lldb_private::ConstString partial_reg_name_const{partial_reg_name};
+  uint32_t value_regs[] = {
+      full_reg->kinds[lldb::eRegisterKindProcessPlugin],
+      LLDB_INVALID_REGNUM,
+  };
+
+  struct lldb_private::RegisterInfo partial_reg {
+    partial_reg_name_const.AsCString(),
+        nullptr, partial_reg_size, LLDB_INVALID_INDEX32, encoding, format,
+        {
+            LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+            LLDB_INVALID_REGNUM, next_regnum_lldb++,
+        },
+        value_regs, nullptr, nullptr, 0
+  };
+
+  info.AddSupplementaryRegister(partial_reg, group);
+}
+
+void ABIAArch64::PreFinalizeDynamicRegisterInfo(DynamicRegisterInfo &info) {
+  uint32_t next_regnum_lldb = info.GetNumRegisters();
+
+  // Create aliases for partial registers: wN for xN, and sN/dN for vN.
+  for (int i = 0; i < 32; i++)
+    AddPartialRegister(info,
+                       info.GetRegisterInfo(llvm::formatv("x{0}", i).str()), 8,
+                       llvm::formatv("w{0}", i), 4, lldb::eEncodingUint,
+                       lldb::eFormatHex, next_regnum_lldb);
+
+  for (int i = 0; i < 32; i++)
+    AddPartialRegister(info,
+                       info.GetRegisterInfo(llvm::formatv("v{0}", i).str()), 16,
+                       llvm::formatv("s{0}", i), 4, lldb::eEncodingIEEE754,
+                       lldb::eFormatFloat, next_regnum_lldb);
+
+  for (int i = 0; i < 32; i++)
+    AddPartialRegister(info,
+                       info.GetRegisterInfo(llvm::formatv("v{0}", i).str()), 16,
+                       llvm::formatv("d{0}", i), 8, lldb::eEncodingIEEE754,
+                       lldb::eFormatFloat, next_regnum_lldb);
+}
Index: lldb/include/lldb/Target/ABI.h
===================================================================
--- lldb/include/lldb/Target/ABI.h
+++ lldb/include/lldb/Target/ABI.h
@@ -21,6 +21,9 @@
 class Type;
 }
 
+// TODO
+class DynamicRegisterInfo;
+
 namespace lldb_private {
 
 class ABI : public PluginInterface {
@@ -128,6 +131,8 @@
   llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
 
   virtual void AugmentRegisterInfo(RegisterInfo &info) = 0;
+  // Routine called before DynamicRegisterInfo::Finalize().
+  virtual void PreFinalizeDynamicRegisterInfo(DynamicRegisterInfo &info) {}
 
   virtual bool GetPointerReturnRegister(const char *&name) { return false; }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D10... Michał Górny via Phabricator via lldb-commits
    • [Lldb-commits] [PATCH... Michał Górny via Phabricator via lldb-commits

Reply via email to