<div dir="ltr">This is really the kind of thing that would be good to write a unit test for.  There's a lot of institutional knowledge hidden away in these kinds of deep low level stuff, and a unit test is good documentation for it.  <div><br></div><div>I suspect this is almost guaranteed to break at some point in the future without an explicit test (especially since it's not immediately obvious why a Target should behave that way)</div><div><br></div><div><br></div><div><div>It should be really easy to write one for this.  You'd need to make a TargetUnitTests target, create an empty target, set the triple to one thing, set it to another thing, and ensure it retains the original value.  +todd in case you're interested in trying, he can probably help</div></div><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 9, 2015 at 8:14 PM Jason Molenda via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jmolenda<br>
Date: Mon Nov  9 22:11:37 2015<br>
New Revision: 252583<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252583&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252583&view=rev</a><br>
Log:<br>
The other half of a change made by Enrico for trying to get a correct<br>
triple for a process.  He writes, "Changes to the way setting the<br>
triple works on a target so that if the target has passed a fully<br>
specified triple, and the newly passed triple is not a revamp of<br>
the current one, and the current one is fully specified, then do<br>
not replace the existing triple."<br>
<br>
Triple handling got a bit more complicated on mac with the addition<br>
of ios/watchos/tvos and their simulators, and tracking the correct<br>
os versions for them so expressions are compiled with the expected<br>
APIs available to the user.<br>
<br>
<rdar://problem/19820698><br>
<br>
Modified:<br>
    lldb/trunk/source/Target/Target.cpp<br>
<br>
Modified: lldb/trunk/source/Target/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=252583&r1=252582&r2=252583&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=252583&r1=252582&r2=252583&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Target/Target.cpp (original)<br>
+++ lldb/trunk/source/Target/Target.cpp Mon Nov  9 22:11:37 2015<br>
@@ -1243,44 +1243,70 @@ bool<br>
 Target::SetArchitecture (const ArchSpec &arch_spec)<br>
 {<br>
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));<br>
-    if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())<br>
+    bool missing_local_arch = (false == m_arch.IsValid());<br>
+    bool replace_local_arch = true;<br>
+    bool compatible_local_arch = false;<br>
+    ArchSpec other(arch_spec);<br>
+<br>
+    if (!missing_local_arch)<br>
+    {<br>
+        if (m_arch.IsCompatibleMatch(arch_spec))<br>
+        {<br>
+            other.MergeFrom(m_arch);<br>
+<br>
+            if (m_arch.IsCompatibleMatch(other))<br>
+            {<br>
+                compatible_local_arch = true;<br>
+                bool arch_changed, vendor_changed, os_changed, os_ver_changed, env_changed;<br>
+<br>
+                m_arch.PiecewiseTripleCompare(other,<br>
+                                              arch_changed,<br>
+                                              vendor_changed,<br>
+                                              os_changed,<br>
+                                              os_ver_changed,<br>
+                                              env_changed);<br>
+<br>
+                if (!arch_changed && !vendor_changed && !os_changed)<br>
+                    replace_local_arch = false;<br>
+            }<br>
+        }<br>
+    }<br>
+<br>
+    if (compatible_local_arch || missing_local_arch)<br>
     {<br>
-        // If we haven't got a valid arch spec, or the architectures are<br>
-        // compatible, so just update the architecture. Architectures can be<br>
-        // equal, yet the triple OS and vendor might change, so we need to do<br>
-        // the assignment here just in case.<br>
-        m_arch = arch_spec;<br>
+        // If we haven't got a valid arch spec, or the architectures are compatible<br>
+        // update the architecture, unless the one we already have is more specified<br>
+        if (replace_local_arch)<br>
+            m_arch = other;<br>
         if (log)<br>
-            log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());<br>
+            log->Printf ("Target::SetArchitecture set architecture to %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());<br>
         return true;<br>
     }<br>
-    else<br>
+<br>
+    // If we have an executable file, try to reset the executable to the desired architecture<br>
+    if (log)<br>
+      log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());<br>
+    m_arch = other;<br>
+    ModuleSP executable_sp = GetExecutableModule ();<br>
+<br>
+    ClearModules(true);<br>
+    // Need to do something about unsetting breakpoints.<br>
+<br>
+    if (executable_sp)<br>
     {<br>
-        // If we have an executable file, try to reset the executable to the desired architecture<br>
         if (log)<br>
-          log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());<br>
-        m_arch = arch_spec;<br>
-        ModuleSP executable_sp = GetExecutableModule ();<br>
-<br>
-        ClearModules(true);<br>
-        // Need to do something about unsetting breakpoints.<br>
-<br>
-        if (executable_sp)<br>
+          log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());<br>
+        ModuleSpec module_spec (executable_sp->GetFileSpec(), other);<br>
+        Error error = ModuleList::GetSharedModule (module_spec,<br>
+                                                   executable_sp,<br>
+                                                   &GetExecutableSearchPaths(),<br>
+                                                   NULL,<br>
+                                                   NULL);<br>
+<br>
+        if (!error.Fail() && executable_sp)<br>
         {<br>
-            if (log)<br>
-              log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());<br>
-            ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);<br>
-            Error error = ModuleList::GetSharedModule (module_spec,<br>
-                                                       executable_sp,<br>
-                                                       &GetExecutableSearchPaths(),<br>
-                                                       NULL,<br>
-                                                       NULL);<br>
-<br>
-            if (!error.Fail() && executable_sp)<br>
-            {<br>
-                SetExecutableModule (executable_sp, true);<br>
-                return true;<br>
-            }<br>
+            SetExecutableModule (executable_sp, true);<br>
+            return true;<br>
         }<br>
     }<br>
     return false;<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div></div>