/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
9 | | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
10 | | |
11 | | #include "lldb/Target/Process.h" |
12 | | #include "lldb/Target/RegisterContext.h" |
13 | | #include "lldb/Utility/LLDBLog.h" |
14 | | #include "lldb/Utility/Log.h" |
15 | | #include "lldb/Utility/Stream.h" |
16 | | |
17 | | using namespace lldb; |
18 | | using namespace lldb_private; |
19 | | |
20 | | // ThreadPlanStepOverBreakpoint: Single steps over a breakpoint bp_site_sp at |
21 | | // the pc. |
22 | | |
23 | | ThreadPlanStepOverBreakpoint::ThreadPlanStepOverBreakpoint(Thread &thread) |
24 | 3.60k | : ThreadPlan( |
25 | 3.60k | ThreadPlan::eKindStepOverBreakpoint, "Step over breakpoint trap", |
26 | 3.60k | thread, eVoteNo, |
27 | 3.60k | eVoteNoOpinion), // We need to report the run since this happens |
28 | | // first in the thread plan stack when stepping over |
29 | | // a breakpoint |
30 | | m_breakpoint_addr(LLDB_INVALID_ADDRESS), |
31 | 3.60k | m_auto_continue(false), m_reenabled_breakpoint_site(false) |
32 | | |
33 | 3.60k | { |
34 | 3.60k | m_breakpoint_addr = thread.GetRegisterContext()->GetPC(); |
35 | 3.60k | m_breakpoint_site_id = |
36 | 3.60k | thread.GetProcess()->GetBreakpointSiteList().FindIDByAddress( |
37 | 3.60k | m_breakpoint_addr); |
38 | 3.60k | } |
39 | | |
40 | 3.60k | ThreadPlanStepOverBreakpoint::~ThreadPlanStepOverBreakpoint() = default; |
41 | | |
42 | | void ThreadPlanStepOverBreakpoint::GetDescription( |
43 | 0 | Stream *s, lldb::DescriptionLevel level) { |
44 | 0 | s->Printf("Single stepping past breakpoint site %" PRIu64 " at 0x%" PRIx64, |
45 | 0 | m_breakpoint_site_id, (uint64_t)m_breakpoint_addr); |
46 | 0 | } |
47 | | |
48 | 7.21k | bool ThreadPlanStepOverBreakpoint::ValidatePlan(Stream *error) { return true; } |
49 | | |
50 | 3.60k | bool ThreadPlanStepOverBreakpoint::DoPlanExplainsStop(Event *event_ptr) { |
51 | 3.60k | StopInfoSP stop_info_sp = GetPrivateStopInfo(); |
52 | 3.60k | if (stop_info_sp) { |
53 | 3.60k | StopReason reason = stop_info_sp->GetStopReason(); |
54 | | |
55 | 3.60k | Log *log = GetLog(LLDBLog::Step); |
56 | 3.60k | LLDB_LOG(log, "Step over breakpoint stopped for reason: {0}.", |
57 | 3.60k | Thread::StopReasonAsString(reason)); |
58 | | |
59 | 3.60k | switch (reason) { |
60 | 3.58k | case eStopReasonTrace: |
61 | 3.58k | case eStopReasonNone: |
62 | 3.58k | return true; |
63 | 21 | case eStopReasonBreakpoint: |
64 | 21 | { |
65 | | // It's a little surprising that we stop here for a breakpoint hit. |
66 | | // However, when you single step ONTO a breakpoint we still want to call |
67 | | // that a breakpoint hit, and trigger the actions, etc. Otherwise you |
68 | | // would see the PC at the breakpoint without having triggered the |
69 | | // actions, then you'd continue, the PC wouldn't change, and you'd see |
70 | | // the breakpoint hit, which would be odd. So the lower levels fake |
71 | | // "step onto breakpoint address" and return that as a breakpoint hit. |
72 | | // So our trace step COULD appear as a breakpoint hit if the next |
73 | | // instruction also contained a breakpoint. We don't want to handle |
74 | | // that, since we really don't know what to do with breakpoint hits. |
75 | | // But make sure we don't set ourselves to auto-continue or we'll wrench |
76 | | // control away from the plans that can deal with this. |
77 | | // Be careful, however, as we may have "seen a breakpoint under the PC |
78 | | // because we stopped without changing the PC, in which case we do want |
79 | | // to re-claim this stop so we'll try again. |
80 | 21 | lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC(); |
81 | | |
82 | 21 | if (pc_addr == m_breakpoint_addr) { |
83 | 0 | LLDB_LOGF(log, |
84 | 0 | "Got breakpoint stop reason but pc: 0x%" PRIx64 |
85 | 0 | "hasn't changed.", |
86 | 0 | pc_addr); |
87 | 0 | return true; |
88 | 0 | } |
89 | | |
90 | 21 | SetAutoContinue(false); |
91 | 21 | return false; |
92 | 21 | } |
93 | 1 | default: |
94 | 1 | return false; |
95 | 3.60k | } |
96 | 3.60k | } |
97 | 0 | return false; |
98 | 3.60k | } |
99 | | |
100 | 3.58k | bool ThreadPlanStepOverBreakpoint::ShouldStop(Event *event_ptr) { |
101 | 3.58k | return !ShouldAutoContinue(event_ptr); |
102 | 3.58k | } |
103 | | |
104 | 3.68k | bool ThreadPlanStepOverBreakpoint::StopOthers() { return true; } |
105 | | |
106 | 7.24k | StateType ThreadPlanStepOverBreakpoint::GetPlanRunState() { |
107 | 7.24k | return eStateStepping; |
108 | 7.24k | } |
109 | | |
110 | | bool ThreadPlanStepOverBreakpoint::DoWillResume(StateType resume_state, |
111 | 3.63k | bool current_plan) { |
112 | 3.63k | if (current_plan) { |
113 | 3.63k | BreakpointSiteSP bp_site_sp( |
114 | 3.63k | m_process.GetBreakpointSiteList().FindByAddress(m_breakpoint_addr)); |
115 | 3.63k | if (bp_site_sp && bp_site_sp->IsEnabled()) { |
116 | 3.60k | m_process.DisableBreakpointSite(bp_site_sp.get()); |
117 | 3.60k | m_reenabled_breakpoint_site = false; |
118 | 3.60k | } |
119 | 3.63k | } |
120 | 3.63k | return true; |
121 | 3.63k | } |
122 | | |
123 | 153 | bool ThreadPlanStepOverBreakpoint::WillStop() { |
124 | 153 | ReenableBreakpointSite(); |
125 | 153 | return true; |
126 | 153 | } |
127 | | |
128 | 3.60k | void ThreadPlanStepOverBreakpoint::DidPop() { ReenableBreakpointSite(); } |
129 | | |
130 | 3.58k | bool ThreadPlanStepOverBreakpoint::MischiefManaged() { |
131 | 3.58k | lldb::addr_t pc_addr = GetThread().GetRegisterContext()->GetPC(); |
132 | | |
133 | 3.58k | if (pc_addr == m_breakpoint_addr) { |
134 | | // If we are still at the PC of our breakpoint, then for some reason we |
135 | | // didn't get a chance to run. |
136 | 0 | return false; |
137 | 3.58k | } else { |
138 | 3.58k | Log *log = GetLog(LLDBLog::Step); |
139 | 3.58k | LLDB_LOGF(log, "Completed step over breakpoint plan."); |
140 | | // Otherwise, re-enable the breakpoint we were stepping over, and we're |
141 | | // done. |
142 | 3.58k | ReenableBreakpointSite(); |
143 | 3.58k | ThreadPlan::MischiefManaged(); |
144 | 3.58k | return true; |
145 | 3.58k | } |
146 | 3.58k | } |
147 | | |
148 | 7.35k | void ThreadPlanStepOverBreakpoint::ReenableBreakpointSite() { |
149 | 7.35k | if (!m_reenabled_breakpoint_site) { |
150 | 3.60k | m_reenabled_breakpoint_site = true; |
151 | 3.60k | BreakpointSiteSP bp_site_sp( |
152 | 3.60k | m_process.GetBreakpointSiteList().FindByAddress(m_breakpoint_addr)); |
153 | 3.60k | if (bp_site_sp) { |
154 | 3.60k | m_process.EnableBreakpointSite(bp_site_sp.get()); |
155 | 3.60k | } |
156 | 3.60k | } |
157 | 7.35k | } |
158 | 16 | void ThreadPlanStepOverBreakpoint::ThreadDestroyed() { |
159 | 16 | ReenableBreakpointSite(); |
160 | 16 | } |
161 | | |
162 | 3.46k | void ThreadPlanStepOverBreakpoint::SetAutoContinue(bool do_it) { |
163 | 3.46k | m_auto_continue = do_it; |
164 | 3.46k | } |
165 | | |
166 | 7.16k | bool ThreadPlanStepOverBreakpoint::ShouldAutoContinue(Event *event_ptr) { |
167 | 7.16k | return m_auto_continue; |
168 | 7.16k | } |
169 | | |
170 | 22 | bool ThreadPlanStepOverBreakpoint::IsPlanStale() { |
171 | 22 | return GetThread().GetRegisterContext()->GetPC() != m_breakpoint_addr; |
172 | 22 | } |