]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Target/ThreadPlanBase.cpp
Upgrade Unbound to 1.6.1. More to follow.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Target / ThreadPlanBase.cpp
1 //===-- 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/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Breakpoint/BreakpointSite.h"
20 #include "lldb/Breakpoint/StoppointCallbackContext.h"
21 #include "lldb/Target/Process.h"
22 #include "lldb/Target/RegisterContext.h"
23 #include "lldb/Target/StopInfo.h"
24 #include "lldb/Utility/Log.h"
25 #include "lldb/Utility/Stream.h"
26
27 using namespace lldb;
28 using 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
36 ThreadPlanBase::ThreadPlanBase(Thread &thread)
37     : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
38                  eVoteNoOpinion) {
39 // Set the tracer to a default tracer.
40 // 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
46   ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
47 #endif
48   new_tracer_sp->EnableTracing(m_thread.GetTraceEnabledState());
49   SetThreadPlanTracer(new_tracer_sp);
50   SetIsMasterPlan(true);
51 }
52
53 ThreadPlanBase::~ThreadPlanBase() {}
54
55 void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {
56   s->Printf("Base thread plan.");
57 }
58
59 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
60
61 bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {
62   // The base plan should defer to its tracer, since by default it
63   // always handles the stop.
64   if (TracerExplainsStop())
65     return false;
66   else
67     return true;
68 }
69
70 Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {
71   StopInfoSP stop_info_sp = m_thread.GetStopInfo();
72   if (stop_info_sp) {
73     bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
74     if (should_notify)
75       return eVoteYes;
76     else
77       return eVoteNoOpinion;
78   } else
79     return eVoteNoOpinion;
80 }
81
82 bool ThreadPlanBase::ShouldStop(Event *event_ptr) {
83   m_stop_vote = eVoteYes;
84   m_run_vote = eVoteYes;
85
86   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
87
88   StopInfoSP stop_info_sp = GetPrivateStopInfo();
89   if (stop_info_sp) {
90     StopReason reason = stop_info_sp->GetStopReason();
91     switch (reason) {
92     case eStopReasonInvalid:
93     case eStopReasonNone:
94       // This
95       m_run_vote = eVoteNoOpinion;
96       m_stop_vote = eVoteNo;
97       return false;
98
99     case eStopReasonBreakpoint:
100     case eStopReasonWatchpoint:
101       if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
102         // If we are going to stop for a breakpoint, then unship the other plans
103         // at this point.  Don't force the discard, however, so Master plans can
104         // stay
105         // in place if they want to.
106         if (log)
107           log->Printf(
108               "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
109               " (breakpoint hit.)",
110               m_thread.GetID());
111         m_thread.DiscardThreadPlans(false);
112         return true;
113       }
114       // If we aren't going to stop at this breakpoint, and it is internal,
115       // don't report this stop or the subsequent running event.
116       // Otherwise we will post the stopped & running, but the stopped event
117       // will get marked
118       // with "restarted" so the UI will know to wait and expect the consequent
119       // "running".
120       if (stop_info_sp->ShouldNotify(event_ptr)) {
121         m_stop_vote = eVoteYes;
122         m_run_vote = eVoteYes;
123       } else {
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,
135       // however,
136       // since on rerun the target may clean up this exception and continue
137       // normally from there.
138       if (log)
139         log->Printf(
140             "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
141             " (exception: %s)",
142             m_thread.GetID(), stop_info_sp->GetDescription());
143       m_thread.DiscardThreadPlans(false);
144       return true;
145
146     case eStopReasonExec:
147       // If we crashed, discard thread plans and stop.  Don't force the discard,
148       // however,
149       // since on rerun the target may clean up this exception and continue
150       // normally from there.
151       if (log)
152         log->Printf(
153             "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
154             " (exec.)",
155             m_thread.GetID());
156       m_thread.DiscardThreadPlans(false);
157       return true;
158
159     case eStopReasonThreadExiting:
160     case eStopReasonSignal:
161       if (stop_info_sp->ShouldStop(event_ptr)) {
162         if (log)
163           log->Printf(
164               "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
165               " (signal: %s)",
166               m_thread.GetID(), stop_info_sp->GetDescription());
167         m_thread.DiscardThreadPlans(false);
168         return true;
169       } else {
170         // We're not going to stop, but while we are here, let's figure out
171         // whether to report this.
172         if (stop_info_sp->ShouldNotify(event_ptr))
173           m_stop_vote = eVoteYes;
174         else
175           m_stop_vote = eVoteNo;
176       }
177       return false;
178
179     default:
180       return true;
181     }
182
183   } else {
184     m_run_vote = eVoteNoOpinion;
185     m_stop_vote = eVoteNo;
186   }
187
188   // If there's no explicit reason to stop, then we will continue.
189   return false;
190 }
191
192 bool ThreadPlanBase::StopOthers() { return false; }
193
194 StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }
195
196 bool ThreadPlanBase::WillStop() { return true; }
197
198 bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,
199                                   bool current_plan) {
200   // Reset these to the default values so we don't set them wrong, then not get
201   // asked
202   // for a while, then return the wrong answer.
203   m_run_vote = eVoteNoOpinion;
204   m_stop_vote = eVoteNo;
205   return true;
206 }
207
208 // The base plan is never done.
209 bool ThreadPlanBase::MischiefManaged() {
210   // The base plan is never done.
211   return false;
212 }