In ThreadPlanCallFunction, do the Takedown right when the thread plan gets popped.  When the function call is discarded (e.g. when it crashes and discard_on_error is true) the plan gets discarded.  You need to make sure that the stack gets restored right then, and not wait till you start again and the thread plan stack is cleared.

git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@123716 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/ThreadPlanCallFunction.cpp b/source/Target/ThreadPlanCallFunction.cpp
index a662ea0..9619f56 100644
--- a/source/Target/ThreadPlanCallFunction.cpp
+++ b/source/Target/ThreadPlanCallFunction.cpp
@@ -129,6 +129,13 @@
 }
 
 void
+ThreadPlanCallFunction::WillPop ()
+{
+    if (m_valid && !IsPlanComplete())
+        DoTakedown();
+}
+
+void
 ThreadPlanCallFunction::GetDescription (Stream *s, lldb::DescriptionLevel level)
 {
     if (level == lldb::eDescriptionLevelBrief)