[Lldb-commits] [lldb] r284001 - [LLDB][MIPS] Fix qProcessInfo to return correct pointer size based on ELF ABI

Nitesh Jain via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 12 03:21:09 PDT 2016


Author: nitesh.jain
Date: Wed Oct 12 05:21:09 2016
New Revision: 284001

URL: http://llvm.org/viewvc/llvm-project?rev=284001&view=rev
Log:
[LLDB][MIPS] Fix qProcessInfo to return correct pointer size based on ELF ABI

Reviewers: clayborg, labath

Subscribers: jaydeep, bhushan, slthakur, lldb-commits

Differential Revision: https://reviews.llvm.org/D25021

Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=284001&r1=284000&r2=284001&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Wed Oct 12 05:21:09 2016
@@ -310,6 +310,13 @@ public:
   std::string GetClangTargetCPU();
 
   //------------------------------------------------------------------
+  /// Return a string representing target application ABI.
+  ///
+  /// @return A string representing target application ABI.
+  //------------------------------------------------------------------
+  std::string GetTargetABI() const;
+
+  //------------------------------------------------------------------
   /// Clears the object state.
   ///
   /// Clears the object state back to a default invalid state.
@@ -596,6 +603,8 @@ public:
 
   void SetFlags(uint32_t flags) { m_flags = flags; }
 
+  void SetFlags(std::string elf_abi);
+
 protected:
   bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
 

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=284001&r1=284000&r2=284001&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Wed Oct 12 05:21:09 2016
@@ -621,6 +621,42 @@ bool ArchSpec::IsMIPS() const {
   return false;
 }
 
+std::string ArchSpec::GetTargetABI() const {
+
+  std::string abi;
+
+  if (IsMIPS()) {
+    switch (GetFlags() & ArchSpec::eMIPSABI_mask) {
+    case ArchSpec::eMIPSABI_N64:
+      abi = "n64";
+      return abi;
+    case ArchSpec::eMIPSABI_N32:
+      abi = "n32";
+      return abi;
+    case ArchSpec::eMIPSABI_O32:
+      abi = "o32";
+      return abi;
+    default:
+      return abi;
+    }
+  }
+  return abi;
+}
+
+void ArchSpec::SetFlags(std::string elf_abi) {
+
+  uint32_t flag = GetFlags();
+  if (IsMIPS()) {
+    if (elf_abi == "n64")
+      flag |= ArchSpec::eMIPSABI_N64;
+    else if (elf_abi == "n32")
+      flag |= ArchSpec::eMIPSABI_N32;
+    else if (elf_abi == "o32")
+      flag |= ArchSpec::eMIPSABI_O32;
+  }
+  SetFlags(flag);
+}
+
 std::string ArchSpec::GetClangTargetCPU() {
   std::string cpu;
   const llvm::Triple::ArchType machine = GetMachine();
@@ -815,7 +851,8 @@ bool ArchSpec::SetTriple(const llvm::Tri
   return IsValid();
 }
 
-bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch) {
+bool lldb_private::ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str,
+                                                 ArchSpec &arch) {
   // Accept "12-10" or "12.10" as cpu type/subtype
   if (triple_str.empty())
     return false;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=284001&r1=284000&r2=284001&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Wed Oct 12 05:21:09 2016
@@ -1849,6 +1849,7 @@ bool GDBRemoteCommunicationClient::GetCu
       std::string os_name;
       std::string vendor_name;
       std::string triple;
+      std::string elf_abi;
       uint32_t pointer_byte_size = 0;
       StringExtractor extractor;
       ByteOrder byte_order = eByteOrderInvalid;
@@ -1885,6 +1886,9 @@ bool GDBRemoteCommunicationClient::GetCu
         } else if (name.equals("pid")) {
           if (!value.getAsInteger(16, pid))
             ++num_keys_decoded;
+        } else if (name.equals("elf_abi")) {
+          elf_abi = value;
+          ++num_keys_decoded;
         }
       }
       if (num_keys_decoded > 0)
@@ -1897,6 +1901,7 @@ bool GDBRemoteCommunicationClient::GetCu
       // Set the ArchSpec from the triple if we have it.
       if (!triple.empty()) {
         m_process_arch.SetTriple(triple.c_str());
+        m_process_arch.SetFlags(elf_abi);
         if (pointer_byte_size) {
           assert(pointer_byte_size == m_process_arch.GetAddressByteSize());
         }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=284001&r1=284000&r2=284001&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Wed Oct 12 05:21:09 2016
@@ -1262,13 +1262,12 @@ void GDBRemoteCommunicationServerCommon:
       // Nothing.
       break;
     }
-
-    if (proc_triple.isArch64Bit())
-      response.PutCString("ptrsize:8;");
-    else if (proc_triple.isArch32Bit())
-      response.PutCString("ptrsize:4;");
-    else if (proc_triple.isArch16Bit())
-      response.PutCString("ptrsize:2;");
+    // In case of MIPS64, pointer size is depend on ELF ABI
+    // For N32 the pointer size is 4 and for N64 it is 8
+    std::string abi = proc_arch.GetTargetABI();
+    if (!abi.empty())
+      response.Printf("elf_abi:%s;", abi.c_str());
+    response.Printf("ptrsize:%d;", proc_arch.GetAddressByteSize());
   }
 }
 




More information about the lldb-commits mailing list