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