[Lldb-commits] [lldb] r251579 - Make sure we don't over specify an architecture when we connect to KDP and use the CPU type and subtype to fill out an architecture. We do this by letting the vendor be an unspecified unknown, or any. We also grab the target architecture, get the KDP host arch, and then merge the two before putting it back into the target.

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 28 16:26:59 PDT 2015


Author: gclayton
Date: Wed Oct 28 18:26:59 2015
New Revision: 251579

URL: http://llvm.org/viewvc/llvm-project?rev=251579&view=rev
Log:
Make sure we don't over specify an architecture when we connect to KDP and use the CPU type and subtype to fill out an architecture. We do this by letting the vendor be an unspecified unknown, or any. We also grab the target architecture, get the KDP host arch, and then merge the two before putting it back into the target.

Also change MH_PRELOAD to be use "unspecified unknown" (any) for the OS and vendor since these mach files can really be anything.


Modified:
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h

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=251579&r1=251578&r2=251579&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Wed Oct 28 18:26:59 2015
@@ -4768,16 +4768,22 @@ ObjectFileMachO::GetArchitecture (const
     if (arch.IsValid())
     {
         llvm::Triple &triple = arch.GetTriple();
+
+        // Set OS to an unspecified unknown or a "*" so it can match any OS
+        triple.setOS(llvm::Triple::UnknownOS);
+        triple.setOSName(llvm::StringRef());
+
         if (header.filetype == MH_PRELOAD)
         {
-            // Set OS to "unknown" - this is a standalone binary with no dyld et al
-            triple.setOS(llvm::Triple::UnknownOS);
+            // Set vendor to an unspecified unknown or a "*" so it can match any vendor
+            triple.setVendor(llvm::Triple::UnknownVendor);
+            triple.setVendorName(llvm::StringRef());
             return true;
         }
         else
         {
             struct load_command load_cmd;
-            
+
             lldb::offset_t offset = lc_offset;
             for (uint32_t i=0; i<header.ncmds; ++i)
             {
@@ -4802,14 +4808,13 @@ ObjectFileMachO::GetArchitecture (const
                 offset = cmd_offset + load_cmd.cmdsize;
             }
             
-            // Only set the OS to iOS for ARM, we don't want to set it for x86 and x86_64.
-            // We do this because we now have MacOSX or iOS as the OS value for x86 and
-            // x86_64 for normal desktop (MacOSX) and simulator (iOS) binaries. And if
-            // we compare a "x86_64-apple-ios" to a "x86_64-apple-" triple, it will say
-            // it is compatible (because the OS is unspecified in the second one and will
-            // match anything in the first
-            if (header.cputype == CPU_TYPE_ARM || header.cputype == CPU_TYPE_ARM64)
-                triple.setOS (llvm::Triple::IOS);
+            if (header.filetype != MH_KEXT_BUNDLE)
+            {
+                // We didn't find a LC_VERSION_MIN load command and this isn't a KEXT
+                // so lets not say our Vendor is Apple, leave it as an unspecified unknown
+                triple.setVendor(llvm::Triple::UnknownVendor);
+                triple.setVendorName(llvm::StringRef());
+            }
         }
     }
     return arch.IsValid();

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=251579&r1=251578&r2=251579&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Wed Oct 28 18:26:59 2015
@@ -244,6 +244,23 @@ ProcessKDP::WillAttachToProcessWithName
     return error;
 }
 
+bool
+ProcessKDP::GetHostArchitecture(ArchSpec &arch)
+{
+    uint32_t cpu = m_comm.GetCPUType();
+    if (cpu)
+    {
+        uint32_t sub = m_comm.GetCPUSubtype();
+        arch.SetArchitecture(eArchTypeMachO, cpu, sub);
+        // Leave architecture vendor as unspecified unknown
+        arch.GetTriple().setVendor(llvm::Triple::UnknownVendor);
+        arch.GetTriple().setVendorName(llvm::StringRef());
+        return true;
+    }
+    arch.Clear();
+    return false;
+}
+
 Error
 ProcessKDP::DoConnectRemote (Stream *strm, const char *remote_url)
 {
@@ -288,13 +305,16 @@ ProcessKDP::DoConnectRemote (Stream *str
                 if (m_comm.SendRequestConnect(reply_port, reply_port, "Greetings from LLDB..."))
                 {
                     m_comm.GetVersion();
-                    uint32_t cpu = m_comm.GetCPUType();
-                    uint32_t sub = m_comm.GetCPUSubtype();
-                    ArchSpec kernel_arch;
-                    kernel_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
+
                     Target &target = GetTarget();
-                    
-                    target.SetArchitecture(kernel_arch);
+                    ArchSpec kernel_arch;
+                    // The host architecture
+                    GetHostArchitecture(kernel_arch);
+                    ArchSpec target_arch = target.GetArchitecture();
+                    // Merge in any unspecified stuff into the target architecture in
+                    // case the target arch isn't set at all or incompletely.
+                    target_arch.MergeFrom(kernel_arch);
+                    target.SetArchitecture(target_arch);
 
                     /* Get the kernel's UUID and load address via KDP_KERNELVERSION packet.  */
                     /* An EFI kdp session has neither UUID nor load address. */
@@ -333,8 +353,8 @@ ProcessKDP::DoConnectRemote (Stream *str
 
                             if (module_spec.GetFileSpec().Exists())
                             {
-                                ModuleSP module_sp(new Module (module_spec.GetFileSpec(), target.GetArchitecture()));
-                                if (module_sp.get() && module_sp->MatchesModuleSpec (module_spec))
+                                ModuleSP module_sp(new Module (module_spec));
+                                if (module_sp.get() && module_sp->GetObjectFile())
                                 {
                                     // Get the current target executable
                                     ModuleSP exe_module_sp (target.GetExecutableModule ());
@@ -441,12 +461,7 @@ ProcessKDP::DidAttach (ArchSpec &process
         log->Printf ("ProcessKDP::DidAttach()");
     if (GetID() != LLDB_INVALID_PROCESS_ID)
     {
-        uint32_t cpu = m_comm.GetCPUType();
-        if (cpu)
-        {
-            uint32_t sub = m_comm.GetCPUSubtype();
-            process_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
-        }
+        GetHostArchitecture(process_arch);
     }
 }
 

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h?rev=251579&r1=251578&r2=251579&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h Wed Oct 28 18:26:59 2015
@@ -218,7 +218,10 @@ protected:
     {
         return state == lldb::eStateExited;
     }
-    
+
+    bool
+    GetHostArchitecture (lldb_private::ArchSpec &arch);
+
     bool
     ProcessIDIsValid ( ) const;
     




More information about the lldb-commits mailing list