[Lldb-commits] [lldb] r316987 - Invert ArchSpec<->Platform dependency

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 31 03:56:04 PDT 2017


Author: labath
Date: Tue Oct 31 03:56:03 2017
New Revision: 316987

URL: http://llvm.org/viewvc/llvm-project?rev=316987&view=rev
Log:
Invert ArchSpec<->Platform dependency

Summary:
ArchSpec::SetTriple was taking a Platform as an argument, and used it to
fill in missing pieces of the specified triple. I invert the dependency
by moving this code to other classes. For this purpose, I've created
three new functions.
- HostInfo::GetAugmentedArchSpec: fills in the triple using the host
  platform (this used to be implemented by passing a null platform
  pointer). By putting this code in the Host module, we can provide a
  way to anyone who does not have a platform instance (lldb-server) an
  easy way to get Host data.
- Platform::GetAugmentedArchSpec: if you have a platform instance, you
  can call this to let it fill in the triple.
- static Platform::GetAugmentedArchSpec: implements the "if platform ==
  0 then use_host() else use_platform()" part.

Reviewers: zturner, jingham, clayborg

Subscribers: mgorny, javed.absar, lldb-commits

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

Added:
    lldb/trunk/unittests/Host/HostInfoTest.cpp
Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/include/lldb/Host/HostInfoBase.h
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/API/SBInstruction.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
    lldb/trunk/source/Commands/CommandObjectPlatform.cpp
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Host/common/HostInfoBase.cpp
    lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
    lldb/trunk/source/Target/Platform.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/unittests/Host/CMakeLists.txt
    lldb/trunk/unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp
    lldb/trunk/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Tue Oct 31 03:56:03 2017
@@ -263,8 +263,6 @@ public:
   explicit ArchSpec(const llvm::Triple &triple);
   explicit ArchSpec(const char *triple_cstr);
   explicit ArchSpec(llvm::StringRef triple_str);
-  ArchSpec(const char *triple_cstr, Platform *platform);
-  ArchSpec(llvm::StringRef triple_str, Platform *platform);
   //------------------------------------------------------------------
   /// Constructor over architecture name.
   ///
@@ -288,6 +286,12 @@ public:
   //------------------------------------------------------------------
   const ArchSpec &operator=(const ArchSpec &rhs);
 
+  //---------------------------------------------------------------------------
+  /// Returns true if the OS, vendor and environment fields of the triple are
+  /// unset. The triple is expected to be normalized (llvm::Triple::normalize).
+  //---------------------------------------------------------------------------
+  static bool ContainsOnlyArch(const llvm::Triple &normalized_triple);
+
   static size_t AutoComplete(llvm::StringRef name, StringList &matches);
 
   //------------------------------------------------------------------
@@ -520,10 +524,6 @@ public:
   bool SetTriple(const llvm::Triple &triple);
 
   bool SetTriple(llvm::StringRef triple_str);
-  bool SetTriple(llvm::StringRef triple_str, Platform *platform);
-
-  bool SetTriple(const char *triple_cstr);
-  bool SetTriple(const char *triple_cstr, Platform *platform);
 
   //------------------------------------------------------------------
   /// Returns the default endianness of the architecture.

Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Tue Oct 31 03:56:03 2017
@@ -81,6 +81,13 @@ public:
   //------------------------------------------------------------------
   static bool GetLLDBPath(lldb::PathType type, FileSpec &file_spec);
 
+  //---------------------------------------------------------------------------
+  /// If the triple does not specify the vendor, os, and environment parts, we
+  /// "augment" these using information from the host and return the resulting
+  /// ArchSpec object.
+  //---------------------------------------------------------------------------
+  static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
+
 protected:
   static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
   static bool ComputeSupportExeDirectory(FileSpec &file_spec);

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Tue Oct 31 03:56:03 2017
@@ -117,9 +117,12 @@ public:
   static lldb::PlatformSP Create(const ArchSpec &arch,
                                  ArchSpec *platform_arch_ptr, Status &error);
 
