blob: dc701b9e83b16b298b9ee7ac43aa8d770741a7ea [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
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Log.h"
17#include "lldb/Core/State.h"
Greg Clayton5205f0b2010-09-03 17:10:42 +000018#include "lldb/Target/RegisterContext.h"
19#include "lldb/Target/Thread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24//----------------------------------------------------------------------
25// ThreadPlan constructor
26//----------------------------------------------------------------------
Jim Ingham5a47e8b2010-06-19 04:45:32 +000027ThreadPlan::ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote stop_vote, Vote run_vote) :
Chris Lattner24943d22010-06-08 16:52:24 +000028 m_thread (thread),
Chris Lattner24943d22010-06-08 16:52:24 +000029 m_stop_vote (stop_vote),
30 m_run_vote (run_vote),
Benjamin Kramer36a08102010-07-16 12:32:33 +000031 m_kind (kind),
32 m_name (name),
33 m_plan_complete_mutex (Mutex::eMutexTypeRecursive),
34 m_plan_complete (false),
35 m_plan_private (false),
Chris Lattner24943d22010-06-08 16:52:24 +000036 m_okay_to_discard (false)
37{
38 SetID (GetNextID());
39}
40
41//----------------------------------------------------------------------
42// Destructor
43//----------------------------------------------------------------------
44ThreadPlan::~ThreadPlan()
45{
46}
47
48const char *
49ThreadPlan::GetName () const
50{
51 return m_name.c_str();
52}
53
54Thread &
55ThreadPlan::GetThread()
56{
57 return m_thread;
58}
59
60
61const Thread &
62ThreadPlan::GetThread() const
63{
64 return m_thread;
65}
66
67bool
68ThreadPlan::IsPlanComplete ()
69{
Greg Claytonbef15832010-07-14 00:18:15 +000070 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000071 return m_plan_complete;
72}
73
74void
75ThreadPlan::SetPlanComplete ()
76{
Greg Claytonbef15832010-07-14 00:18:15 +000077 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000078 m_plan_complete = true;
79}
80
81bool
82ThreadPlan::MischiefManaged ()
83{
Greg Claytonbef15832010-07-14 00:18:15 +000084 Mutex::Locker locker(m_plan_complete_mutex);
Chris Lattner24943d22010-06-08 16:52:24 +000085 m_plan_complete = true;
86 return true;
87}
88
89Vote
90ThreadPlan::ShouldReportStop (Event *event_ptr)
91{
Greg Clayton5205f0b2010-09-03 17:10:42 +000092 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
93
Chris Lattner24943d22010-06-08 16:52:24 +000094 if (m_stop_vote == eVoteNoOpinion)
95 {
96 ThreadPlan *prev_plan = GetPreviousPlan ();
97 if (prev_plan)
Greg Clayton5205f0b2010-09-03 17:10:42 +000098 {
99 Vote prev_vote = prev_plan->ShouldReportStop (event_ptr);
100 if (log)
Greg Claytonf04d6612010-09-03 22:45:01 +0000101 log->Printf ("ThreadPlan::ShouldReportStop() returning previous thread plan vote: %s", GetVoteAsCString (prev_vote));
Greg Clayton5205f0b2010-09-03 17:10:42 +0000102 return prev_vote;
103 }
Chris Lattner24943d22010-06-08 16:52:24 +0000104 }
Greg Clayton5205f0b2010-09-03 17:10:42 +0000105 if (log)
Greg Claytonf04d6612010-09-03 22:45:01 +0000106 log->Printf ("ThreadPlan::ShouldReportStop() returning vote: %s", GetVoteAsCString (m_stop_vote));
Chris Lattner24943d22010-06-08 16:52:24 +0000107 return m_stop_vote;
108}
109
110Vote
111ThreadPlan::ShouldReportRun (Event *event_ptr)
112{
113 if (m_run_vote == eVoteNoOpinion)
114 {
115 ThreadPlan *prev_plan = GetPreviousPlan ();
116 if (prev_plan)
117 return prev_plan->ShouldReportRun (event_ptr);
118 }
119 return m_run_vote;
120}
121
122bool
123ThreadPlan::StopOthers ()
124{
125 ThreadPlan *prev_plan;
126 prev_plan = GetPreviousPlan ();
127 if (prev_plan == NULL)
128 return false;
129 else
130 return prev_plan->StopOthers();
131}
132
133bool
134ThreadPlan::WillResume (StateType resume_state, bool current_plan)
135{
136 if (current_plan)
137 {
138 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
139
140 if (log)
Greg Clayton5205f0b2010-09-03 17:10:42 +0000141 {
142 RegisterContext *reg_ctx = m_thread.GetRegisterContext();
143 addr_t pc = reg_ctx->GetPC();
144 addr_t sp = reg_ctx->GetSP();
145 addr_t fp = reg_ctx->GetFP();
Greg Claytonf04d6612010-09-03 22:45:01 +0000146 log->Printf("%s Thread #%u: tid = 0x%4.4x, pc = 0x%8.8llx, sp = 0x%8.8llx, fp = 0x%8.8llx, plan = '%s', state = %s, stop others = %d",
147 __FUNCTION__,
Greg Clayton5205f0b2010-09-03 17:10:42 +0000148 m_thread.GetIndexID(),
149 m_thread.GetID(),
150 (uint64_t)pc,
151 (uint64_t)sp,
152 (uint64_t)fp,
153 m_name.c_str(),
154 StateAsCString(resume_state),
155 StopOthers());
156 }
Chris Lattner24943d22010-06-08 16:52:24 +0000157 }
158 return true;
159}
160
161lldb::user_id_t
162ThreadPlan::GetNextID()
163{
164 static uint32_t g_nextPlanID = 0;
165 return ++g_nextPlanID;
166}
167
168void
169ThreadPlan::DidPush()
170{
171}
172
173void
174ThreadPlan::WillPop()
175{
176}
177
178void
179ThreadPlan::PushPlan (ThreadPlanSP &thread_plan_sp)
180{
181 m_thread.PushPlan (thread_plan_sp);
182}
183
184ThreadPlan *
185ThreadPlan::GetPreviousPlan ()
186{
187 return m_thread.GetPreviousPlan (this);
188}
189
190void
191ThreadPlan::SetPrivate (bool input)
192{
193 m_plan_private = input;
194}
195
196bool
197ThreadPlan::GetPrivate (void)
198{
199 return m_plan_private;
200}
201
202bool
203ThreadPlan::OkayToDiscard()
204{
205 if (!IsMasterPlan())
206 return true;
207 else
208 return m_okay_to_discard;
209}
210