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
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
61 // we still want to call that a breakpoint hit, and trigger the actions,
62 // etc. Otherwise you would see the
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.
66 // So the lower levels fake "step onto breakpoint address" and return that
67 // as a breakpoint. So our trace
68 // step COULD appear as a breakpoint hit if the next instruction also
69 // contained a breakpoint.
70 StopReason reason = stop_info_sp->GetStopReason();
73 case eStopReasonTrace:
76 case eStopReasonBreakpoint:
77 // It's a little surprising that we stop here for a breakpoint hit.
78 // However, when you single step ONTO a
79 // breakpoint we still want to call that a breakpoint hit, and trigger the
80 // actions, etc. Otherwise you
81 // would see the PC at the breakpoint without having triggered the
82 // actions, then you'd continue, the PC
83 // wouldn't change, and you'd see the breakpoint hit, which would be odd.
84 // So the lower levels fake "step onto breakpoint address" and return that
85 // as a breakpoint hit. So our trace
86 // step COULD appear as a breakpoint hit if the next instruction also
87 // contained a breakpoint. We don't want
88 // to handle that, since we really don't know what to do with breakpoint
89 // hits. But make sure we don't set
90 // ourselves to auto-continue or we'll wrench control away from the plans
91 // that can deal with this.
92 SetAutoContinue(false);
101 bool ThreadPlanStepOverBreakpoint::ShouldStop(Event *event_ptr) {
102 return !ShouldAutoContinue(event_ptr);
105 bool ThreadPlanStepOverBreakpoint::StopOthers() { return true; }
107 StateType ThreadPlanStepOverBreakpoint::GetPlanRunState() {
108 return eStateStepping;
111 bool ThreadPlanStepOverBreakpoint::DoWillResume(StateType resume_state,
114 BreakpointSiteSP bp_site_sp(
115 m_thread.GetProcess()->GetBreakpointSiteList().FindByAddress(
117 if (bp_site_sp && bp_site_sp->IsEnabled())
118 m_thread.GetProcess()->DisableBreakpointSite(bp_site_sp.get());
123 bool ThreadPlanStepOverBreakpoint::WillStop() {
124 ReenableBreakpointSite();
128 bool ThreadPlanStepOverBreakpoint::MischiefManaged() {
129 lldb::addr_t pc_addr = m_thread.GetRegisterContext()->GetPC();
131 if (pc_addr == m_breakpoint_addr) {
132 // If we are still at the PC of our breakpoint, then for some reason we
134 // get a chance to run.
137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
139 log->Printf("Completed step over breakpoint plan.");
140 // Otherwise, re-enable the breakpoint we were stepping over, and we're
142 ReenableBreakpointSite();
143 ThreadPlan::MischiefManaged();
148 void ThreadPlanStepOverBreakpoint::ReenableBreakpointSite() {
149 if (!m_reenabled_breakpoint_site) {
150 m_reenabled_breakpoint_site = true;
151 BreakpointSiteSP bp_site_sp(
152 m_thread.GetProcess()->GetBreakpointSiteList().FindByAddress(
155 m_thread.GetProcess()->EnableBreakpointSite(bp_site_sp.get());
159 void ThreadPlanStepOverBreakpoint::ThreadDestroyed() {
160 ReenableBreakpointSite();
163 void ThreadPlanStepOverBreakpoint::SetAutoContinue(bool do_it) {
164 m_auto_continue = do_it;
167 bool ThreadPlanStepOverBreakpoint::ShouldAutoContinue(Event *event_ptr) {
168 return m_auto_continue;
171 bool ThreadPlanStepOverBreakpoint::IsPlanStale() {
172 return m_thread.GetRegisterContext()->GetPC() != m_breakpoint_addr;