annotate lldb/source/Target/ThreadPlanRunToAddress.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents c4bab56944e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- ThreadPlanRunToAddress.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/ThreadPlanRunToAddress.h"
anatofuz
parents:
diff changeset
10 #include "lldb/Target/Process.h"
anatofuz
parents:
diff changeset
11 #include "lldb/Target/RegisterContext.h"
anatofuz
parents:
diff changeset
12 #include "lldb/Target/Target.h"
anatofuz
parents:
diff changeset
13 #include "lldb/Target/Thread.h"
236
c4bab56944e8 LLVM 16
kono
parents: 173
diff changeset
14 #include "lldb/Utility/LLDBLog.h"
150
anatofuz
parents:
diff changeset
15 #include "lldb/Utility/Log.h"
anatofuz
parents:
diff changeset
16 #include "lldb/Utility/Stream.h"
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 using namespace lldb;
anatofuz
parents:
diff changeset
19 using namespace lldb_private;
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 // ThreadPlanRunToAddress: Continue plan
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 ThreadPlanRunToAddress::ThreadPlanRunToAddress(Thread &thread, Address &address,
anatofuz
parents:
diff changeset
24 bool stop_others)
anatofuz
parents:
diff changeset
25 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
anatofuz
parents:
diff changeset
26 eVoteNoOpinion, eVoteNoOpinion),
anatofuz
parents:
diff changeset
27 m_stop_others(stop_others), m_addresses(), m_break_ids() {
anatofuz
parents:
diff changeset
28 m_addresses.push_back(
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 address.GetOpcodeLoadAddress(thread.CalculateTarget().get()));
150
anatofuz
parents:
diff changeset
30 SetInitialBreakpoints();
anatofuz
parents:
diff changeset
31 }
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 ThreadPlanRunToAddress::ThreadPlanRunToAddress(Thread &thread,
anatofuz
parents:
diff changeset
34 lldb::addr_t address,
anatofuz
parents:
diff changeset
35 bool stop_others)
anatofuz
parents:
diff changeset
36 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
anatofuz
parents:
diff changeset
37 eVoteNoOpinion, eVoteNoOpinion),
anatofuz
parents:
diff changeset
38 m_stop_others(stop_others), m_addresses(), m_break_ids() {
anatofuz
parents:
diff changeset
39 m_addresses.push_back(
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
40 thread.CalculateTarget()->GetOpcodeLoadAddress(address));
150
anatofuz
parents:
diff changeset
41 SetInitialBreakpoints();
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 ThreadPlanRunToAddress::ThreadPlanRunToAddress(
anatofuz
parents:
diff changeset
45 Thread &thread, const std::vector<lldb::addr_t> &addresses,
anatofuz
parents:
diff changeset
46 bool stop_others)
anatofuz
parents:
diff changeset
47 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
anatofuz
parents:
diff changeset
48 eVoteNoOpinion, eVoteNoOpinion),
anatofuz
parents:
diff changeset
49 m_stop_others(stop_others), m_addresses(addresses), m_break_ids() {
anatofuz
parents:
diff changeset
50 // Convert all addresses into opcode addresses to make sure we set
anatofuz
parents:
diff changeset
51 // breakpoints at the correct address.
anatofuz
parents:
diff changeset
52 Target &target = thread.GetProcess()->GetTarget();
anatofuz
parents:
diff changeset
53 std::vector<lldb::addr_t>::iterator pos, end = m_addresses.end();
anatofuz
parents:
diff changeset
54 for (pos = m_addresses.begin(); pos != end; ++pos)
anatofuz
parents:
diff changeset
55 *pos = target.GetOpcodeLoadAddress(*pos);
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 SetInitialBreakpoints();
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 void ThreadPlanRunToAddress::SetInitialBreakpoints() {
anatofuz
parents:
diff changeset
61 size_t num_addresses = m_addresses.size();
anatofuz
parents:
diff changeset
62 m_break_ids.resize(num_addresses);
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 for (size_t i = 0; i < num_addresses; i++) {
anatofuz
parents:
diff changeset
65 Breakpoint *breakpoint;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
66 breakpoint =
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
67 GetTarget().CreateBreakpoint(m_addresses[i], true, false).get();
150
anatofuz
parents:
diff changeset
68 if (breakpoint != nullptr) {
anatofuz
parents:
diff changeset
69 if (breakpoint->IsHardware() && !breakpoint->HasResolvedLocations())
anatofuz
parents:
diff changeset
70 m_could_not_resolve_hw_bp = true;
anatofuz
parents:
diff changeset
71 m_break_ids[i] = breakpoint->GetID();
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
72 breakpoint->SetThreadID(m_tid);
150
anatofuz
parents:
diff changeset
73 breakpoint->SetBreakpointKind("run-to-address");
anatofuz
parents:
diff changeset
74 }
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 ThreadPlanRunToAddress::~ThreadPlanRunToAddress() {
anatofuz
parents:
diff changeset
79 size_t num_break_ids = m_break_ids.size();
anatofuz
parents:
diff changeset
80 for (size_t i = 0; i < num_break_ids; i++) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81 GetTarget().RemoveBreakpointByID(m_break_ids[i]);
150
anatofuz
parents:
diff changeset
82 }
anatofuz
parents:
diff changeset
83 m_could_not_resolve_hw_bp = false;
anatofuz
parents:
diff changeset
84 }
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 void ThreadPlanRunToAddress::GetDescription(Stream *s,
anatofuz
parents:
diff changeset
87 lldb::DescriptionLevel level) {
anatofuz
parents:
diff changeset
88 size_t num_addresses = m_addresses.size();
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 if (level == lldb::eDescriptionLevelBrief) {
anatofuz
parents:
diff changeset
91 if (num_addresses == 0) {
anatofuz
parents:
diff changeset
92 s->Printf("run to address with no addresses given.");
anatofuz
parents:
diff changeset
93 return;
anatofuz
parents:
diff changeset
94 } else if (num_addresses == 1)
anatofuz
parents:
diff changeset
95 s->Printf("run to address: ");
anatofuz
parents:
diff changeset
96 else
anatofuz
parents:
diff changeset
97 s->Printf("run to addresses: ");
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 for (size_t i = 0; i < num_addresses; i++) {
anatofuz
parents:
diff changeset
100 DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
anatofuz
parents:
diff changeset
101 s->Printf(" ");
anatofuz
parents:
diff changeset
102 }
anatofuz
parents:
diff changeset
103 } else {
anatofuz
parents:
diff changeset
104 if (num_addresses == 0) {
anatofuz
parents:
diff changeset
105 s->Printf("run to address with no addresses given.");
anatofuz
parents:
diff changeset
106 return;
anatofuz
parents:
diff changeset
107 } else if (num_addresses == 1)
anatofuz
parents:
diff changeset
108 s->Printf("Run to address: ");
anatofuz
parents:
diff changeset
109 else {
anatofuz
parents:
diff changeset
110 s->Printf("Run to addresses: ");
anatofuz
parents:
diff changeset
111 }
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 for (size_t i = 0; i < num_addresses; i++) {
anatofuz
parents:
diff changeset
114 if (num_addresses > 1) {
anatofuz
parents:
diff changeset
115 s->Printf("\n");
anatofuz
parents:
diff changeset
116 s->Indent();
anatofuz
parents:
diff changeset
117 }
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
anatofuz
parents:
diff changeset
120 s->Printf(" using breakpoint: %d - ", m_break_ids[i]);
anatofuz
parents:
diff changeset
121 Breakpoint *breakpoint =
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
122 GetTarget().GetBreakpointByID(m_break_ids[i]).get();
150
anatofuz
parents:
diff changeset
123 if (breakpoint)
anatofuz
parents:
diff changeset
124 breakpoint->Dump(s);
anatofuz
parents:
diff changeset
125 else
anatofuz
parents:
diff changeset
126 s->Printf("but the breakpoint has been deleted.");
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128 }
anatofuz
parents:
diff changeset
129 }
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 bool ThreadPlanRunToAddress::ValidatePlan(Stream *error) {
anatofuz
parents:
diff changeset
132 if (m_could_not_resolve_hw_bp) {
anatofuz
parents:
diff changeset
133 if (error)
anatofuz
parents:
diff changeset
134 error->Printf("Could not set hardware breakpoint(s)");
anatofuz
parents:
diff changeset
135 return false;
anatofuz
parents:
diff changeset
136 }
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 // If we couldn't set the breakpoint for some reason, then this won't work.
anatofuz
parents:
diff changeset
139 bool all_bps_good = true;
anatofuz
parents:
diff changeset
140 size_t num_break_ids = m_break_ids.size();
anatofuz
parents:
diff changeset
141 for (size_t i = 0; i < num_break_ids; i++) {
anatofuz
parents:
diff changeset
142 if (m_break_ids[i] == LLDB_INVALID_BREAK_ID) {
anatofuz
parents:
diff changeset
143 all_bps_good = false;
anatofuz
parents:
diff changeset
144 if (error) {
anatofuz
parents:
diff changeset
145 error->Printf("Could not set breakpoint for address: ");
anatofuz
parents:
diff changeset
146 DumpAddress(error->AsRawOstream(), m_addresses[i], sizeof(addr_t));
anatofuz
parents:
diff changeset
147 error->Printf("\n");
anatofuz
parents:
diff changeset
148 }
anatofuz
parents:
diff changeset
149 }
anatofuz
parents:
diff changeset
150 }
anatofuz
parents:
diff changeset
151 return all_bps_good;
anatofuz
parents:
diff changeset
152 }
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 bool ThreadPlanRunToAddress::DoPlanExplainsStop(Event *event_ptr) {
anatofuz
parents:
diff changeset
155 return AtOurAddress();
anatofuz
parents:
diff changeset
156 }
anatofuz
parents:
diff changeset
157
anatofuz
parents:
diff changeset
158 bool ThreadPlanRunToAddress::ShouldStop(Event *event_ptr) {
anatofuz
parents:
diff changeset
159 return AtOurAddress();
anatofuz
parents:
diff changeset
160 }
anatofuz
parents:
diff changeset
161
anatofuz
parents:
diff changeset
162 bool ThreadPlanRunToAddress::StopOthers() { return m_stop_others; }
anatofuz
parents:
diff changeset
163
anatofuz
parents:
diff changeset
164 void ThreadPlanRunToAddress::SetStopOthers(bool new_value) {
anatofuz
parents:
diff changeset
165 m_stop_others = new_value;
anatofuz
parents:
diff changeset
166 }
anatofuz
parents:
diff changeset
167
anatofuz
parents:
diff changeset
168 StateType ThreadPlanRunToAddress::GetPlanRunState() { return eStateRunning; }
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 bool ThreadPlanRunToAddress::WillStop() { return true; }
anatofuz
parents:
diff changeset
171
anatofuz
parents:
diff changeset
172 bool ThreadPlanRunToAddress::MischiefManaged() {
236
c4bab56944e8 LLVM 16
kono
parents: 173
diff changeset
173 Log *log = GetLog(LLDBLog::Step);
150
anatofuz
parents:
diff changeset
174
anatofuz
parents:
diff changeset
175 if (AtOurAddress()) {
anatofuz
parents:
diff changeset
176 // Remove the breakpoint
anatofuz
parents:
diff changeset
177 size_t num_break_ids = m_break_ids.size();
anatofuz
parents:
diff changeset
178
anatofuz
parents:
diff changeset
179 for (size_t i = 0; i < num_break_ids; i++) {
anatofuz
parents:
diff changeset
180 if (m_break_ids[i] != LLDB_INVALID_BREAK_ID) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
181 GetTarget().RemoveBreakpointByID(m_break_ids[i]);
150
anatofuz
parents:
diff changeset
182 m_break_ids[i] = LLDB_INVALID_BREAK_ID;
anatofuz
parents:
diff changeset
183 }
anatofuz
parents:
diff changeset
184 }
anatofuz
parents:
diff changeset
185 LLDB_LOGF(log, "Completed run to address plan.");
anatofuz
parents:
diff changeset
186 ThreadPlan::MischiefManaged();
anatofuz
parents:
diff changeset
187 return true;
anatofuz
parents:
diff changeset
188 } else
anatofuz
parents:
diff changeset
189 return false;
anatofuz
parents:
diff changeset
190 }
anatofuz
parents:
diff changeset
191
anatofuz
parents:
diff changeset
192 bool ThreadPlanRunToAddress::AtOurAddress() {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
193 lldb::addr_t current_address = GetThread().GetRegisterContext()->GetPC();
150
anatofuz
parents:
diff changeset
194 bool found_it = false;
anatofuz
parents:
diff changeset
195 size_t num_addresses = m_addresses.size();
anatofuz
parents:
diff changeset
196 for (size_t i = 0; i < num_addresses; i++) {
anatofuz
parents:
diff changeset
197 if (m_addresses[i] == current_address) {
anatofuz
parents:
diff changeset
198 found_it = true;
anatofuz
parents:
diff changeset
199 break;
anatofuz
parents:
diff changeset
200 }
anatofuz
parents:
diff changeset
201 }
anatofuz
parents:
diff changeset
202 return found_it;
anatofuz
parents:
diff changeset
203 }