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"
13 #include "lldb/Utility/Log.h"
14 #include "lldb/Utility/Stream.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 // ThreadPlanStepOverBreakpoint: Single steps over a breakpoint bp_site_sp at
20 // the pc.
21 
22 ThreadPlanStepOverBreakpoint::ThreadPlanStepOverBreakpoint(Thread &thread)
23  : ThreadPlan(
24  ThreadPlan::eKindStepOverBreakpoint, "Step over breakpoint trap",
25  thread, eVoteNo,
26  eVoteNoOpinion), // We need to report the run since this happens
27  // first in the thread plan stack when stepping over
28  // a breakpoint
29  m_breakpoint_addr(LLDB_INVALID_ADDRESS),
30  m_auto_continue(false), m_reenabled_breakpoint_site(false)
31 
32 {
33  m_breakpoint_addr = thread.GetRegisterContext()->GetPC();
35  thread.GetProcess()->GetBreakpointSiteList().FindIDByAddress(
37 }
38 
40 
42  Stream *s, lldb::DescriptionLevel level) {
43  s->Printf("Single stepping past breakpoint site %" PRIu64 " at 0x%" PRIx64,
45 }
46 
48 
50  StopInfoSP stop_info_sp = GetPrivateStopInfo();
51  if (stop_info_sp) {
52  StopReason reason = stop_info_sp->GetStopReason();
53 
55  LLDB_LOG(log, "Step over breakpoint stopped for reason: {0}.",
57 
58  switch (reason) {
59  case eStopReasonTrace:
60  case eStopReasonNone:
61  return true;
63  {
64  // It's a little surprising that we stop here for a breakpoint hit.
65  // However, when you single step ONTO a breakpoint we still want to call
66  // that a breakpoint hit, and trigger the actions, etc. Otherwise you
67  // would see the PC at the breakpoint without having triggered the
68  // actions, then you'd continue, the PC wouldn't change, and you'd see
69  // the breakpoint hit, which would be odd. So the lower levels fake
70  // "step onto breakpoint address" and return that as a breakpoint hit.
71  // So our trace step COULD appear as a breakpoint hit if the next
72  // instruction also contained a breakpoint. We don't want to handle
73  // that, since we really don't know what to do with breakpoint hits.
74  // But make sure we don't set ourselves to auto-continue or we'll wrench
75  // control away from the plans that can deal with this.
76  // Be careful, however, as we may have "seen a breakpoint under the PC
77  // because we stopped without changing the PC, in which case we do want
78  // to re-claim this stop so we'll try again.
79  lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC();
80 
81  if (pc_addr == m_breakpoint_addr) {
82  LLDB_LOGF(log,
83  "Got breakpoint stop reason but pc: 0x%" PRIx64
84  "hasn't changed.",
85  pc_addr);
86  return true;
87  }
88 
89  SetAutoContinue(false);
90  return false;
91  }
92  default:
93  return false;
94  }
95  }
96  return false;
97 }
98 
100  return !ShouldAutoContinue(event_ptr);
101 }
102 
104 
106  return eStateStepping;
107 }
108 
110  bool current_plan) {
111  if (current_plan) {
112  BreakpointSiteSP bp_site_sp(
114  if (bp_site_sp && bp_site_sp->IsEnabled()) {
115  m_process.DisableBreakpointSite(bp_site_sp.get());
117  }
118  }
119  return true;
120 }
121 
124  return true;
125 }
126 
128 
130  lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC();
131 
132  if (pc_addr == m_breakpoint_addr) {
133  // If we are still at the PC of our breakpoint, then for some reason we
134  // didn't get a chance to run.
135  return false;
136  } else {
138  LLDB_LOGF(log, "Completed step over breakpoint plan.");
139  // Otherwise, re-enable the breakpoint we were stepping over, and we're
140  // done.
143  return true;
144  }
145 }
146 
150  BreakpointSiteSP bp_site_sp(
152  if (bp_site_sp) {
153  m_process.EnableBreakpointSite(bp_site_sp.get());
154  }
155  }
156 }
159 }
160 
162  m_auto_continue = do_it;
163 }
164 
166  return m_auto_continue;
167 }
168 
170  return GetThread().GetRegisterContext()->GetPC() != m_breakpoint_addr;
171 }
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb_private::ThreadPlanStepOverBreakpoint::ReenableBreakpointSite
void ReenableBreakpointSite()
Definition: ThreadPlanStepOverBreakpoint.cpp:147
lldb_private::Event
Definition: Event.h:180
lldb_private::ThreadPlanStepOverBreakpoint::m_auto_continue
bool m_auto_continue
Definition: ThreadPlanStepOverBreakpoint.h:47
lldb_private::ThreadPlanStepOverBreakpoint::ThreadDestroyed
void ThreadDestroyed() override
Definition: ThreadPlanStepOverBreakpoint.cpp:157
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::Process::GetBreakpointSiteList
BreakpointSiteList & GetBreakpointSiteList()
Definition: Process.cpp:1554
lldb_private::ThreadPlanStepOverBreakpoint::IsPlanStale
bool IsPlanStale() override
Definition: ThreadPlanStepOverBreakpoint.cpp:169
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb_private::ThreadPlanStepOverBreakpoint::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanStepOverBreakpoint.cpp:41
lldb_private::eVoteNoOpinion
@ eVoteNoOpinion
Definition: lldb-private-enumerations.h:59
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb::eStopReasonTrace
@ eStopReasonTrace
Definition: lldb-enumerations.h:242
Process.h
lldb_private::ThreadPlanStepOverBreakpoint::StopOthers
bool StopOthers() override
Definition: ThreadPlanStepOverBreakpoint.cpp:103
lldb_private::Thread::GetProcess
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadPlan
Definition: ThreadPlan.h:282
lldb_private::BreakpointSiteList::FindByAddress
lldb::BreakpointSiteSP FindByAddress(lldb::addr_t addr)
Returns a shared pointer to the breakpoint site at address addr.
Definition: BreakpointSiteList.cpp:132
lldb_private::eVoteNo
@ eVoteNo
Definition: lldb-private-enumerations.h:59
Log.h
lldb_private::ThreadPlan::MischiefManaged
virtual bool MischiefManaged()
Definition: ThreadPlan.cpp:71
lldb_private::Thread
Definition: Thread.h:62
lldb::eStopReasonNone
@ eStopReasonNone
Definition: lldb-enumerations.h:241
lldb_private::ThreadPlanStepOverBreakpoint::ShouldAutoContinue
bool ShouldAutoContinue(Event *event_ptr) override
Returns whether this thread plan overrides the ShouldStop of subsequently processed plans.
Definition: ThreadPlanStepOverBreakpoint.cpp:165
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::ThreadPlanStepOverBreakpoint::m_breakpoint_site_id
lldb::user_id_t m_breakpoint_site_id
Definition: ThreadPlanStepOverBreakpoint.h:46
lldb_private::ThreadPlanStepOverBreakpoint::DoWillResume
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override
Definition: ThreadPlanStepOverBreakpoint.cpp:109
ThreadPlanStepOverBreakpoint.h
lldb_private::ThreadPlanStepOverBreakpoint::ValidatePlan
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
Definition: ThreadPlanStepOverBreakpoint.cpp:47
lldb_private::ThreadPlanStepOverBreakpoint::m_breakpoint_addr
lldb::addr_t m_breakpoint_addr
Definition: ThreadPlanStepOverBreakpoint.h:45
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldb_private::ThreadPlanStepOverBreakpoint::DidPop
void DidPop() override
Definition: ThreadPlanStepOverBreakpoint.cpp:127
lldb_private::ThreadPlanStepOverBreakpoint::ShouldStop
bool ShouldStop(Event *event_ptr) override
Definition: ThreadPlanStepOverBreakpoint.cpp:99
lldb_private::ThreadPlanStepOverBreakpoint::GetPlanRunState
lldb::StateType GetPlanRunState() override
Definition: ThreadPlanStepOverBreakpoint.cpp:105
lldb_private::ThreadPlanStepOverBreakpoint::WillStop
bool WillStop() override
Definition: ThreadPlanStepOverBreakpoint.cpp:122
lldb_private::ThreadPlanStepOverBreakpoint::SetAutoContinue
void SetAutoContinue(bool do_it)
Definition: ThreadPlanStepOverBreakpoint.cpp:161
lldb_private::ThreadPlanStepOverBreakpoint::MischiefManaged
bool MischiefManaged() override
Definition: ThreadPlanStepOverBreakpoint.cpp:129
lldb_private::ThreadPlanStepOverBreakpoint::DoPlanExplainsStop
bool DoPlanExplainsStop(Event *event_ptr) override
Definition: ThreadPlanStepOverBreakpoint.cpp:49
lldb::eStopReasonBreakpoint
@ eStopReasonBreakpoint
Definition: lldb-enumerations.h:243
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::ThreadPlanStepOverBreakpoint::m_reenabled_breakpoint_site
bool m_reenabled_breakpoint_site
Definition: ThreadPlanStepOverBreakpoint.h:48
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LIBLLDB_LOG_STEP
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
lldb_private::Process::EnableBreakpointSite
virtual Status EnableBreakpointSite(BreakpointSite *bp_site)
Definition: Process.h:2047
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
Stream.h
lldb_private::Thread::StopReasonAsString
static std::string StopReasonAsString(lldb::StopReason reason)
Definition: Thread.cpp:1664
lldb_private::Log
Definition: Log.h:49
lldb_private::ThreadPlan::GetPrivateStopInfo
lldb::StopInfoSP GetPrivateStopInfo()
Definition: ThreadPlan.h:510
lldb_private::Thread::GetRegisterContext
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb_private::ThreadPlan::m_process
Process & m_process
Definition: ThreadPlan.h:523
lldb
Definition: SBAddress.h:15
RegisterContext.h
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::ThreadPlanStepOverBreakpoint::~ThreadPlanStepOverBreakpoint
~ThreadPlanStepOverBreakpoint() override
lldb_private::Process::DisableBreakpointSite
virtual Status DisableBreakpointSite(BreakpointSite *bp_site)
Definition: Process.h:2055