annotate lldb/source/Target/ThreadPlanBase.cpp @ 227:21e6aa2e49ef

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 19 Jul 2021 06:57:16 +0900
parents 5f17cb93ff66
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- ThreadPlanBase.cpp ------------------------------------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #include "lldb/Target/ThreadPlanBase.h"
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 //
anatofuz
parents:
diff changeset
12 #include "lldb/Breakpoint/Breakpoint.h"
anatofuz
parents:
diff changeset
13 #include "lldb/Breakpoint/BreakpointLocation.h"
anatofuz
parents:
diff changeset
14 #include "lldb/Breakpoint/BreakpointSite.h"
anatofuz
parents:
diff changeset
15 #include "lldb/Breakpoint/StoppointCallbackContext.h"
anatofuz
parents:
diff changeset
16 #include "lldb/Target/Process.h"
anatofuz
parents:
diff changeset
17 #include "lldb/Target/RegisterContext.h"
anatofuz
parents:
diff changeset
18 #include "lldb/Target/StopInfo.h"
anatofuz
parents:
diff changeset
19 #include "lldb/Utility/Log.h"
anatofuz
parents:
diff changeset
20 #include "lldb/Utility/Stream.h"
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 using namespace lldb;
anatofuz
parents:
diff changeset
23 using namespace lldb_private;
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 // ThreadPlanBase: This one always stops, and never has anything particular to
anatofuz
parents:
diff changeset
26 // do.
anatofuz
parents:
diff changeset
27 // FIXME: The "signal handling" policies should probably go here.
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 ThreadPlanBase::ThreadPlanBase(Thread &thread)
anatofuz
parents:
diff changeset
30 : ThreadPlan(ThreadPlan::eKindBase, "base plan", thread, eVoteYes,
anatofuz
parents:
diff changeset
31 eVoteNoOpinion) {
anatofuz
parents:
diff changeset
32 // Set the tracer to a default tracer.
anatofuz
parents:
diff changeset
33 // FIXME: need to add a thread settings variable to pix various tracers...
anatofuz
parents:
diff changeset
34 #define THREAD_PLAN_USE_ASSEMBLY_TRACER 1
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 #ifdef THREAD_PLAN_USE_ASSEMBLY_TRACER
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
37 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanAssemblyTracer(thread));
150
anatofuz
parents:
diff changeset
38 #else
anatofuz
parents:
diff changeset
39 ThreadPlanTracerSP new_tracer_sp(new ThreadPlanTracer(m_thread));
anatofuz
parents:
diff changeset
40 #endif
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
41 new_tracer_sp->EnableTracing(thread.GetTraceEnabledState());
150
anatofuz
parents:
diff changeset
42 SetThreadPlanTracer(new_tracer_sp);
anatofuz
parents:
diff changeset
43 SetIsMasterPlan(true);
anatofuz
parents:
diff changeset
44 }
anatofuz
parents:
diff changeset
45
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
46 ThreadPlanBase::~ThreadPlanBase() = default;
150
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 void ThreadPlanBase::GetDescription(Stream *s, lldb::DescriptionLevel level) {
anatofuz
parents:
diff changeset
49 s->Printf("Base thread plan.");
anatofuz
parents:
diff changeset
50 }
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 bool ThreadPlanBase::ValidatePlan(Stream *error) { return true; }
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 bool ThreadPlanBase::DoPlanExplainsStop(Event *event_ptr) {
anatofuz
parents:
diff changeset
55 // The base plan should defer to its tracer, since by default it always
anatofuz
parents:
diff changeset
56 // handles the stop.
anatofuz
parents:
diff changeset
57 return !TracerExplainsStop();
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 Vote ThreadPlanBase::ShouldReportStop(Event *event_ptr) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
61 StopInfoSP stop_info_sp = GetThread().GetStopInfo();
150
anatofuz
parents:
diff changeset
62 if (stop_info_sp) {
anatofuz
parents:
diff changeset
63 bool should_notify = stop_info_sp->ShouldNotify(event_ptr);
anatofuz
parents:
diff changeset
64 if (should_notify)
anatofuz
parents:
diff changeset
65 return eVoteYes;
anatofuz
parents:
diff changeset
66 else
anatofuz
parents:
diff changeset
67 return eVoteNoOpinion;
anatofuz
parents:
diff changeset
68 } else
anatofuz
parents:
diff changeset
69 return eVoteNoOpinion;
anatofuz
parents:
diff changeset
70 }
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 bool ThreadPlanBase::ShouldStop(Event *event_ptr) {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
73 m_report_stop_vote = eVoteYes;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
74 m_report_run_vote = eVoteYes;
150
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 StopInfoSP stop_info_sp = GetPrivateStopInfo();
anatofuz
parents:
diff changeset
79 if (stop_info_sp) {
anatofuz
parents:
diff changeset
80 StopReason reason = stop_info_sp->GetStopReason();
anatofuz
parents:
diff changeset
81 switch (reason) {
anatofuz
parents:
diff changeset
82 case eStopReasonInvalid:
anatofuz
parents:
diff changeset
83 case eStopReasonNone:
anatofuz
parents:
diff changeset
84 // This
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
85 m_report_run_vote = eVoteNoOpinion;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
86 m_report_stop_vote = eVoteNo;
150
anatofuz
parents:
diff changeset
87 return false;
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 case eStopReasonBreakpoint:
anatofuz
parents:
diff changeset
90 case eStopReasonWatchpoint:
anatofuz
parents:
diff changeset
91 if (stop_info_sp->ShouldStopSynchronous(event_ptr)) {
anatofuz
parents:
diff changeset
92 // If we are going to stop for a breakpoint, then unship the other
anatofuz
parents:
diff changeset
93 // plans at this point. Don't force the discard, however, so Master
anatofuz
parents:
diff changeset
94 // plans can stay in place if they want to.
anatofuz
parents:
diff changeset
95 LLDB_LOGF(
anatofuz
parents:
diff changeset
96 log,
anatofuz
parents:
diff changeset
97 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
anatofuz
parents:
diff changeset
98 " (breakpoint hit.)",
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
99 m_tid);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
100 GetThread().DiscardThreadPlans(false);
150
anatofuz
parents:
diff changeset
101 return true;
anatofuz
parents:
diff changeset
102 }
anatofuz
parents:
diff changeset
103 // If we aren't going to stop at this breakpoint, and it is internal,
anatofuz
parents:
diff changeset
104 // don't report this stop or the subsequent running event. Otherwise we
anatofuz
parents:
diff changeset
105 // will post the stopped & running, but the stopped event will get marked
anatofuz
parents:
diff changeset
106 // with "restarted" so the UI will know to wait and expect the consequent
anatofuz
parents:
diff changeset
107 // "running".
anatofuz
parents:
diff changeset
108 if (stop_info_sp->ShouldNotify(event_ptr)) {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
109 m_report_stop_vote = eVoteYes;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
110 m_report_run_vote = eVoteYes;
150
anatofuz
parents:
diff changeset
111 } else {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
112 m_report_stop_vote = eVoteNo;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
113 m_report_run_vote = eVoteNo;
150
anatofuz
parents:
diff changeset
114 }
anatofuz
parents:
diff changeset
115 return false;
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 // TODO: the break below was missing, was this intentional??? If so
anatofuz
parents:
diff changeset
118 // please mention it
anatofuz
parents:
diff changeset
119 break;
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 case eStopReasonException:
anatofuz
parents:
diff changeset
122 // If we crashed, discard thread plans and stop. Don't force the
anatofuz
parents:
diff changeset
123 // discard, however, since on rerun the target may clean up this
anatofuz
parents:
diff changeset
124 // exception and continue normally from there.
anatofuz
parents:
diff changeset
125 LLDB_LOGF(
anatofuz
parents:
diff changeset
126 log,
anatofuz
parents:
diff changeset
127 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
128 " (exception: %s)",
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
129 m_tid, stop_info_sp->GetDescription());
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
130 GetThread().DiscardThreadPlans(false);
150
anatofuz
parents:
diff changeset
131 return true;
anatofuz
parents:
diff changeset
132
anatofuz
parents:
diff changeset
133 case eStopReasonExec:
anatofuz
parents:
diff changeset
134 // If we crashed, discard thread plans and stop. Don't force the
anatofuz
parents:
diff changeset
135 // discard, however, since on rerun the target may clean up this
anatofuz
parents:
diff changeset
136 // exception and continue normally from there.
anatofuz
parents:
diff changeset
137 LLDB_LOGF(
anatofuz
parents:
diff changeset
138 log,
anatofuz
parents:
diff changeset
139 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
anatofuz
parents:
diff changeset
140 " (exec.)",
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
141 m_tid);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
142 GetThread().DiscardThreadPlans(false);
150
anatofuz
parents:
diff changeset
143 return true;
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 case eStopReasonThreadExiting:
anatofuz
parents:
diff changeset
146 case eStopReasonSignal:
anatofuz
parents:
diff changeset
147 if (stop_info_sp->ShouldStop(event_ptr)) {
anatofuz
parents:
diff changeset
148 LLDB_LOGF(
anatofuz
parents:
diff changeset
149 log,
anatofuz
parents:
diff changeset
150 "Base plan discarding thread plans for thread tid = 0x%4.4" PRIx64
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
151 " (signal: %s)",
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
152 m_tid, stop_info_sp->GetDescription());
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
153 GetThread().DiscardThreadPlans(false);
150
anatofuz
parents:
diff changeset
154 return true;
anatofuz
parents:
diff changeset
155 } else {
anatofuz
parents:
diff changeset
156 // We're not going to stop, but while we are here, let's figure out
anatofuz
parents:
diff changeset
157 // whether to report this.
anatofuz
parents:
diff changeset
158 if (stop_info_sp->ShouldNotify(event_ptr))
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
159 m_report_stop_vote = eVoteYes;
150
anatofuz
parents:
diff changeset
160 else
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
161 m_report_stop_vote = eVoteNo;
150
anatofuz
parents:
diff changeset
162 }
anatofuz
parents:
diff changeset
163 return false;
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 default:
anatofuz
parents:
diff changeset
166 return true;
anatofuz
parents:
diff changeset
167 }
anatofuz
parents:
diff changeset
168
anatofuz
parents:
diff changeset
169 } else {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
170 m_report_run_vote = eVoteNoOpinion;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
171 m_report_stop_vote = eVoteNo;
150
anatofuz
parents:
diff changeset
172 }
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 // If there's no explicit reason to stop, then we will continue.
anatofuz
parents:
diff changeset
175 return false;
anatofuz
parents:
diff changeset
176 }
anatofuz
parents:
diff changeset
177
anatofuz
parents:
diff changeset
178 bool ThreadPlanBase::StopOthers() { return false; }
anatofuz
parents:
diff changeset
179
anatofuz
parents:
diff changeset
180 StateType ThreadPlanBase::GetPlanRunState() { return eStateRunning; }
anatofuz
parents:
diff changeset
181
anatofuz
parents:
diff changeset
182 bool ThreadPlanBase::WillStop() { return true; }
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 bool ThreadPlanBase::DoWillResume(lldb::StateType resume_state,
anatofuz
parents:
diff changeset
185 bool current_plan) {
anatofuz
parents:
diff changeset
186 // Reset these to the default values so we don't set them wrong, then not get
anatofuz
parents:
diff changeset
187 // asked for a while, then return the wrong answer.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
188 m_report_run_vote = eVoteNoOpinion;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
189 m_report_stop_vote = eVoteNo;
150
anatofuz
parents:
diff changeset
190 return true;
anatofuz
parents:
diff changeset
191 }
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 // The base plan is never done.
anatofuz
parents:
diff changeset
194 bool ThreadPlanBase::MischiefManaged() {
anatofuz
parents:
diff changeset
195 // The base plan is never done.
anatofuz
parents:
diff changeset
196 return false;
anatofuz
parents:
diff changeset
197 }