diff options
author | Todd Fiala <todd.fiala@gmail.com> | 2015-10-13 23:41:19 +0000 |
---|---|---|
committer | Todd Fiala <todd.fiala@gmail.com> | 2015-10-13 23:41:19 +0000 |
commit | 7df337f85c78e64c3fb2d36c859212e8d06f7725 (patch) | |
tree | 15a3679c4ff89174f81de59b3e73546575d3e5a8 | |
parent | a59fcbae4ff25ed039728ac66af0fcf625fa22d4 (diff) | |
download | bcm5719-llvm-7df337f85c78e64c3fb2d36c859212e8d06f7725.tar.gz bcm5719-llvm-7df337f85c78e64c3fb2d36c859212e8d06f7725.zip |
ArchSpec: fix unintentional promotion of unspecified unknowns to specified unknowns
* ArchSpec::MergeFrom() would erroneously promote an unspecified
unknown to a specified unknown when both the ArchSpec and the merged
in ArchSpec were both unspecified unknowns. This no longer happens,
which fixes issues with global module cache lookup in some
situations.
* Added ArchSpec::DumpTriple(Stream&) that now properly prints
unspecified unknowns as '*' and specified unknows as 'unknown'.
This makes it trivial to tell the difference between the two.
Converted printing code over ot using DumpTriple() rather than
building from scratch.
* Fixed up a couple places that were not guaranteeing that an
unspecified unknown was recorded as such.
llvm-svn: 250253
-rw-r--r-- | lldb/include/lldb/Core/ArchSpec.h | 15 | ||||
-rw-r--r-- | lldb/include/lldb/Core/ModuleSpec.h | 5 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 16 | ||||
-rw-r--r-- | lldb/source/Core/ArchSpec.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Host/linux/HostInfoLinux.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Target/Platform.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Target/TargetList.cpp | 9 | ||||
-rw-r--r-- | lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py | 14 |
10 files changed, 85 insertions, 27 deletions
diff --git a/lldb/include/lldb/Core/ArchSpec.h b/lldb/include/lldb/Core/ArchSpec.h index ac3e6870d35..3a9c1d45e19 100644 --- a/lldb/include/lldb/Core/ArchSpec.h +++ b/lldb/include/lldb/Core/ArchSpec.h @@ -341,11 +341,23 @@ public: } bool + TripleVendorIsUnspecifiedUnknown() const + { + return m_triple.getVendor() == llvm::Triple::UnknownVendor && m_triple.getVendorName().empty(); + } + + bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); } + bool + TripleOSIsUnspecifiedUnknown() const + { + return m_triple.getOS() == llvm::Triple::UnknownOS && m_triple.getOSName().empty(); + } + //------------------------------------------------------------------ /// Merges fields from another ArchSpec into this ArchSpec. /// @@ -484,6 +496,9 @@ public: return m_triple; } + void + DumpTriple(Stream &s) const; + //------------------------------------------------------------------ /// Architecture tripple setter. /// diff --git a/lldb/include/lldb/Core/ModuleSpec.h b/lldb/include/lldb/Core/ModuleSpec.h index be7041981a0..5cfe4af05aa 100644 --- a/lldb/include/lldb/Core/ModuleSpec.h +++ b/lldb/include/lldb/Core/ModuleSpec.h @@ -329,7 +329,7 @@ public: } void - Dump (Stream &strm) + Dump (Stream &strm) const { bool dumped_something = false; if (m_file) @@ -361,7 +361,8 @@ public: { if (dumped_something) strm.PutCString(", "); - strm.Printf("arch = %s", m_arch.GetTriple().str().c_str()); + strm.Printf("arch = "); + m_arch.DumpTriple(strm); dumped_something = true; } if (m_uuid.IsValid()) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index 9a84c347c0e..b530517074e 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -79,7 +79,8 @@ DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bo uint32_t properties = 0; if (target_arch.IsValid()) { - strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str()); + strm.Printf ("%sarch=", properties++ > 0 ? ", " : " ( "); + target_arch.DumpTriple (strm); properties++; } PlatformSP platform_sp (target->GetPlatform()); @@ -1459,15 +1460,18 @@ DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t { if (module) { - const char *arch_cstr; + StreamString arch_strm; + if (full_triple) - arch_cstr = module->GetArchitecture().GetTriple().str().c_str(); + module->GetArchitecture().DumpTriple(arch_strm); else - arch_cstr = module->GetArchitecture().GetArchitectureName(); + arch_strm.PutCString(module->GetArchitecture().GetArchitectureName()); + std::string arch_str = arch_strm.GetString(); + if (width) - strm.Printf("%-*s", width, arch_cstr); + strm.Printf("%-*s", width, arch_str.c_str()); else - strm.PutCString(arch_cstr); + strm.PutCString(arch_str.c_str()); } } diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp index e38501c81ed..27335420008 100644 --- a/lldb/source/Core/ArchSpec.cpp +++ b/lldb/source/Core/ArchSpec.cpp @@ -844,9 +844,9 @@ ArchSpec::SetTriple (const char *triple_cstr, Platform *platform) void ArchSpec::MergeFrom(const ArchSpec &other) { - if (GetTriple().getVendor() == llvm::Triple::UnknownVendor && !TripleVendorWasSpecified()) + if (TripleVendorIsUnspecifiedUnknown() && !other.TripleVendorIsUnspecifiedUnknown()) GetTriple().setVendor(other.GetTriple().getVendor()); - if (GetTriple().getOS() == llvm::Triple::UnknownOS && !TripleOSWasSpecified()) + if (TripleOSIsUnspecifiedUnknown() && !other.TripleOSIsUnspecifiedUnknown()) GetTriple().setOS(other.GetTriple().getOS()); if (GetTriple().getArch() == llvm::Triple::UnknownArch) GetTriple().setArch(other.GetTriple().getArch()); @@ -1444,3 +1444,18 @@ ArchSpec::GetStopInfoOverrideCallback () const return StopInfoOverrideCallbackTypeARM; return NULL; } + +void +ArchSpec::DumpTriple(Stream &s) const +{ + const llvm::Triple &triple = GetTriple(); + llvm::StringRef arch_str = triple.getArchName(); + llvm::StringRef vendor_str = triple.getVendorName(); + llvm::StringRef os_str = triple.getOSName(); + + s.Printf("%s-%s-%s", + arch_str.empty() ? "*" : arch_str.str().c_str(), + vendor_str.empty() ? "*" : vendor_str.str().c_str(), + os_str.empty() ? "*" : os_str.str().c_str() + ); +} diff --git a/lldb/source/Host/linux/HostInfoLinux.cpp b/lldb/source/Host/linux/HostInfoLinux.cpp index 3a3023b1343..4732a2a571b 100644 --- a/lldb/source/Host/linux/HostInfoLinux.cpp +++ b/lldb/source/Host/linux/HostInfoLinux.cpp @@ -271,12 +271,12 @@ HostInfoLinux::ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_ { arch_32.SetDistributionId(distribution_id); if (arch_32.GetTriple().getVendor() == llvm::Triple::UnknownVendor) - arch_32.GetTriple().setVendorName(""); + arch_32.GetTriple().setVendorName(llvm::StringRef()); } if (arch_64.IsValid()) { arch_64.SetDistributionId(distribution_id); if (arch_64.GetTriple().getVendor() == llvm::Triple::UnknownVendor) - arch_64.GetTriple().setVendorName(""); + arch_64.GetTriple().setVendorName(llvm::StringRef()); } } diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index f9f035878c4..0884a1c8ff2 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -1605,6 +1605,12 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl §ion_headers, } } + // Make any unknown triple components to be unspecified unknowns. + if (arch_spec.GetTriple().getVendor() == llvm::Triple::UnknownVendor) + arch_spec.GetTriple().setVendorName (llvm::StringRef()); + if (arch_spec.GetTriple().getOS() == llvm::Triple::UnknownOS) + arch_spec.GetTriple().setOSName (llvm::StringRef()); + return section_headers.size(); } } diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index e43cdc63646..33446a9fb3a 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -475,7 +475,11 @@ Platform::GetStatus (Stream &strm) if (arch.IsValid()) { if (!arch.GetTriple().str().empty()) - strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); + { + strm.Printf(" Triple: "); + arch.DumpTriple(strm); + strm.EOL(); + } } if (GetOSVersion(major, minor, update)) diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 8863fd04fc7..cf3090664b9 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -316,8 +316,12 @@ ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const } } - if (m_arch.IsValid()) - s.Printf (" arch = %s\n", m_arch.GetTriple().str().c_str()); + if (m_arch.IsValid()) + { + s.Printf (" arch = "); + m_arch.DumpTriple(s); + s.EOL(); + } if (m_uid != UINT32_MAX) { @@ -370,7 +374,10 @@ ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_ar const char *cstr; s.Printf ("%-6" PRIu64 " %-6" PRIu64 " ", m_pid, m_parent_pid); - + StreamString arch_strm; + if (m_arch.IsValid()) + m_arch.DumpTriple(arch_strm); + if (verbose) { cstr = platform->GetUserName (m_uid); @@ -396,13 +403,14 @@ ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_ar s.Printf ("%-10s ", cstr); else s.Printf ("%-10u ", m_egid); - s.Printf ("%-24s ", m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); + + s.Printf ("%-24s ", arch_strm.GetString().c_str()); } else { s.Printf ("%-10s %-24s ", platform->GetUserName (m_euid), - m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); + arch_strm.GetString().c_str()); } if (verbose || show_args) diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 552e951496f..af596f79f4b 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -179,9 +179,14 @@ TargetList::CreateTargetInternal (Debugger &debugger, } else { + StreamString platform_arch_strm; + StreamString module_arch_strm; + + platform_arch.DumpTriple(platform_arch_strm); + matching_module_spec.GetArchitecture().DumpTriple(module_arch_strm); error.SetErrorStringWithFormat("the specified architecture '%s' is not compatible with '%s' in '%s'", - platform_arch.GetTriple().str().c_str(), - matching_module_spec.GetArchitecture().GetTriple().str().c_str(), + platform_arch_strm.GetString().c_str(), + module_arch_strm.GetString().c_str(), module_spec.GetFileSpec().GetPath().c_str()); return error; } diff --git a/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py b/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py index 165a41fdffa..47e7db4b366 100644 --- a/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py +++ b/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py @@ -19,13 +19,13 @@ class TestImageListMultiArchitecture(TestBase): def test_image_list_shows_multiple_architectures(self): """Test that image list properly shows the correct architecture for a set of different architecture object files.""" images = { - "hello-freebsd-10.0-x86_64-clang-3.3": re.compile(r"x86_64-(unknown)?-freebsd10.0(-unknown)? x86_64"), - "hello-freebsd-10.0-x86_64-gcc-4.7.3": re.compile(r"x86_64-(unknown)?-freebsd10.0(-unknown)? x86_64"), - "hello-netbsd-6.1-x86_64-gcc-4.5.3": re.compile(r"x86_64-(unknown)?-netbsd(-unknown)? x86_64"), - "hello-ubuntu-14.04-x86_64-gcc-4.8.2": re.compile(r"x86_64-(unknown)?-linux(-unknown)? x86_64"), - "hello-ubuntu-14.04-x86_64-clang-3.5pre": re.compile(r"x86_64-(unknown)?-linux(-unknown)? x86_64"), - "hello-unknown-kalimba_arch4-kcc-36": re.compile(r"kalimba4-csr-unknown(-unknown)? kalimba"), - "hello-unknown-kalimba_arch5-kcc-39": re.compile(r"kalimba5-csr-unknown(-unknown)? kalimba"), + "hello-freebsd-10.0-x86_64-clang-3.3": re.compile(r"x86_64-(\*)?-freebsd10.0(-unknown)? x86_64"), + "hello-freebsd-10.0-x86_64-gcc-4.7.3": re.compile(r"x86_64-(\*)?-freebsd10.0(-unknown)? x86_64"), + "hello-netbsd-6.1-x86_64-gcc-4.5.3": re.compile(r"x86_64-(\*)?-netbsd(-unknown)? x86_64"), + "hello-ubuntu-14.04-x86_64-gcc-4.8.2": re.compile(r"x86_64-(\*)?-linux(-unknown)? x86_64"), + "hello-ubuntu-14.04-x86_64-clang-3.5pre": re.compile(r"x86_64-(\*)?-linux(-unknown)? x86_64"), + "hello-unknown-kalimba_arch4-kcc-36": re.compile(r"kalimba4-csr-(unknown|\*)(-unknown)? kalimba"), + "hello-unknown-kalimba_arch5-kcc-39": re.compile(r"kalimba5-csr-(unknown|\*)(-unknown)? kalimba"), } for image_name in images: |