blob: 3be8e9a36bd015464cb2e2056c93efc795300324 [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//----------------------------------------------------------------------
26ThreadPlan::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//----------------------------------------------------------------------
42ThreadPlan::~ThreadPlan()
43{
44}
45
46const char *
47ThreadPlan::GetName () const
48{
49 return m_name.c_str();
50}
51
52Thread &
53ThreadPlan::GetThread()
54{
55 return m_thread;
56}
57
58
59const Thread &
60ThreadPlan::GetThread() const
61{
62 return m_thread;
63}
64
65bool
66ThreadPlan::IsPlanComplete ()
67{
68 Mutex::Locker (m_plan_complete_mutex);
69 return m_plan_complete;
70}
71
72void
73ThreadPlan::SetPlanComplete ()
74{
75 Mutex::Locker (m_plan_complete_mutex);
76 m_plan_complete = true;
77}
78
79bool
80ThreadPlan::MischiefManaged ()
81{
82 Mutex::Locker (m_plan_complete_mutex);
83 m_plan_complete = true;
84 return true;
85}
86
87Vote
88ThreadPlan::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
99Vote
100ThreadPlan::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
111bool
112ThreadPlan::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
122bool
123ThreadPlan::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)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000130 log->Printf("Thread #%u: tid = 0x%4.4x about to resume the \"%s\" plan - state: %s - stop others: %d.",
131 m_thread.GetIndexID(), m_thread.GetID(), m_name.c_str(), StateAsCString(resume_state), StopOthers());
Chris Lattner24943d22010-06-08 16:52:24 +0000132 }
133 return true;
134}
135
136lldb::user_id_t
137ThreadPlan::GetNextID()
138{
139 static uint32_t g_nextPlanID = 0;
140 return ++g_nextPlanID;
141}
142
143void
144ThreadPlan::DidPush()
145{
146}
147
148void
149ThreadPlan::WillPop()
150{
151}
152
153void
154ThreadPlan::PushPlan (ThreadPlanSP &thread_plan_sp)
155{
156 m_thread.PushPlan (thread_plan_sp);
157}
158
159ThreadPlan *
160ThreadPlan::GetPreviousPlan ()
161{
162 return m_thread.GetPreviousPlan (this);
163}
164
165void
166ThreadPlan::SetPrivate (bool input)
167{
168 m_plan_private = input;
169}
170
171bool
172ThreadPlan::GetPrivate (void)
173{
174 return m_plan_private;
175}
176
177bool
178ThreadPlan::OkayToDiscard()
179{
180 if (!IsMasterPlan())
181 return true;
182 else
183 return m_okay_to_discard;
184}
185