[Lldb-commits] [lldb] r247133 - Change the looping stack detection code

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 9 03:26:50 PDT 2015


Author: tberghammer
Date: Wed Sep  9 05:26:50 2015
New Revision: 247133

URL: http://llvm.org/viewvc/llvm-project?rev=247133&view=rev
Log:
Change the looping stack detection code

In some special case (e.g. signal handlers, hand written assembly) it is
valid to have 2 stack frame with the same CFA value. This CL change the
looping stack detection code to report a loop only if at least 3
consecutive frames have the same CFA.

Differential revision: http://reviews.llvm.org/D12699

Modified:
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=247133&r1=247132&r2=247133&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Wed Sep  9 05:26:50 2015
@@ -634,28 +634,30 @@ bool
 RegisterContextLLDB::CheckIfLoopingStack ()
 {
     // If we have a bad stack setup, we can get the same CFA value multiple times -- or even
-    // more devious, we can actually oscillate between two CFA values.  Detect that here and
+    // more devious, we can actually oscillate between two CFA values. Detect that here and
     // break out to avoid a possible infinite loop in lldb trying to unwind the stack.
-    addr_t next_frame_cfa;
-    addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
-    if (GetNextFrame().get() && GetNextFrame()->GetCFA(next_frame_cfa))
+    // To detect when we have the same CFA value multiple times, we compare the CFA of the current
+    // frame with the 2nd next frame because in some specail case (e.g. signal hanlders, hand
+    // written assembly without ABI compiance) we can have 2 frames with the same CFA (in theory we
+    // can have arbitrary number of frames with the same CFA, but more then 2 is very very unlikely)
+
+    RegisterContextLLDB::SharedPtr next_frame = GetNextFrame();
+    if (next_frame)
     {
-        if (next_frame_cfa == m_cfa)
-        {
-            // We have a loop in the stack unwind
-            return true;
-        }
-        if (GetNextFrame()->GetNextFrame().get() && GetNextFrame()->GetNextFrame()->GetCFA(next_next_frame_cfa)
-            && next_next_frame_cfa == m_cfa)
+        RegisterContextLLDB::SharedPtr next_next_frame = next_frame->GetNextFrame();
+        addr_t next_next_frame_cfa = LLDB_INVALID_ADDRESS;
+        if (next_next_frame && next_next_frame->GetCFA(next_next_frame_cfa))
         {
-            // We have a loop in the stack unwind
-            return true; 
+            if (next_next_frame_cfa == m_cfa)
+            {
+                // We have a loop in the stack unwind
+                return true; 
+            }
         }
     }
     return false;
 }
 
-
 bool
 RegisterContextLLDB::IsFrameZero () const
 {




More information about the lldb-commits mailing list