Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanStepOut.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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 14 | #include "lldb/Target/ThreadPlanStepOut.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Breakpoint/Breakpoint.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Value.h" |
| 18 | #include "lldb/Core/ValueObjectConstResult.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/Block.h" |
| 20 | #include "lldb/Symbol/Function.h" |
| 21 | #include "lldb/Symbol/Type.h" |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 22 | #include "lldb/Target/ABI.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
| 24 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 25 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Target.h" |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 27 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 28 | #include "lldb/Target/ThreadPlanStepThrough.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 33 | uint32_t ThreadPlanStepOut::s_default_flag_values = 0; |
| 34 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | //---------------------------------------------------------------------- |
| 36 | // ThreadPlanStepOut: Step out of the current frame |
| 37 | //---------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | ThreadPlanStepOut::ThreadPlanStepOut |
| 39 | ( |
| 40 | Thread &thread, |
| 41 | SymbolContext *context, |
| 42 | bool first_insn, |
| 43 | bool stop_others, |
| 44 | Vote stop_vote, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 45 | Vote run_vote, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 46 | uint32_t frame_idx, |
| 47 | LazyBool step_out_avoids_code_without_debug_info |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | ) : |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 49 | ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote), |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 50 | ThreadPlanShouldStopHere (this), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | m_step_from_insn (LLDB_INVALID_ADDRESS), |
Benjamin Kramer | 1ee0d4f | 2010-07-16 12:32:33 +0000 | [diff] [blame] | 52 | m_return_bp_id (LLDB_INVALID_BREAK_ID), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | m_return_addr (LLDB_INVALID_ADDRESS), |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 54 | m_stop_others (stop_others), |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 55 | m_immediate_step_from_function(nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 57 | SetFlagsToDefault(); |
| 58 | SetupAvoidNoDebug(step_out_avoids_code_without_debug_info); |
| 59 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0); |
| 61 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 62 | StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1)); |
| 63 | StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (frame_idx)); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 64 | |
Sean Callanan | 632d2f7 | 2012-03-13 16:34:56 +0000 | [diff] [blame] | 65 | if (!return_frame_sp || !immediate_return_from_sp) |
| 66 | return; // we can't do anything here. ValidatePlan() will return false. |
| 67 | |
Jim Ingham | b5c0d1c | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 68 | m_step_out_to_id = return_frame_sp->GetStackID(); |
| 69 | m_immediate_step_from_id = immediate_return_from_sp->GetStackID(); |
| 70 | |
| 71 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 72 | |
| 73 | // If the frame directly below the one we are returning to is inlined, we have to be |
| 74 | // a little more careful. It is non-trivial to determine the real "return code address" for |
| 75 | // an inlined frame, so we have to work our way to that frame and then step out. |
| 76 | if (immediate_return_from_sp && immediate_return_from_sp->IsInlined()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | { |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 78 | if (frame_idx > 0) |
| 79 | { |
| 80 | // First queue a plan that gets us to this inlined frame, and when we get there we'll queue a second |
| 81 | // plan that walks us out of this frame. |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 82 | m_step_out_to_inline_plan_sp.reset(new ThreadPlanStepOut(m_thread, |
| 83 | nullptr, |
| 84 | false, |
| 85 | stop_others, |
| 86 | eVoteNoOpinion, |
| 87 | eVoteNoOpinion, |
| 88 | frame_idx - 1, |
| 89 | eLazyBoolNo)); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 90 | static_cast<ThreadPlanStepOut *>(m_step_out_to_inline_plan_sp.get())->SetShouldStopHereCallbacks(nullptr, nullptr); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 91 | m_step_out_to_inline_plan_sp->SetPrivate(true); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 92 | } |
| 93 | else |
| 94 | { |
| 95 | // If we're already at the inlined frame we're stepping through, then just do that now. |
| 96 | QueueInlinedStepPlan(false); |
| 97 | } |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 98 | } |
| 99 | else if (return_frame_sp) |
| 100 | { |
| 101 | // Find the return address and set a breakpoint there: |
| 102 | // FIXME - can we do this more securely if we know first_insn? |
| 103 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 104 | m_return_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()->GetTarget()); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 105 | |
| 106 | if (m_return_addr == LLDB_INVALID_ADDRESS) |
| 107 | return; |
| 108 | |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 109 | Breakpoint *return_bp = m_thread.CalculateTarget()->CreateBreakpoint (m_return_addr, true, false).get(); |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 110 | if (return_bp != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | { |
| 112 | return_bp->SetThreadID(m_thread.GetID()); |
| 113 | m_return_bp_id = return_bp->GetID(); |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 114 | return_bp->SetBreakpointKind ("step-out"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 116 | |
| 117 | if (immediate_return_from_sp) |
| 118 | { |
| 119 | const SymbolContext &sc = immediate_return_from_sp->GetSymbolContext(eSymbolContextFunction); |
| 120 | if (sc.function) |
| 121 | { |
| 122 | m_immediate_step_from_function = sc.function; |
| 123 | } |
| 124 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | } |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 129 | ThreadPlanStepOut::SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info) |
| 130 | { |
| 131 | bool avoid_nodebug = true; |
| 132 | switch (step_out_avoids_code_without_debug_info) |
| 133 | { |
| 134 | case eLazyBoolYes: |
| 135 | avoid_nodebug = true; |
| 136 | break; |
| 137 | case eLazyBoolNo: |
| 138 | avoid_nodebug = false; |
| 139 | break; |
| 140 | case eLazyBoolCalculate: |
| 141 | avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug(); |
| 142 | break; |
| 143 | } |
| 144 | if (avoid_nodebug) |
| 145 | GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); |
| 146 | else |
| 147 | GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug); |
| 148 | } |
| 149 | |
| 150 | void |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 151 | ThreadPlanStepOut::DidPush() |
| 152 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 153 | if (m_step_out_to_inline_plan_sp) |
| 154 | m_thread.QueueThreadPlan(m_step_out_to_inline_plan_sp, false); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 155 | else if (m_step_through_inline_plan_sp) |
| 156 | m_thread.QueueThreadPlan(m_step_through_inline_plan_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | ThreadPlanStepOut::~ThreadPlanStepOut () |
| 160 | { |
| 161 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 162 | m_thread.CalculateTarget()->RemoveBreakpointByID(m_return_bp_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void |
| 166 | ThreadPlanStepOut::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 167 | { |
| 168 | if (level == lldb::eDescriptionLevelBrief) |
| 169 | s->Printf ("step out"); |
| 170 | else |
| 171 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 172 | if (m_step_out_to_inline_plan_sp) |
Jim Ingham | b5c0d1c | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 173 | s->Printf ("Stepping out to inlined frame so we can walk through it."); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 174 | else if (m_step_through_inline_plan_sp) |
| 175 | s->Printf ("Stepping out by stepping through inlined function."); |
| 176 | else |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 177 | { |
| 178 | s->Printf ("Stepping out from "); |
| 179 | Address tmp_address; |
| 180 | if (tmp_address.SetLoadAddress (m_step_from_insn, &GetTarget())) |
| 181 | { |
| 182 | tmp_address.Dump(s, &GetThread(), Address::DumpStyleResolvedDescription, Address::DumpStyleLoadAddress); |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | s->Printf ("address 0x%" PRIx64 "", (uint64_t)m_step_from_insn); |
| 187 | } |
| 188 | |
| 189 | // FIXME: find some useful way to present the m_return_id, since there may be multiple copies of the |
| 190 | // same function on the stack. |
| 191 | |
Jason Molenda | afdf6cb | 2015-12-04 02:52:49 +0000 | [diff] [blame] | 192 | s->Printf (" returning to frame at "); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 193 | if (tmp_address.SetLoadAddress (m_return_addr, &GetTarget())) |
| 194 | { |
| 195 | tmp_address.Dump(s, &GetThread(), Address::DumpStyleResolvedDescription, Address::DumpStyleLoadAddress); |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | s->Printf ("address 0x%" PRIx64 "", (uint64_t)m_return_addr); |
| 200 | } |
| 201 | |
| 202 | if (level == eDescriptionLevelVerbose) |
| 203 | s->Printf(" using breakpoint site %d", m_return_bp_id); |
| 204 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | bool |
| 209 | ThreadPlanStepOut::ValidatePlan (Stream *error) |
| 210 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 211 | if (m_step_out_to_inline_plan_sp) |
| 212 | return m_step_out_to_inline_plan_sp->ValidatePlan (error); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 213 | else if (m_step_through_inline_plan_sp) |
| 214 | return m_step_through_inline_plan_sp->ValidatePlan (error); |
| 215 | else if (m_return_bp_id == LLDB_INVALID_BREAK_ID) |
| 216 | { |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 217 | if (error) |
| 218 | error->PutCString("Could not create return address breakpoint."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | return false; |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 220 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | else |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 226 | ThreadPlanStepOut::DoPlanExplainsStop (Event *event_ptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 228 | // If the step out plan is done, then we just need to step through the inlined frame. |
| 229 | if (m_step_out_to_inline_plan_sp) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 230 | { |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 231 | return m_step_out_to_inline_plan_sp->MischiefManaged(); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 232 | } |
| 233 | else if (m_step_through_inline_plan_sp) |
| 234 | { |
| 235 | if (m_step_through_inline_plan_sp->MischiefManaged()) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 236 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 237 | CalculateReturnValue(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 238 | SetPlanComplete(); |
| 239 | return true; |
| 240 | } |
| 241 | else |
| 242 | return false; |
| 243 | } |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 244 | else if (m_step_out_further_plan_sp) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 245 | { |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 246 | return m_step_out_further_plan_sp->MischiefManaged(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | // We don't explain signals or breakpoints (breakpoints that handle stepping in or |
| 250 | // out will be handled by a child plan. |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 251 | |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 252 | StopInfoSP stop_info_sp = GetPrivateStopInfo (); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 253 | if (stop_info_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | { |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 255 | StopReason reason = stop_info_sp->GetStopReason(); |
Jim Ingham | 9b03fa0 | 2015-07-23 19:55:02 +0000 | [diff] [blame] | 256 | if (reason == eStopReasonBreakpoint) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 257 | { |
| 258 | // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 259 | BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue())); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 260 | if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | { |
Jim Ingham | b5c0d1c | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 262 | bool done; |
| 263 | |
| 264 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
| 265 | |
| 266 | if (m_step_out_to_id == frame_zero_id) |
| 267 | done = true; |
| 268 | else if (m_step_out_to_id < frame_zero_id) |
| 269 | { |
| 270 | // Either we stepped past the breakpoint, or the stack ID calculation |
| 271 | // was incorrect and we should probably stop. |
| 272 | done = true; |
| 273 | } |
| 274 | else |
| 275 | { |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 276 | done = (m_immediate_step_from_id < frame_zero_id); |
Jim Ingham | b5c0d1c | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | if (done) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 280 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 281 | if (InvokeShouldStopHereCallback (eFrameCompareOlder)) |
| 282 | { |
| 283 | CalculateReturnValue(); |
| 284 | SetPlanComplete(); |
| 285 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 286 | } |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 287 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 288 | // If there was only one owner, then we're done. But if we also hit some |
| 289 | // user breakpoint on our way out, we should mark ourselves as done, but |
| 290 | // also not claim to explain the stop, since it is more important to report |
| 291 | // the user breakpoint than the step out completion. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 293 | if (site_sp->GetNumberOfOwners() == 1) |
| 294 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 296 | return false; |
| 297 | } |
Jim Ingham | 9b03fa0 | 2015-07-23 19:55:02 +0000 | [diff] [blame] | 298 | else if (IsUsuallyUnexplainedStopReason(reason)) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 299 | return false; |
Jim Ingham | 9b03fa0 | 2015-07-23 19:55:02 +0000 | [diff] [blame] | 300 | else |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 301 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | } |
| 303 | return true; |
| 304 | } |
| 305 | |
| 306 | bool |
| 307 | ThreadPlanStepOut::ShouldStop (Event *event_ptr) |
| 308 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 309 | if (IsPlanComplete()) |
| 310 | return true; |
| 311 | |
| 312 | bool done = false; |
| 313 | if (m_step_out_to_inline_plan_sp) |
| 314 | { |
| 315 | if (m_step_out_to_inline_plan_sp->MischiefManaged()) |
| 316 | { |
| 317 | // Now step through the inlined stack we are in: |
| 318 | if (QueueInlinedStepPlan(true)) |
| 319 | { |
| 320 | // If we can't queue a plan to do this, then just call ourselves done. |
| 321 | m_step_out_to_inline_plan_sp.reset(); |
| 322 | SetPlanComplete (false); |
| 323 | return true; |
| 324 | } |
| 325 | else |
| 326 | done = true; |
| 327 | } |
| 328 | else |
| 329 | return m_step_out_to_inline_plan_sp->ShouldStop(event_ptr); |
| 330 | } |
| 331 | else if (m_step_through_inline_plan_sp) |
| 332 | { |
| 333 | if (m_step_through_inline_plan_sp->MischiefManaged()) |
| 334 | done = true; |
| 335 | else |
| 336 | return m_step_through_inline_plan_sp->ShouldStop(event_ptr); |
| 337 | } |
| 338 | else if (m_step_out_further_plan_sp) |
| 339 | { |
| 340 | if (m_step_out_further_plan_sp->MischiefManaged()) |
| 341 | m_step_out_further_plan_sp.reset(); |
| 342 | else |
| 343 | return m_step_out_further_plan_sp->ShouldStop(event_ptr); |
| 344 | } |
| 345 | |
| 346 | if (!done) |
| 347 | { |
Jim Ingham | b5c0d1c | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 348 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 349 | done = !(frame_zero_id < m_step_out_to_id); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | // The normal step out computations think we are done, so all we need to do is consult the ShouldStopHere, |
| 353 | // and we are done. |
| 354 | |
| 355 | if (done) |
| 356 | { |
| 357 | if (InvokeShouldStopHereCallback(eFrameCompareOlder)) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 358 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 359 | CalculateReturnValue(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 360 | SetPlanComplete(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 361 | } |
| 362 | else |
| 363 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 364 | m_step_out_further_plan_sp = QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder); |
| 365 | done = false; |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 366 | } |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | return done; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | bool |
| 373 | ThreadPlanStepOut::StopOthers () |
| 374 | { |
| 375 | return m_stop_others; |
| 376 | } |
| 377 | |
| 378 | StateType |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 379 | ThreadPlanStepOut::GetPlanRunState () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | { |
| 381 | return eStateRunning; |
| 382 | } |
| 383 | |
| 384 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 385 | ThreadPlanStepOut::DoWillResume (StateType resume_state, bool current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 387 | if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 388 | return true; |
| 389 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 390 | if (m_return_bp_id == LLDB_INVALID_BREAK_ID) |
| 391 | return false; |
| 392 | |
| 393 | if (current_plan) |
| 394 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 395 | Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get(); |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 396 | if (return_bp != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | return_bp->SetEnabled (true); |
| 398 | } |
| 399 | return true; |
| 400 | } |
| 401 | |
| 402 | bool |
| 403 | ThreadPlanStepOut::WillStop () |
| 404 | { |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 405 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
| 406 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 407 | Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get(); |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 408 | if (return_bp != nullptr) |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 409 | return_bp->SetEnabled (false); |
| 410 | } |
| 411 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | return true; |
| 413 | } |
| 414 | |
| 415 | bool |
| 416 | ThreadPlanStepOut::MischiefManaged () |
| 417 | { |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 418 | if (IsPlanComplete()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | { |
| 420 | // Did I reach my breakpoint? If so I'm done. |
| 421 | // |
| 422 | // I also check the stack depth, since if we've blown past the breakpoint for some |
| 423 | // reason and we're now stopping for some other reason altogether, then we're done |
| 424 | // with this step out operation. |
| 425 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 426 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 427 | if (log) |
| 428 | log->Printf("Completed step out plan."); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 429 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
| 430 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 431 | m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 432 | m_return_bp_id = LLDB_INVALID_BREAK_ID; |
| 433 | } |
| 434 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | ThreadPlan::MischiefManaged (); |
| 436 | return true; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | } |
| 443 | |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 444 | bool |
| 445 | ThreadPlanStepOut::QueueInlinedStepPlan (bool queue_now) |
| 446 | { |
| 447 | // Now figure out the range of this inlined block, and set up a "step through range" |
| 448 | // plan for that. If we've been provided with a context, then use the block in that |
| 449 | // context. |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 450 | StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0)); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 451 | if (!immediate_return_from_sp) |
| 452 | return false; |
| 453 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 454 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 455 | if (log) |
| 456 | { |
| 457 | StreamString s; |
| 458 | immediate_return_from_sp->Dump(&s, true, false); |
| 459 | log->Printf("Queuing inlined frame to step past: %s.", s.GetData()); |
| 460 | } |
| 461 | |
| 462 | Block *from_block = immediate_return_from_sp->GetFrameBlock(); |
| 463 | if (from_block) |
| 464 | { |
| 465 | Block *inlined_block = from_block->GetContainingInlinedBlock(); |
| 466 | if (inlined_block) |
| 467 | { |
| 468 | size_t num_ranges = inlined_block->GetNumRanges(); |
| 469 | AddressRange inline_range; |
| 470 | if (inlined_block->GetRangeAtIndex(0, inline_range)) |
| 471 | { |
| 472 | SymbolContext inlined_sc; |
| 473 | inlined_block->CalculateSymbolContext(&inlined_sc); |
Jim Ingham | 5f1a4e1 | 2012-07-26 18:23:21 +0000 | [diff] [blame] | 474 | inlined_sc.target_sp = GetTarget().shared_from_this(); |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 475 | RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads; |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 476 | const LazyBool avoid_no_debug = eLazyBoolNo; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 477 | |
| 478 | m_step_through_inline_plan_sp.reset (new ThreadPlanStepOverRange(m_thread, |
| 479 | inline_range, |
| 480 | inlined_sc, |
| 481 | run_mode, |
| 482 | avoid_no_debug)); |
| 483 | ThreadPlanStepOverRange *step_through_inline_plan_ptr |
| 484 | = static_cast<ThreadPlanStepOverRange *>(m_step_through_inline_plan_sp.get()); |
| 485 | m_step_through_inline_plan_sp->SetPrivate(true); |
| 486 | |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 487 | step_through_inline_plan_ptr->SetOkayToDiscard(true); |
| 488 | StreamString errors; |
| 489 | if (!step_through_inline_plan_ptr->ValidatePlan(&errors)) |
| 490 | { |
| 491 | //FIXME: Log this failure. |
| 492 | delete step_through_inline_plan_ptr; |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | for (size_t i = 1; i < num_ranges; i++) |
| 497 | { |
| 498 | if (inlined_block->GetRangeAtIndex (i, inline_range)) |
| 499 | step_through_inline_plan_ptr->AddRange (inline_range); |
| 500 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 501 | |
Jim Ingham | a5ce6c8 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 502 | if (queue_now) |
| 503 | m_thread.QueueThreadPlan (m_step_through_inline_plan_sp, false); |
| 504 | return true; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | return false; |
| 510 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 511 | |
| 512 | void |
| 513 | ThreadPlanStepOut::CalculateReturnValue () |
| 514 | { |
| 515 | if (m_return_valobj_sp) |
| 516 | return; |
| 517 | |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 518 | if (m_immediate_step_from_function != nullptr) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 519 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 520 | CompilerType return_compiler_type = m_immediate_step_from_function->GetCompilerType().GetFunctionReturnType(); |
| 521 | if (return_compiler_type) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 522 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 523 | lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI(); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 524 | if (abi_sp) |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 525 | m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, return_compiler_type); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 529 | |
| 530 | bool |
| 531 | ThreadPlanStepOut::IsPlanStale() |
| 532 | { |
| 533 | // If we are still lower on the stack than the frame we are returning to, then |
| 534 | // there's something for us to do. Otherwise, we're stale. |
| 535 | |
| 536 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame^] | 537 | return !(frame_zero_id < m_step_out_to_id); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 538 | } |