-  static uint32_t GetNumConnectedRemotePlatforms();
-
-  static lldb::PlatformSP GetConnectedRemotePlatformAtIndex(uint32_t idx);
+  //------------------------------------------------------------------------
+  /// Augments the triple either with information from platform or the host
+  /// system (if platform is null).
+  //------------------------------------------------------------------------
+  static ArchSpec GetAugmentedArchSpec(Platform *platform,
+                                       llvm::StringRef triple);
 
   //------------------------------------------------------------------
   /// Find a platform plugin for a given process.
@@ -513,6 +516,13 @@ public:
       m_os_version_set_while_connected = m_system_arch.IsValid();
   }
 
+  //---------------------------------------------------------------------------
+  /// If the triple contains not specify the vendor, os, and environment parts,
+  /// we "augment" these using information from the platform and return the
+  /// resulting ArchSpec object.
+  //---------------------------------------------------------------------------
+  ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
+
   // Used for column widths
   size_t GetMaxUserIDNameLength() const { return m_max_uid_name_len; }
 

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Tue Oct 31 03:56:03 2017
@@ -694,8 +694,8 @@ SBTarget SBDebugger::FindTargetWithFileA
   SBTarget sb_target;
   if (m_opaque_sp && filename && filename[0]) {
     // No need to lock, the target list is thread safe
-    ArchSpec arch(arch_name,
-                  m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
+    ArchSpec arch = Platform::GetAugmentedArchSpec(
+        m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
     TargetSP target_sp(
         m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
             FileSpec(filename, false), arch_name ? &arch : nullptr));

Modified: lldb/trunk/source/API/SBInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstruction.cpp (original)
+++ lldb/trunk/source/API/SBInstruction.cpp Tue Oct 31 03:56:03 2017
@@ -20,6 +20,7 @@
 #include "lldb/Core/EmulateInstruction.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
@@ -259,8 +260,7 @@ bool SBInstruction::EmulateWithFrame(lld
 bool SBInstruction::DumpEmulation(const char *triple) {
   lldb::InstructionSP inst_sp(GetOpaque());
   if (inst_sp && triple) {
-    lldb_private::ArchSpec arch(triple, NULL);
-    return inst_sp->DumpEmulation(arch);
+    return inst_sp->DumpEmulation(HostInfo::GetAugmentedArchSpec(triple));
   }
   return false;
 }

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Oct 31 03:56:03 2017
@@ -1442,8 +1442,8 @@ lldb::SBModule SBTarget::AddModule(const
       module_spec.GetUUID().SetFromCString(uuid_cstr);
 
     if (triple)
-      module_spec.GetArchitecture().SetTriple(triple,
-                                              target_sp->GetPlatform().get());
+      module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
+          target_sp->GetPlatform().get(), triple);
     else
       module_spec.GetArchitecture() = target_sp->GetArchitecture();
 

Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Tue Oct 31 03:56:03 2017
@@ -163,8 +163,7 @@ Status CommandObjectDisassemble::Command
       auto target_sp =
           execution_context ? execution_context->GetTargetSP() : TargetSP();
       auto platform_sp = target_sp ? target_sp->GetPlatform() : PlatformSP();
-      if (!arch.SetTriple(option_arg, platform_sp.get()))
-        arch.SetTriple(option_arg);
+      arch = Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
     }
     break;
 

Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Tue Oct 31 03:56:03 2017
@@ -1337,8 +1337,8 @@ protected:
         PlatformSP platform_sp =
             debugger_sp ? debugger_sp->GetPlatformList().GetSelectedPlatform()
                         : PlatformSP();
-        match_info.GetProcessInfo().GetArchitecture().SetTriple(
-            option_arg, platform_sp.get());
+        match_info.GetProcessInfo().GetArchitecture() =
+            Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
       } break;
 
       case 'n':

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Tue Oct 31 03:56:03 2017
@@ -10,7 +10,6 @@
 #include "lldb/Core/ArchSpec.h"
 
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Target/Platform.h"
 #include "lldb/Utility/NameMatches.h"
 #include "lldb/Utility/Stream.h" // for Stream
 #include "lldb/Utility/StringList.h"
@@ -555,15 +554,6 @@ FindArchDefinitionEntry(const ArchDefini
 
 ArchSpec::ArchSpec() {}
 
-ArchSpec::ArchSpec(const char *triple_cstr, Platform *platform) {
-  if (triple_cstr)
-    SetTriple(triple_cstr, platform);
-}
-
-ArchSpec::ArchSpec(llvm::StringRef triple_str, Platform *platform) {
-  SetTriple(triple_str, platform);
-}
-
 ArchSpec::ArchSpec(const char *triple_cstr) {
   if (triple_cstr)
     SetTriple(triple_cstr);
@@ -873,16 +863,6 @@ bool lldb_private::ParseMachCPUDashSubty
   return true;
 }
 
-bool ArchSpec::SetTriple(const char *triple_cstr) {
-  llvm::StringRef str(triple_cstr ? triple_cstr : "");
-  return SetTriple(str);
-}
-
-bool ArchSpec::SetTriple(const char *triple_cstr, Platform *platform) {
-  llvm::StringRef str(triple_cstr ? triple_cstr : "");
-  return SetTriple(str, platform);
-}
-
 bool ArchSpec::SetTriple(llvm::StringRef triple) {
   if (triple.empty()) {
     Clear();
@@ -906,73 +886,11 @@ bool ArchSpec::SetTriple(llvm::StringRef
   return IsValid();
 }
 
-bool ArchSpec::SetTriple(llvm::StringRef triple, Platform *platform) {
-  if (triple.empty()) {
-    Clear();
-    return false;
-  }
-  if (ParseMachCPUDashSubtypeTriple(triple, *this))
-    return true;
-
-  if (triple.startswith(LLDB_ARCH_DEFAULT)) {
-    // Special case for the current host default architectures...
-    if (triple.equals(LLDB_ARCH_DEFAULT_32BIT))
-      *this = HostInfo::GetArchitecture(HostInfo::eArchKind32);
-    else if (triple.equals(LLDB_ARCH_DEFAULT_64BIT))
-      *this = HostInfo::GetArchitecture(HostInfo::eArchKind64);
-    else if (triple.equals(LLDB_ARCH_DEFAULT))
-      *this = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
-    return IsValid();
-  }
-
-  ArchSpec raw_arch(triple);
-
-  llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
-
-  const bool os_specified = !normalized_triple.getOSName().empty();
-  const bool vendor_specified = !normalized_triple.getVendorName().empty();
-  const bool env_specified = !normalized_triple.getEnvironmentName().empty();
-
-  if (os_specified || vendor_specified || env_specified) {
-    SetTriple(normalized_triple);
-    return IsValid();
-  }
-
-  // We got an arch only.  If there is no platform, fallback to the host system
-  // for defaults.
-  if (!platform) {
-    llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
-    if (!vendor_specified)
-      normalized_triple.setVendor(host_triple.getVendor());
-    if (!vendor_specified)
-      normalized_triple.setOS(host_triple.getOS());
-    if (!env_specified && host_triple.getEnvironmentName().size())
-      normalized_triple.setEnvironment(host_triple.getEnvironment());
-    SetTriple(normalized_triple);
-    return IsValid();
-  }
-
-  // If we were given a platform, use the platform's system architecture. If
-  // this is not available (might not be connected) use the first supported
-  // architecture.
-  ArchSpec compatible_arch;
-  if (!platform->IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) {
-    *this = raw_arch;
-    return IsValid();
-  }
-
-  if (compatible_arch.IsValid()) {
-    const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
-    if (!vendor_specified)
-      normalized_triple.setVendor(compatible_triple.getVendor());
-    if (!os_specified)
-      normalized_triple.setOS(compatible_triple.getOS());
-    if (!env_specified && compatible_triple.hasEnvironment())
-      normalized_triple.setEnvironment(compatible_triple.getEnvironment());
-  }
-
-  SetTriple(normalized_triple);
-  return IsValid();
+bool ArchSpec::ContainsOnlyArch(const llvm::Triple &normalized_triple) {
+  return !normalized_triple.getArchName().empty() &&
+         normalized_triple.getOSName().empty() &&
+         normalized_triple.getVendorName().empty() &&
+         normalized_triple.getEnvironmentName().empty();
 }
 
 void ArchSpec::MergeFrom(const ArchSpec &other) {

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Tue Oct 31 03:56:03 2017
@@ -251,6 +251,24 @@ bool HostInfoBase::GetLLDBPath(lldb::Pat
   return true;
 }
 
+ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) {
+  if (triple.empty())
+    return ArchSpec();
+  llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
+  if (!ArchSpec::ContainsOnlyArch(normalized_triple))
+    return ArchSpec(triple);
+
+  llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple());
+
+  if (normalized_triple.getVendorName().empty())
+    normalized_triple.setVendor(host_triple.getVendor());
+  if (normalized_triple.getOSName().empty())
+    normalized_triple.setOS(host_triple.getOS());
+  if (normalized_triple.getEnvironmentName().empty())
+    normalized_triple.setEnvironment(host_triple.getEnvironment());
+  return ArchSpec(normalized_triple);
+}
+
 bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) {
   // To get paths related to LLDB we get the path to the executable that
   // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB",

Modified: lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupArchitecture.cpp Tue Oct 31 03:56:03 2017
@@ -8,12 +8,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Interpreter/OptionGroupArchitecture.h"
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
 #include "lldb/Host/OptionParser.h"
+#include "lldb/Target/Platform.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -34,10 +30,7 @@ llvm::ArrayRef<OptionDefinition> OptionG
 
 bool OptionGroupArchitecture::GetArchitecture(Platform *platform,
                                               ArchSpec &arch) {
-  if (m_arch_str.empty())
-    arch.Clear();
-  else
-    arch.SetTriple(m_arch_str.c_str(), platform);
+  arch = Platform::GetAugmentedArchSpec(platform, m_arch_str);
   return arch.IsValid();
 }
 

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=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Tue Oct 31 03:56:03 2017
@@ -403,8 +403,8 @@ GDBRemoteCommunicationServerCommon::Hand
         match_info.SetMatchAllUsers(
             Args::StringToBoolean(value, false, &success));
       } else if (key.equals("triple")) {
-        match_info.GetProcessInfo().GetArchitecture().SetTriple(
-            value.str().c_str(), NULL);
+        match_info.GetProcessInfo().GetArchitecture() =
+            HostInfo::GetAugmentedArchSpec(value);
       } else {
         success = false;
       }
@@ -973,8 +973,7 @@ GDBRemoteCommunicationServerCommon::Hand
   const uint32_t bytes_left = packet.GetBytesLeft();
   if (bytes_left > 0) {
     const char *arch_triple = packet.Peek();
-    ArchSpec arch_spec(arch_triple, NULL);
-    m_process_launch_info.SetArchitecture(arch_spec);
+    m_process_launch_info.SetArchitecture(HostInfo::GetAugmentedArchSpec(arch_triple));
     return SendOKResponse();
   }
   return SendErrorResponse(13);

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Tue Oct 31 03:56:03 2017
@@ -356,6 +356,12 @@ PlatformSP Platform::Create(const ArchSp
   return platform_sp;
 }
 
+ArchSpec Platform::GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple) {
+  if (platform)
+    return platform->GetAugmentedArchSpec(triple);
+  return HostInfo::GetAugmentedArchSpec(triple);
+}
+
 //------------------------------------------------------------------
 /// Default Constructor
 //------------------------------------------------------------------
@@ -963,6 +969,31 @@ const ArchSpec &Platform::GetSystemArchi
   return m_system_arch;
 }
 
+ArchSpec Platform::GetAugmentedArchSpec(llvm::StringRef triple) {
+  if (triple.empty())
+    return ArchSpec();
+  llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
+  if (!ArchSpec::ContainsOnlyArch(normalized_triple))
+    return ArchSpec(triple);
+
+  ArchSpec compatible_arch;
+  ArchSpec raw_arch(triple);
+  if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch))
+    return raw_arch;
+
+  if (!compatible_arch.IsValid())
+    return ArchSpec(normalized_triple);
+
+  const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
+  if (normalized_triple.getVendorName().empty())
+    normalized_triple.setVendor(compatible_triple.getVendor());
+  if (normalized_triple.getOSName().empty())
+    normalized_triple.setOS(compatible_triple.getOS());
+  if (normalized_triple.getEnvironmentName().empty())
+    normalized_triple.setEnvironment(compatible_triple.getEnvironment());
+  return ArchSpec(normalized_triple);
+}
+
 Status Platform::ConnectRemote(Args &args) {
   Status error;
   if (IsHost())

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Oct 31 03:56:03 2017
@@ -480,8 +480,8 @@ Status ProcessLaunchCommandOptions::SetO
         execution_context ? execution_context->GetTargetSP() : TargetSP();
     PlatformSP platform_sp =
         target_sp ? target_sp->GetPlatform() : PlatformSP();
-    if (!launch_info.GetArchitecture().SetTriple(option_arg, platform_sp.get()))
-      launch_info.GetArchitecture().SetTriple(option_arg);
+    launch_info.GetArchitecture() =
+        Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
   } break;
 
   case 'A': // Disable ASLR.

