Index: include/lldb/Core/ArchSpec.h =================================================================== --- include/lldb/Core/ArchSpec.h +++ include/lldb/Core/ArchSpec.h @@ -263,8 +263,6 @@ 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,8 @@ //------------------------------------------------------------------ const ArchSpec &operator=(const ArchSpec &rhs); + static bool ContainsMoreThanArch(llvm::StringRef triple); + static size_t AutoComplete(llvm::StringRef name, StringList &matches); //------------------------------------------------------------------ @@ -520,10 +520,6 @@ 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. Index: include/lldb/Host/HostInfoBase.h =================================================================== --- include/lldb/Host/HostInfoBase.h +++ include/lldb/Host/HostInfoBase.h @@ -81,6 +81,13 @@ //------------------------------------------------------------------ static bool GetLLDBPath(lldb::PathType type, FileSpec &file_spec); + //--------------------------------------------------------------------------- + /// If the triple contains 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); Index: include/lldb/Target/Platform.h =================================================================== --- include/lldb/Target/Platform.h +++ include/lldb/Target/Platform.h @@ -117,9 +117,12 @@ 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 @@ 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; } Index: source/API/SBDebugger.cpp =================================================================== --- source/API/SBDebugger.cpp +++ source/API/SBDebugger.cpp @@ -694,8 +694,8 @@ 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)); Index: source/API/SBInstruction.cpp =================================================================== --- source/API/SBInstruction.cpp +++ source/API/SBInstruction.cpp @@ -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::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; } Index: source/API/SBTarget.cpp =================================================================== --- source/API/SBTarget.cpp +++ source/API/SBTarget.cpp @@ -1442,8 +1442,8 @@ 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(); Index: source/Commands/CommandObjectDisassemble.cpp =================================================================== --- source/Commands/CommandObjectDisassemble.cpp +++ source/Commands/CommandObjectDisassemble.cpp @@ -163,8 +163,7 @@ 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; Index: source/Commands/CommandObjectPlatform.cpp =================================================================== --- source/Commands/CommandObjectPlatform.cpp +++ source/Commands/CommandObjectPlatform.cpp @@ -1337,8 +1337,8 @@ 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': Index: source/Core/ArchSpec.cpp =================================================================== --- source/Core/ArchSpec.cpp +++ source/Core/ArchSpec.cpp @@ -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 @@ 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 @@ 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 @@ 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); - +bool ArchSpec::ContainsMoreThanArch(llvm::StringRef 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(); + return !normalized_triple.getOSName().empty() || + !normalized_triple.getVendorName().empty() || + !normalized_triple.getEnvironmentName().empty(); } void ArchSpec::MergeFrom(const ArchSpec &other) { Index: source/Host/common/HostInfoBase.cpp =================================================================== --- source/Host/common/HostInfoBase.cpp +++ source/Host/common/HostInfoBase.cpp @@ -251,6 +251,24 @@ return true; } +ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) { + if (triple.empty()) + return ArchSpec(); + if (ArchSpec::ContainsMoreThanArch(triple)) + return ArchSpec(triple); + + llvm::Triple normalized_triple(llvm::Triple::normalize(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", Index: source/Interpreter/OptionGroupArchitecture.cpp =================================================================== --- source/Interpreter/OptionGroupArchitecture.cpp +++ source/Interpreter/OptionGroupArchitecture.cpp @@ -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 @@ 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(); } Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -403,8 +403,8 @@ 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 @@ 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); Index: source/Target/Platform.cpp =================================================================== --- source/Target/Platform.cpp +++ source/Target/Platform.cpp @@ -356,6 +356,12 @@ 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 @@ return m_system_arch; } +ArchSpec Platform::GetAugmentedArchSpec(llvm::StringRef triple) { + if (triple.empty()) + return ArchSpec(); + if (ArchSpec::ContainsMoreThanArch(triple)) + return ArchSpec(triple); + + ArchSpec compatible_arch; + ArchSpec raw_arch(triple); + if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) + return raw_arch; + + llvm::Triple normalized_triple(llvm::Triple::normalize(triple)); + if (compatible_arch.IsValid()) { + 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()) Index: source/Target/Process.cpp =================================================================== --- source/Target/Process.cpp +++ source/Target/Process.cpp @@ -480,8 +480,8 @@ 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. Index: unittests/Host/CMakeLists.txt =================================================================== --- unittests/Host/CMakeLists.txt +++ unittests/Host/CMakeLists.txt @@ -1,6 +1,7 @@ set (FILES FileSpecTest.cpp FileSystemTest.cpp + HostInfoTest.cpp HostTest.cpp MainLoopTest.cpp SocketAddressTest.cpp Index: unittests/Host/HostInfoTest.cpp =================================================================== --- /dev/null +++ unittests/Host/HostInfoTest.cpp @@ -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()); +} Index: unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp =================================================================== --- unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp +++ unittests/UnwindAssembly/InstEmulation/TestArm64InstEmulation.cpp @@ -55,7 +55,7 @@ } TEST_F(TestArm64InstEmulation, TestSimpleDarwinFunction) { - ArchSpec arch("arm64-apple-ios10", nullptr); + ArchSpec arch("arm64-apple-ios10"); UnwindAssemblyInstEmulation *engine = static_cast( UnwindAssemblyInstEmulation::CreateInstance(arch)); @@ -151,7 +151,7 @@ } TEST_F(TestArm64InstEmulation, TestMediumDarwinFunction) { - ArchSpec arch("arm64-apple-ios10", nullptr); + ArchSpec arch("arm64-apple-ios10"); UnwindAssemblyInstEmulation *engine = static_cast( UnwindAssemblyInstEmulation::CreateInstance(arch)); @@ -313,7 +313,7 @@ } TEST_F(TestArm64InstEmulation, TestFramelessThreeEpilogueFunction) { - ArchSpec arch("arm64-apple-ios10", nullptr); + ArchSpec arch("arm64-apple-ios10"); UnwindAssemblyInstEmulation *engine = static_cast( UnwindAssemblyInstEmulation::CreateInstance(arch)); @@ -408,7 +408,7 @@ } TEST_F(TestArm64InstEmulation, TestRegisterSavedTwice) { - ArchSpec arch("arm64-apple-ios10", nullptr); + ArchSpec arch("arm64-apple-ios10"); UnwindAssemblyInstEmulation *engine = static_cast( UnwindAssemblyInstEmulation::CreateInstance(arch)); @@ -510,7 +510,7 @@ } TEST_F(TestArm64InstEmulation, TestRegisterDoubleSpills) { - ArchSpec arch("arm64-apple-ios10", nullptr); + ArchSpec arch("arm64-apple-ios10"); UnwindAssemblyInstEmulation *engine = static_cast( UnwindAssemblyInstEmulation::CreateInstance(arch)); Index: unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp =================================================================== --- unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp +++ unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp @@ -95,7 +95,7 @@ std::unique_ptr Getx86_64Inspector() { - ArchSpec arch("x86_64-apple-macosx", nullptr); + ArchSpec arch("x86_64-apple-macosx"); std::unique_ptr engine( new x86AssemblyInspectionEngine(arch)); @@ -114,7 +114,7 @@ std::unique_ptr Geti386Inspector() { - ArchSpec arch("i386-apple-macosx", nullptr); + ArchSpec arch("i386-apple-macosx"); std::unique_ptr engine( new x86AssemblyInspectionEngine(arch));