1 //===-- ThreadPlanStepOverBreakpoint.cpp ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
14 // Other libraries and framework includes
16 #include "lldb/Target/Process.h"
17 #include "lldb/Target/RegisterContext.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/Stream.h"
22 using namespace lldb_private;
24 //----------------------------------------------------------------------
25 // ThreadPlanStepOverBreakpoint: Single steps over a breakpoint bp_site_sp at
27 //----------------------------------------------------------------------
29 ThreadPlanStepOverBreakpoint::ThreadPlanStepOverBreakpoint(Thread &thread)
31 ThreadPlan::eKindStepOverBreakpoint, "Step over breakpoint trap",
33 eVoteNoOpinion), // We need to report the run since this happens
34 // first in the thread plan stack when stepping over
36 m_breakpoint_addr(LLDB_INVALID_ADDRESS),
37 m_auto_continue(false), m_reenabled_breakpoint_site(false)
40 m_breakpoint_addr = m_thread.GetRegisterContext()->GetPC();
41 m_breakpoint_site_id =
42 m_thread.GetProcess()->GetBreakpointSiteList().FindIDByAddress(
46 ThreadPlanStepOverBreakpoint::~ThreadPlanStepOverBreakpoint() {}
48 void ThreadPlanStepOverBreakpoint::GetDescription(
49 Stream *s, lldb::DescriptionLevel level) {
50 s->Printf("Single stepping past breakpoint site %" PRIu64 " at 0x%" PRIx64,
51 m_breakpoint_site_id, (uint64_t)m_breakpoint_addr);
54 bool ThreadPlanStepOverBreakpoint::ValidatePlan(Stream *error) { return true; }
56 bool ThreadPlanStepOverBreakpoint::DoPlanExplainsStop(Event *event_ptr) {
57 StopInfoSP stop_info_sp = GetPrivateStopInfo();
59 // It's a little surprising that we stop here for a breakpoint hit.
60 // However, when you single step ONTO a breakpoint we still want to call
61 // that a breakpoint hit, and trigger the actions, etc. Otherwise you
63 // PC at the breakpoint without having triggered the actions, then you'd
64 // continue, the PC wouldn't change,
65 // and you'd see the breakpoint hit, which would be odd. So the lower
66 // levels fake "step onto breakpoint address" and return that as a
67 // breakpoint. So our trace step COULD appear as a breakpoint hit if the
68 // next instruction also contained a breakpoint.
69 StopReason reason = stop_info_sp->GetStopReason();
71 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
74 log->Printf("Step over breakpoint stopped for reason: %s.",
75 Thread::StopReasonAsCString(reason));
78 case eStopReasonTrace:
81 case eStopReasonBreakpoint:
83 // It's a little surprising that we stop here for a breakpoint hit.
84 // However, when you single step ONTO a breakpoint we still want to call
85 // that a breakpoint hit, and trigger the actions, etc. Otherwise you
86 // would see the PC at the breakpoint without having triggered the
87 // actions, then you'd continue, the PC wouldn't change, and you'd see
88 // the breakpoint hit, which would be odd. So the lower levels fake
89 // "step onto breakpoint address" and return that as a breakpoint hit.
90 // So our trace step COULD appear as a breakpoint hit if the next
91 // instruction also contained a breakpoint. We don't want to handle
92 // that, since we really don't know what to do with breakpoint hits.
93 // But make sure we don't set ourselves to auto-continue or we'll wrench
94 // control away from the plans that can deal with this.
95 // Be careful, however, as we may have "seen a breakpoint under the PC
96 // because we stopped without changing the PC, in which case we do want
97 // to re-claim this stop so we'll try again.
98 lldb::addr_t pc_addr = m_thread.GetRegisterContext()->GetPC();
100 if (pc_addr == m_breakpoint_addr) {
102 log->Printf("Got breakpoint stop reason but pc: 0x%" PRIx64
103 "hasn't changed.", pc_addr);
107 SetAutoContinue(false);
117 bool ThreadPlanStepOverBreakpoint::ShouldStop(Event *event_ptr) {
118 return !ShouldAutoContinue(event_ptr);
121 bool ThreadPlanStepOverBreakpoint::StopOthers() { return true; }
123 StateType ThreadPlanStepOverBreakpoint::GetPlanRunState() {
124 return eStateStepping;
127 bool ThreadPlanStepOverBreakpoint::DoWillResume(StateType resume_state,
130 BreakpointSiteSP bp_site_sp(
131 m_thread.GetProcess()->GetBreakpointSiteList().FindByAddress(
133 if (bp_site_sp && bp_site_sp->IsEnabled()) {
134 m_thread.GetProcess()->DisableBreakpointSite(bp_site_sp.get());
135 m_reenabled_breakpoint_site = false;
141 bool ThreadPlanStepOverBreakpoint::WillStop() {
142 ReenableBreakpointSite();
146 void ThreadPlanStepOverBreakpoint::WillPop() {
147 ReenableBreakpointSite();
150 bool ThreadPlanStepOverBreakpoint::MischiefManaged() {
151 lldb::addr_t pc_addr = m_thread.GetRegisterContext()->GetPC();
153 if (pc_addr == m_breakpoint_addr) {
154 // If we are still at the PC of our breakpoint, then for some reason we
155 // didn't get a chance to run.
158 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
160 log->Printf("Completed step over breakpoint plan.");
161 // Otherwise, re-enable the breakpoint we were stepping over, and we're
163 ReenableBreakpointSite();
164 ThreadPlan::MischiefManaged();
169 void ThreadPlanStepOverBreakpoint::ReenableBreakpointSite() {
170 if (!m_reenabled_breakpoint_site) {
171 m_reenabled_breakpoint_site = true;
172 BreakpointSiteSP bp_site_sp(
173 m_thread.GetProcess()->GetBreakpointSiteList().FindByAddress(
176 m_thread.GetProcess()->EnableBreakpointSite(bp_site_sp.get());
180 void ThreadPlanStepOverBreakpoint::ThreadDestroyed() {
181 ReenableBreakpointSite();
184 void ThreadPlanStepOverBreakpoint::SetAutoContinue(bool do_it) {
185 m_auto_continue = do_it;
188 bool ThreadPlanStepOverBreakpoint::ShouldAutoContinue(Event *event_ptr) {
189 return m_auto_continue;
192 bool ThreadPlanStepOverBreakpoint::IsPlanStale() {
193 return m_thread.GetRegisterContext()->GetPC() != m_breakpoint_addr;