Modified: lldb/trunk/unittests/Host/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/CMakeLists.txt?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Host/CMakeLists.txt Tue Oct 31 03:56:03 2017
@@ -1,6 +1,7 @@
 set (FILES
   FileSpecTest.cpp
   FileSystemTest.cpp
+  HostInfoTest.cpp
   HostTest.cpp
   MainLoopTest.cpp
   SocketAddressTest.cpp

Added: lldb/trunk/unittests/Host/HostInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=316987&view=auto
==============================================================================
--- lldb/trunk/unittests/Host/HostInfoTest.cpp (added)
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp Tue Oct 31 03:56:03 2017
@@ -0,0 +1,40 @@
+//===-- HostTest.cpp --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/HostInfo.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class HostInfoTest: public ::testing::Test {
+  public:
+    void SetUp() override { HostInfo::Initialize(); }
+    void TearDown() override { HostInfo::Terminate(); }
+};
+}
+
+TEST_F(HostInfoTest, GetAugmentedArchSpec) {
+  // Fully specified triple should not be changed.
+  ArchSpec spec = HostInfo::GetAugmentedArchSpec("x86_64-pc-linux-gnu");
+  EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc-linux-gnu");
+
+  // Same goes if we specify at least one of (os, vendor, env).
+  spec = HostInfo::GetAugmentedArchSpec("x86_64-pc");
+  EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc");
+
+  // But if we specify only an arch, we should fill in the rest from the host.
+  spec = HostInfo::GetAugmentedArchSpec("x86_64");
+  Triple triple(sys::getDefaultTargetTriple());
+  EXPECT_EQ(spec.GetTriple().getArch(), Triple::x86_64);
+  EXPECT_EQ(spec.GetTriple().getOS(), triple.getOS());
+  EXPECT_EQ(spec.GetTriple().getVendor(), triple.getVendor());
+  EXPECT_EQ(spec.GetTriple().getEnvironment(), triple.getEnvironment());
+}

