[Lldb-commits] [lldb] r250253 - ArchSpec: fix unintentional promotion of unspecified unknowns to specified unknowns

Todd Fiala via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 13 16:41:19 PDT 2015


Author: tfiala
Date: Tue Oct 13 18:41:19 2015
New Revision: 250253

URL: http://llvm.org/viewvc/llvm-project?rev=250253&view=rev
Log:
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.

Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/include/lldb/Core/ModuleSpec.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Host/linux/HostInfoLinux.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Target/Platform.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/TargetList.cpp
    lldb/trunk/test/functionalities/object-file/TestImageListMultiArchitecture.py

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Tue Oct 13 18:41:19 2015
@@ -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.
     ///

Modified: lldb/trunk/include/lldb/Core/ModuleSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleSpec.h?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleSpec.h Tue Oct 13 18:41:19 2015
@@ -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())

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Oct 13 18:41:19 2015
@@ -79,7 +79,8 @@ DumpTargetInfo (uint32_t target_idx, Tar
     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, Mo
 {
     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());
     }
 }
 

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Tue Oct 13 18:41:19 2015
@@ -844,9 +844,9 @@ ArchSpec::SetTriple (const char *triple_
 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 ()
         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()
+             );
+}

Modified: lldb/trunk/source/Host/linux/HostInfoLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/HostInfoLinux.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/HostInfoLinux.cpp (original)
+++ lldb/trunk/source/Host/linux/HostInfoLinux.cpp Tue Oct 13 18:41:19 2015
@@ -271,12 +271,12 @@ HostInfoLinux::ComputeHostArchitectureSu
     {
         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());
     }
 }

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Oct 13 18:41:19 2015
@@ -1605,6 +1605,12 @@ ObjectFileELF::GetSectionHeaderInfo(Sect
                 }
             }
 
+            // 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();
         }
     }

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Tue Oct 13 18:41:19 2015
@@ -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))

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Oct 13 18:41:19 2015
@@ -316,8 +316,12 @@ ProcessInstanceInfo::Dump (Stream &s, Pl
         }
     }
 
-    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 (Str
         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 (Str
                 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)

Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Tue Oct 13 18:41:19 2015
@@ -179,9 +179,14 @@ TargetList::CreateTargetInternal (Debugg
                         }
                         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;
                         }

Modified: lldb/trunk/test/functionalities/object-file/TestImageListMultiArchitecture.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/object-file/TestImageListMultiArchitecture.py?rev=250253&r1=250252&r2=250253&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/object-file/TestImageListMultiArchitecture.py (original)
+++ lldb/trunk/test/functionalities/object-file/TestImageListMultiArchitecture.py Tue Oct 13 18:41:19 2015
@@ -19,13 +19,13 @@ class TestImageListMultiArchitecture(Tes
     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:




More information about the lldb-commits mailing list