blob: 17bd0f7323c8070cc03968835b0c18080c5a4585 [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"
Zachary Turner32abc6e2015-03-03 19:23:09 +000024#include "lldb/Target/ABI.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Target/Process.h"
26#include "lldb/Target/RegisterContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000027#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/Target.h"
Jim Inghama5ce6c82011-10-15 00:57:28 +000029#include "lldb/Target/ThreadPlanStepOverRange.h"
Jim Ingham4b4b2472014-03-13 02:47:14 +000030#include "lldb/Target/ThreadPlanStepThrough.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
32using namespace lldb;
33using namespace lldb_private;
34
Jim Ingham4b4b2472014-03-13 02:47:14 +000035uint32_t ThreadPlanStepOut::s_default_flag_values = 0;
36
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037//----------------------------------------------------------------------
38// ThreadPlanStepOut: Step out of the current frame
39//----------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040ThreadPlanStepOut::ThreadPlanStepOut
41(
42 Thread &thread,
43 SymbolContext *context,
44 bool first_insn,
45 bool stop_others,
46 Vote stop_vote,
Greg Clayton481cef22011-01-21 06:11:58 +000047 Vote run_vote,
Jim Ingham4b4b2472014-03-13 02:47:14 +000048 uint32_t frame_idx,
49 LazyBool step_out_avoids_code_without_debug_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050) :
Jim Inghamb01e7422010-06-19 04:45:32 +000051 ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote),
Jim Ingham4b4b2472014-03-13 02:47:14 +000052 ThreadPlanShouldStopHere (this),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 m_step_from_insn (LLDB_INVALID_ADDRESS),
Benjamin Kramer1ee0d4f2010-07-16 12:32:33 +000054 m_return_bp_id (LLDB_INVALID_BREAK_ID),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055 m_return_addr (LLDB_INVALID_ADDRESS),
Jim Inghama5ce6c82011-10-15 00:57:28 +000056 m_stop_others (stop_others),
Jim Ingham73ca05a2011-12-17 01:35:57 +000057 m_immediate_step_from_function(NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058{
Jim Ingham4b4b2472014-03-13 02:47:14 +000059 SetFlagsToDefault();
60 SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0);
63
Jason Molendab57e4a12013-11-04 09:33:30 +000064 StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1));
65 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (frame_idx));
Jim Inghama5ce6c82011-10-15 00:57:28 +000066
Sean Callanan632d2f72012-03-13 16:34:56 +000067 if (!return_frame_sp || !immediate_return_from_sp)
68 return; // we can't do anything here. ValidatePlan() will return false.
69
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000070 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 Inghama5ce6c82011-10-15 00:57:28 +000074
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 Lattner30fdc8d2010-06-08 16:52:24 +000079 {
Jim Inghama5ce6c82011-10-15 00:57:28 +000080 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.
Jim Ingham4b4b2472014-03-13 02:47:14 +000084 m_step_out_to_inline_plan_sp.reset (new ThreadPlanStepOut(m_thread,
Jim Inghamb5c0d1c2012-03-01 00:50:50 +000085 NULL,
86 false,
87 stop_others,
88 eVoteNoOpinion,
89 eVoteNoOpinion,
Jim Ingham4b4b2472014-03-13 02:47:14 +000090 frame_idx - 1,
91 eLazyBoolNo));
92 static_cast<ThreadPlanStepOut *>(m_step_out_to_inline_plan_sp.get())->SetShouldStopHereCallbacks(nullptr, nullptr);
Jim Ingham2bdbfd52014-09-29 23:17:18 +000093 m_step_out_to_inline_plan_sp->SetPrivate(true);
Jim Inghama5ce6c82011-10-15 00:57:28 +000094 }
95 else
96 {
97 // If we're already at the inlined frame we're stepping through, then just do that now.
98 QueueInlinedStepPlan(false);
99 }
100
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
Greg Clayton1ac04c32012-02-21 00:09:25 +0000107 m_return_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()->GetTarget());
Sean Callanan708709c2012-07-31 22:19:25 +0000108
109 if (m_return_addr == LLDB_INVALID_ADDRESS)
110 return;
111
Greg Claytoneb023e72013-10-11 19:48:25 +0000112 Breakpoint *return_bp = m_thread.CalculateTarget()->CreateBreakpoint (m_return_addr, true, false).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113 if (return_bp != NULL)
114 {
115 return_bp->SetThreadID(m_thread.GetID());
116 m_return_bp_id = return_bp->GetID();
Jim Ingham29950772013-01-26 02:19:28 +0000117 return_bp->SetBreakpointKind ("step-out");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000119
120 if (immediate_return_from_sp)
121 {
122 const SymbolContext &sc = immediate_return_from_sp->GetSymbolContext(eSymbolContextFunction);
123 if (sc.function)
124 {
125 m_immediate_step_from_function = sc.function;
126 }
127 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 }
129
Jim Inghama5ce6c82011-10-15 00:57:28 +0000130}
131
132void
Jim Ingham4b4b2472014-03-13 02:47:14 +0000133ThreadPlanStepOut::SetupAvoidNoDebug(LazyBool step_out_avoids_code_without_debug_info)
134{
135 bool avoid_nodebug = true;
136 switch (step_out_avoids_code_without_debug_info)
137 {
138 case eLazyBoolYes:
139 avoid_nodebug = true;
140 break;
141 case eLazyBoolNo:
142 avoid_nodebug = false;
143 break;
144 case eLazyBoolCalculate:
145 avoid_nodebug = m_thread.GetStepOutAvoidsNoDebug();
146 break;
147 }
148 if (avoid_nodebug)
149 GetFlags().Set (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
150 else
151 GetFlags().Clear (ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
152}
153
154void
Jim Inghama5ce6c82011-10-15 00:57:28 +0000155ThreadPlanStepOut::DidPush()
156{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000157 if (m_step_out_to_inline_plan_sp)
158 m_thread.QueueThreadPlan(m_step_out_to_inline_plan_sp, false);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000159 else if (m_step_through_inline_plan_sp)
160 m_thread.QueueThreadPlan(m_step_through_inline_plan_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161}
162
163ThreadPlanStepOut::~ThreadPlanStepOut ()
164{
165 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000166 m_thread.CalculateTarget()->RemoveBreakpointByID(m_return_bp_id);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169void
170ThreadPlanStepOut::GetDescription (Stream *s, lldb::DescriptionLevel level)
171{
172 if (level == lldb::eDescriptionLevelBrief)
173 s->Printf ("step out");
174 else
175 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000176 if (m_step_out_to_inline_plan_sp)
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000177 s->Printf ("Stepping out to inlined frame so we can walk through it.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000178 else if (m_step_through_inline_plan_sp)
179 s->Printf ("Stepping out by stepping through inlined function.");
180 else
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000181 {
182 s->Printf ("Stepping out from ");
183 Address tmp_address;
184 if (tmp_address.SetLoadAddress (m_step_from_insn, &GetTarget()))
185 {
186 tmp_address.Dump(s, &GetThread(), Address::DumpStyleResolvedDescription, Address::DumpStyleLoadAddress);
187 }
188 else
189 {
190 s->Printf ("address 0x%" PRIx64 "", (uint64_t)m_step_from_insn);
191 }
192
193 // FIXME: find some useful way to present the m_return_id, since there may be multiple copies of the
194 // same function on the stack.
195
196 s->Printf ("returning to frame at ");
197 if (tmp_address.SetLoadAddress (m_return_addr, &GetTarget()))
198 {
199 tmp_address.Dump(s, &GetThread(), Address::DumpStyleResolvedDescription, Address::DumpStyleLoadAddress);
200 }
201 else
202 {
203 s->Printf ("address 0x%" PRIx64 "", (uint64_t)m_return_addr);
204 }
205
206 if (level == eDescriptionLevelVerbose)
207 s->Printf(" using breakpoint site %d", m_return_bp_id);
208 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000209 }
210}
211
212bool
213ThreadPlanStepOut::ValidatePlan (Stream *error)
214{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000215 if (m_step_out_to_inline_plan_sp)
216 return m_step_out_to_inline_plan_sp->ValidatePlan (error);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000217 else if (m_step_through_inline_plan_sp)
218 return m_step_through_inline_plan_sp->ValidatePlan (error);
219 else if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
220 {
Sean Callanan708709c2012-07-31 22:19:25 +0000221 if (error)
222 error->PutCString("Could not create return address breakpoint.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223 return false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 else
226 return true;
227}
228
229bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000230ThreadPlanStepOut::DoPlanExplainsStop (Event *event_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000232 // If the step out plan is done, then we just need to step through the inlined frame.
233 if (m_step_out_to_inline_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000234 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000235 if (m_step_out_to_inline_plan_sp->MischiefManaged())
236 return true;
237 else
238 return false;
239 }
240 else if (m_step_through_inline_plan_sp)
241 {
242 if (m_step_through_inline_plan_sp->MischiefManaged())
Jim Inghama5ce6c82011-10-15 00:57:28 +0000243 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000244 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000245 SetPlanComplete();
246 return true;
247 }
248 else
249 return false;
250 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000251 else if (m_step_out_further_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000252 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000253 if (m_step_out_further_plan_sp->MischiefManaged())
Jim Inghama5ce6c82011-10-15 00:57:28 +0000254 return true;
255 else
256 return false;
257 }
258
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 // We don't explain signals or breakpoints (breakpoints that handle stepping in or
260 // out will be handled by a child plan.
Jim Inghama5ce6c82011-10-15 00:57:28 +0000261
Jim Ingham60c41182013-06-04 01:40:51 +0000262 StopInfoSP stop_info_sp = GetPrivateStopInfo ();
Jim Inghamb15bfc72010-10-20 00:39:53 +0000263 if (stop_info_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Jim Inghamb15bfc72010-10-20 00:39:53 +0000265 StopReason reason = stop_info_sp->GetStopReason();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266 switch (reason)
267 {
Greg Claytonf4b47e12010-08-04 01:40:35 +0000268 case eStopReasonBreakpoint:
269 {
270 // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened...
Greg Clayton1ac04c32012-02-21 00:09:25 +0000271 BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue()));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000272 if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000274 bool done;
275
276 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
277
278 if (m_step_out_to_id == frame_zero_id)
279 done = true;
280 else if (m_step_out_to_id < frame_zero_id)
281 {
282 // Either we stepped past the breakpoint, or the stack ID calculation
283 // was incorrect and we should probably stop.
284 done = true;
285 }
286 else
287 {
288 if (m_immediate_step_from_id < frame_zero_id)
289 done = true;
290 else
291 done = false;
292 }
293
294 if (done)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000295 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000296 if (InvokeShouldStopHereCallback (eFrameCompareOlder))
297 {
298 CalculateReturnValue();
299 SetPlanComplete();
300 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000301 }
Greg Clayton481cef22011-01-21 06:11:58 +0000302
Greg Claytonf4b47e12010-08-04 01:40:35 +0000303 // If there was only one owner, then we're done. But if we also hit some
304 // user breakpoint on our way out, we should mark ourselves as done, but
305 // also not claim to explain the stop, since it is more important to report
306 // the user breakpoint than the step out completion.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307
Greg Claytonf4b47e12010-08-04 01:40:35 +0000308 if (site_sp->GetNumberOfOwners() == 1)
309 return true;
310
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000312 return false;
313 }
314 case eStopReasonWatchpoint:
315 case eStopReasonSignal:
316 case eStopReasonException:
Greg Clayton90ba8112012-12-05 00:16:59 +0000317 case eStopReasonExec:
Andrew Kaylorf85defa2012-12-20 23:08:03 +0000318 case eStopReasonThreadExiting:
Greg Claytonf4b47e12010-08-04 01:40:35 +0000319 return false;
320
321 default:
322 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323 }
324 }
325 return true;
326}
327
328bool
329ThreadPlanStepOut::ShouldStop (Event *event_ptr)
330{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000331 if (IsPlanComplete())
332 return true;
333
334 bool done = false;
335 if (m_step_out_to_inline_plan_sp)
336 {
337 if (m_step_out_to_inline_plan_sp->MischiefManaged())
338 {
339 // Now step through the inlined stack we are in:
340 if (QueueInlinedStepPlan(true))
341 {
342 // If we can't queue a plan to do this, then just call ourselves done.
343 m_step_out_to_inline_plan_sp.reset();
344 SetPlanComplete (false);
345 return true;
346 }
347 else
348 done = true;
349 }
350 else
351 return m_step_out_to_inline_plan_sp->ShouldStop(event_ptr);
352 }
353 else if (m_step_through_inline_plan_sp)
354 {
355 if (m_step_through_inline_plan_sp->MischiefManaged())
356 done = true;
357 else
358 return m_step_through_inline_plan_sp->ShouldStop(event_ptr);
359 }
360 else if (m_step_out_further_plan_sp)
361 {
362 if (m_step_out_further_plan_sp->MischiefManaged())
363 m_step_out_further_plan_sp.reset();
364 else
365 return m_step_out_further_plan_sp->ShouldStop(event_ptr);
366 }
367
368 if (!done)
369 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000370 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
371 if (frame_zero_id < m_step_out_to_id)
372 done = false;
373 else
374 done = true;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000375 }
376
377 // The normal step out computations think we are done, so all we need to do is consult the ShouldStopHere,
378 // and we are done.
379
380 if (done)
381 {
382 if (InvokeShouldStopHereCallback(eFrameCompareOlder))
Jim Inghama5ce6c82011-10-15 00:57:28 +0000383 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000384 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000385 SetPlanComplete();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000386 }
387 else
388 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000389 m_step_out_further_plan_sp = QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder);
390 done = false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000391 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000392 }
393
394 return done;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395}
396
397bool
398ThreadPlanStepOut::StopOthers ()
399{
400 return m_stop_others;
401}
402
403StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000404ThreadPlanStepOut::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405{
406 return eStateRunning;
407}
408
409bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000410ThreadPlanStepOut::DoWillResume (StateType resume_state, bool current_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000412 if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000413 return true;
414
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
416 return false;
417
418 if (current_plan)
419 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000420 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 if (return_bp != NULL)
422 return_bp->SetEnabled (true);
423 }
424 return true;
425}
426
427bool
428ThreadPlanStepOut::WillStop ()
429{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000430 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
431 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000432 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000433 if (return_bp != NULL)
434 return_bp->SetEnabled (false);
435 }
436
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 return true;
438}
439
440bool
441ThreadPlanStepOut::MischiefManaged ()
442{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000443 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 {
445 // Did I reach my breakpoint? If so I'm done.
446 //
447 // I also check the stack depth, since if we've blown past the breakpoint for some
448 // reason and we're now stopping for some other reason altogether, then we're done
449 // with this step out operation.
450
Greg Clayton5160ce52013-03-27 23:08:40 +0000451 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 if (log)
453 log->Printf("Completed step out plan.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000454 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
455 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000456 m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000457 m_return_bp_id = LLDB_INVALID_BREAK_ID;
458 }
459
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 ThreadPlan::MischiefManaged ();
461 return true;
462 }
463 else
464 {
465 return false;
466 }
467}
468
Jim Inghama5ce6c82011-10-15 00:57:28 +0000469bool
470ThreadPlanStepOut::QueueInlinedStepPlan (bool queue_now)
471{
472 // Now figure out the range of this inlined block, and set up a "step through range"
473 // plan for that. If we've been provided with a context, then use the block in that
474 // context.
Jason Molendab57e4a12013-11-04 09:33:30 +0000475 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000476 if (!immediate_return_from_sp)
477 return false;
478
Greg Clayton5160ce52013-03-27 23:08:40 +0000479 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000480 if (log)
481 {
482 StreamString s;
483 immediate_return_from_sp->Dump(&s, true, false);
484 log->Printf("Queuing inlined frame to step past: %s.", s.GetData());
485 }
486
487 Block *from_block = immediate_return_from_sp->GetFrameBlock();
488 if (from_block)
489 {
490 Block *inlined_block = from_block->GetContainingInlinedBlock();
491 if (inlined_block)
492 {
493 size_t num_ranges = inlined_block->GetNumRanges();
494 AddressRange inline_range;
495 if (inlined_block->GetRangeAtIndex(0, inline_range))
496 {
497 SymbolContext inlined_sc;
498 inlined_block->CalculateSymbolContext(&inlined_sc);
Jim Ingham5f1a4e12012-07-26 18:23:21 +0000499 inlined_sc.target_sp = GetTarget().shared_from_this();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000500 RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000501 const LazyBool avoid_no_debug = eLazyBoolNo;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000502
503 m_step_through_inline_plan_sp.reset (new ThreadPlanStepOverRange(m_thread,
504 inline_range,
505 inlined_sc,
506 run_mode,
507 avoid_no_debug));
508 ThreadPlanStepOverRange *step_through_inline_plan_ptr
509 = static_cast<ThreadPlanStepOverRange *>(m_step_through_inline_plan_sp.get());
510 m_step_through_inline_plan_sp->SetPrivate(true);
511
Jim Inghama5ce6c82011-10-15 00:57:28 +0000512 step_through_inline_plan_ptr->SetOkayToDiscard(true);
513 StreamString errors;
514 if (!step_through_inline_plan_ptr->ValidatePlan(&errors))
515 {
516 //FIXME: Log this failure.
517 delete step_through_inline_plan_ptr;
518 return false;
519 }
520
521 for (size_t i = 1; i < num_ranges; i++)
522 {
523 if (inlined_block->GetRangeAtIndex (i, inline_range))
524 step_through_inline_plan_ptr->AddRange (inline_range);
525 }
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000526
Jim Inghama5ce6c82011-10-15 00:57:28 +0000527 if (queue_now)
528 m_thread.QueueThreadPlan (m_step_through_inline_plan_sp, false);
529 return true;
530 }
531 }
532 }
533
534 return false;
535}
Jim Ingham73ca05a2011-12-17 01:35:57 +0000536
537void
538ThreadPlanStepOut::CalculateReturnValue ()
539{
540 if (m_return_valobj_sp)
541 return;
542
543 if (m_immediate_step_from_function != NULL)
544 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000545 ClangASTType return_clang_type = m_immediate_step_from_function->GetClangType().GetFunctionReturnType();
546 if (return_clang_type)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000547 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000548 lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000549 if (abi_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000550 m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, return_clang_type);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000551 }
552 }
553}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000554
555bool
556ThreadPlanStepOut::IsPlanStale()
557{
558 // If we are still lower on the stack than the frame we are returning to, then
559 // there's something for us to do. Otherwise, we're stale.
560
561 StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
562 if (frame_zero_id < m_step_out_to_id)
563 return false;
564 else
565 return true;
566}