Modified: lldb/trunk/unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp (original)
+++ lldb/trunk/unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp Tue Oct 31 03:56:03 2017
@@ -55,7 +55,7 @@ void TestArm64InstEmulation::TearDownTes
 }
 
 TEST_F(TestArm64InstEmulation, TestSimpleDarwinFunction) {
-  ArchSpec arch("arm64-apple-ios10", nullptr);
+  ArchSpec arch("arm64-apple-ios10");
   UnwindAssemblyInstEmulation *engine =
       static_cast<UnwindAssemblyInstEmulation *>(
           UnwindAssemblyInstEmulation::CreateInstance(arch));
@@ -151,7 +151,7 @@ TEST_F(TestArm64InstEmulation, TestSimpl
 }
 
 TEST_F(TestArm64InstEmulation, TestMediumDarwinFunction) {
-  ArchSpec arch("arm64-apple-ios10", nullptr);
+  ArchSpec arch("arm64-apple-ios10");
   UnwindAssemblyInstEmulation *engine =
       static_cast<UnwindAssemblyInstEmulation *>(
           UnwindAssemblyInstEmulation::CreateInstance(arch));
@@ -313,7 +313,7 @@ TEST_F(TestArm64InstEmulation, TestMediu
 }
 
 TEST_F(TestArm64InstEmulation, TestFramelessThreeEpilogueFunction) {
-  ArchSpec arch("arm64-apple-ios10", nullptr);
+  ArchSpec arch("arm64-apple-ios10");
   UnwindAssemblyInstEmulation *engine =
       static_cast<UnwindAssemblyInstEmulation *>(
           UnwindAssemblyInstEmulation::CreateInstance(arch));
@@ -408,7 +408,7 @@ TEST_F(TestArm64InstEmulation, TestFrame
 }
 
 TEST_F(TestArm64InstEmulation, TestRegisterSavedTwice) {
-  ArchSpec arch("arm64-apple-ios10", nullptr);
+  ArchSpec arch("arm64-apple-ios10");
   UnwindAssemblyInstEmulation *engine =
       static_cast<UnwindAssemblyInstEmulation *>(
           UnwindAssemblyInstEmulation::CreateInstance(arch));
@@ -510,7 +510,7 @@ TEST_F(TestArm64InstEmulation, TestRegis
 }
 
 TEST_F(TestArm64InstEmulation, TestRegisterDoubleSpills) {
-  ArchSpec arch("arm64-apple-ios10", nullptr);
+  ArchSpec arch("arm64-apple-ios10");
   UnwindAssemblyInstEmulation *engine =
       static_cast<UnwindAssemblyInstEmulation *>(
           UnwindAssemblyInstEmulation::CreateInstance(arch));

Modified: lldb/trunk/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp?rev=316987&r1=316986&r2=316987&view=diff
==============================================================================
--- lldb/trunk/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp (original)
+++ lldb/trunk/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp Tue Oct 31 03:56:03 2017
@@ -95,7 +95,7 @@ enum i386_regs {
 
 std::unique_ptr<x86AssemblyInspectionEngine> Getx86_64Inspector() {
 
-  ArchSpec arch("x86_64-apple-macosx", nullptr);
+  ArchSpec arch("x86_64-apple-macosx");
   std::unique_ptr<x86AssemblyInspectionEngine> engine(
       new x86AssemblyInspectionEngine(arch));
 
@@ -114,7 +114,7 @@ std::unique_ptr<x86AssemblyInspectionEng
 
 std::unique_ptr<x86AssemblyInspectionEngine> Geti386Inspector() {
 
-  ArchSpec arch("i386-apple-macosx", nullptr);
+  ArchSpec arch("i386-apple-macosx");
   std::unique_ptr<x86AssemblyInspectionEngine> engine(
       new x86AssemblyInspectionEngine(arch));
 




More information about the lldb-commits mailing list