xiaobai updated this revision to Diff 188457. xiaobai added a comment. Fix typo
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58653/new/ https://reviews.llvm.org/D58653 Files: include/lldb/Utility/ArchSpec.h source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp source/Utility/ArchSpec.cpp unittests/Utility/ArchSpecTest.cpp
Index: unittests/Utility/ArchSpecTest.cpp =================================================================== --- unittests/Utility/ArchSpecTest.cpp +++ unittests/Utility/ArchSpecTest.cpp @@ -232,3 +232,76 @@ EXPECT_FALSE(ArchSpec()); EXPECT_TRUE(ArchSpec("x86_64-pc-linux")); } + +TEST(ArchSpecTest, TripleComponentsWereSpecified) { + { + ArchSpec A(""); + ArchSpec B("-"); + ArchSpec C("--"); + ArchSpec D("---"); + + ASSERT_FALSE(A.TripleVendorWasSpecified()); + ASSERT_FALSE(A.TripleOSWasSpecified()); + ASSERT_FALSE(A.TripleEnvironmentWasSpecified()); + + ASSERT_FALSE(B.TripleVendorWasSpecified()); + ASSERT_FALSE(B.TripleOSWasSpecified()); + ASSERT_FALSE(B.TripleEnvironmentWasSpecified()); + + ASSERT_FALSE(C.TripleVendorWasSpecified()); + ASSERT_FALSE(C.TripleOSWasSpecified()); + ASSERT_FALSE(C.TripleEnvironmentWasSpecified()); + + ASSERT_FALSE(D.TripleVendorWasSpecified()); + ASSERT_FALSE(D.TripleOSWasSpecified()); + ASSERT_FALSE(D.TripleEnvironmentWasSpecified()); + } + { + // TODO: llvm::Triple::normalize treats the missing components from these + // triples as specified unknown components instead of unspecified + // components. We need to either change the behavior in llvm or work around + // this in lldb. + ArchSpec A("armv7"); + ArchSpec B("armv7-"); + ArchSpec C("armv7--"); + ArchSpec D("armv7---"); + + ASSERT_FALSE(A.TripleVendorWasSpecified()); + ASSERT_FALSE(A.TripleOSWasSpecified()); + ASSERT_FALSE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(B.TripleVendorWasSpecified()); + ASSERT_FALSE(B.TripleOSWasSpecified()); + ASSERT_FALSE(B.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(C.TripleVendorWasSpecified()); + ASSERT_TRUE(C.TripleOSWasSpecified()); + ASSERT_FALSE(C.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(D.TripleVendorWasSpecified()); + ASSERT_TRUE(D.TripleOSWasSpecified()); + ASSERT_TRUE(D.TripleEnvironmentWasSpecified()); + } + { + ArchSpec A("x86_64-unknown"); + ArchSpec B("powerpc-unknown-linux"); + ArchSpec C("i386-pc-windows-msvc"); + ArchSpec D("aarch64-unknown-linux-android"); + + ASSERT_TRUE(A.TripleVendorWasSpecified()); + ASSERT_FALSE(A.TripleOSWasSpecified()); + ASSERT_FALSE(A.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(B.TripleVendorWasSpecified()); + ASSERT_TRUE(B.TripleOSWasSpecified()); + ASSERT_FALSE(B.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(C.TripleVendorWasSpecified()); + ASSERT_TRUE(C.TripleOSWasSpecified()); + ASSERT_TRUE(C.TripleEnvironmentWasSpecified()); + + ASSERT_TRUE(D.TripleVendorWasSpecified()); + ASSERT_TRUE(D.TripleOSWasSpecified()); + ASSERT_TRUE(D.TripleEnvironmentWasSpecified()); + } +} Index: source/Utility/ArchSpec.cpp =================================================================== --- source/Utility/ArchSpec.cpp +++ source/Utility/ArchSpec.cpp @@ -889,10 +889,9 @@ } void ArchSpec::MergeFrom(const ArchSpec &other) { - if (TripleVendorIsUnspecifiedUnknown() && - !other.TripleVendorIsUnspecifiedUnknown()) + if (!TripleVendorWasSpecified() && other.TripleVendorWasSpecified()) GetTriple().setVendor(other.GetTriple().getVendor()); - if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown()) + if (!TripleOSWasSpecified() && other.TripleVendorWasSpecified()) GetTriple().setOS(other.GetTriple().getOS()); if (GetTriple().getArch() == llvm::Triple::UnknownArch) { GetTriple().setArch(other.GetTriple().getArch()); @@ -903,8 +902,8 @@ if (other.GetCore() != eCore_uknownMach64) UpdateCore(); } - if (GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && - !TripleVendorWasSpecified()) { + if (!TripleEnvironmentWasSpecified() && + other.TripleEnvironmentWasSpecified() && !TripleVendorWasSpecified()) { if (other.TripleVendorWasSpecified()) GetTriple().setEnvironment(other.GetTriple().getEnvironment()); } Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -3309,7 +3309,7 @@ } if (CalculateType() == eTypeCoreFile && - m_arch_spec.TripleOSIsUnspecifiedUnknown()) { + !m_arch_spec.TripleOSWasSpecified()) { // Core files don't have section headers yet they have PT_NOTE program // headers that might shed more light on the architecture for (const elf::ELFProgramHeader &H : ProgramHeaders()) { Index: include/lldb/Utility/ArchSpec.h =================================================================== --- include/lldb/Utility/ArchSpec.h +++ include/lldb/Utility/ArchSpec.h @@ -376,20 +376,10 @@ return !m_triple.getVendorName().empty(); } - bool TripleVendorIsUnspecifiedUnknown() const { - return m_triple.getVendor() == llvm::Triple::UnknownVendor && - m_triple.getVendorName().empty(); - } - bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); } bool TripleEnvironmentWasSpecified() const { - return !m_triple.getEnvironmentName().empty(); - } - - bool TripleOSIsUnspecifiedUnknown() const { - return m_triple.getOS() == llvm::Triple::UnknownOS && - m_triple.getOSName().empty(); + return m_triple.hasEnvironment(); } //------------------------------------------------------------------
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits