Rework how master plans declare themselves.  Also make "PlanIsBasePlan" not rely only on this being the bottom plan in the stack, but allow the plan to declare itself as such.

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@154351 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Thread.cpp b/source/Target/Thread.cpp
index 6a86a3b..fe5c429 100644
--- a/source/Target/Thread.cpp
+++ b/source/Target/Thread.cpp
@@ -349,7 +349,7 @@
         }
         else
         {
-            // If the current plan doesn't explain the stop, then, find one that
+            // If the current plan doesn't explain the stop, then find one that
             // does and let it handle the situation.
             ThreadPlan *plan_ptr = current_plan;
             while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
@@ -839,6 +839,17 @@
     }
 }
 
+bool
+Thread::PlanIsBasePlan (ThreadPlan *plan_ptr)
+{
+    if (plan_ptr->IsBasePlan())
+        return true;
+    else if (m_plan_stack.size() == 0)
+        return false;
+    else
+       return m_plan_stack[0].get() == plan_ptr;
+}
+
 ThreadPlan *
 Thread::QueueFundamentalPlan (bool abort_other_plans)
 {
diff --git a/source/Target/ThreadPlan.cpp b/source/Target/ThreadPlan.cpp
index 8e9cb47..5f396d9 100644
--- a/source/Target/ThreadPlan.cpp
+++ b/source/Target/ThreadPlan.cpp
@@ -36,7 +36,8 @@
     m_plan_complete_mutex (Mutex::eMutexTypeRecursive),
     m_plan_complete (false),
     m_plan_private (false),
-    m_okay_to_discard (false)
+    m_okay_to_discard (false),
+    m_is_master_plan (false)
 {
     SetID (GetNextID());
 }
diff --git a/source/Target/ThreadPlanBase.cpp b/source/Target/ThreadPlanBase.cpp
index ebaa4dc..fcb8683 100644
--- a/source/Target/ThreadPlanBase.cpp
+++ b/source/Target/ThreadPlanBase.cpp
@@ -47,6 +47,7 @@
 #endif
     new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
     SetThreadPlanTracer(new_tracer_sp);
+    SetIsMasterPlan (true);
 }
 
 ThreadPlanBase::~ThreadPlanBase ()
diff --git a/source/Target/ThreadPlanCallFunction.cpp b/source/Target/ThreadPlanCallFunction.cpp
index 09bdd3d..9f6c18e 100644
--- a/source/Target/ThreadPlanCallFunction.cpp
+++ b/source/Target/ThreadPlanCallFunction.cpp
@@ -52,6 +52,9 @@
     m_takedown_done (false),
     m_stop_address (LLDB_INVALID_ADDRESS)
 {
+    // Call function thread plans need to be master plans so that they can potentially stay on the stack when
+    // a breakpoint is hit during the function call.
+    SetIsMasterPlan (true);
     SetOkayToDiscard (discard_on_error);
 
     ProcessSP process_sp (thread.GetProcess());
@@ -172,6 +175,9 @@
     m_return_type (return_type),
     m_takedown_done (false)
 {
+    // Call function thread plans need to be master plans so that they can potentially stay on the stack when
+    // a breakpoint is hit during the function call.
+    SetIsMasterPlan (true);
     SetOkayToDiscard (discard_on_error);
     
     ProcessSP process_sp (thread.GetProcess());
diff --git a/source/Target/ThreadPlanStepOverRange.cpp b/source/Target/ThreadPlanStepOverRange.cpp
index 54fe8ea..c147e83 100644
--- a/source/Target/ThreadPlanStepOverRange.cpp
+++ b/source/Target/ThreadPlanStepOverRange.cpp
@@ -43,6 +43,9 @@
 ) :
     ThreadPlanStepRange (ThreadPlan::eKindStepOverRange, "Step range stepping over", thread, range, addr_context, stop_others)
 {
+    // Step over range plans can be master plans, since you could hit a breakpoint while stepping over, step around
+    // a bit, then continue to finish up the step over.
+    SetIsMasterPlan (true);
     SetOkayToDiscard (okay_to_discard);
 }
 
diff --git a/source/Target/ThreadPlanStepUntil.cpp b/source/Target/ThreadPlanStepUntil.cpp
index 79c2544..3c418f2 100644
--- a/source/Target/ThreadPlanStepUntil.cpp
+++ b/source/Target/ThreadPlanStepUntil.cpp
@@ -52,7 +52,11 @@
     m_stop_others (stop_others)
 {
 
+    // Step until plans can be master plans, since you could hit a breakpoint while stepping to the stop point, step around
+    // a bit, then continue to finish up the step until.
+    SetIsMasterPlan (true);
     SetOkayToDiscard(true);
+    
     // Stash away our "until" addresses:
     TargetSP target_sp (m_thread.CalculateTarget());