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