blob: 0ded99b3091d5eb3c1446299625a3ff6305ef9dd [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
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"
17#include "lldb/lldb-private-log.h"
18#include "lldb/Core/Log.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000019#include "lldb/Core/Value.h"
20#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000021#include "lldb/Symbol/Block.h"
22#include "lldb/Symbol/Function.h"
23#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Target/Process.h"
25#include "lldb/Target/RegisterContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000026#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Target/Target.h"
Jim Inghama5ce6c82011-10-15 00:57:28 +000028#include "lldb/Target/ThreadPlanStepOverRange.h"
Jim Ingham4b4b2472014-03-13 02:47:14 +000029#include "lldb/Target/ThreadPlanStepThrough.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
31using namespace lldb;
32using namespace lldb_private;
33
Jim Ingham4b4b2472014-03-13 02:47:14 +000034uint32_t ThreadPlanStepOut::s_default_flag_values = 0;
35
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036//----------------------------------------------------------------------
37// ThreadPlanStepOut: Step out of the current frame
38//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039ThreadPlanStepOut::ThreadPlanStepOut
40(
41 Thread &thread,
42 SymbolContext *context,
43 bool first_insn,
44 bool stop_others,
45 Vote stop_vote,
Greg Clayton481cef22011-01-21 06:11:58 +000046 Vote run_vote,
Jim Ingham4b4b2472014-03-13 02:47:14 +000047 uint32_t frame_idx,
48 LazyBool step_out_avoids_code_without_debug_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049) :
Jim Inghamb01e7422010-06-19 04:45:32 +000050 ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote),
Jim Ingham4b4b2472014-03-13 02:47:14 +000051 ThreadPlanShouldStopHere (this),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052 m_step_from_insn (LLDB_INVALID_ADDRESS),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33 +000053 m_return_bp_id (LLDB_INVALID_BREAK_ID),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054 m_return_addr (LLDB_INVALID_ADDRESS),
Jim Inghama5ce6c82011-10-15 00:57:28 +000055 m_stop_others (stop_others),
Jim Ingham73ca05a2011-12-17 01:35:57 +000056 m_immediate_step_from_function(NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057{
Jim Ingham4b4b2472014-03-13 02:47:14 +000058 SetFlagsToDefault();
59 SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
60
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061 m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0);
62
Jason Molendab57e4a12013-11-04 09:33:30 +000063 StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1));
64 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (frame_idx));
Jim Inghama5ce6c82011-10-15 00:57:28 +000065
Sean Callanan632d2f72012-03-13 16:34:56 +000066 if (!return_frame_sp || !immediate_return_from_sp)
67 return; // we can't do anything here. ValidatePlan() will return false.
68
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000069 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 Inghama5ce6c82011-10-15 00:57:28 +000073
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 Lattner30fdc8d2010-06-08 16:52:24 +000078 {
Jim Inghama5ce6c82011-10-15 00:57:28 +000079 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 Ingham4b4b2472014-03-13 02:47:14 +000083 m_step_out_to_inline_plan_sp.reset (new ThreadPlanStepOut(m_thread,
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000084 NULL,
85 false,
86 stop_others,
87 eVoteNoOpinion,
88 eVoteNoOpinion,
Jim Ingham4b4b2472014-03-13 02:47:14 +000089 frame_idx - 1,
90 eLazyBoolNo));
91 static_cast<ThreadPlanStepOut *>(m_step_out_to_inline_plan_sp.get())->SetShouldStopHereCallbacks(nullptr, nullptr);
Jim Ingham2bdbfd52014-09-29 23:17:18 +000092 m_step_out_to_inline_plan_sp->SetPrivate(true);
Jim Inghama5ce6c82011-10-15 00:57:28 +000093 }
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 Clayton1ac04c32012-02-21 00:09:25 +0000106 m_return_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()->GetTarget());
Sean Callanan708709c2012-07-31 22:19:25 +0000107
108 if (m_return_addr == LLDB_INVALID_ADDRESS)
109 return;
110
Greg Claytoneb023e72013-10-11 19:48:25 +0000111 Breakpoint *return_bp = m_thread.CalculateTarget()->CreateBreakpoint (m_return_addr, true, false).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112 if (return_bp != NULL)
113 {
114 return_bp->SetThreadID(m_thread.GetID());
115 m_return_bp_id = return_bp->GetID();
Jim Ingham29950772013-01-26 02:19:28 +0000116 return_bp->SetBreakpointKind ("step-out");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000118
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 Lattner30fdc8d2010-06-08 16:52:24 +0000127 }
128
Jim Inghama5ce6c82011-10-15 00:57:28 +0000129}
130
131void
Jim Ingham4b4b2472014-03-13 02:47:14 +0000132ThreadPlanStepOut::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
153void
Jim Inghama5ce6c82011-10-15 00:57:28 +0000154ThreadPlanStepOut::DidPush()
155{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000156 if (m_step_out_to_inline_plan_sp)
157 m_thread.QueueThreadPlan(m_step_out_to_inline_plan_sp, false);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000158 else if (m_step_through_inline_plan_sp)
159 m_thread.QueueThreadPlan(m_step_through_inline_plan_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160}
161
162ThreadPlanStepOut::~ThreadPlanStepOut ()
163{
164 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000165 m_thread.CalculateTarget()->RemoveBreakpointByID(m_return_bp_id);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166}
167
168void
169ThreadPlanStepOut::GetDescription (Stream *s, lldb::DescriptionLevel level)
170{
171 if (level == lldb::eDescriptionLevelBrief)
172 s->Printf ("step out");
173 else
174 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000175 if (m_step_out_to_inline_plan_sp)
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000176 s->Printf ("Stepping out to inlined frame so we can walk through it.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000177 else if (m_step_through_inline_plan_sp)
178 s->Printf ("Stepping out by stepping through inlined function.");
179 else
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000180 {
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 Lattner30fdc8d2010-06-08 16:52:24 +0000208 }
209}
210
211bool
212ThreadPlanStepOut::ValidatePlan (Stream *error)
213{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000214 if (m_step_out_to_inline_plan_sp)
215 return m_step_out_to_inline_plan_sp->ValidatePlan (error);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000216 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 Callanan708709c2012-07-31 22:19:25 +0000220 if (error)
221 error->PutCString("Could not create return address breakpoint.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000222 return false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 else
225 return true;
226}
227
228bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000229ThreadPlanStepOut::DoPlanExplainsStop (Event *event_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000231 // 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 Inghama5ce6c82011-10-15 00:57:28 +0000233 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000234 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 Inghama5ce6c82011-10-15 00:57:28 +0000242 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000243 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000244 SetPlanComplete();
245 return true;
246 }
247 else
248 return false;
249 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000250 else if (m_step_out_further_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000251 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000252 if (m_step_out_further_plan_sp->MischiefManaged())
Jim Inghama5ce6c82011-10-15 00:57:28 +0000253 return true;
254 else
255 return false;
256 }
257
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 // We don't explain signals or breakpoints (breakpoints that handle stepping in or
259 // out will be handled by a child plan.
Jim Inghama5ce6c82011-10-15 00:57:28 +0000260
Jim Ingham60c41182013-06-04 01:40:51 +0000261 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Inghamb15bfc72010-10-20 00:39:53 +0000262 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000264 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 switch (reason)
266 {
Greg Claytonf4b47e12010-08-04 01:40:35 +0000267 case eStopReasonBreakpoint:
268 {
269 // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened...
Greg Clayton1ac04c32012-02-21 00:09:25 +0000270 BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue()));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000271 if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000273 bool done;
274
275 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
276
277 if (m_step_out_to_id == frame_zero_id)
278 done = true;
279 else if (m_step_out_to_id < frame_zero_id)
280 {
281 // Either we stepped past the breakpoint, or the stack ID calculation
282 // was incorrect and we should probably stop.
283 done = true;
284 }
285 else
286 {
287 if (m_immediate_step_from_id < frame_zero_id)
288 done = true;
289 else
290 done = false;
291 }
292
293 if (done)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000294 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000295 if (InvokeShouldStopHereCallback (eFrameCompareOlder))
296 {
297 CalculateReturnValue();
298 SetPlanComplete();
299 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000300 }
Greg Clayton481cef22011-01-21 06:11:58 +0000301
Greg Claytonf4b47e12010-08-04 01:40:35 +0000302 // If there was only one owner, then we're done. But if we also hit some
303 // user breakpoint on our way out, we should mark ourselves as done, but
304 // also not claim to explain the stop, since it is more important to report
305 // the user breakpoint than the step out completion.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306
Greg Claytonf4b47e12010-08-04 01:40:35 +0000307 if (site_sp->GetNumberOfOwners() == 1)
308 return true;
309
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000311 return false;
312 }
313 case eStopReasonWatchpoint:
314 case eStopReasonSignal:
315 case eStopReasonException:
Greg Clayton90ba8112012-12-05 00:16:59 +0000316 case eStopReasonExec:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000317 case eStopReasonThreadExiting:
Greg Claytonf4b47e12010-08-04 01:40:35 +0000318 return false;
319
320 default:
321 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322 }
323 }
324 return true;
325}
326
327bool
328ThreadPlanStepOut::ShouldStop (Event *event_ptr)
329{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000330 if (IsPlanComplete())
331 return true;
332
333 bool done = false;
334 if (m_step_out_to_inline_plan_sp)
335 {
336 if (m_step_out_to_inline_plan_sp->MischiefManaged())
337 {
338 // Now step through the inlined stack we are in:
339 if (QueueInlinedStepPlan(true))
340 {
341 // If we can't queue a plan to do this, then just call ourselves done.
342 m_step_out_to_inline_plan_sp.reset();
343 SetPlanComplete (false);
344 return true;
345 }
346 else
347 done = true;
348 }
349 else
350 return m_step_out_to_inline_plan_sp->ShouldStop(event_ptr);
351 }
352 else if (m_step_through_inline_plan_sp)
353 {
354 if (m_step_through_inline_plan_sp->MischiefManaged())
355 done = true;
356 else
357 return m_step_through_inline_plan_sp->ShouldStop(event_ptr);
358 }
359 else if (m_step_out_further_plan_sp)
360 {
361 if (m_step_out_further_plan_sp->MischiefManaged())
362 m_step_out_further_plan_sp.reset();
363 else
364 return m_step_out_further_plan_sp->ShouldStop(event_ptr);
365 }
366
367 if (!done)
368 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000369 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
370 if (frame_zero_id < m_step_out_to_id)
371 done = false;
372 else
373 done = true;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000374 }
375
376 // The normal step out computations think we are done, so all we need to do is consult the ShouldStopHere,
377 // and we are done.
378
379 if (done)
380 {
381 if (InvokeShouldStopHereCallback(eFrameCompareOlder))
Jim Inghama5ce6c82011-10-15 00:57:28 +0000382 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000383 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000384 SetPlanComplete();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000385 }
386 else
387 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000388 m_step_out_further_plan_sp = QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder);
389 done = false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000390 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000391 }
392
393 return done;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394}
395
396bool
397ThreadPlanStepOut::StopOthers ()
398{
399 return m_stop_others;
400}
401
402StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000403ThreadPlanStepOut::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404{
405 return eStateRunning;
406}
407
408bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000409ThreadPlanStepOut::DoWillResume (StateType resume_state, bool current_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000411 if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000412 return true;
413
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
415 return false;
416
417 if (current_plan)
418 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000419 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 if (return_bp != NULL)
421 return_bp->SetEnabled (true);
422 }
423 return true;
424}
425
426bool
427ThreadPlanStepOut::WillStop ()
428{
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 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000432 if (return_bp != NULL)
433 return_bp->SetEnabled (false);
434 }
435
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 return true;
437}
438
439bool
440ThreadPlanStepOut::MischiefManaged ()
441{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000442 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 {
444 // Did I reach my breakpoint? If so I'm done.
445 //
446 // I also check the stack depth, since if we've blown past the breakpoint for some
447 // reason and we're now stopping for some other reason altogether, then we're done
448 // with this step out operation.
449
Greg Clayton5160ce52013-03-27 23:08:40 +0000450 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 if (log)
452 log->Printf("Completed step out plan.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000453 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
454 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000455 m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000456 m_return_bp_id = LLDB_INVALID_BREAK_ID;
457 }
458
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 ThreadPlan::MischiefManaged ();
460 return true;
461 }
462 else
463 {
464 return false;
465 }
466}
467
Jim Inghama5ce6c82011-10-15 00:57:28 +0000468bool
469ThreadPlanStepOut::QueueInlinedStepPlan (bool queue_now)
470{
471 // Now figure out the range of this inlined block, and set up a "step through range"
472 // plan for that. If we've been provided with a context, then use the block in that
473 // context.
Jason Molendab57e4a12013-11-04 09:33:30 +0000474 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000475 if (!immediate_return_from_sp)
476 return false;
477
Greg Clayton5160ce52013-03-27 23:08:40 +0000478 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000479 if (log)
480 {
481 StreamString s;
482 immediate_return_from_sp->Dump(&s, true, false);
483 log->Printf("Queuing inlined frame to step past: %s.", s.GetData());
484 }
485
486 Block *from_block = immediate_return_from_sp->GetFrameBlock();
487 if (from_block)
488 {
489 Block *inlined_block = from_block->GetContainingInlinedBlock();
490 if (inlined_block)
491 {
492 size_t num_ranges = inlined_block->GetNumRanges();
493 AddressRange inline_range;
494 if (inlined_block->GetRangeAtIndex(0, inline_range))
495 {
496 SymbolContext inlined_sc;
497 inlined_block->CalculateSymbolContext(&inlined_sc);
Jim Ingham5f1a4e12012-07-26 18:23:21 +0000498 inlined_sc.target_sp = GetTarget().shared_from_this();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000499 RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000500 const LazyBool avoid_no_debug = eLazyBoolNo;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000501
502 m_step_through_inline_plan_sp.reset (new ThreadPlanStepOverRange(m_thread,
503 inline_range,
504 inlined_sc,
505 run_mode,
506 avoid_no_debug));
507 ThreadPlanStepOverRange *step_through_inline_plan_ptr
508 = static_cast<ThreadPlanStepOverRange *>(m_step_through_inline_plan_sp.get());
509 m_step_through_inline_plan_sp->SetPrivate(true);
510
Jim Inghama5ce6c82011-10-15 00:57:28 +0000511 step_through_inline_plan_ptr->SetOkayToDiscard(true);
512 StreamString errors;
513 if (!step_through_inline_plan_ptr->ValidatePlan(&errors))
514 {
515 //FIXME: Log this failure.
516 delete step_through_inline_plan_ptr;
517 return false;
518 }
519
520 for (size_t i = 1; i < num_ranges; i++)
521 {
522 if (inlined_block->GetRangeAtIndex (i, inline_range))
523 step_through_inline_plan_ptr->AddRange (inline_range);
524 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000525
Jim Inghama5ce6c82011-10-15 00:57:28 +0000526 if (queue_now)
527 m_thread.QueueThreadPlan (m_step_through_inline_plan_sp, false);
528 return true;
529 }
530 }
531 }
532
533 return false;
534}
Jim Ingham73ca05a2011-12-17 01:35:57 +0000535
536void
537ThreadPlanStepOut::CalculateReturnValue ()
538{
539 if (m_return_valobj_sp)
540 return;
541
542 if (m_immediate_step_from_function != NULL)
543 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000544 ClangASTType return_clang_type = m_immediate_step_from_function->GetClangType().GetFunctionReturnType();
545 if (return_clang_type)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000546 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000547 lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000548 if (abi_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000549 m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, return_clang_type);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000550 }
551 }
552}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000553
554bool
555ThreadPlanStepOut::IsPlanStale()
556{
557 // If we are still lower on the stack than the frame we are returning to, then
558 // there's something for us to do. Otherwise, we're stale.
559
560 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
561 if (frame_zero_id < m_step_out_to_id)
562 return false;
563 else
564 return true;
565}