[Lldb-commits] [lldb] r317779 - Simplify NativeProcessProtocol::GetArchitecture/GetByteOrder

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 9 02:43:16 PST 2017


Author: labath
Date: Thu Nov  9 02:43:16 2017
New Revision: 317779

URL: http://llvm.org/viewvc/llvm-project?rev=317779&view=rev
Log:
Simplify NativeProcessProtocol::GetArchitecture/GetByteOrder

Summary:
These functions used to return bool to signify whether they were able to
retrieve the data. This is redundant because the ArchSpec and ByteOrder
already have their own "invalid" states, *and* because both of the
current implementations (linux, netbsd) can always provide a valid
result.

This allows us to simplify bits of the code handling these values.

Reviewers: eugene, krytarowski

Subscribers: javed.absar, lldb-commits

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

Modified:
    lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
    lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
    lldb/trunk/source/Host/common/NativeRegisterContext.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
    lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
    lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
    lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
    lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Modified: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h (original)
+++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h Thu Nov  9 02:43:16 2017
@@ -13,6 +13,7 @@
 #include "NativeBreakpointList.h"
 #include "NativeThreadProtocol.h"
 #include "NativeWatchpointList.h"
+#include "lldb/Core/ArchSpec.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/MainLoop.h"
 #include "lldb/Utility/Status.h"
@@ -100,7 +101,7 @@ public:
 
   virtual size_t UpdateThreads() = 0;
 
-  virtual bool GetArchitecture(ArchSpec &arch) const = 0;
+  virtual const ArchSpec &GetArchitecture() const = 0;
 
   //----------------------------------------------------------------------
   // Breakpoint functions
@@ -151,7 +152,9 @@ public:
 
   bool CanResume() const { return m_state == lldb::eStateStopped; }
 
-  bool GetByteOrder(lldb::ByteOrder &byte_order) const;
+  lldb::ByteOrder GetByteOrder() const {
+    return GetArchitecture().GetByteOrder();
+  }
 
   virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   GetAuxvData() const = 0;

Modified: lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeProcessProtocol.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/NativeProcessProtocol.cpp (original)
+++ lldb/trunk/source/Host/common/NativeProcessProtocol.cpp Thu Nov  9 02:43:16 2017
@@ -8,8 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Host/common/NativeProcessProtocol.h"
-
-#include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/State.h"
 #include "lldb/Host/Host.h"
@@ -116,14 +114,6 @@ bool NativeProcessProtocol::IsAlive() co
          m_state != eStateInvalid && m_state != eStateUnloaded;
 }
 
-bool NativeProcessProtocol::GetByteOrder(lldb::ByteOrder &byte_order) const {
-  ArchSpec process_arch;
-  if (!GetArchitecture(process_arch))
-    return false;
-  byte_order = process_arch.GetByteOrder();
-  return true;
-}
-
 const NativeWatchpointList::WatchpointMap &
 NativeProcessProtocol::GetWatchpointMap() const {
   return m_watchpoint_list.GetWatchpointMap();

Modified: lldb/trunk/source/Host/common/NativeRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeRegisterContext.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/NativeRegisterContext.cpp (original)
+++ lldb/trunk/source/Host/common/NativeRegisterContext.cpp Thu Nov  9 02:43:16 2017
@@ -368,13 +368,8 @@ Status NativeRegisterContext::ReadRegist
   // TODO: we might need to add a parameter to this function in case the byte
   // order of the memory data doesn't match the process. For now we are assuming
   // they are the same.
-  lldb::ByteOrder byte_order;
-  if (process.GetByteOrder(byte_order)) {
-    error.SetErrorString("NativeProcessProtocol::GetByteOrder () failed");
-    return error;
-  }
-
-  reg_value.SetFromMemoryData(reg_info, src, src_len, byte_order, error);
+  reg_value.SetFromMemoryData(reg_info, src, src_len, process.GetByteOrder(),
+                              error);
 
   return error;
 }
@@ -393,12 +388,8 @@ Status NativeRegisterContext::WriteRegis
   // order of the memory data doesn't match the process. For now we are
   // assuming
   // they are the same.
