LLDB mainline
ThreadPlanStepOverBreakpoint.cpp
Go to the documentation of this file.
1//===-- ThreadPlanStepOverBreakpoint.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
11#include "lldb/Target/Process.h"
15#include "lldb/Utility/Log.h"
16#include "lldb/Utility/Stream.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21// ThreadPlanStepOverBreakpoint: Single steps over a breakpoint bp_site_sp at
22// the pc.
23
26 "Step over breakpoint trap", thread, eVoteNo,
27 eVoteNoOpinion), // We need to report the run since this
28 // happens first in the thread plan stack when
29 // stepping over a breakpoint
33
34{
35 m_breakpoint_addr = thread.GetRegisterContext()->GetPC();
37 thread.GetProcess()->GetBreakpointSiteList().FindIDByAddress(
39}
40
42
45 s->Printf("Single stepping past breakpoint site %" PRIu64 " at 0x%" PRIx64,
47}
48
50
52 StopInfoSP stop_info_sp = GetPrivateStopInfo();
53 if (stop_info_sp) {
54 StopReason reason = stop_info_sp->GetStopReason();
55
56 Log *log = GetLog(LLDBLog::Step);
57 LLDB_LOG(log, "Step over breakpoint stopped for reason: {0}.",
59
60 switch (reason) {
62 case eStopReasonNone:
63 return true;
65 {
66 // It's a little surprising that we stop here for a breakpoint hit.
67 // However, when you single step ONTO a breakpoint we still want to call
68 // that a breakpoint hit, and trigger the actions, etc. Otherwise you
69 // would see the PC at the breakpoint without having triggered the
70 // actions, then you'd continue, the PC wouldn't change, and you'd see
71 // the breakpoint hit, which would be odd. So the lower levels fake
72 // "step onto breakpoint address" and return that as a breakpoint hit.
73 // So our trace step COULD appear as a breakpoint hit if the next
74 // instruction also contained a breakpoint. We don't want to handle
75 // that, since we really don't know what to do with breakpoint hits.
76 // But make sure we don't set ourselves to auto-continue or we'll wrench
77 // control away from the plans that can deal with this.
78 // Be careful, however, as we may have "seen a breakpoint under the PC
79 // because we stopped without changing the PC, in which case we do want
80 // to re-claim this stop so we'll try again.
81 lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC();
82
83 if (pc_addr == m_breakpoint_addr) {
84 LLDB_LOGF(log,
85 "Got breakpoint stop reason but pc: 0x%" PRIx64
86 "hasn't changed.",
87 pc_addr);
88 return true;
89 }
90
91 SetAutoContinue(false);
92 return false;
93 }
94 default:
95 return false;
96 }
97 }
98 return false;
99}
100
102 return !ShouldAutoContinue(event_ptr);
103}
104
106
107// This thread plan does a single instruction step over a breakpoint instruction
108// and needs to not resume other threads, so return false to stop the
109// ThreadPlanSingleThreadTimeout from timing out and trying to resume all
110// threads. If all threads gets resumed before we disable, single step and
111// re-enable the breakpoint, we can miss breakpoints on other threads.
113
117
119 bool current_plan) {
120 if (current_plan) {
121 BreakpointSiteSP bp_site_sp(
122 m_process.GetBreakpointSiteList().FindByAddress(m_breakpoint_addr));
123 if (bp_site_sp && bp_site_sp->IsEnabled()) {
124 m_process.DisableBreakpointSite(bp_site_sp.get());
126 }
127 }
128 return true;
129}
130
135
137
139 lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC();
140
141 if (pc_addr == m_breakpoint_addr) {
142 // If we are still at the PC of our breakpoint, then for some reason we
143 // didn't get a chance to run.
144 return false;
145 } else {
146 Log *log = GetLog(LLDBLog::Step);
147 LLDB_LOGF(log, "Completed step over breakpoint plan.");
148 // Otherwise, re-enable the breakpoint we were stepping over, and we're
149 // done.
152 return true;
153 }
154}
155
159
161 // Let ThreadList track all threads stepping over this breakpoint.
162 // It will re-enable the breakpoint only when ALL threads have finished.
163 m_process.GetThreadList().ThreadFinishedSteppingOverBreakpoint(
165 } else {
166 // Default behavior: re-enable the breakpoint directly.
167 if (BreakpointSiteSP bp_site_sp =
168 m_process.GetBreakpointSiteList().FindByAddress(
170 m_process.EnableBreakpointSite(bp_site_sp.get());
171 }
172 }
173}
177
181
185
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:369
#define LLDB_LOGF(log,...)
Definition Log.h:376
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
bool ShouldAutoContinue(Event *event_ptr) override
Returns whether this thread plan overrides the ShouldStop of subsequently processed plans.
ThreadPlan(ThreadPlanKind kind, const char *name, Thread &thread, Vote report_stop_vote, Vote report_run_vote)
Thread & GetThread()
Returns the Thread that is using this thread plan.
virtual bool MischiefManaged()
lldb::StopInfoSP GetPrivateStopInfo()
Definition ThreadPlan.h:544
virtual lldb::RegisterContextSP GetRegisterContext()=0
static std::string StopReasonAsString(lldb::StopReason reason)
Definition Thread.cpp:1906
#define LLDB_INVALID_ADDRESS
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:332
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
StateType
Process and Thread States.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
@ eStopReasonBreakpoint
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47