blob: 81fe21550f28d23348f9d478b1de107cc9a2eb43 [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"
21#include "lldb/Core/Stream.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/RegisterContext.h"
Greg Clayton643ee732010-08-04 01:40:35 +000024#include "lldb/Target/StopInfo.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025
26using namespace lldb;
27using namespace lldb_private;
28
29//----------------------------------------------------------------------
30// ThreadPlanBase: This one always stops, and never has anything particular
31// to do.
32// FIXME: The "signal handling" policies should probably go here.
33//----------------------------------------------------------------------
34
35ThreadPlanBase::ThreadPlanBase (Thread &thread) :
Jim Ingham5a47e8b2010-06-19 04:45:32 +000036 ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes, eVoteNoOpinion)
Chris Lattner24943d22010-06-08 16:52:24 +000037{
38
39}
40
41ThreadPlanBase::~ThreadPlanBase ()
42{
43
44}
45
46void
47ThreadPlanBase::GetDescription (Stream *s, lldb::DescriptionLevel level)
48{
49 s->Printf ("Base thread plan.");
50}
51
52bool
53ThreadPlanBase::ValidatePlan (Stream *error)
54{
55 return true;
56}
57
58bool
59ThreadPlanBase::PlanExplainsStop ()
60{
61 return true;
62}
63
64bool
65ThreadPlanBase::ShouldStop (Event *event_ptr)
66{
67 m_stop_vote = eVoteYes;
68 m_run_vote = eVoteYes;
69
Greg Clayton643ee732010-08-04 01:40:35 +000070 StopInfo *stop_info = m_thread.GetStopInfo();
71 if (stop_info)
Chris Lattner24943d22010-06-08 16:52:24 +000072 {
Greg Clayton643ee732010-08-04 01:40:35 +000073 StopReason reason = stop_info->GetStopReason();
Chris Lattner24943d22010-06-08 16:52:24 +000074 switch (reason)
75 {
Greg Clayton643ee732010-08-04 01:40:35 +000076 case eStopReasonInvalid:
77 case eStopReasonNone:
78 m_run_vote = eVoteNo;
79 m_stop_vote = eVoteNo;
80 return false;
81
82 case eStopReasonBreakpoint:
83 if (stop_info->ShouldStop(event_ptr))
Chris Lattner24943d22010-06-08 16:52:24 +000084 {
Greg Clayton643ee732010-08-04 01:40:35 +000085 // If we are going to stop for a breakpoint, then unship the other plans
86 // at this point. Don't force the discard, however, so Master plans can stay
87 // in place if they want to.
Chris Lattner24943d22010-06-08 16:52:24 +000088 m_thread.DiscardThreadPlans(false);
89 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000090 }
Greg Clayton643ee732010-08-04 01:40:35 +000091 // If we aren't going to stop at this breakpoint, and it is internal,
92 // don't report this stop or the subsequent running event.
93 // Otherwise we will post the stopped & running, but the stopped event will get marked
94 // with "restarted" so the UI will know to wait and expect the consequent "running".
95 if (stop_info->ShouldNotify (event_ptr))
96 {
97 m_stop_vote = eVoteYes;
98 m_run_vote = eVoteYes;
99 }
100 else
101 {
102 m_stop_vote = eVoteNo;
103 m_run_vote = eVoteNo;
104 }
105 return false;
106
107 // TODO: the break below was missing, was this intentional??? If so
108 // please mention it
109 break;
110
111 case eStopReasonException:
112 // If we crashed, discard thread plans and stop. Don't force the discard, however,
113 // since on rerun the target may clean up this exception and continue normally from there.
114 m_thread.DiscardThreadPlans(false);
115 return true;
116
117 case eStopReasonSignal:
118 if (stop_info->ShouldStop(event_ptr))
119 {
120 m_thread.DiscardThreadPlans(false);
Chris Lattner24943d22010-06-08 16:52:24 +0000121 return true;
Greg Clayton643ee732010-08-04 01:40:35 +0000122 }
123 else
124 {
125 // We're not going to stop, but while we are here, let's figure out
126 // whether to report this.
127 if (stop_info->ShouldNotify(event_ptr))
128 m_stop_vote = eVoteYes;
129 else
130 m_stop_vote = eVoteNo;
131 }
132 return false;
133
134 default:
135 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000136 }
137
138 }
Greg Clayton643ee732010-08-04 01:40:35 +0000139 else
140 {
141 m_run_vote = eVoteNo;
142 m_stop_vote = eVoteNo;
143 }
Chris Lattner24943d22010-06-08 16:52:24 +0000144
145 // If there's no explicit reason to stop, then we will continue.
146 return false;
147}
148
149bool
150ThreadPlanBase::StopOthers ()
151{
152 return false;
153}
154
155StateType
156ThreadPlanBase::RunState ()
157{
158 return eStateRunning;
159}
160
161bool
162ThreadPlanBase::WillStop ()
163{
164 return true;
165}
166
167// The base plan is never done.
168bool
169ThreadPlanBase::MischiefManaged ()
170{
171 // The base plan is never done.
172 return false;
173}
174