Partially revert a patch from Ashok Thirumurthi in r191430.
The original code was not completely correct, but a form of
this check is necessary to avoid an infinite recursion on
some unwind cases where a function unwinds to itself with the
same CFA.  Ashok thought the recursion would be caught in
RegisterContextLLDB but this one isn't - we still need it here.
<rdar://problem/15664282> 

llvm-svn: 197761
diff --git a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
index 552ae50..203d4c1 100644
--- a/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -95,7 +95,13 @@
     first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
     m_frames.push_back (first_cursor_sp);
     return true;
+
 unwind_done:
+    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
+    if (log)
+    {
+        log->Printf ("th%d Unwind of this thread is complete.", m_thread.GetIndexID());
+    }
     m_unwind_complete = true;
     return false;
 }
@@ -138,7 +144,12 @@
     }
 
     if (reg_ctx_sp.get() == NULL)
+    {
+        if (log)
+            log->Printf ("%*sFrame %d did not get a RegisterContext, stopping.",
+                         cur_idx < 100 ? cur_idx : 100, "", cur_idx);
         goto unwind_done;
+    }
 
     if (!reg_ctx_sp->IsValid())
     {
@@ -185,12 +196,26 @@
         }
         goto unwind_done;
     }
+    if (!m_frames.empty())
+    {
+        // Infinite loop where the current cursor is the same as the previous one...
+        if (m_frames.back()->start_pc == cursor_sp->start_pc && m_frames.back()->cfa == cursor_sp->cfa)
+        {
+            if (log)
+                log->Printf ("th%d pc of this frame is the same as the previous frame and CFAs for both frames are identical -- stopping unwind", m_thread.GetIndexID());
+            goto unwind_done; 
+        }
+    }
 
     cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp;
     m_frames.push_back (cursor_sp);
     return true;
     
 unwind_done:
+    if (log)
+    {
+        log->Printf ("th%d Unwind of this thread is complete.", m_thread.GetIndexID());
+    }
     m_unwind_complete = true;
     return false;
 }