blob: 5447778a42eb58bd2ddc788fb06a178ba7cd8cd9 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
20using namespace lldb;
21using namespace lldb_private;
22
23//----------------------------------------------------------------------
24// ThreadPlan constructor
25//----------------------------------------------------------------------
Jim Ingham5a47e8b2010-06-19 04:45:32 +000026ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) :
27 m_kind (kind),
Chris Lattner24943d22010-06-08 16:52:24 +000028 m_name (name),
29 m_thread (thread),
30 m_plan_complete(false),
31 m_plan_complete_mutex (Mutex::eMutexTypeRecursive),
32 m_plan_private (false),
33 m_stop_vote (stop_vote),
34 m_run_vote (run_vote),
35 m_okay_to_discard (false)
36{
37 SetID (GetNextID());
38}
39
40//----------------------------------------------------------------------
41// Destructor
42//----------------------------------------------------------------------
43ThreadPlan::~ThreadPlan()
44{
45}
46
47const char *
48ThreadPlan::GetName () const
49{
50 return m_name.c_str();
51}
52
53Thread &
54ThreadPlan::GetThread()
55{
56 return m_thread;
57}
58
59
60const Thread &
61ThreadPlan::GetThread() const
62{
63 return m_thread;
64}
65
66bool
67ThreadPlan::IsPlanComplete ()
68{
Greg Claytonbef15832010-07-14 00:18:15 +000069 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000070 return m_plan_complete;
71}
72
73void
74ThreadPlan::SetPlanComplete ()
75{
Greg Claytonbef15832010-07-14 00:18:15 +000076 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000077 m_plan_complete = true;
78}
79
80bool
81ThreadPlan::MischiefManaged ()
82{
Greg Claytonbef15832010-07-14 00:18:15 +000083 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000084 m_plan_complete = true;
85 return true;
86}
87
88Vote
89ThreadPlan::ShouldReportStop (Event *event_ptr)
90{
91 if (m_stop_vote == eVoteNoOpinion)
92 {
93 ThreadPlan *prev_plan = GetPreviousPlan ();
94 if (prev_plan)
95 return prev_plan->ShouldReportStop (event_ptr);
96 }
97 return m_stop_vote;
98}
99
100Vote
101ThreadPlan::ShouldReportRun (Event *event_ptr)
102{
103 if (m_run_vote == eVoteNoOpinion)
104 {
105 ThreadPlan *prev_plan = GetPreviousPlan ();
106 if (prev_plan)
107 return prev_plan->ShouldReportRun (event_ptr);
108 }
109 return m_run_vote;
110}
111
112bool
113ThreadPlan::StopOthers ()
114{
115 ThreadPlan *prev_plan;
116 prev_plan = GetPreviousPlan ();
117 if (prev_plan == NULL)
118 return false;
119 else
120 return prev_plan->StopOthers();
121}
122
123bool
124ThreadPlan::WillResume (StateType resume_state, bool current_plan)
125{
126 if (current_plan)
127 {
128 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
129
130 if (log)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000131 log->Printf("Thread #%u: tid = 0x%4.4x about to resume the \"%s\" plan - state: %s - stop others: %d.",
132 m_thread.GetIndexID(), m_thread.GetID(), m_name.c_str(), StateAsCString(resume_state), StopOthers());
Chris Lattner24943d22010-06-08 16:52:24 +0000133 }
134 return true;
135}
136
137lldb::user_id_t
138ThreadPlan::GetNextID()
139{
140 static uint32_t g_nextPlanID = 0;
141 return ++g_nextPlanID;
142}
143
144void
145ThreadPlan::DidPush()
146{
147}
148
149void
150ThreadPlan::WillPop()
151{
152}
153
154void
155ThreadPlan::PushPlan (ThreadPlanSP &thread_plan_sp)
156{
157 m_thread.PushPlan (thread_plan_sp);
158}
159
160ThreadPlan *
161ThreadPlan::GetPreviousPlan ()
162{
163 return m_thread.GetPreviousPlan (this);
164}
165
166void
167ThreadPlan::SetPrivate (bool input)
168{
169 m_plan_private = input;
170}
171
172bool
173ThreadPlan::GetPrivate (void)
174{
175 return m_plan_private;
176}
177
178bool
179ThreadPlan::OkayToDiscard()
180{
181 if (!IsMasterPlan())
182 return true;
183 else
184 return m_okay_to_discard;
185}
186