blob: 9b39d1ceaf259bb2f5ae52051cdb92cbe5e10a20 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Log.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000018#include "lldb/Core/Value.h"
19#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Symbol/Block.h"
21#include "lldb/Symbol/Function.h"
22#include "lldb/Symbol/Type.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000023#include "lldb/Target/ABI.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();
Jim Ingham9b03fa02015-07-23 19:55:02 +0000265 if (reason == eStopReasonBreakpoint)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000266 {
267 // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened...
Greg Clayton1ac04c32012-02-21 00:09:25 +0000268 BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue()));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000269 if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 {
Jim Inghamb5c0d1c2012-03-01 00:50:50 +0000271 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 Ingham73ca05a2011-12-17 01:35:57 +0000292 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000293 if (InvokeShouldStopHereCallback (eFrameCompareOlder))
294 {
295 CalculateReturnValue();
296 SetPlanComplete();
297 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000298 }
Greg Clayton481cef22011-01-21 06:11:58 +0000299
Greg Claytonf4b47e12010-08-04 01:40:35 +0000300 // 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 Lattner30fdc8d2010-06-08 16:52:24 +0000304
Greg Claytonf4b47e12010-08-04 01:40:35 +0000305 if (site_sp->GetNumberOfOwners() == 1)
306 return true;
307
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000309 return false;
310 }
Jim Ingham9b03fa02015-07-23 19:55:02 +0000311 else if (IsUsuallyUnexplainedStopReason(reason))
Greg Claytonf4b47e12010-08-04 01:40:35 +0000312 return false;
Jim Ingham9b03fa02015-07-23 19:55:02 +0000313 else
Greg Claytonf4b47e12010-08-04 01:40:35 +0000314 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 }
316 return true;
317}
318
319bool
320ThreadPlanStepOut::ShouldStop (Event *event_ptr)
321{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000322 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 Inghamb5c0d1c2012-03-01 00:50:50 +0000361 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 Ingham4b4b2472014-03-13 02:47:14 +0000366 }
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 Inghama5ce6c82011-10-15 00:57:28 +0000374 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000375 CalculateReturnValue();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000376 SetPlanComplete();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000377 }
378 else
379 {
Jim Ingham4b4b2472014-03-13 02:47:14 +0000380 m_step_out_further_plan_sp = QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder);
381 done = false;
Jim Inghama5ce6c82011-10-15 00:57:28 +0000382 }
Jim Ingham4b4b2472014-03-13 02:47:14 +0000383 }
384
385 return done;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386}
387
388bool
389ThreadPlanStepOut::StopOthers ()
390{
391 return m_stop_others;
392}
393
394StateType
Jim Ingham06e827c2010-11-11 19:26:09 +0000395ThreadPlanStepOut::GetPlanRunState ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396{
397 return eStateRunning;
398}
399
400bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000401ThreadPlanStepOut::DoWillResume (StateType resume_state, bool current_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402{
Jim Ingham4b4b2472014-03-13 02:47:14 +0000403 if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp)
Jim Inghama5ce6c82011-10-15 00:57:28 +0000404 return true;
405
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406 if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
407 return false;
408
409 if (current_plan)
410 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000411 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 if (return_bp != NULL)
413 return_bp->SetEnabled (true);
414 }
415 return true;
416}
417
418bool
419ThreadPlanStepOut::WillStop ()
420{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000421 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
422 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000423 Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000424 if (return_bp != NULL)
425 return_bp->SetEnabled (false);
426 }
427
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 return true;
429}
430
431bool
432ThreadPlanStepOut::MischiefManaged ()
433{
Jim Inghama5ce6c82011-10-15 00:57:28 +0000434 if (IsPlanComplete())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 {
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 Clayton5160ce52013-03-27 23:08:40 +0000442 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 if (log)
444 log->Printf("Completed step out plan.");
Jim Inghama5ce6c82011-10-15 00:57:28 +0000445 if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
446 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000447 m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id);
Jim Inghama5ce6c82011-10-15 00:57:28 +0000448 m_return_bp_id = LLDB_INVALID_BREAK_ID;
449 }
450
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 ThreadPlan::MischiefManaged ();
452 return true;
453 }
454 else
455 {
456 return false;
457 }
458}
459
Jim Inghama5ce6c82011-10-15 00:57:28 +0000460bool
461ThreadPlanStepOut::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 Molendab57e4a12013-11-04 09:33:30 +0000466 StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000467 if (!immediate_return_from_sp)
468 return false;
469
Greg Clayton5160ce52013-03-27 23:08:40 +0000470 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghama5ce6c82011-10-15 00:57:28 +0000471 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 Ingham5f1a4e12012-07-26 18:23:21 +0000490 inlined_sc.target_sp = GetTarget().shared_from_this();
Jim Inghama5ce6c82011-10-15 00:57:28 +0000491 RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads;
Jim Ingham4b4b2472014-03-13 02:47:14 +0000492 const LazyBool avoid_no_debug = eLazyBoolNo;
Jim Ingham2bdbfd52014-09-29 23:17:18 +0000493
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 Inghama5ce6c82011-10-15 00:57:28 +0000503 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 Ingham2bdbfd52014-09-29 23:17:18 +0000517
Jim Inghama5ce6c82011-10-15 00:57:28 +0000518 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 Ingham73ca05a2011-12-17 01:35:57 +0000527
528void
529ThreadPlanStepOut::CalculateReturnValue ()
530{
531 if (m_return_valobj_sp)
532 return;
533
534 if (m_immediate_step_from_function != NULL)
535 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000536 ClangASTType return_clang_type = m_immediate_step_from_function->GetClangType().GetFunctionReturnType();
537 if (return_clang_type)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000538 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000539 lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000540 if (abi_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +0000541 m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, return_clang_type);
Jim Ingham73ca05a2011-12-17 01:35:57 +0000542 }
543 }
544}
Jim Ingham64e7ead2012-05-03 21:19:36 +0000545
546bool
547ThreadPlanStepOut::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}