-  lldb::ByteOrder byte_order;
-  if (!process.GetByteOrder(byte_order))
-    return Status("NativeProcessProtocol::GetByteOrder () failed");
-
-  const size_t bytes_copied =
-      reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
+  const size_t bytes_copied = reg_value.GetAsMemoryData(
+      reg_info, dst, dst_len, process.GetByteOrder(), error);
 
   if (error.Success()) {
     if (bytes_copied == 0) {

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Nov  9 02:43:16 2017
@@ -1542,11 +1542,6 @@ size_t NativeProcessLinux::UpdateThreads
   return m_threads.size();
 }
 
-bool NativeProcessLinux::GetArchitecture(ArchSpec &arch) const {
-  arch = m_arch;
-  return true;
-}
-
 Status NativeProcessLinux::GetSoftwareBreakpointPCOffset(
     uint32_t &actual_opcode_size) {
   // FIXME put this behind a breakpoint protocol class that can be

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Thu Nov  9 02:43:16 2017
@@ -87,7 +87,7 @@ public:
 
   size_t UpdateThreads() override;
 
-  bool GetArchitecture(ArchSpec &arch) const override;
+  const ArchSpec &GetArchitecture() const override { return m_arch; }
 
   Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
                        bool hardware) override;

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp Thu Nov  9 02:43:16 2017
@@ -26,15 +26,7 @@ NativeRegisterContextLinux::NativeRegist
                                         reg_info_interface_p) {}
 
 lldb::ByteOrder NativeRegisterContextLinux::GetByteOrder() const {
-  // Get the target process whose privileged thread was used for the register
-  // read.
-  lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
-
-  if (!m_thread.GetProcess().GetByteOrder(byte_order)) {
-    // FIXME log here
-  }
-
-  return byte_order;
+  return m_thread.GetProcess().GetByteOrder();
 }
 
 Status NativeRegisterContextLinux::ReadRegisterRaw(uint32_t reg_index,

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp Thu Nov  9 02:43:16 2017
@@ -872,12 +872,8 @@ Status NativeRegisterContextLinux_arm64:
     error = NativeProcessLinux::PtraceWrapper(
         PTRACE_GETREGSET, m_thread.GetID(), &regset, &ioVec, sizeof regs);
     if (error.Success()) {
-      ArchSpec arch;
-      if (m_thread.GetProcess().GetArchitecture(arch))
-        value.SetBytes((void *)(((unsigned char *)(&regs)) + offset), 16,
-                       arch.GetByteOrder());
-      else
-        error.SetErrorString("failed to get architecture");
+      value.SetBytes((void *)(((unsigned char *)(&regs)) + offset), 16,
+                     m_thread.GetProcess().GetByteOrder());
     }
   } else {
     elf_gregset_t regs;
@@ -889,12 +885,8 @@ Status NativeRegisterContextLinux_arm64:
     error = NativeProcessLinux::PtraceWrapper(
         PTRACE_GETREGSET, m_thread.GetID(), &regset, &ioVec, sizeof regs);
     if (error.Success()) {
-      ArchSpec arch;
-      if (m_thread.GetProcess().GetArchitecture(arch))
-        value.SetBytes((void *)(((unsigned char *)(regs)) + offset), 8,
-                       arch.GetByteOrder());
-      else
-        error.SetErrorString("failed to get architecture");
+      value.SetBytes((void *)(((unsigned char *)(regs)) + offset), 8,
+                     m_thread.GetProcess().GetByteOrder());
     }
   }
   return error;

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp Thu Nov  9 02:43:16 2017
@@ -1033,13 +1033,11 @@ Status NativeRegisterContextLinux_mips64
   Status error = NativeProcessLinux::PtraceWrapper(
       PTRACE_GETREGS, m_thread.GetID(), NULL, &regs, sizeof regs);
   if (error.Success()) {
-    lldb_private::ArchSpec arch;
-    if (m_thread.GetProcess().GetArchitecture(arch)) {
-      void *target_address = ((uint8_t *)&regs) + offset +
-                             4 * (arch.GetMachine() == llvm::Triple::mips);
-      value.SetUInt(*(uint32_t *)target_address, size);
-    } else
-      error.SetErrorString("failed to get architecture");
+    const lldb_private::ArchSpec &arch =
+        m_thread.GetProcess().GetArchitecture();
+    void *target_address = ((uint8_t *)&regs) + offset +
+                           4 * (arch.GetMachine() == llvm::Triple::mips);
+    value.SetUInt(*(uint32_t *)target_address, size);
   }
   return error;
 }

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp Thu Nov  9 02:43:16 2017
@@ -144,14 +144,10 @@ NativeRegisterContextSP NativeThreadLinu
   if (m_reg_context_sp)
     return m_reg_context_sp;
 
