blob: 92403cb92ed34cbe079402574ab41cb0717c747c [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000014#include "lldb/Target/ThreadPlanStepOut.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Breakpoint/Breakpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Log.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000017#include "lldb/Core/Value.h"
18#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Symbol/Block.h"
20#include "lldb/Symbol/Function.h"
21#include "lldb/Symbol/Type.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000022#include "lldb/Target/ABI.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000025#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Target.h"
Jim Inghama5ce6c82011-10-15 00:57:28 +000027#include "lldb/Target/ThreadPlanStepOverRange.h"
Jim Ingham4b4b2472014-03-13 02:47:14 +000028#include "lldb/Target/ThreadPlanStepThrough.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
30using namespace lldb;
31using namespace lldb_private;
32
Jim Ingham4b4b2472014-03-13 02:47:14 +000033uint32_t ThreadPlanStepOut::s_default_flag_values = 0;
34
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035//----------------------------------------------------------------------
36// ThreadPlanStepOut: Step out of the current frame
37//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038ThreadPlanStepOut::ThreadPlanStepOut
39(
40 Thread &thread,
41 SymbolContext *context,
42 bool first_insn,
43 bool stop_others,
44 Vote stop_vote,
Greg Clayton481cef22011-01-21 06:11:58 +000045 Vote run_vote,
Jim Ingham4b4b2472014-03-13 02:47:14 +000046 uint32_t frame_idx,
47 LazyBool step_out_avoids_code_without_debug_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048) :
Jim Inghamb01e7422010-06-19 04:45:32 +000049 ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote),
Jim Ingham4b4b2472014-03-13 02:47:14 +000050 ThreadPlanShouldStopHere (this),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 m_step_from_insn (LLDB_INVALID_ADDRESS),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33 +000052 m_return_bp_id (LLDB_INVALID_BREAK_ID),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 m_return_addr (LLDB_INVALID_ADDRESS),
Jim Inghama5ce6c82011-10-15 00:57:28 +000054 m_stop_others (stop_others),
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000055 m_immediate_step_from_function(nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056{
Jim Ingham4b4b2472014-03-13 02:47:14 +000057 SetFlagsToDefault();
58 SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
59
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0);
61
Jason Molendab57e4a12013-11-04 09:33:30 +000062 StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1));
63 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (frame_idx));
Jim Inghama5ce6c82011-10-15 00:57:28 +000064
Sean Callanan632d2f72012-03-13 16:34:56 +000065 if (!return_frame_sp || !immediate_return_from_sp)
66 return; // we can't do anything here. ValidatePlan() will return false.
67
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000068 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 Inghama5ce6c82011-10-15 00:57:28 +000072
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 Lattner30fdc8d2010-06-08 16:52:24 +000077 {
Jim Inghama5ce6c82011-10-15 00:57:28 +000078 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 Zelenkoe65b2cf2015-12-15 01:33:19 +000082 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 Ingham4b4b2472014-03-13 02:47:14 +000090 static_cast<ThreadPlanStepOut *>(m_step_out_to_inline_plan_sp.get())->SetShouldStopHereCallbacks(nullptr, nullptr);
Jim Ingham2bdbfd52014-09-29 23:17:18 +000091 m_step_out_to_inline_plan_sp->SetPrivate(true);
Jim Inghama5ce6c82011-10-15 00:57:28 +000092 }
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 Inghama5ce6c82011-10-15 00:57:28 +000098 }
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 Clayton1ac04c32012-02-21 00:09:25 +0000104 m_return_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()->GetTarget());
Sean Callanan708709c2012-07-31 22:19:25 +0000105
106 if (m_return_addr == LLDB_INVALID_ADDRESS)
107 return;
108
Greg Claytoneb023e72013-10-11 19:48:25 +0000109 Breakpoint *return_bp = m_thread.CalculateTarget()->CreateBreakpoint (m_return_addr, true, false).get();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000110 if (return_bp != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 {
112 return_bp->SetThreadID(m_thread.GetID());
113 m_return_bp_id = return_bp->GetID();
Jim Ingham29950772013-01-26 02:19:28 +0000114 return_bp->SetBreakpointKind ("step-out");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000116
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 Lattner30fdc8d2010-06-08 16:52:24 +0000125 }
Jim Inghama5ce6c82011-10-15 00:57:28 +0000126}
127
128void
Jim Ingham4b4b2472014-03-13 02:47:14 +0000129ThreadPlanStepOut::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
150void
Jim Inghama5ce6c82011-10-15 00:57:28 +0000151ThreadPlanStepOut::DidPush()
152{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000153 if (m_step_out_to_inline_plan_sp)
154 m_thread.QueueThreadPlan(m_step_out_to_inline_plan_sp, false);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000155 else if (m_step_through_inline_plan_sp)
156 m_thread.QueueThreadPlan(m_step_through_inline_plan_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157}
158
159ThreadPlanStepOut::~ThreadPlanStepOut ()
160{
161 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000162 m_thread.CalculateTarget()->RemoveBreakpointByID(m_return_bp_id);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163}
164
165void
166ThreadPlanStepOut::GetDescription (Stream *s, lldb::DescriptionLevel level)
167{
168 if (level == lldb::eDescriptionLevelBrief)
169 s->Printf ("step out");
170 else
171 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000172 if (m_step_out_to_inline_plan_sp)
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000173 s->Printf ("Stepping out to inlined frame so we can walk through it.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000174 else if (m_step_through_inline_plan_sp)
175 s->Printf ("Stepping out by stepping through inlined function.");
176 else
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000177 {
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 Molendaafdf6cb2015-12-04 02:52:49 +0000192 s->Printf (" returning to frame at ");
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000193 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 Lattner30fdc8d2010-06-08 16:52:24 +0000205 }
206}
207
208bool
209ThreadPlanStepOut::ValidatePlan (Stream *error)
210{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000211 if (m_step_out_to_inline_plan_sp)
212 return m_step_out_to_inline_plan_sp->ValidatePlan (error);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000213 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 Callanan708709c2012-07-31 22:19:25 +0000217 if (error)
218 error->PutCString("Could not create return address breakpoint.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000219 return false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000220 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221 else
222 return true;
223}
224
225bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000226ThreadPlanStepOut::DoPlanExplainsStop (Event *event_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000228 // 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 Inghama5ce6c82011-10-15 00:57:28 +0000230 {
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000231 return m_step_out_to_inline_plan_sp->MischiefManaged();
Jim Ingham4b4b2472014-03-13 02:47:14 +0000232 }
233 else if (m_step_through_inline_plan_sp)
234 {
235 if (m_step_through_inline_plan_sp->MischiefManaged())
Jim Inghama5ce6c82011-10-15 00:57:28 +0000236 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000237 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000238 SetPlanComplete();
239 return true;
240 }
241 else
242 return false;
243 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000244 else if (m_step_out_further_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000245 {
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000246 return m_step_out_further_plan_sp->MischiefManaged();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000247 }
248
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 // We don't explain signals or breakpoints (breakpoints that handle stepping in or
250 // out will be handled by a child plan.
Jim Inghama5ce6c82011-10-15 00:57:28 +0000251
Jim Ingham60c41182013-06-04 01:40:51 +0000252 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Inghamb15bfc72010-10-20 00:39:53 +0000253 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000255 StopReason reason = stop_info_sp->GetStopReason();
Jim Ingham9b03fa02015-07-23 19:55:02 +0000256 if (reason == eStopReasonBreakpoint)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000257 {
258 // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened...
Greg Clayton1ac04c32012-02-21 00:09:25 +0000259 BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue()));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000260 if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000262 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 Zelenkoe65b2cf2015-12-15 01:33:19 +0000276 done = (m_immediate_step_from_id < frame_zero_id);
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000277 }
278
279 if (done)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000280 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000281 if (InvokeShouldStopHereCallback (eFrameCompareOlder))
282 {
283 CalculateReturnValue();
284 SetPlanComplete();
285 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000286 }
Greg Clayton481cef22011-01-21 06:11:58 +0000287
Greg Claytonf4b47e12010-08-04 01:40:35 +0000288 // 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 Lattner30fdc8d2010-06-08 16:52:24 +0000292
Greg Claytonf4b47e12010-08-04 01:40:35 +0000293 if (site_sp->GetNumberOfOwners() == 1)
294 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000296 return false;
297 }
Jim Ingham9b03fa02015-07-23 19:55:02 +0000298 else if (IsUsuallyUnexplainedStopReason(reason))
Greg Claytonf4b47e12010-08-04 01:40:35 +0000299 return false;
Jim Ingham9b03fa02015-07-23 19:55:02 +0000300 else
Greg Claytonf4b47e12010-08-04 01:40:35 +0000301 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302 }
303 return true;
304}
305
306bool
307ThreadPlanStepOut::ShouldStop (Event *event_ptr)
308{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000309 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 Inghamb5c0d1c2012-03-01 00:50:50 +0000348 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000349 done = !(frame_zero_id < m_step_out_to_id);
Jim Ingham4b4b2472014-03-13 02:47:14 +0000350 }
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 Inghama5ce6c82011-10-15 00:57:28 +0000358 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000359 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000360 SetPlanComplete();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000361 }
362 else
363 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000364 m_step_out_further_plan_sp = QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder);
365 done = false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000366 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000367 }
368
369 return done;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370}
371
372bool
373ThreadPlanStepOut::StopOthers ()
374{
375 return m_stop_others;
376}
377
378StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000379ThreadPlanStepOut::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380{
381 return eStateRunning;
382}
383
384bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000385ThreadPlanStepOut::DoWillResume (StateType resume_state, bool current_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000387 if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000388 return true;
389
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
391 return false;
392
393 if (current_plan)
394 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000395 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000396 if (return_bp != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397 return_bp->SetEnabled (true);
398 }
399 return true;
400}
401
402bool
403ThreadPlanStepOut::WillStop ()
404{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000405 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
406 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000407 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000408 if (return_bp != nullptr)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000409 return_bp->SetEnabled (false);
410 }
411
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 return true;
413}
414
415bool
416ThreadPlanStepOut::MischiefManaged ()
417{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000418 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 {
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 Clayton5160ce52013-03-27 23:08:40 +0000426 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 if (log)
428 log->Printf("Completed step out plan.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000429 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
430 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000431 m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000432 m_return_bp_id = LLDB_INVALID_BREAK_ID;
433 }
434
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 ThreadPlan::MischiefManaged ();
436 return true;
437 }
438 else
439 {
440 return false;
441 }
442}
443
Jim Inghama5ce6c82011-10-15 00:57:28 +0000444bool
445ThreadPlanStepOut::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 Molendab57e4a12013-11-04 09:33:30 +0000450 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000451 if (!immediate_return_from_sp)
452 return false;
453
Greg Clayton5160ce52013-03-27 23:08:40 +0000454 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000455 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 Ingham5f1a4e12012-07-26 18:23:21 +0000474 inlined_sc.target_sp = GetTarget().shared_from_this();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000475 RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000476 const LazyBool avoid_no_debug = eLazyBoolNo;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000477
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 Inghama5ce6c82011-10-15 00:57:28 +0000487 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 Ingham2bdbfd52014-09-29 23:17:18 +0000501
Jim Inghama5ce6c82011-10-15 00:57:28 +0000502 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 Ingham73ca05a2011-12-17 01:35:57 +0000511
512void
513ThreadPlanStepOut::CalculateReturnValue ()
514{
515 if (m_return_valobj_sp)
516 return;
517
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +0000518 if (m_immediate_step_from_function != nullptr)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000519 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000520 CompilerType return_compiler_type = m_immediate_step_from_function->GetCompilerType().GetFunctionReturnType();
521 if (return_compiler_type)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000522 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000523 lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000524 if (abi_sp)
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000525 m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, return_compiler_type);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000526 }
527 }
528}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000529
530bool
531ThreadPlanStepOut::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 Zelenkoe65b2cf2015-12-15 01:33:19 +0000537 return !(frame_zero_id < m_step_out_to_id);
Jim Ingham64e7ead2012-05-03 21:19:36 +0000538}