blob: ebaa4dcf86f0d6d616c1220e5e8ddd08bc9e3101 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ThreadPlanBase.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/ThreadPlanBase.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16//
17#include "lldb/Breakpoint/StoppointCallbackContext.h"
18#include "lldb/Breakpoint/BreakpointSite.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Breakpoint/Breakpoint.h"
Jim Inghamf9f40c22011-02-08 05:20:59 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Stream.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
Greg Clayton643ee732010-08-04 01:40:35 +000025#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30//----------------------------------------------------------------------
31// ThreadPlanBase: This one always stops, and never has anything particular
32// to do.
33// FIXME: The "signal handling" policies should probably go here.
34//----------------------------------------------------------------------
35
36ThreadPlanBase::ThreadPlanBase (Thread &thread) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000037 ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
Chris Lattner24943d22010-06-08 16:52:24 +000038{
Jim Ingham745ac7a2010-11-11 19:26:09 +000039 // Set the tracer to a default tracer.
Jim Inghamcdea2362010-11-18 02:47:07 +000040 // FIXME: need to add a thread settings variable to pix various tracers...
41#define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
42
43#ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
44 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanAssemblyTracer (m_thread));
45#else
Jim Ingham745ac7a2010-11-11 19:26:09 +000046 ThreadPlanTracerSP new_tracer_sp (new ThreadPlanTracer (m_thread));
Jim Inghamcdea2362010-11-18 02:47:07 +000047#endif
Jim Ingham745ac7a2010-11-11 19:26:09 +000048 new_tracer_sp->EnableTracing (m_thread.GetTraceEnabledState());
49 SetThreadPlanTracer(new_tracer_sp);
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52ThreadPlanBase::~ThreadPlanBase ()
53{
54
55}
56
57void
58ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
59{
60 s->Printf ("Base thread plan.");
61}
62
63bool
64ThreadPlanBase::ValidatePlan (Stream *error)
65{
66 return true;
67}
68
69bool
70ThreadPlanBase::PlanExplainsStop ()
71{
Jim Ingham745ac7a2010-11-11 19:26:09 +000072 // The base plan should defer to its tracer, since by default it
73 // always handles the stop.
74 if (TracerExplainsStop())
75 return false;
76 else
77 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000078}
79
80bool
81ThreadPlanBase::ShouldStop (Event *event_ptr)
82{
83 m_stop_vote = eVoteYes;
84 m_run_vote = eVoteYes;
85
Jim Inghamf9f40c22011-02-08 05:20:59 +000086 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
87
Jim Ingham6297a3a2010-10-20 00:39:53 +000088 StopInfoSP stop_info_sp = GetPrivateStopReason();
89 if (stop_info_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000090 {
Jim Ingham6297a3a2010-10-20 00:39:53 +000091 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000092 switch (reason)
93 {
Greg Clayton643ee732010-08-04 01:40:35 +000094 case eStopReasonInvalid:
95 case eStopReasonNone:
Jim Inghamac959662011-01-24 06:34:17 +000096 // This
97 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +000098 m_stop_vote = eVoteNo;
99 return false;
100
101 case eStopReasonBreakpoint:
Johnny Chen043f8c22011-09-21 22:47:15 +0000102 case eStopReasonWatchpoint:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000103 if (stop_info_sp->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +0000104 {
Greg Clayton643ee732010-08-04 01:40:35 +0000105 // If we are going to stop for a breakpoint, then unship the other plans
106 // at this point. Don't force the discard, however, so Master plans can stay
107 // in place if they want to.
Jim Inghamf9f40c22011-02-08 05:20:59 +0000108 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000109 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (breakpoint hit.)", m_thread.GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000110 m_thread.DiscardThreadPlans(false);
111 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000112 }
Greg Clayton643ee732010-08-04 01:40:35 +0000113 // If we aren't going to stop at this breakpoint, and it is internal,
114 // don't report this stop or the subsequent running event.
115 // Otherwise we will post the stopped & running, but the stopped event will get marked
116 // with "restarted" so the UI will know to wait and expect the consequent "running".
Jim Ingham6297a3a2010-10-20 00:39:53 +0000117 if (stop_info_sp->ShouldNotify (event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000118 {
119 m_stop_vote = eVoteYes;
120 m_run_vote = eVoteYes;
121 }
122 else
123 {
124 m_stop_vote = eVoteNo;
125 m_run_vote = eVoteNo;
126 }
127 return false;
128
129 // TODO: the break below was missing, was this intentional??? If so
130 // please mention it
131 break;
132
133 case eStopReasonException:
134 // If we crashed, discard thread plans and stop. Don't force the discard, however,
135 // since on rerun the target may clean up this exception and continue normally from there.
Jim Inghamf9f40c22011-02-08 05:20:59 +0000136 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000137 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (exception.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000138 m_thread.DiscardThreadPlans(false);
139 return true;
140
141 case eStopReasonSignal:
Jim Ingham6297a3a2010-10-20 00:39:53 +0000142 if (stop_info_sp->ShouldStop(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000143 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000144 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000145 log->Printf("Base plan discarding thread plans for thread tid = 0x%4.4llx (signal.)", m_thread.GetID());
Greg Clayton643ee732010-08-04 01:40:35 +0000146 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000147 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000148 }
149 else
150 {
151 // We're not going to stop, but while we are here, let's figure out
152 // whether to report this.
Jim Ingham6297a3a2010-10-20 00:39:53 +0000153 if (stop_info_sp->ShouldNotify(event_ptr))
Greg Clayton643ee732010-08-04 01:40:35 +0000154 m_stop_vote = eVoteYes;
155 else
156 m_stop_vote = eVoteNo;
157 }
158 return false;
159
160 default:
161 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000162 }
163
164 }
Greg Clayton643ee732010-08-04 01:40:35 +0000165 else
166 {
Jim Inghamac959662011-01-24 06:34:17 +0000167 m_run_vote = eVoteNoOpinion;
Greg Clayton643ee732010-08-04 01:40:35 +0000168 m_stop_vote = eVoteNo;
169 }
Chris Lattner24943d22010-06-08 16:52:24 +0000170
171 // If there's no explicit reason to stop, then we will continue.
172 return false;
173}
174
175bool
176ThreadPlanBase::StopOthers ()
177{
178 return false;
179}
180
181StateType
Jim Ingham745ac7a2010-11-11 19:26:09 +0000182ThreadPlanBase::GetPlanRunState ()
Chris Lattner24943d22010-06-08 16:52:24 +0000183{
184 return eStateRunning;
185}
186
187bool
188ThreadPlanBase::WillStop ()
189{
190 return true;
191}
192
Jim Inghamac959662011-01-24 06:34:17 +0000193bool
194ThreadPlanBase::WillResume (lldb::StateType resume_state, bool current_plan)
195{
196 // Reset these to the default values so we don't set them wrong, then not get asked
197 // for a while, then return the wrong answer.
198 m_run_vote = eVoteNoOpinion;
199 m_stop_vote = eVoteNo;
200 return true;
201}
202
203
Chris Lattner24943d22010-06-08 16:52:24 +0000204// The base plan is never done.
205bool
206ThreadPlanBase::MischiefManaged ()
207{
208 // The base plan is never done.
209 return false;
210}
211