LLDB mainline
ThreadPlanRunToAddress.cpp
Go to the documentation of this file.
1//===-- ThreadPlanRunToAddress.cpp ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Target/Process.h"
12#include "lldb/Target/Target.h"
13#include "lldb/Target/Thread.h"
15#include "lldb/Utility/Log.h"
16#include "lldb/Utility/Stream.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21// ThreadPlanRunToAddress: Continue plan
22
24 bool stop_others)
25 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
27 m_stop_others(stop_others), m_addresses(), m_break_ids() {
28 m_addresses.push_back(
29 address.GetOpcodeLoadAddress(thread.CalculateTarget().get()));
31}
32
34 lldb::addr_t address,
35 bool stop_others)
36 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
38 m_stop_others(stop_others), m_addresses(), m_break_ids() {
39 m_addresses.push_back(
40 thread.CalculateTarget()->GetOpcodeLoadAddress(address));
42}
43
45 Thread &thread, const std::vector<lldb::addr_t> &addresses,
46 bool stop_others)
47 : ThreadPlan(ThreadPlan::eKindRunToAddress, "Run to address plan", thread,
49 m_stop_others(stop_others), m_addresses(addresses), m_break_ids() {
50 // Convert all addresses into opcode addresses to make sure we set
51 // breakpoints at the correct address.
52 Target &target = thread.GetProcess()->GetTarget();
53 std::vector<lldb::addr_t>::iterator pos, end = m_addresses.end();
54 for (pos = m_addresses.begin(); pos != end; ++pos)
55 *pos = target.GetOpcodeLoadAddress(*pos);
56
58}
59
61 size_t num_addresses = m_addresses.size();
62 m_break_ids.resize(num_addresses);
63
64 for (size_t i = 0; i < num_addresses; i++) {
65 Breakpoint *breakpoint;
66 breakpoint =
67 GetTarget().CreateBreakpoint(m_addresses[i], true, false).get();
68 if (breakpoint != nullptr) {
69 if (breakpoint->IsHardware() && !breakpoint->HasResolvedLocations())
71 m_break_ids[i] = breakpoint->GetID();
72 breakpoint->SetThreadID(m_tid);
73 breakpoint->SetBreakpointKind("run-to-address");
74 }
75 }
76}
77
79 size_t num_break_ids = m_break_ids.size();
80 for (size_t i = 0; i < num_break_ids; i++) {
82 }
84}
85
88 size_t num_addresses = m_addresses.size();
89
90 if (level == lldb::eDescriptionLevelBrief) {
91 if (num_addresses == 0) {
92 s->Printf("run to address with no addresses given.");
93 return;
94 } else if (num_addresses == 1)
95 s->Printf("run to address: ");
96 else
97 s->Printf("run to addresses: ");
98
99 for (size_t i = 0; i < num_addresses; i++) {
100 DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
101 s->Printf(" ");
102 }
103 } else {
104 if (num_addresses == 0) {
105 s->Printf("run to address with no addresses given.");
106 return;
107 } else if (num_addresses == 1)
108 s->Printf("Run to address: ");
109 else {
110 s->Printf("Run to addresses: ");
111 }
112
113 for (size_t i = 0; i < num_addresses; i++) {
114 if (num_addresses > 1) {
115 s->Printf("\n");
116 s->Indent();
117 }
118
119 DumpAddress(s->AsRawOstream(), m_addresses[i], sizeof(addr_t));
120 s->Printf(" using breakpoint: %d - ", m_break_ids[i]);
121 Breakpoint *breakpoint =
123 if (breakpoint)
124 breakpoint->Dump(s);
125 else
126 s->Printf("but the breakpoint has been deleted.");
127 }
128 }
129}
130
133 if (error)
134 error->Printf("Could not set hardware breakpoint(s)");
135 return false;
136 }
137
138 // If we couldn't set the breakpoint for some reason, then this won't work.
139 bool all_bps_good = true;
140 size_t num_break_ids = m_break_ids.size();
141 for (size_t i = 0; i < num_break_ids; i++) {
143 all_bps_good = false;
144 if (error) {
145 error->Printf("Could not set breakpoint for address: ");
146 DumpAddress(error->AsRawOstream(), m_addresses[i], sizeof(addr_t));
147 error->Printf("\n");
148 }
149 }
150 }
151 return all_bps_good;
152}
153
155 return AtOurAddress();
156}
157
159 return AtOurAddress();
160}
161
163
165 m_stop_others = new_value;
166}
167
169
170bool ThreadPlanRunToAddress::WillStop() { return true; }
171
173 Log *log = GetLog(LLDBLog::Step);
174
175 if (AtOurAddress()) {
176 // Remove the breakpoint
177 size_t num_break_ids = m_break_ids.size();
178
179 for (size_t i = 0; i < num_break_ids; i++) {
183 }
184 }
185 LLDB_LOGF(log, "Completed run to address plan.");
187 return true;
188 } else
189 return false;
190}
191
193 lldb::addr_t current_address = GetThread().GetRegisterContext()->GetPC();
194 bool found_it = false;
195 size_t num_addresses = m_addresses.size();
196 for (size_t i = 0; i < num_addresses; i++) {
197 if (m_addresses[i] == current_address) {
198 found_it = true;
199 break;
200 }
201 }
202 return found_it;
203}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:349
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
Definition: Address.cpp:370
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
void SetBreakpointKind(const char *kind)
Set the "kind" description for a breakpoint.
Definition: Breakpoint.h:452
bool HasResolvedLocations() const
Return whether this breakpoint has any resolved locations.
Definition: Breakpoint.cpp:826
bool IsHardware() const
Definition: Breakpoint.h:520
void SetThreadID(lldb::tid_t thread_id)
Set the valid thread to be checked when the breakpoint is hit.
Definition: Breakpoint.cpp:336
void Dump(Stream *s) override
Standard "Dump" method. At present it does nothing.
Definition: Breakpoint.cpp:818
lldb::break_id_t GetID() const
Definition: Stoppoint.cpp:22
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
lldb::addr_t GetOpcodeLoadAddress(lldb::addr_t load_addr, AddressClass addr_class=AddressClass::eInvalid) const
Get load_addr as an opcode for this target.
Definition: Target.cpp:2811
lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id)
Definition: Target.cpp:328
bool RemoveBreakpointByID(lldb::break_id_t break_id)
Definition: Target.cpp:1004
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition: Target.cpp:395
std::vector< lldb::addr_t > m_addresses
ThreadPlanRunToAddress(Thread &thread, Address &address, bool stop_others)
void SetStopOthers(bool new_value) override
bool ShouldStop(Event *event_ptr) override
std::vector< lldb::break_id_t > m_break_ids
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
bool DoPlanExplainsStop(Event *event_ptr) override
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:42
virtual bool MischiefManaged()
Definition: ThreadPlan.cpp:72
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1390
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
Definition: Stream.cpp:108
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
StateType
Process and Thread States.
@ eStateRunning
Process or thread is running and can't be examined.
uint64_t addr_t
Definition: lldb-types.h:79