1 //===-- ThreadPlan.cpp ------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Target/ThreadPlan.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Target/Thread.h" 17 #include "lldb/Core/Log.h" 18 #include "lldb/Core/State.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 //---------------------------------------------------------------------- 24 // ThreadPlan constructor 25 //---------------------------------------------------------------------- 26 ThreadPlan::ThreadPlan(const char *name, Thread &thread, Vote stop_vote, Vote run_vote) : 27 m_name (name), 28 m_thread (thread), 29 m_plan_complete(false), 30 m_plan_complete_mutex (Mutex::eMutexTypeRecursive), 31 m_plan_private (false), 32 m_stop_vote (stop_vote), 33 m_run_vote (run_vote), 34 m_okay_to_discard (false) 35 { 36 SetID (GetNextID()); 37 } 38 39 //---------------------------------------------------------------------- 40 // Destructor 41 //---------------------------------------------------------------------- 42 ThreadPlan::~ThreadPlan() 43 { 44 } 45 46 const char * 47 ThreadPlan::GetName () const 48 { 49 return m_name.c_str(); 50 } 51 52 Thread & 53 ThreadPlan::GetThread() 54 { 55 return m_thread; 56 } 57 58 59 const Thread & 60 ThreadPlan::GetThread() const 61 { 62 return m_thread; 63 } 64 65 bool 66 ThreadPlan::IsPlanComplete () 67 { 68 Mutex::Locker (m_plan_complete_mutex); 69 return m_plan_complete; 70 } 71 72 void 73 ThreadPlan::SetPlanComplete () 74 { 75 Mutex::Locker (m_plan_complete_mutex); 76 m_plan_complete = true; 77 } 78 79 bool 80 ThreadPlan::MischiefManaged () 81 { 82 Mutex::Locker (m_plan_complete_mutex); 83 m_plan_complete = true; 84 return true; 85 } 86 87 Vote 88 ThreadPlan::ShouldReportStop (Event *event_ptr) 89 { 90 if (m_stop_vote == eVoteNoOpinion) 91 { 92 ThreadPlan *prev_plan = GetPreviousPlan (); 93 if (prev_plan) 94 return prev_plan->ShouldReportStop (event_ptr); 95 } 96 return m_stop_vote; 97 } 98 99 Vote 100 ThreadPlan::ShouldReportRun (Event *event_ptr) 101 { 102 if (m_run_vote == eVoteNoOpinion) 103 { 104 ThreadPlan *prev_plan = GetPreviousPlan (); 105 if (prev_plan) 106 return prev_plan->ShouldReportRun (event_ptr); 107 } 108 return m_run_vote; 109 } 110 111 bool 112 ThreadPlan::StopOthers () 113 { 114 ThreadPlan *prev_plan; 115 prev_plan = GetPreviousPlan (); 116 if (prev_plan == NULL) 117 return false; 118 else 119 return prev_plan->StopOthers(); 120 } 121 122 bool 123 ThreadPlan::WillResume (StateType resume_state, bool current_plan) 124 { 125 if (current_plan) 126 { 127 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP); 128 129 if (log) 130 log->Printf("About to resume the \"%s\" plan - state: %s - stop others: %d.", 131 m_name.c_str(), StateAsCString(resume_state), StopOthers()); 132 } 133 return true; 134 } 135 136 lldb::user_id_t 137 ThreadPlan::GetNextID() 138 { 139 static uint32_t g_nextPlanID = 0; 140 return ++g_nextPlanID; 141 } 142 143 void 144 ThreadPlan::DidPush() 145 { 146 } 147 148 void 149 ThreadPlan::WillPop() 150 { 151 } 152 153 void 154 ThreadPlan::PushPlan (ThreadPlanSP &thread_plan_sp) 155 { 156 m_thread.PushPlan (thread_plan_sp); 157 } 158 159 ThreadPlan * 160 ThreadPlan::GetPreviousPlan () 161 { 162 return m_thread.GetPreviousPlan (this); 163 } 164 165 void 166 ThreadPlan::SetPrivate (bool input) 167 { 168 m_plan_private = input; 169 } 170 171 bool 172 ThreadPlan::GetPrivate (void) 173 { 174 return m_plan_private; 175 } 176 177 bool 178 ThreadPlan::OkayToDiscard() 179 { 180 if (!IsMasterPlan()) 181 return true; 182 else 183 return m_okay_to_discard; 184 } 185 186