-  ArchSpec target_arch;
-  if (!m_process.GetArchitecture(target_arch))
-    return NativeRegisterContextSP();
-
   const uint32_t concrete_frame_idx = 0;
   m_reg_context_sp.reset(
       NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
-          target_arch, *this, concrete_frame_idx));
+          m_process.GetArchitecture(), *this, concrete_frame_idx));
 
   return m_reg_context_sp;
 }

Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp Thu Nov  9 02:43:16 2017
@@ -678,11 +678,6 @@ lldb::addr_t NativeProcessNetBSD::GetSha
 
 size_t NativeProcessNetBSD::UpdateThreads() { return m_threads.size(); }
 
-bool NativeProcessNetBSD::GetArchitecture(ArchSpec &arch) const {
-  arch = m_arch;
-  return true;
-}
-
 Status NativeProcessNetBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
                                           bool hardware) {
   if (hardware)

Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h Thu Nov  9 02:43:16 2017
@@ -77,7 +77,7 @@ public:
 
   size_t UpdateThreads() override;
 
-  bool GetArchitecture(ArchSpec &arch) const override;
+  const ArchSpec &GetArchitecture() const override { return m_arch; }
 
   Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
                        bool hardware) override;

Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp Thu Nov  9 02:43:16 2017
@@ -144,14 +144,10 @@ NativeRegisterContextSP NativeThreadNetB
   if (m_reg_context_sp)
     return m_reg_context_sp;
 
-  ArchSpec target_arch;
-  if (!m_process.GetArchitecture(target_arch))
-    return NativeRegisterContextSP();
-
   const uint32_t concrete_frame_idx = 0;
   m_reg_context_sp.reset(
       NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(
-          target_arch, *this, concrete_frame_idx));
+          m_process.GetArchitecture(), *this, concrete_frame_idx));
 
   return m_reg_context_sp;
 }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp?rev=317779&r1=317778&r2=317779&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Thu Nov  9 02:43:16 2017
@@ -2041,17 +2041,6 @@ GDBRemoteCommunicationServerLLGS::Handle
     return SendIllFormedResponse(
         packet, "P packet missing '=' char after register number");
 
-  // Get process architecture.
-  ArchSpec process_arch;
-  if (!m_debugged_process_up ||
-      !m_debugged_process_up->GetArchitecture(process_arch)) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to retrieve "
-                  "inferior architecture",
-                  __FUNCTION__);
-    return SendErrorResponse(0x49);
-  }
-
   // Parse out the value.
   uint8_t reg_bytes[32]; // big enough to support up to 256 bit ymmN register
   size_t reg_size = packet.GetHexBytesAvail(reg_bytes);
@@ -2109,7 +2098,9 @@ GDBRemoteCommunicationServerLLGS::Handle
   // Build the reginfos response.
   StreamGDBRemote response;
 
-  RegisterValue reg_value(reg_bytes, reg_size, process_arch.GetByteOrder());
+  RegisterValue reg_value(
+      reg_bytes, reg_size,
+      m_debugged_process_up->GetArchitecture().GetByteOrder());
   Status error = reg_context_sp->WriteRegister(reg_info, reg_value);
   if (error.Fail()) {
     if (log)




More information about the lldb-commits mailing list