<rdar://problem/12990038>

Fixed an issue where the platform auto select code was changing the architecture and causing the wrong architecture to be assigned to the target.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@172251 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 22fb997..6dbdcb2 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -145,12 +145,27 @@
     {
         uint32_t idx;
         PlatformCreateInstance create_callback;
+        // First try exact arch matches across all platform plug-ins
+        bool exact = true;
         for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
         {
             if (create_callback)
+            {
                 platform_sp.reset(create_callback(false, &arch));
-            if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, platform_arch_ptr))
-                return platform_sp;
+                if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
+                    return platform_sp;
+            }
+        }
+        // Next try compatible arch matches across all platform plug-ins
+        exact = false;
+        for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
+        {
+            if (create_callback)
+            {
+                platform_sp.reset(create_callback(false, &arch));
+                if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
+                    return platform_sp;
+            }
         }
     }
     else
@@ -680,19 +695,35 @@
 /// architecture and the target triple contained within.
 //------------------------------------------------------------------
 bool
-Platform::IsCompatibleArchitecture (const ArchSpec &arch, ArchSpec *compatible_arch_ptr)
+Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
 {
     // If the architecture is invalid, we must answer true...
     if (arch.IsValid())
     {
         ArchSpec platform_arch;
-        for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
+        // Try for an exact architecture match first.
+        if (exact_arch_match)
         {
-            if (arch.IsCompatibleMatch(platform_arch))
+            for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
             {
-                if (compatible_arch_ptr)
-                    *compatible_arch_ptr = platform_arch;
-                return true;
+                if (arch.IsExactMatch(platform_arch))
+                {
+                    if (compatible_arch_ptr)
+                        *compatible_arch_ptr = platform_arch;
+                    return true;
+                }
+            }
+        }
+        else
+        {
+            for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
+            {
+                if (arch.IsCompatibleMatch(platform_arch))
+                {
+                    if (compatible_arch_ptr)
+                        *compatible_arch_ptr = platform_arch;
+                    return true;
+                }
             }
         }
     }
@@ -702,6 +733,7 @@
     
 }
 
+
 lldb::BreakpointSP
 Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
 {