[Lldb-commits] [lldb] r140236 - in /lldb/trunk: lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme source/Core/ArchSpec.cpp source/Core/Module.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Greg Clayton gclayton at apple.com
Tue Sep 20 20:57:31 PDT 2011


Author: gclayton
Date: Tue Sep 20 22:57:31 2011
New Revision: 140236

URL: http://llvm.org/viewvc/llvm-project?rev=140236&view=rev
Log:
The first part of a fix for being able to select an architecture slice from
a file when the target has a triple with an unknown vendor and/or OS and the
slice of the file itself has a valid vendor and/or OS.

The Module now adopts the ObjectFile's architecture after a valid architecture
has been loaded to make sure the module matches the object file.


Modified:
    lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme?rev=140236&r1=140235&r2=140236&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme (original)
+++ lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme Tue Sep 20 22:57:31 2011
@@ -99,12 +99,6 @@
             ReferencedContainer = "container:lldb.xcodeproj">
          </BuildableReference>
       </BuildableProductRunnable>
-      <CommandLineArguments>
-         <CommandLineArgument
-            argument = "/Volumes/work/gclayton/Documents/src/args/a.out"
-            isEnabled = "YES">
-         </CommandLineArgument>
-      </CommandLineArguments>
       <EnvironmentVariables>
          <EnvironmentVariable
             key = "LLDB_LAUNCH_FLAG_DISABLE_ASLR"

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=140236&r1=140235&r2=140236&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Tue Sep 20 22:57:31 2011
@@ -538,7 +538,9 @@
             {
                 m_core = core_def->core;
                 update_triple = false;
-                m_triple.setArch (core_def->machine);
+                // Always use the architecture name because it might be more descriptive
+                // than the architecture enum ("armv7" -> llvm::Triple::arm).
+                m_triple.setArchName(llvm::StringRef(core_def->name));
                 if (arch_type == eArchTypeMachO)
                 {
                     m_triple.setVendor (llvm::Triple::Apple);
@@ -549,6 +551,9 @@
                     m_triple.setVendor (llvm::Triple::UnknownVendor);
                     m_triple.setOS (llvm::Triple::UnknownOS);
                 }
+                // Fall back onto setting the machine type if the arch by name failed...
+                if (m_triple.getArch () == llvm::Triple::UnknownArch)
+                    m_triple.setArch (core_def->machine);
             }
         }
     }
@@ -665,13 +670,38 @@
     {
         const llvm::Triple &lhs_triple = lhs.GetTriple();
         const llvm::Triple &rhs_triple = rhs.GetTriple();
-        if (lhs_triple.getVendor() != rhs_triple.getVendor()
-            || lhs_triple.getOS() != rhs_triple.getOS()
-            || lhs_triple.getArch() != rhs_triple.getArch()
-            || lhs_triple.getEnvironment() != rhs_triple.getEnvironment())
-            return false;
-        else
-            return true;
+
+        const llvm::Triple::VendorType lhs_triple_vendor = lhs_triple.getVendor();
+        const llvm::Triple::VendorType rhs_triple_vendor = rhs_triple.getVendor();
+        if (lhs_triple_vendor != rhs_triple_vendor)
+        {
+            // Only fail if both vendor types are not unknown
+            if (lhs_triple_vendor != llvm::Triple::UnknownVendor &&
+                rhs_triple_vendor != llvm::Triple::UnknownVendor)
+                return false;
+        }
+        
+        const llvm::Triple::OSType lhs_triple_os = lhs_triple.getOS();
+        const llvm::Triple::OSType rhs_triple_os = rhs_triple.getOS();
+        if (lhs_triple_os != rhs_triple_os)
+        {
+            // Only fail if both os types are not unknown
+            if (lhs_triple_os != llvm::Triple::UnknownOS &&
+                rhs_triple_os != llvm::Triple::UnknownOS)
+                return false;
+        }
+
+        const llvm::Triple::EnvironmentType lhs_triple_env = lhs_triple.getEnvironment();
+        const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment();
+            
+        if (lhs_triple_env != rhs_triple_env)
+        {
+            // Only fail if both environment types are not unknown
+            if (lhs_triple_env != llvm::Triple::UnknownEnvironment &&
+                rhs_triple_env != llvm::Triple::UnknownEnvironment)
+                return false;
+        }
+        return true;
     }
 }
 

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=140236&r1=140235&r2=140236&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Sep 20 22:57:31 2011
@@ -637,6 +637,13 @@
         Timer scoped_timer(__PRETTY_FUNCTION__,
                            "Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
         m_objfile_sp = ObjectFile::FindPlugin(this, &m_file, m_object_offset, m_file.GetByteSize());
+        if (m_objfile_sp)
+        {
+			// Once we get the object file, update our module with the object file's 
+			// architecture since it might differ in vendor/os if some parts were
+			// unknown.
+            m_objfile_sp->GetArchitecture (m_arch);
+        }
     }
     return m_objfile_sp.get();
 }

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=140236&r1=140235&r2=140236&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Tue Sep 20 22:57:31 2011
@@ -1792,6 +1792,15 @@
 {
     lldb_private::Mutex::Locker locker(m_mutex);
     arch.SetArchitecture (eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
+    
+    // Files with type MH_PRELOAD are currently used in cases where the image
+    // debugs at the addresses in the file itself. Below we set the OS to 
+    // unknown to make sure we use the DynamicLoaderStatic()...
+    if (m_header.filetype == HeaderFileTypePreloadedExecutable)
+    {
+        arch.GetTriple().setOS (llvm::Triple::UnknownOS);
+    }
+
     return true;
 }
 





More information about the lldb-commits mailing list