blob: 3896a0b247145b30d43109404331e9206b9d23d1 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadPlanStepOverBreakpoint.cpp ------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Target/Process.h"
17#include "lldb/Target/RegisterContext.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000018#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000019#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000025// ThreadPlanStepOverBreakpoint: Single steps over a breakpoint bp_site_sp at
26// the pc.
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027//----------------------------------------------------------------------
28
Kate Stoneb9c1b512016-09-06 20:57:50 +000029ThreadPlanStepOverBreakpoint::ThreadPlanStepOverBreakpoint(Thread &thread)
30 : ThreadPlan(
31 ThreadPlan::eKindStepOverBreakpoint, "Step over breakpoint trap",
32 thread, eVoteNo,
33 eVoteNoOpinion), // We need to report the run since this happens
34 // first in the thread plan stack when stepping
35 // over a breakpoint
36 m_breakpoint_addr(LLDB_INVALID_ADDRESS),
37 m_auto_continue(false), m_reenabled_breakpoint_site(false)
Jim Inghamb01e7422010-06-19 04:45:32 +000038
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039{
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 m_breakpoint_addr = m_thread.GetRegisterContext()->GetPC();
41 m_breakpoint_site_id =
42 m_thread.GetProcess()->GetBreakpointSiteList().FindIDByAddress(
43 m_breakpoint_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046ThreadPlanStepOverBreakpoint::~ThreadPlanStepOverBreakpoint() {}
47
48void 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);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054bool ThreadPlanStepOverBreakpoint::ValidatePlan(Stream *error) { return true; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056bool ThreadPlanStepOverBreakpoint::DoPlanExplainsStop(Event *event_ptr) {
57 StopInfoSP stop_info_sp = GetPrivateStopInfo();
58 if (stop_info_sp) {
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();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 switch (reason) {
73 case eStopReasonTrace:
74 case eStopReasonNone:
75 return true;
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);
93 return false;
94 default:
95 return false;
Jim Inghambc1d7f72012-06-22 20:42:22 +000096 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 }
98 return false;
99}
100
101bool ThreadPlanStepOverBreakpoint::ShouldStop(Event *event_ptr) {
102 return !ShouldAutoContinue(event_ptr);
103}
104
105bool ThreadPlanStepOverBreakpoint::StopOthers() { return true; }
106
107StateType ThreadPlanStepOverBreakpoint::GetPlanRunState() {
108 return eStateStepping;
109}
110
111bool ThreadPlanStepOverBreakpoint::DoWillResume(StateType resume_state,
112 bool current_plan) {
113 if (current_plan) {
114 BreakpointSiteSP bp_site_sp(
115 m_thread.GetProcess()->GetBreakpointSiteList().FindByAddress(
116 m_breakpoint_addr));
117 if (bp_site_sp && bp_site_sp->IsEnabled())
118 m_thread.GetProcess()->DisableBreakpointSite(bp_site_sp.get());
119 }
120 return true;
121}
122
123bool ThreadPlanStepOverBreakpoint::WillStop() {
124 ReenableBreakpointSite();
125 return true;
126}
127
128bool ThreadPlanStepOverBreakpoint::MischiefManaged() {
129 lldb::addr_t pc_addr = m_thread.GetRegisterContext()->GetPC();
130
131 if (pc_addr == m_breakpoint_addr) {
132 // If we are still at the PC of our breakpoint, then for some reason we
133 // didn't
134 // get a chance to run.
Jim Inghambc1d7f72012-06-22 20:42:22 +0000135 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000136 } else {
137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
138 if (log)
139 log->Printf("Completed step over breakpoint plan.");
140 // Otherwise, re-enable the breakpoint we were stepping over, and we're
141 // done.
142 ReenableBreakpointSite();
143 ThreadPlan::MischiefManaged();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146}
147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148void 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(
153 m_breakpoint_addr));
154 if (bp_site_sp) {
155 m_thread.GetProcess()->EnableBreakpointSite(bp_site_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157 }
158}
159void ThreadPlanStepOverBreakpoint::ThreadDestroyed() {
160 ReenableBreakpointSite();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161}
162
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163void ThreadPlanStepOverBreakpoint::SetAutoContinue(bool do_it) {
164 m_auto_continue = do_it;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165}
166
Kate Stoneb9c1b512016-09-06 20:57:50 +0000167bool ThreadPlanStepOverBreakpoint::ShouldAutoContinue(Event *event_ptr) {
168 return m_auto_continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169}
170
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171bool ThreadPlanStepOverBreakpoint::IsPlanStale() {
172 return m_thread.GetRegisterContext()->GetPC() != m_breakpoint_addr;
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000173}