blob: f2f3cad471feb0f581c30fa69647b58daa903ec3 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- StackFrameList.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
Greg Clayton12daf9462010-08-25 00:35:26 +000010#include "lldb/Target/StackFrameList.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Jim Inghamc6355002012-09-08 00:26:49 +000016#include "lldb/Breakpoint/BreakpointLocation.h"
17#include "lldb/Breakpoint/Breakpoint.h"
Jim Ingham6cd41da2012-09-07 23:35:54 +000018#include "lldb/Core/Log.h"
Greg Clayton5082c5f2010-08-27 18:24:16 +000019#include "lldb/Core/StreamFile.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000020#include "lldb/Core/SourceManager.h"
Greg Clayton12daf9462010-08-25 00:35:26 +000021#include "lldb/Symbol/Block.h"
22#include "lldb/Symbol/Function.h"
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000023#include "lldb/Symbol/Symbol.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000024#include "lldb/Target/Process.h"
Greg Clayton12daf9462010-08-25 00:35:26 +000025#include "lldb/Target/RegisterContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/StackFrame.h"
Jim Ingham513c6bb2012-09-01 01:02:41 +000027#include "lldb/Target/StopInfo.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000028#include "lldb/Target/Target.h"
Greg Clayton12daf9462010-08-25 00:35:26 +000029#include "lldb/Target/Thread.h"
30#include "lldb/Target/Unwind.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Clayton5082c5f2010-08-27 18:24:16 +000032//#define DEBUG_STACK_FRAMES 1
33
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034using namespace lldb;
35using namespace lldb_private;
36
37//----------------------------------------------------------------------
38// StackFrameList constructor
39//----------------------------------------------------------------------
Greg Clayton2cad65a2010-09-03 17:10:42 +000040StackFrameList::StackFrameList
41(
42 Thread &thread,
43 const lldb::StackFrameListSP &prev_frames_sp,
44 bool show_inline_frames
45) :
Greg Clayton12daf9462010-08-25 00:35:26 +000046 m_thread (thread),
Greg Clayton2cad65a2010-09-03 17:10:42 +000047 m_prev_frames_sp (prev_frames_sp),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton5082c5f2010-08-27 18:24:16 +000049 m_frames (),
Stephen Wilson71c21d12011-04-11 19:41:40 +000050 m_selected_frame_idx (0),
Jim Inghamb0c72a52012-02-29 03:40:22 +000051 m_concrete_frames_fetched (0),
Jim Ingham513c6bb2012-09-01 01:02:41 +000052 m_current_inlined_depth (UINT32_MAX),
53 m_current_inlined_pc (LLDB_INVALID_ADDRESS),
Stephen Wilson71c21d12011-04-11 19:41:40 +000054 m_show_inlined_frames (show_inline_frames)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055{
Jim Ingham513c6bb2012-09-01 01:02:41 +000056 if (prev_frames_sp)
57 {
58 m_current_inlined_depth = prev_frames_sp->m_current_inlined_depth;
59 m_current_inlined_pc = prev_frames_sp->m_current_inlined_pc;
60 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061}
62
63//----------------------------------------------------------------------
64// Destructor
65//----------------------------------------------------------------------
66StackFrameList::~StackFrameList()
67{
Greg Claytonca5ce182013-03-28 18:41:44 +000068 // Call clear since this takes a lock and clears the stack frame list
69 // in case another thread is currently using this stack frame list
70 Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}
72
Jim Inghamb0c72a52012-02-29 03:40:22 +000073void
Jim Ingham513c6bb2012-09-01 01:02:41 +000074StackFrameList::CalculateCurrentInlinedDepth()
75{
76 uint32_t cur_inlined_depth = GetCurrentInlinedDepth();
77 if (cur_inlined_depth == UINT32_MAX)
78 {
79 ResetCurrentInlinedDepth();
80 }
81}
82
83uint32_t
84StackFrameList::GetCurrentInlinedDepth ()
85{
Jim Ingham6cd41da2012-09-07 23:35:54 +000086 if (m_show_inlined_frames && m_current_inlined_pc != LLDB_INVALID_ADDRESS)
Jim Ingham513c6bb2012-09-01 01:02:41 +000087 {
88 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
89 if (cur_pc != m_current_inlined_pc)
90 {
91 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
92 m_current_inlined_depth = UINT32_MAX;
Greg Clayton5160ce52013-03-27 23:08:40 +000093 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham6cd41da2012-09-07 23:35:54 +000094 if (log && log->GetVerbose())
95 log->Printf ("GetCurrentInlinedDepth: invalidating current inlined depth.\n");
Jim Ingham513c6bb2012-09-01 01:02:41 +000096 }
97 return m_current_inlined_depth;
98 }
99 else
100 {
101 return UINT32_MAX;
102 }
103}
104
Jim Ingham513c6bb2012-09-01 01:02:41 +0000105void
106StackFrameList::ResetCurrentInlinedDepth ()
107{
Keno Fischer47db4a22015-10-16 05:17:25 +0000108 Mutex::Locker locker (m_mutex);
109
Jim Inghame7e6ffc2012-09-05 21:14:28 +0000110 if (m_show_inlined_frames)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000111 {
112 GetFramesUpTo(0);
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000113 if (m_frames.size() == 0)
114 return;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000115 if (!m_frames[0]->IsInlined())
116 {
117 m_current_inlined_depth = UINT32_MAX;
118 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
Greg Clayton5160ce52013-03-27 23:08:40 +0000119 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham6cd41da2012-09-07 23:35:54 +0000120 if (log && log->GetVerbose())
121 log->Printf ("ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
Jim Ingham513c6bb2012-09-01 01:02:41 +0000122 }
123 else
124 {
125 // We only need to do something special about inlined blocks when we
126 // are at the beginning of an inlined function:
127 // FIXME: We probably also have to do something special if the PC is at the END
128 // of an inlined function, which coincides with the end of either its containing
129 // function or another inlined function.
130
131 lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC();
132 Block *block_ptr = m_frames[0]->GetFrameBlock();
133 if (block_ptr)
134 {
135 Address pc_as_address;
136 pc_as_address.SetLoadAddress(curr_pc, &(m_thread.GetProcess()->GetTarget()));
137 AddressRange containing_range;
138 if (block_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
139 {
140 if (pc_as_address == containing_range.GetBaseAddress())
141 {
142 // If we got here because of a breakpoint hit, then set the inlined depth depending on where
143 // the breakpoint was set.
144 // If we got here because of a crash, then set the inlined depth to the deepest most block.
145 // Otherwise, we stopped here naturally as the result of a step, so set ourselves in the
146 // containing frame of the whole set of nested inlines, so the user can then "virtually"
147 // step into the frames one by one, or next over the whole mess.
148 // Note: We don't have to handle being somewhere in the middle of the stack here, since
149 // ResetCurrentInlinedDepth doesn't get called if there is a valid inlined depth set.
150 StopInfoSP stop_info_sp = m_thread.GetStopInfo();
151 if (stop_info_sp)
152 {
153 switch (stop_info_sp->GetStopReason())
154 {
Jim Ingham513c6bb2012-09-01 01:02:41 +0000155 case eStopReasonWatchpoint:
156 case eStopReasonException:
Greg Clayton90ba8112012-12-05 00:16:59 +0000157 case eStopReasonExec:
Jim Ingham513c6bb2012-09-01 01:02:41 +0000158 case eStopReasonSignal:
159 // In all these cases we want to stop in the deepest most frame.
160 m_current_inlined_pc = curr_pc;
161 m_current_inlined_depth = 0;
162 break;
Jim Ingham7da851a2012-09-07 01:11:08 +0000163 case eStopReasonBreakpoint:
164 {
165 // FIXME: Figure out what this break point is doing, and set the inline depth
166 // appropriately. Be careful to take into account breakpoints that implement
167 // step over prologue, since that should do the default calculation.
Jim Inghamc6355002012-09-08 00:26:49 +0000168 // For now, if the breakpoints corresponding to this hit are all internal,
169 // I set the stop location to the top of the inlined stack, since that will make
170 // things like stepping over prologues work right. But if there are any non-internal
171 // breakpoints I do to the bottom of the stack, since that was the old behavior.
172 uint32_t bp_site_id = stop_info_sp->GetValue();
173 BreakpointSiteSP bp_site_sp(m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id));
174 bool all_internal = true;
175 if (bp_site_sp)
176 {
177 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
178 for (uint32_t i = 0; i < num_owners; i++)
179 {
180 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
181 if (!bp_ref.IsInternal())
182 {
183 all_internal = false;
184 }
185 }
186 }
187 if (!all_internal)
188 {
189 m_current_inlined_pc = curr_pc;
190 m_current_inlined_depth = 0;
191 break;
192 }
Jim Ingham7da851a2012-09-07 01:11:08 +0000193 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000194 default:
195 {
196 // Otherwise, we should set ourselves at the container of the inlining, so that the
197 // user can descend into them.
198 // So first we check whether we have more than one inlined block sharing this PC:
199 int num_inlined_functions = 0;
200
201 for (Block *container_ptr = block_ptr->GetInlinedParent();
202 container_ptr != NULL;
203 container_ptr = container_ptr->GetInlinedParent())
204 {
205 if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
206 break;
207 if (pc_as_address != containing_range.GetBaseAddress())
208 break;
209
210 num_inlined_functions++;
211 }
212 m_current_inlined_pc = curr_pc;
213 m_current_inlined_depth = num_inlined_functions + 1;
Greg Clayton5160ce52013-03-27 23:08:40 +0000214 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham6cd41da2012-09-07 23:35:54 +0000215 if (log && log->GetVerbose())
Daniel Malead01b2952012-11-29 21:49:15 +0000216 log->Printf ("ResetCurrentInlinedDepth: setting inlined depth: %d 0x%" PRIx64 ".\n", m_current_inlined_depth, curr_pc);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000217
218 }
219 break;
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227}
228
229bool
230StackFrameList::DecrementCurrentInlinedDepth ()
231{
232 if (m_show_inlined_frames)
233 {
234 uint32_t current_inlined_depth = GetCurrentInlinedDepth();
235 if (current_inlined_depth != UINT32_MAX)
236 {
237 if (current_inlined_depth > 0)
Jim Ingham9786eee2012-09-06 19:24:57 +0000238 {
Jim Ingham513c6bb2012-09-01 01:02:41 +0000239 m_current_inlined_depth--;
Jim Ingham9786eee2012-09-06 19:24:57 +0000240 return true;
241 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000242 }
243 }
244 return false;
245}
246
247void
Jim Ingham6cd41da2012-09-07 23:35:54 +0000248StackFrameList::SetCurrentInlinedDepth (uint32_t new_depth)
249{
250 m_current_inlined_depth = new_depth;
251 if (new_depth == UINT32_MAX)
252 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
253 else
254 m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
255}
256
257void
Jim Inghamb0c72a52012-02-29 03:40:22 +0000258StackFrameList::GetFramesUpTo(uint32_t end_idx)
259{
Enrico Granataebafd2f2013-03-15 17:25:04 +0000260 // this makes sure we do not fetch frames for an invalid thread
261 if (m_thread.IsValid() == false)
262 return;
263
Jim Inghamb0c72a52012-02-29 03:40:22 +0000264 // We've already gotten more frames than asked for, or we've already finished unwinding, return.
265 if (m_frames.size() > end_idx || GetAllFramesFetched())
266 return;
267
268 Unwind *unwinder = m_thread.GetUnwinder ();
269
270 if (m_show_inlined_frames)
271 {
272#if defined (DEBUG_STACK_FRAMES)
273 StreamFile s(stdout, false);
274#endif
Jim Ingham513c6bb2012-09-01 01:02:41 +0000275 // If we are hiding some frames from the outside world, we need to add those onto the total count of
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000276 // frames to fetch. However, we don't need to do that if end_idx is 0 since in that case we always
Jim Ingham6cd41da2012-09-07 23:35:54 +0000277 // get the first concrete frame and all the inlined frames below it... And of course, if end_idx is
278 // UINT32_MAX that means get all, so just do that...
Jim Ingham513c6bb2012-09-01 01:02:41 +0000279
280 uint32_t inlined_depth = 0;
Jim Ingham6cd41da2012-09-07 23:35:54 +0000281 if (end_idx > 0 && end_idx != UINT32_MAX)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000282 {
283 inlined_depth = GetCurrentInlinedDepth();
284 if (inlined_depth != UINT32_MAX)
285 {
286 if (end_idx > 0)
287 end_idx += inlined_depth;
288 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000289 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000290
Jason Molendab57e4a12013-11-04 09:33:30 +0000291 StackFrameSP unwind_frame_sp;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000292 do
293 {
294 uint32_t idx = m_concrete_frames_fetched++;
Greg Clayton8012cad2014-11-17 19:39:20 +0000295 lldb::addr_t pc = LLDB_INVALID_ADDRESS;
296 lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000297 if (idx == 0)
298 {
299 // We might have already created frame zero, only create it
300 // if we need to
301 if (m_frames.empty())
302 {
Greg Claytonb3ae8762013-04-12 20:07:46 +0000303 RegisterContextSP reg_ctx_sp (m_thread.GetRegisterContext());
Jim Ingham376c4852012-03-01 02:53:40 +0000304
Greg Claytonb3ae8762013-04-12 20:07:46 +0000305 if (reg_ctx_sp)
306 {
307
Greg Claytonec6829e2013-11-22 21:03:42 +0000308 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
Greg Claytonb3ae8762013-04-12 20:07:46 +0000309 // There shouldn't be any way not to get the frame info for frame 0.
310 // But if the unwinder can't make one, lets make one by hand with the
311 // SP as the CFA and see if that gets any further.
312 if (!success)
313 {
314 cfa = reg_ctx_sp->GetSP();
315 pc = reg_ctx_sp->GetPC();
316 }
317
318 unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(),
319 m_frames.size(),
320 idx,
321 reg_ctx_sp,
322 cfa,
323 pc,
324 NULL));
325 m_frames.push_back (unwind_frame_sp);
326 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000327 }
328 else
329 {
330 unwind_frame_sp = m_frames.front();
Jason Molendab57e4a12013-11-04 09:33:30 +0000331 cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000332 }
333 }
334 else
335 {
Greg Claytonec6829e2013-11-22 21:03:42 +0000336 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000337 if (!success)
338 {
339 // We've gotten to the end of the stack.
340 SetAllFramesFetched();
341 break;
342 }
Jason Molenda99618472013-11-04 11:02:52 +0000343 const bool cfa_is_valid = true;
344 const bool stop_id_is_valid = false;
345 const bool is_history_frame = false;
346 unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), m_frames.size(), idx, cfa, cfa_is_valid, pc, 0, stop_id_is_valid, is_history_frame, NULL));
Jim Inghamb0c72a52012-02-29 03:40:22 +0000347 m_frames.push_back (unwind_frame_sp);
348 }
349
Ed Masteff1b5c42015-02-23 18:12:20 +0000350 assert(unwind_frame_sp);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000351 SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction);
352 Block *unwind_block = unwind_sc.block;
353 if (unwind_block)
354 {
355 Address curr_frame_address (unwind_frame_sp->GetFrameCodeAddress());
356 // Be sure to adjust the frame address to match the address
357 // that was used to lookup the symbol context above. If we are
358 // in the first concrete frame, then we lookup using the current
359 // address, else we decrement the address by one to get the correct
360 // location.
361 if (idx > 0)
Tamas Berghammer0f8452b2015-06-01 10:38:23 +0000362 {
363 if (curr_frame_address.GetOffset() == 0)
364 {
365 // If curr_frame_address points to the first address in a section then after
366 // adjustment it will point to an other section. In that case resolve the
367 // address again to the correct section plus offset form.
368 TargetSP target = m_thread.CalculateTarget();
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000369 addr_t load_addr = curr_frame_address.GetOpcodeLoadAddress(target.get(), eAddressClassCode);
370 curr_frame_address.SetOpcodeLoadAddress(load_addr - 1, target.get(), eAddressClassCode);
Tamas Berghammer0f8452b2015-06-01 10:38:23 +0000371 }
372 else
373 {
374 curr_frame_address.Slide(-1);
375 }
376 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000377
378 SymbolContext next_frame_sc;
379 Address next_frame_address;
380
381 while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address))
382 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000383 StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(),
Jim Inghamb0c72a52012-02-29 03:40:22 +0000384 m_frames.size(),
385 idx,
386 unwind_frame_sp->GetRegisterContextSP (),
387 cfa,
388 next_frame_address,
389 &next_frame_sc));
390
391 m_frames.push_back (frame_sp);
392 unwind_sc = next_frame_sc;
393 curr_frame_address = next_frame_address;
394 }
395 }
396 } while (m_frames.size() - 1 < end_idx);
397
398 // Don't try to merge till you've calculated all the frames in this stack.
399 if (GetAllFramesFetched() && m_prev_frames_sp)
400 {
401 StackFrameList *prev_frames = m_prev_frames_sp.get();
402 StackFrameList *curr_frames = this;
Jim Ingham9786eee2012-09-06 19:24:57 +0000403
Jim Ingham6cd41da2012-09-07 23:35:54 +0000404 //curr_frames->m_current_inlined_depth = prev_frames->m_current_inlined_depth;
405 //curr_frames->m_current_inlined_pc = prev_frames->m_current_inlined_pc;
Daniel Malead01b2952012-11-29 21:49:15 +0000406 //printf ("GetFramesUpTo: Copying current inlined depth: %d 0x%" PRIx64 ".\n", curr_frames->m_current_inlined_depth, curr_frames->m_current_inlined_pc);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000407
408#if defined (DEBUG_STACK_FRAMES)
409 s.PutCString("\nprev_frames:\n");
410 prev_frames->Dump (&s);
411 s.PutCString("\ncurr_frames:\n");
412 curr_frames->Dump (&s);
413 s.EOL();
414#endif
415 size_t curr_frame_num, prev_frame_num;
416
417 for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size();
418 curr_frame_num > 0 && prev_frame_num > 0;
419 --curr_frame_num, --prev_frame_num)
420 {
421 const size_t curr_frame_idx = curr_frame_num-1;
422 const size_t prev_frame_idx = prev_frame_num-1;
Jason Molendab57e4a12013-11-04 09:33:30 +0000423 StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]);
424 StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000425
426#if defined (DEBUG_STACK_FRAMES)
427 s.Printf("\n\nCurr frame #%u ", curr_frame_idx);
428 if (curr_frame_sp)
429 curr_frame_sp->Dump (&s, true, false);
430 else
431 s.PutCString("NULL");
432 s.Printf("\nPrev frame #%u ", prev_frame_idx);
433 if (prev_frame_sp)
434 prev_frame_sp->Dump (&s, true, false);
435 else
436 s.PutCString("NULL");
437#endif
438
Jason Molendab57e4a12013-11-04 09:33:30 +0000439 StackFrame *curr_frame = curr_frame_sp.get();
440 StackFrame *prev_frame = prev_frame_sp.get();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000441
442 if (curr_frame == NULL || prev_frame == NULL)
443 break;
444
445 // Check the stack ID to make sure they are equal
446 if (curr_frame->GetStackID() != prev_frame->GetStackID())
447 break;
448
449 prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame);
450 // Now copy the fixed up previous frame into the current frames
451 // so the pointer doesn't change
452 m_frames[curr_frame_idx] = prev_frame_sp;
453 //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame);
454
455#if defined (DEBUG_STACK_FRAMES)
456 s.Printf("\n Copying previous frame to current frame");
457#endif
458 }
459 // We are done with the old stack frame list, we can release it now
460 m_prev_frames_sp.reset();
461 }
462
463#if defined (DEBUG_STACK_FRAMES)
Stephane Sezercdb2a112015-10-15 22:24:17 +0000464 s.PutCString("\n\nNew frames:\n");
465 Dump (&s);
466 s.EOL();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000467#endif
468 }
469 else
470 {
471 if (end_idx < m_concrete_frames_fetched)
472 return;
Greg Claytonec6829e2013-11-22 21:03:42 +0000473
474 if (unwinder)
Jim Inghamb0c72a52012-02-29 03:40:22 +0000475 {
Greg Claytonec6829e2013-11-22 21:03:42 +0000476 uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
477 if (num_frames <= end_idx + 1)
478 {
479 //Done unwinding.
480 m_concrete_frames_fetched = UINT32_MAX;
481 }
482 m_frames.resize(num_frames);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000483 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000484 }
485}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486
487uint32_t
Greg Clayton2cad65a2010-09-03 17:10:42 +0000488StackFrameList::GetNumFrames (bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489{
490 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000491
Jim Inghamb0c72a52012-02-29 03:40:22 +0000492 if (can_create)
493 GetFramesUpTo (UINT32_MAX);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000494
495 uint32_t inlined_depth = GetCurrentInlinedDepth();
496 if (inlined_depth == UINT32_MAX)
497 return m_frames.size();
498 else
499 return m_frames.size() - inlined_depth;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000500}
501
502void
503StackFrameList::Dump (Stream *s)
504{
505 if (s == NULL)
506 return;
507 Mutex::Locker locker (m_mutex);
508
509 const_iterator pos, begin = m_frames.begin(), end = m_frames.end();
510 for (pos = begin; pos != end; ++pos)
Greg Clayton12daf9462010-08-25 00:35:26 +0000511 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000512 StackFrame *frame = (*pos).get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000513 s->Printf("%p: ", static_cast<void*>(frame));
Greg Clayton5082c5f2010-08-27 18:24:16 +0000514 if (frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000515 {
516 frame->GetStackID().Dump (s);
Greg Clayton0603aa92010-10-04 01:05:56 +0000517 frame->DumpUsingSettingsFormat (s);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000518 }
Greg Clayton5082c5f2010-08-27 18:24:16 +0000519 else
Greg Claytondce502e2011-11-04 03:34:56 +0000520 s->Printf("frame #%u", (uint32_t)std::distance (begin, pos));
Greg Clayton5082c5f2010-08-27 18:24:16 +0000521 s->EOL();
Greg Clayton12daf9462010-08-25 00:35:26 +0000522 }
Greg Clayton5082c5f2010-08-27 18:24:16 +0000523 s->EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524}
525
Jason Molendab57e4a12013-11-04 09:33:30 +0000526StackFrameSP
Greg Clayton12daf9462010-08-25 00:35:26 +0000527StackFrameList::GetFrameAtIndex (uint32_t idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528{
Jason Molendab57e4a12013-11-04 09:33:30 +0000529 StackFrameSP frame_sp;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000530 Mutex::Locker locker (m_mutex);
Jim Ingham5cb9a182013-03-28 00:13:30 +0000531 uint32_t original_idx = idx;
532
Jim Ingham513c6bb2012-09-01 01:02:41 +0000533 uint32_t inlined_depth = GetCurrentInlinedDepth();
534 if (inlined_depth != UINT32_MAX)
535 idx += inlined_depth;
536
Greg Clayton5082c5f2010-08-27 18:24:16 +0000537 if (idx < m_frames.size())
538 frame_sp = m_frames[idx];
539
540 if (frame_sp)
541 return frame_sp;
Greg Clayton0445d8f2010-08-26 02:28:22 +0000542
Jim Ingham5cb9a182013-03-28 00:13:30 +0000543 // GetFramesUpTo will fill m_frames with as many frames as you asked for,
544 // if there are that many. If there weren't then you asked for too many
545 // frames.
546 GetFramesUpTo (idx);
547 if (idx < m_frames.size())
548 {
549 if (m_show_inlined_frames)
Greg Clayton5082c5f2010-08-27 18:24:16 +0000550 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000551 // When inline frames are enabled we actually create all the frames in GetFramesUpTo.
552 frame_sp = m_frames[idx];
553 }
554 else
555 {
556 Unwind *unwinder = m_thread.GetUnwinder ();
557 if (unwinder)
Greg Clayton5082c5f2010-08-27 18:24:16 +0000558 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000559 addr_t pc, cfa;
560 if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
Greg Clayton5082c5f2010-08-27 18:24:16 +0000561 {
Jason Molenda99618472013-11-04 11:02:52 +0000562 const bool cfa_is_valid = true;
563 const bool stop_id_is_valid = false;
564 const bool is_history_frame = false;
565 frame_sp.reset (new StackFrame (m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid, pc, 0, stop_id_is_valid, is_history_frame, NULL));
Jim Ingham5cb9a182013-03-28 00:13:30 +0000566
567 Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
568 if (function)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000569 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000570 // When we aren't showing inline functions we always use
571 // the top most function block as the scope.
572 frame_sp->SetSymbolContextScope (&function->GetBlock(false));
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000573 }
Jim Ingham5cb9a182013-03-28 00:13:30 +0000574 else
575 {
576 // Set the symbol scope from the symbol regardless if it is NULL or valid.
577 frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
578 }
579 SetFrameAtIndex(idx, frame_sp);
Greg Clayton5082c5f2010-08-27 18:24:16 +0000580 }
581 }
Greg Clayton12daf9462010-08-25 00:35:26 +0000582 }
Jim Ingham5cb9a182013-03-28 00:13:30 +0000583 }
584 else if (original_idx == 0)
585 {
586 // There should ALWAYS be a frame at index 0. If something went wrong with the CurrentInlinedDepth such that
587 // there weren't as many frames as we thought taking that into account, then reset the current inlined depth
588 // and return the real zeroth frame.
589 if (m_frames.size() > 0)
590 {
591 ResetCurrentInlinedDepth();
592 frame_sp = m_frames[original_idx];
593 }
594 else
595 {
596 // Why do we have a thread with zero frames, that should not ever happen...
597 if (m_thread.IsValid())
598 assert ("A valid thread has no frames.");
599
600 }
601 }
602
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 return frame_sp;
604}
605
Jason Molendab57e4a12013-11-04 09:33:30 +0000606StackFrameSP
Greg Clayton5ccbd292011-01-06 22:15:06 +0000607StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
608{
609 // First try assuming the unwind index is the same as the frame index. The
610 // unwind index is always greater than or equal to the frame index, so it
611 // is a good place to start. If we have inlined frames we might have 5
612 // concrete frames (frame unwind indexes go from 0-4), but we might have 15
613 // frames after we make all the inlined frames. Most of the time the unwind
614 // frame index (or the concrete frame index) is the same as the frame index.
615 uint32_t frame_idx = unwind_idx;
Jason Molendab57e4a12013-11-04 09:33:30 +0000616 StackFrameSP frame_sp (GetFrameAtIndex (frame_idx));
Greg Clayton5ccbd292011-01-06 22:15:06 +0000617 while (frame_sp)
618 {
619 if (frame_sp->GetFrameIndex() == unwind_idx)
620 break;
621 frame_sp = GetFrameAtIndex (++frame_idx);
622 }
623 return frame_sp;
624}
625
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000626static bool
Jason Molendab57e4a12013-11-04 09:33:30 +0000627CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id)
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000628{
629 return stack_sp->GetStackID() < stack_id;
630}
631
Jason Molendab57e4a12013-11-04 09:33:30 +0000632StackFrameSP
Greg Claytoncc4d0142012-02-17 07:49:44 +0000633StackFrameList::GetFrameWithStackID (const StackID &stack_id)
Jim Ingham3a195b72011-03-31 00:15:49 +0000634{
Jason Molendab57e4a12013-11-04 09:33:30 +0000635 StackFrameSP frame_sp;
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000636
637 if (stack_id.IsValid())
Jim Ingham3a195b72011-03-31 00:15:49 +0000638 {
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000639 Mutex::Locker locker (m_mutex);
640 uint32_t frame_idx = 0;
641 // Do a binary search in case the stack frame is already in our cache
642 collection::const_iterator begin = m_frames.begin();
643 collection::const_iterator end = m_frames.end();
644 if (begin != end)
645 {
646 collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID);
Greg Clayton8012cad2014-11-17 19:39:20 +0000647 if (pos != end)
648 {
649 if ((*pos)->GetStackID() == stack_id)
650 return *pos;
651 }
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000652
Greg Clayton8012cad2014-11-17 19:39:20 +0000653// if (m_frames.back()->GetStackID() < stack_id)
654// frame_idx = m_frames.size();
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000655 }
656 do
657 {
658 frame_sp = GetFrameAtIndex (frame_idx);
659 if (frame_sp && frame_sp->GetStackID() == stack_id)
660 break;
661 frame_idx++;
662 }
663 while (frame_sp);
Jim Ingham3a195b72011-03-31 00:15:49 +0000664 }
Jim Ingham3a195b72011-03-31 00:15:49 +0000665 return frame_sp;
666}
Greg Clayton5ccbd292011-01-06 22:15:06 +0000667
Greg Clayton12daf9462010-08-25 00:35:26 +0000668bool
Jason Molendab57e4a12013-11-04 09:33:30 +0000669StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
Greg Clayton12daf9462010-08-25 00:35:26 +0000670{
Greg Clayton5082c5f2010-08-27 18:24:16 +0000671 if (idx >= m_frames.size())
672 m_frames.resize(idx + 1);
Greg Clayton12daf9462010-08-25 00:35:26 +0000673 // Make sure allocation succeeded by checking bounds again
Greg Clayton5082c5f2010-08-27 18:24:16 +0000674 if (idx < m_frames.size())
Greg Clayton12daf9462010-08-25 00:35:26 +0000675 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000676 m_frames[idx] = frame_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 return true;
678 }
679 return false; // resize failed, out of memory?
680}
681
682uint32_t
Jim Ingham2976d002010-08-26 21:32:51 +0000683StackFrameList::GetSelectedFrameIndex () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684{
685 Mutex::Locker locker (m_mutex);
Jim Ingham2976d002010-08-26 21:32:51 +0000686 return m_selected_frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687}
688
689
690uint32_t
Jason Molendab57e4a12013-11-04 09:33:30 +0000691StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692{
693 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000694 const_iterator pos;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000695 const_iterator begin = m_frames.begin();
696 const_iterator end = m_frames.end();
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000697 m_selected_frame_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698 for (pos = begin; pos != end; ++pos)
699 {
700 if (pos->get() == frame)
701 {
Jim Ingham2976d002010-08-26 21:32:51 +0000702 m_selected_frame_idx = std::distance (begin, pos);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000703 uint32_t inlined_depth = GetCurrentInlinedDepth();
704 if (inlined_depth != UINT32_MAX)
705 m_selected_frame_idx -= inlined_depth;
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000706 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000707 }
708 }
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000709 SetDefaultFileAndLineToSelectedFrame();
Jim Ingham2976d002010-08-26 21:32:51 +0000710 return m_selected_frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711}
712
713// Mark a stack frame as the current frame using the frame index
Jim Inghamb0c72a52012-02-29 03:40:22 +0000714bool
Jim Ingham2976d002010-08-26 21:32:51 +0000715StackFrameList::SetSelectedFrameByIndex (uint32_t idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716{
717 Mutex::Locker locker (m_mutex);
Jason Molendab57e4a12013-11-04 09:33:30 +0000718 StackFrameSP frame_sp (GetFrameAtIndex (idx));
Jim Inghamb0c72a52012-02-29 03:40:22 +0000719 if (frame_sp)
720 {
721 SetSelectedFrame(frame_sp.get());
722 return true;
723 }
724 else
725 return false;
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000726}
727
728void
729StackFrameList::SetDefaultFileAndLineToSelectedFrame()
730{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000731 if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID())
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000732 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000733 StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex()));
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000734 if (frame_sp)
735 {
Greg Clayton252d0ed2011-10-05 03:14:31 +0000736 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry);
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000737 if (sc.line_entry.file)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000738 m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file,
Greg Clayton252d0ed2011-10-05 03:14:31 +0000739 sc.line_entry.line);
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000740 }
741 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742}
743
744// The thread has been run, reset the number stack frames to zero so we can
745// determine how many frames we have lazily.
746void
747StackFrameList::Clear ()
748{
749 Mutex::Locker locker (m_mutex);
Greg Clayton5082c5f2010-08-27 18:24:16 +0000750 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000751 m_concrete_frames_fetched = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752}
753
754void
755StackFrameList::InvalidateFrames (uint32_t start_idx)
756{
757 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000758 if (m_show_inlined_frames)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 {
Greg Clayton12daf9462010-08-25 00:35:26 +0000760 Clear();
761 }
762 else
763 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000764 const size_t num_frames = m_frames.size();
Greg Clayton12daf9462010-08-25 00:35:26 +0000765 while (start_idx < num_frames)
766 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000767 m_frames[start_idx].reset();
Greg Clayton12daf9462010-08-25 00:35:26 +0000768 ++start_idx;
769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771}
Greg Clayton2cad65a2010-09-03 17:10:42 +0000772
773void
Greg Clayton7b0992d2013-04-18 22:45:39 +0000774StackFrameList::Merge (std::unique_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000775{
Jim Ingham10ebffa2012-05-04 23:02:50 +0000776 Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL);
777 Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000778
779#if defined (DEBUG_STACK_FRAMES)
Johnny Chen2c595272011-08-25 17:27:02 +0000780 StreamFile s(stdout, false);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000781 s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n");
782 if (prev_sp.get())
783 prev_sp->Dump (&s);
784 else
785 s.PutCString ("NULL");
786 s.PutCString("\nCurr:\n");
787 if (curr_ap.get())
788 curr_ap->Dump (&s);
789 else
790 s.PutCString ("NULL");
791 s.EOL();
792#endif
793
794 if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0)
795 {
796#if defined (DEBUG_STACK_FRAMES)
797 s.PutCString("No current frames, leave previous frames alone...\n");
798#endif
799 curr_ap.release();
800 return;
801 }
802
803 if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0)
804 {
805#if defined (DEBUG_STACK_FRAMES)
806 s.PutCString("No previous frames, so use current frames...\n");
807#endif
808 // We either don't have any previous frames, or since we have more than
809 // one current frames it means we have all the frames and can safely
810 // replace our previous frames.
811 prev_sp.reset (curr_ap.release());
812 return;
813 }
814
815 const uint32_t num_curr_frames = curr_ap->GetNumFrames (false);
816
817 if (num_curr_frames > 1)
818 {
819#if defined (DEBUG_STACK_FRAMES)
820 s.PutCString("We have more than one current frame, so use current frames...\n");
821#endif
822 // We have more than one current frames it means we have all the frames
823 // and can safely replace our previous frames.
824 prev_sp.reset (curr_ap.release());
825
826#if defined (DEBUG_STACK_FRAMES)
827 s.PutCString("\nMerged:\n");
828 prev_sp->Dump (&s);
829#endif
830 return;
831 }
832
Jason Molendab57e4a12013-11-04 09:33:30 +0000833 StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0));
834 StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0));
Greg Clayton2cad65a2010-09-03 17:10:42 +0000835 StackID curr_stack_id (curr_frame_zero_sp->GetStackID());
836 StackID prev_stack_id (prev_frame_zero_sp->GetStackID());
837
Greg Clayton2cad65a2010-09-03 17:10:42 +0000838#if defined (DEBUG_STACK_FRAMES)
Johnny Chen2c595272011-08-25 17:27:02 +0000839 const uint32_t num_prev_frames = prev_sp->GetNumFrames (false);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000840 s.Printf("\n%u previous frames with one current frame\n", num_prev_frames);
841#endif
842
843 // We have only a single current frame
844 // Our previous stack frames only had a single frame as well...
845 if (curr_stack_id == prev_stack_id)
846 {
847#if defined (DEBUG_STACK_FRAMES)
848 s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n");
849#endif
850
851 curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp);
852// prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp);
853// prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp);
854 }
855 else if (curr_stack_id < prev_stack_id)
856 {
857#if defined (DEBUG_STACK_FRAMES)
858 s.Printf("\nCurrent frame #0 has a stack ID that is less than the previous frame #0, insert current frame zero in front of previous\n");
859#endif
860 prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp);
861 }
862
863 curr_ap.release();
864
865#if defined (DEBUG_STACK_FRAMES)
866 s.PutCString("\nMerged:\n");
867 prev_sp->Dump (&s);
868#endif
869
870
871}
Jim Inghame4284b72010-09-23 17:40:12 +0000872
Jason Molendab57e4a12013-11-04 09:33:30 +0000873lldb::StackFrameSP
874StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
Jim Inghame4284b72010-09-23 17:40:12 +0000875{
876 const_iterator pos;
877 const_iterator begin = m_frames.begin();
878 const_iterator end = m_frames.end();
Jason Molendab57e4a12013-11-04 09:33:30 +0000879 lldb::StackFrameSP ret_sp;
Jim Inghame4284b72010-09-23 17:40:12 +0000880
881 for (pos = begin; pos != end; ++pos)
882 {
883 if (pos->get() == stack_frame_ptr)
884 {
885 ret_sp = (*pos);
886 break;
887 }
888 }
889 return ret_sp;
890}
891
Greg Clayton7260f622011-04-18 08:33:37 +0000892size_t
893StackFrameList::GetStatus (Stream& strm,
894 uint32_t first_frame,
895 uint32_t num_frames,
896 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000897 uint32_t num_frames_with_source,
898 const char *selected_frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +0000899{
900 size_t num_frames_displayed = 0;
901
902 if (num_frames == 0)
903 return 0;
904
Jason Molendab57e4a12013-11-04 09:33:30 +0000905 StackFrameSP frame_sp;
Greg Clayton7260f622011-04-18 08:33:37 +0000906 uint32_t frame_idx = 0;
907 uint32_t last_frame;
908
909 // Don't let the last frame wrap around...
910 if (num_frames == UINT32_MAX)
911 last_frame = UINT32_MAX;
912 else
913 last_frame = first_frame + num_frames;
914
Jason Molendab57e4a12013-11-04 09:33:30 +0000915 StackFrameSP selected_frame_sp = m_thread.GetSelectedFrame();
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000916 const char *unselected_marker = NULL;
917 std::string buffer;
918 if (selected_frame_marker)
919 {
920 size_t len = strlen(selected_frame_marker);
921 buffer.insert(buffer.begin(), len, ' ');
922 unselected_marker = buffer.c_str();
923 }
924 const char *marker = NULL;
925
Greg Clayton7260f622011-04-18 08:33:37 +0000926 for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx)
927 {
928 frame_sp = GetFrameAtIndex(frame_idx);
929 if (frame_sp.get() == NULL)
930 break;
931
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000932 if (selected_frame_marker != NULL)
933 {
934 if (frame_sp == selected_frame_sp)
935 marker = selected_frame_marker;
936 else
937 marker = unselected_marker;
938 }
939
Greg Clayton7260f622011-04-18 08:33:37 +0000940 if (!frame_sp->GetStatus (strm,
941 show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000942 num_frames_with_source > (first_frame - frame_idx), marker))
Greg Clayton7260f622011-04-18 08:33:37 +0000943 break;
944 ++num_frames_displayed;
945 }
946
947 strm.IndentLess();
948 return num_frames_displayed;
949}
950