LLDB mainline
ThreadPlanRunToBreakpoint.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11#include "lldb/Target/Process.h"
13#include "lldb/Target/Target.h"
14#include "lldb/Target/Thread.h"
16#include "lldb/Utility/Log.h"
17#include "lldb/Utility/Stream.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
23 BreakpointSP bkpt_sp,
24 bool stop_others)
25 : ThreadPlan(ThreadPlan::eKindRunToBreakpoint, "Run to breakpoint plan",
27 m_stop_others(stop_others) {
28 if (bkpt_sp)
29 m_breakpoints.push_back(std::move(bkpt_sp));
30}
31
33 Thread &thread, const std::vector<BreakpointSP> &breakpoints,
34 bool stop_others)
35 : ThreadPlan(ThreadPlan::eKindRunToBreakpoint, "Run to breakpoint plan",
37 m_stop_others(stop_others) {
38 for (auto bkpt_sp : breakpoints) {
39 // Make the breakpoints thread specific:
40 if (bkpt_sp) {
41 bkpt_sp->SetThreadID(thread.GetID());
42 m_breakpoints.push_back(bkpt_sp);
43 }
44 }
45}
46
51
54 size_t num_bkpts = m_breakpoints.size();
55 if (level == lldb::eDescriptionLevelBrief) {
56 if (num_bkpts == 0) {
57 s->PutCString("run to breakpoint with no breakpoints given.");
58 return;
59 } else if (num_bkpts == 1)
60 s->PutCString("run to breakpoint: ");
61 else
62 s->PutCString("run to breakpoints: ");
63
64 for (auto bkpt_sp : m_breakpoints) {
65 *s << llvm::formatv("{0} ", bkpt_sp->GetID());
66 }
67 } else {
68 if (num_bkpts == 0) {
69 s->PutCString("run to breakpoint with no breakpoints given.");
70 return;
71 } else if (num_bkpts == 1)
72 s->PutCString("Run to breakpoint: ");
73 else {
74 s->PutCString("Run to breakpoints: ");
75 }
76
77 // FIXME: I'm not preserving breakpoint ID's
78 // in case I'm asked GetDescription after I've removed them.
79 for (auto bkpt_sp : m_breakpoints) {
80 s->PutCString("\n");
81 s->Indent();
82 bkpt_sp->Dump(s);
83 }
84 }
85}
86
88 // We don't require that the breakpoints we were given actually
89 // resolve to something when the plan was pushed. The only error
90 // was not to have passed any breakpoints.
91 return m_breakpoints.size() != 0;
92}
93
97
99 return AtOurBreakpoint();
100}
101
103
105 m_stop_others = new_value;
106}
107
109
111
113 Log *log = GetLog(LLDBLog::Step);
114
115 if (AtOurBreakpoint()) {
116 // Remove the breakpoints
117 for (auto bkpt_sp : m_breakpoints) {
118 GetTarget().RemoveBreakpointByID(bkpt_sp->GetID());
119 }
120 m_breakpoints.clear();
121 LLDB_LOGF(log, "Completed run to breakpoint plan.");
123 return true;
124 }
125 return false;
126}
127
129 lldb::addr_t current_addr = GetThread().GetRegisterContext()->GetPC();
130 Address current_address;
131 current_address.SetLoadAddress(current_addr, &GetTarget());
132 bool found_it = false;
133 for (auto bkpt_sp : m_breakpoints) {
134 if (auto location_sp = bkpt_sp->FindLocationByAddress(current_address)) {
135 StreamString s;
136 location_sp->GetDescription(&s, eDescriptionLevelBrief);
137 LLDB_LOG(GetLog(LLDBLog::Step), "RunToBreakpoint hit breakpoint: {0}", s);
138 found_it = true;
139 break;
140 }
141 }
142 return found_it;
143}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
A section + offset based address class.
Definition Address.h:62
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition Address.cpp:1029
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
bool RemoveBreakpointByID(lldb::break_id_t break_id)
Definition Target.cpp:1207
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
std::vector< lldb::BreakpointSP > m_breakpoints
bool DoPlanExplainsStop(Event *event_ptr) override
ThreadPlanRunToBreakpoint(Thread &thread, lldb::BreakpointSP breakpoint_sp, bool stop_others)
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.
virtual bool MischiefManaged()
virtual lldb::RegisterContextSP GetRegisterContext()=0
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
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.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
uint64_t addr_t
Definition lldb-types.h:80