Found one more place where the OkayToDiscard needs to be consulted.
Also changed the defaults for SBThread::Step* to not delete extant plans.
Also added some test cases to test more complex stepping scenarios.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@156667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBFrame.cpp b/source/API/SBFrame.cpp
index 27c07ef..b38fa3d 100644
--- a/source/API/SBFrame.cpp
+++ b/source/API/SBFrame.cpp
@@ -1028,6 +1028,12 @@
 SBValue
 SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value)
 {
+    return EvaluateExpression (expr, fetch_dynamic_value, true);
+}
+
+SBValue
+SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error)
+{
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     
     LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -1056,7 +1062,6 @@
                                                  expr, fetch_dynamic_value, frame_description.GetString().c_str());
 
             const bool coerce_to_id = false;
-            const bool unwind_on_error = true;
             const bool keep_in_memory = false;
 
             exe_results = target->EvaluateExpression (expr, 
diff --git a/source/API/SBThread.cpp b/source/API/SBThread.cpp
index 7d8398d..b831a4f 100644
--- a/source/API/SBThread.cpp
+++ b/source/API/SBThread.cpp
@@ -531,7 +531,7 @@
     {
         Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
         Thread *thread = exe_ctx.GetThreadPtr();
-        bool abort_other_plans = true;
+        bool abort_other_plans = false;
         StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
         ThreadPlan *new_plan = NULL;
 
@@ -574,7 +574,7 @@
     if (exe_ctx.HasThreadScope())
     {
         Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
-        bool abort_other_plans = true;
+        bool abort_other_plans = false;
 
         Thread *thread = exe_ctx.GetThreadPtr();
         StackFrameSP frame_sp(thread->GetStackFrameAtIndex (0));
@@ -616,7 +616,7 @@
     if (exe_ctx.HasThreadScope())
     {
         Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
-        bool abort_other_plans = true;
+        bool abort_other_plans = false;
         bool stop_other_threads = true;
 
         Thread *thread = exe_ctx.GetThreadPtr();
@@ -651,7 +651,7 @@
     if (exe_ctx.HasThreadScope())
     {
         Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
-        bool abort_other_plans = true;
+        bool abort_other_plans = false;
         bool stop_other_threads = true;
         Thread *thread = exe_ctx.GetThreadPtr();
 
@@ -703,7 +703,7 @@
     if (exe_ctx.HasThreadScope())
     {
         Mutex::Locker api_locker (exe_ctx.GetTargetPtr()->GetAPIMutex());
-        bool abort_other_plans = true;
+        bool abort_other_plans = false;
         bool stop_other_threads = true;
 
         Address target_addr (addr);
@@ -806,7 +806,7 @@
         AddressRange fun_range = frame_sc.function->GetAddressRange();
         
         std::vector<addr_t> step_over_until_addrs;
-        const bool abort_other_plans = true;
+        const bool abort_other_plans = false;
         const bool stop_other_threads = true;
         const bool check_inlines = true;
         const bool exact = false;
diff --git a/source/Commands/CommandObjectThread.cpp b/source/Commands/CommandObjectThread.cpp
index 73cc9a2..040278b 100644
--- a/source/Commands/CommandObjectThread.cpp
+++ b/source/Commands/CommandObjectThread.cpp
@@ -946,7 +946,7 @@
                 return false;
             }
 
-            const bool abort_other_plans = true;
+            const bool abort_other_plans = false;
 
             StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
             if (frame == NULL)
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp
index 822015a..1792aac 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -375,8 +375,8 @@
                     
                     if (plan_ptr->MischiefManaged())
                     {
-                        // We're going to pop the plans up to AND INCLUDING the plan that explains the stop.
-                        plan_ptr = GetPreviousPlan(plan_ptr);
+                        // We're going to pop the plans up to the plan that explains the stop.
+                        ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr);
                         
                         do 
                         {
@@ -384,8 +384,13 @@
                                 current_plan->WillStop();
                             PopPlan();
                         }
-                        while ((current_plan = GetCurrentPlan()) != plan_ptr);
-                        done_processing_current_plan = false;
+                        while ((current_plan = GetCurrentPlan()) != prev_plan_ptr);
+                        // Now, if the responsible plan was not "Okay to discard" then we're done,
+                        // otherwise we forward this to the next plan in the stack below.
+                        if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard())
+                            done_processing_current_plan = true;
+                        else
+                            done_processing_current_plan = false;
                     }
                     else
                         done_processing_current_plan = true;
diff --git a/source/Target/ThreadPlanCallFunction.cpp b/source/Target/ThreadPlanCallFunction.cpp
index 8e91e8b..3ab2a56 100644
--- a/source/Target/ThreadPlanCallFunction.cpp
+++ b/source/Target/ThreadPlanCallFunction.cpp
@@ -416,7 +416,7 @@
 bool
 ThreadPlanCallFunction::ShouldStop (Event *event_ptr)
 {
-    if (PlanExplainsStop())
+    if (IsPlanComplete() || PlanExplainsStop())
     {
         ReportRegisterState ("Function completed.  Register state was:");