blob: a8ce95ea922f4eceeeea81647706e3f1e80bf1c7 [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{
Jim Inghame7e6ffc2012-09-05 21:14:28 +0000108 if (m_show_inlined_frames)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000109 {
110 GetFramesUpTo(0);
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000111 if (m_frames.size() == 0)
112 return;
Jim Ingham513c6bb2012-09-01 01:02:41 +0000113 if (!m_frames[0]->IsInlined())
114 {
115 m_current_inlined_depth = UINT32_MAX;
116 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
Greg Clayton5160ce52013-03-27 23:08:40 +0000117 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham6cd41da2012-09-07 23:35:54 +0000118 if (log && log->GetVerbose())
119 log->Printf ("ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
Jim Ingham513c6bb2012-09-01 01:02:41 +0000120 }
121 else
122 {
123 // We only need to do something special about inlined blocks when we
124 // are at the beginning of an inlined function:
125 // FIXME: We probably also have to do something special if the PC is at the END
126 // of an inlined function, which coincides with the end of either its containing
127 // function or another inlined function.
128
129 lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC();
130 Block *block_ptr = m_frames[0]->GetFrameBlock();
131 if (block_ptr)
132 {
133 Address pc_as_address;
134 pc_as_address.SetLoadAddress(curr_pc, &(m_thread.GetProcess()->GetTarget()));
135 AddressRange containing_range;
136 if (block_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
137 {
138 if (pc_as_address == containing_range.GetBaseAddress())
139 {
140 // If we got here because of a breakpoint hit, then set the inlined depth depending on where
141 // the breakpoint was set.
142 // If we got here because of a crash, then set the inlined depth to the deepest most block.
143 // Otherwise, we stopped here naturally as the result of a step, so set ourselves in the
144 // containing frame of the whole set of nested inlines, so the user can then "virtually"
145 // step into the frames one by one, or next over the whole mess.
146 // Note: We don't have to handle being somewhere in the middle of the stack here, since
147 // ResetCurrentInlinedDepth doesn't get called if there is a valid inlined depth set.
148 StopInfoSP stop_info_sp = m_thread.GetStopInfo();
149 if (stop_info_sp)
150 {
151 switch (stop_info_sp->GetStopReason())
152 {
Jim Ingham513c6bb2012-09-01 01:02:41 +0000153 case eStopReasonWatchpoint:
154 case eStopReasonException:
Greg Clayton90ba8112012-12-05 00:16:59 +0000155 case eStopReasonExec:
Jim Ingham513c6bb2012-09-01 01:02:41 +0000156 case eStopReasonSignal:
157 // In all these cases we want to stop in the deepest most frame.
158 m_current_inlined_pc = curr_pc;
159 m_current_inlined_depth = 0;
160 break;
Jim Ingham7da851a2012-09-07 01:11:08 +0000161 case eStopReasonBreakpoint:
162 {
163 // FIXME: Figure out what this break point is doing, and set the inline depth
164 // appropriately. Be careful to take into account breakpoints that implement
165 // step over prologue, since that should do the default calculation.
Jim Inghamc6355002012-09-08 00:26:49 +0000166 // For now, if the breakpoints corresponding to this hit are all internal,
167 // I set the stop location to the top of the inlined stack, since that will make
168 // things like stepping over prologues work right. But if there are any non-internal
169 // breakpoints I do to the bottom of the stack, since that was the old behavior.
170 uint32_t bp_site_id = stop_info_sp->GetValue();
171 BreakpointSiteSP bp_site_sp(m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id));
172 bool all_internal = true;
173 if (bp_site_sp)
174 {
175 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
176 for (uint32_t i = 0; i < num_owners; i++)
177 {
178 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
179 if (!bp_ref.IsInternal())
180 {
181 all_internal = false;
182 }
183 }
184 }
185 if (!all_internal)
186 {
187 m_current_inlined_pc = curr_pc;
188 m_current_inlined_depth = 0;
189 break;
190 }
Jim Ingham7da851a2012-09-07 01:11:08 +0000191 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000192 default:
193 {
194 // Otherwise, we should set ourselves at the container of the inlining, so that the
195 // user can descend into them.
196 // So first we check whether we have more than one inlined block sharing this PC:
197 int num_inlined_functions = 0;
198
199 for (Block *container_ptr = block_ptr->GetInlinedParent();
200 container_ptr != NULL;
201 container_ptr = container_ptr->GetInlinedParent())
202 {
203 if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
204 break;
205 if (pc_as_address != containing_range.GetBaseAddress())
206 break;
207
208 num_inlined_functions++;
209 }
210 m_current_inlined_pc = curr_pc;
211 m_current_inlined_depth = num_inlined_functions + 1;
Greg Clayton5160ce52013-03-27 23:08:40 +0000212 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham6cd41da2012-09-07 23:35:54 +0000213 if (log && log->GetVerbose())
Daniel Malead01b2952012-11-29 21:49:15 +0000214 log->Printf ("ResetCurrentInlinedDepth: setting inlined depth: %d 0x%" PRIx64 ".\n", m_current_inlined_depth, curr_pc);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000215
216 }
217 break;
218 }
219 }
220 }
221 }
222 }
223 }
224 }
225}
226
227bool
228StackFrameList::DecrementCurrentInlinedDepth ()
229{
230 if (m_show_inlined_frames)
231 {
232 uint32_t current_inlined_depth = GetCurrentInlinedDepth();
233 if (current_inlined_depth != UINT32_MAX)
234 {
235 if (current_inlined_depth > 0)
Jim Ingham9786eee2012-09-06 19:24:57 +0000236 {
Jim Ingham513c6bb2012-09-01 01:02:41 +0000237 m_current_inlined_depth--;
Jim Ingham9786eee2012-09-06 19:24:57 +0000238 return true;
239 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000240 }
241 }
242 return false;
243}
244
245void
Jim Ingham6cd41da2012-09-07 23:35:54 +0000246StackFrameList::SetCurrentInlinedDepth (uint32_t new_depth)
247{
248 m_current_inlined_depth = new_depth;
249 if (new_depth == UINT32_MAX)
250 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
251 else
252 m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
253}
254
255void
Jim Inghamb0c72a52012-02-29 03:40:22 +0000256StackFrameList::GetFramesUpTo(uint32_t end_idx)
257{
Enrico Granataebafd2f2013-03-15 17:25:04 +0000258 // this makes sure we do not fetch frames for an invalid thread
259 if (m_thread.IsValid() == false)
260 return;
261
Jim Inghamb0c72a52012-02-29 03:40:22 +0000262 // We've already gotten more frames than asked for, or we've already finished unwinding, return.
263 if (m_frames.size() > end_idx || GetAllFramesFetched())
264 return;
265
266 Unwind *unwinder = m_thread.GetUnwinder ();
267
268 if (m_show_inlined_frames)
269 {
270#if defined (DEBUG_STACK_FRAMES)
271 StreamFile s(stdout, false);
272#endif
Jim Ingham513c6bb2012-09-01 01:02:41 +0000273 // 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 +0000274 // 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 +0000275 // get the first concrete frame and all the inlined frames below it... And of course, if end_idx is
276 // UINT32_MAX that means get all, so just do that...
Jim Ingham513c6bb2012-09-01 01:02:41 +0000277
278 uint32_t inlined_depth = 0;
Jim Ingham6cd41da2012-09-07 23:35:54 +0000279 if (end_idx > 0 && end_idx != UINT32_MAX)
Jim Ingham513c6bb2012-09-01 01:02:41 +0000280 {
281 inlined_depth = GetCurrentInlinedDepth();
282 if (inlined_depth != UINT32_MAX)
283 {
284 if (end_idx > 0)
285 end_idx += inlined_depth;
286 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000287 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000288
Jason Molendab57e4a12013-11-04 09:33:30 +0000289 StackFrameSP unwind_frame_sp;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000290 do
291 {
292 uint32_t idx = m_concrete_frames_fetched++;
Greg Clayton8012cad2014-11-17 19:39:20 +0000293 lldb::addr_t pc = LLDB_INVALID_ADDRESS;
294 lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000295 if (idx == 0)
296 {
297 // We might have already created frame zero, only create it
298 // if we need to
299 if (m_frames.empty())
300 {
Greg Claytonb3ae8762013-04-12 20:07:46 +0000301 RegisterContextSP reg_ctx_sp (m_thread.GetRegisterContext());
Jim Ingham376c4852012-03-01 02:53:40 +0000302
Greg Claytonb3ae8762013-04-12 20:07:46 +0000303 if (reg_ctx_sp)
304 {
305
Greg Claytonec6829e2013-11-22 21:03:42 +0000306 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
Greg Claytonb3ae8762013-04-12 20:07:46 +0000307 // There shouldn't be any way not to get the frame info for frame 0.
308 // But if the unwinder can't make one, lets make one by hand with the
309 // SP as the CFA and see if that gets any further.
310 if (!success)
311 {
312 cfa = reg_ctx_sp->GetSP();
313 pc = reg_ctx_sp->GetPC();
314 }
315
316 unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(),
317 m_frames.size(),
318 idx,
319 reg_ctx_sp,
320 cfa,
321 pc,
322 NULL));
323 m_frames.push_back (unwind_frame_sp);
324 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000325 }
326 else
327 {
328 unwind_frame_sp = m_frames.front();
Jason Molendab57e4a12013-11-04 09:33:30 +0000329 cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000330 }
331 }
332 else
333 {
Greg Claytonec6829e2013-11-22 21:03:42 +0000334 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000335 if (!success)
336 {
337 // We've gotten to the end of the stack.
338 SetAllFramesFetched();
339 break;
340 }
Jason Molenda99618472013-11-04 11:02:52 +0000341 const bool cfa_is_valid = true;
342 const bool stop_id_is_valid = false;
343 const bool is_history_frame = false;
344 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 +0000345 m_frames.push_back (unwind_frame_sp);
346 }
347
Ed Masteff1b5c42015-02-23 18:12:20 +0000348 assert(unwind_frame_sp);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000349 SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction);
350 Block *unwind_block = unwind_sc.block;
351 if (unwind_block)
352 {
353 Address curr_frame_address (unwind_frame_sp->GetFrameCodeAddress());
354 // Be sure to adjust the frame address to match the address
355 // that was used to lookup the symbol context above. If we are
356 // in the first concrete frame, then we lookup using the current
357 // address, else we decrement the address by one to get the correct
358 // location.
359 if (idx > 0)
Tamas Berghammer0f8452b2015-06-01 10:38:23 +0000360 {
361 if (curr_frame_address.GetOffset() == 0)
362 {
363 // If curr_frame_address points to the first address in a section then after
364 // adjustment it will point to an other section. In that case resolve the
365 // address again to the correct section plus offset form.
366 TargetSP target = m_thread.CalculateTarget();
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000367 addr_t load_addr = curr_frame_address.GetOpcodeLoadAddress(target.get(), eAddressClassCode);
368 curr_frame_address.SetOpcodeLoadAddress(load_addr - 1, target.get(), eAddressClassCode);
Tamas Berghammer0f8452b2015-06-01 10:38:23 +0000369 }
370 else
371 {
372 curr_frame_address.Slide(-1);
373 }
374 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000375
376 SymbolContext next_frame_sc;
377 Address next_frame_address;
378
379 while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address))
380 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000381 StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(),
Jim Inghamb0c72a52012-02-29 03:40:22 +0000382 m_frames.size(),
383 idx,
384 unwind_frame_sp->GetRegisterContextSP (),
385 cfa,
386 next_frame_address,
387 &next_frame_sc));
388
389 m_frames.push_back (frame_sp);
390 unwind_sc = next_frame_sc;
391 curr_frame_address = next_frame_address;
392 }
393 }
394 } while (m_frames.size() - 1 < end_idx);
395
396 // Don't try to merge till you've calculated all the frames in this stack.
397 if (GetAllFramesFetched() && m_prev_frames_sp)
398 {
399 StackFrameList *prev_frames = m_prev_frames_sp.get();
400 StackFrameList *curr_frames = this;
Jim Ingham9786eee2012-09-06 19:24:57 +0000401
Jim Ingham6cd41da2012-09-07 23:35:54 +0000402 //curr_frames->m_current_inlined_depth = prev_frames->m_current_inlined_depth;
403 //curr_frames->m_current_inlined_pc = prev_frames->m_current_inlined_pc;
Daniel Malead01b2952012-11-29 21:49:15 +0000404 //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 +0000405
406#if defined (DEBUG_STACK_FRAMES)
407 s.PutCString("\nprev_frames:\n");
408 prev_frames->Dump (&s);
409 s.PutCString("\ncurr_frames:\n");
410 curr_frames->Dump (&s);
411 s.EOL();
412#endif
413 size_t curr_frame_num, prev_frame_num;
414
415 for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size();
416 curr_frame_num > 0 && prev_frame_num > 0;
417 --curr_frame_num, --prev_frame_num)
418 {
419 const size_t curr_frame_idx = curr_frame_num-1;
420 const size_t prev_frame_idx = prev_frame_num-1;
Jason Molendab57e4a12013-11-04 09:33:30 +0000421 StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]);
422 StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000423
424#if defined (DEBUG_STACK_FRAMES)
425 s.Printf("\n\nCurr frame #%u ", curr_frame_idx);
426 if (curr_frame_sp)
427 curr_frame_sp->Dump (&s, true, false);
428 else
429 s.PutCString("NULL");
430 s.Printf("\nPrev frame #%u ", prev_frame_idx);
431 if (prev_frame_sp)
432 prev_frame_sp->Dump (&s, true, false);
433 else
434 s.PutCString("NULL");
435#endif
436
Jason Molendab57e4a12013-11-04 09:33:30 +0000437 StackFrame *curr_frame = curr_frame_sp.get();
438 StackFrame *prev_frame = prev_frame_sp.get();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000439
440 if (curr_frame == NULL || prev_frame == NULL)
441 break;
442
443 // Check the stack ID to make sure they are equal
444 if (curr_frame->GetStackID() != prev_frame->GetStackID())
445 break;
446
447 prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame);
448 // Now copy the fixed up previous frame into the current frames
449 // so the pointer doesn't change
450 m_frames[curr_frame_idx] = prev_frame_sp;
451 //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame);
452
453#if defined (DEBUG_STACK_FRAMES)
454 s.Printf("\n Copying previous frame to current frame");
455#endif
456 }
457 // We are done with the old stack frame list, we can release it now
458 m_prev_frames_sp.reset();
459 }
460
461#if defined (DEBUG_STACK_FRAMES)
Stephane Sezercdb2a112015-10-15 22:24:17 +0000462 s.PutCString("\n\nNew frames:\n");
463 Dump (&s);
464 s.EOL();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000465#endif
466 }
467 else
468 {
469 if (end_idx < m_concrete_frames_fetched)
470 return;
Greg Claytonec6829e2013-11-22 21:03:42 +0000471
472 if (unwinder)
Jim Inghamb0c72a52012-02-29 03:40:22 +0000473 {
Greg Claytonec6829e2013-11-22 21:03:42 +0000474 uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
475 if (num_frames <= end_idx + 1)
476 {
477 //Done unwinding.
478 m_concrete_frames_fetched = UINT32_MAX;
479 }
480 m_frames.resize(num_frames);
Jim Inghamb0c72a52012-02-29 03:40:22 +0000481 }
Jim Inghamb0c72a52012-02-29 03:40:22 +0000482 }
483}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484
485uint32_t
Greg Clayton2cad65a2010-09-03 17:10:42 +0000486StackFrameList::GetNumFrames (bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
488 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000489
Jim Inghamb0c72a52012-02-29 03:40:22 +0000490 if (can_create)
491 GetFramesUpTo (UINT32_MAX);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000492
493 uint32_t inlined_depth = GetCurrentInlinedDepth();
494 if (inlined_depth == UINT32_MAX)
495 return m_frames.size();
496 else
497 return m_frames.size() - inlined_depth;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000498}
499
500void
501StackFrameList::Dump (Stream *s)
502{
503 if (s == NULL)
504 return;
505 Mutex::Locker locker (m_mutex);
506
507 const_iterator pos, begin = m_frames.begin(), end = m_frames.end();
508 for (pos = begin; pos != end; ++pos)
Greg Clayton12daf9462010-08-25 00:35:26 +0000509 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000510 StackFrame *frame = (*pos).get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000511 s->Printf("%p: ", static_cast<void*>(frame));
Greg Clayton5082c5f2010-08-27 18:24:16 +0000512 if (frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000513 {
514 frame->GetStackID().Dump (s);
Greg Clayton0603aa92010-10-04 01:05:56 +0000515 frame->DumpUsingSettingsFormat (s);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000516 }
Greg Clayton5082c5f2010-08-27 18:24:16 +0000517 else
Greg Claytondce502e2011-11-04 03:34:56 +0000518 s->Printf("frame #%u", (uint32_t)std::distance (begin, pos));
Greg Clayton5082c5f2010-08-27 18:24:16 +0000519 s->EOL();
Greg Clayton12daf9462010-08-25 00:35:26 +0000520 }
Greg Clayton5082c5f2010-08-27 18:24:16 +0000521 s->EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522}
523
Jason Molendab57e4a12013-11-04 09:33:30 +0000524StackFrameSP
Greg Clayton12daf9462010-08-25 00:35:26 +0000525StackFrameList::GetFrameAtIndex (uint32_t idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526{
Jason Molendab57e4a12013-11-04 09:33:30 +0000527 StackFrameSP frame_sp;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000528 Mutex::Locker locker (m_mutex);
Jim Ingham5cb9a182013-03-28 00:13:30 +0000529 uint32_t original_idx = idx;
530
Jim Ingham513c6bb2012-09-01 01:02:41 +0000531 uint32_t inlined_depth = GetCurrentInlinedDepth();
532 if (inlined_depth != UINT32_MAX)
533 idx += inlined_depth;
534
Greg Clayton5082c5f2010-08-27 18:24:16 +0000535 if (idx < m_frames.size())
536 frame_sp = m_frames[idx];
537
538 if (frame_sp)
539 return frame_sp;
Greg Clayton0445d8f2010-08-26 02:28:22 +0000540
Jim Ingham5cb9a182013-03-28 00:13:30 +0000541 // GetFramesUpTo will fill m_frames with as many frames as you asked for,
542 // if there are that many. If there weren't then you asked for too many
543 // frames.
544 GetFramesUpTo (idx);
545 if (idx < m_frames.size())
546 {
547 if (m_show_inlined_frames)
Greg Clayton5082c5f2010-08-27 18:24:16 +0000548 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000549 // When inline frames are enabled we actually create all the frames in GetFramesUpTo.
550 frame_sp = m_frames[idx];
551 }
552 else
553 {
554 Unwind *unwinder = m_thread.GetUnwinder ();
555 if (unwinder)
Greg Clayton5082c5f2010-08-27 18:24:16 +0000556 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000557 addr_t pc, cfa;
558 if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
Greg Clayton5082c5f2010-08-27 18:24:16 +0000559 {
Jason Molenda99618472013-11-04 11:02:52 +0000560 const bool cfa_is_valid = true;
561 const bool stop_id_is_valid = false;
562 const bool is_history_frame = false;
563 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 +0000564
565 Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
566 if (function)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000567 {
Jim Ingham5cb9a182013-03-28 00:13:30 +0000568 // When we aren't showing inline functions we always use
569 // the top most function block as the scope.
570 frame_sp->SetSymbolContextScope (&function->GetBlock(false));
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000571 }
Jim Ingham5cb9a182013-03-28 00:13:30 +0000572 else
573 {
574 // Set the symbol scope from the symbol regardless if it is NULL or valid.
575 frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
576 }
577 SetFrameAtIndex(idx, frame_sp);
Greg Clayton5082c5f2010-08-27 18:24:16 +0000578 }
579 }
Greg Clayton12daf9462010-08-25 00:35:26 +0000580 }
Jim Ingham5cb9a182013-03-28 00:13:30 +0000581 }
582 else if (original_idx == 0)
583 {
584 // There should ALWAYS be a frame at index 0. If something went wrong with the CurrentInlinedDepth such that
585 // there weren't as many frames as we thought taking that into account, then reset the current inlined depth
586 // and return the real zeroth frame.
587 if (m_frames.size() > 0)
588 {
589 ResetCurrentInlinedDepth();
590 frame_sp = m_frames[original_idx];
591 }
592 else
593 {
594 // Why do we have a thread with zero frames, that should not ever happen...
595 if (m_thread.IsValid())
596 assert ("A valid thread has no frames.");
597
598 }
599 }
600
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 return frame_sp;
602}
603
Jason Molendab57e4a12013-11-04 09:33:30 +0000604StackFrameSP
Greg Clayton5ccbd292011-01-06 22:15:06 +0000605StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
606{
607 // First try assuming the unwind index is the same as the frame index. The
608 // unwind index is always greater than or equal to the frame index, so it
609 // is a good place to start. If we have inlined frames we might have 5
610 // concrete frames (frame unwind indexes go from 0-4), but we might have 15
611 // frames after we make all the inlined frames. Most of the time the unwind
612 // frame index (or the concrete frame index) is the same as the frame index.
613 uint32_t frame_idx = unwind_idx;
Jason Molendab57e4a12013-11-04 09:33:30 +0000614 StackFrameSP frame_sp (GetFrameAtIndex (frame_idx));
Greg Clayton5ccbd292011-01-06 22:15:06 +0000615 while (frame_sp)
616 {
617 if (frame_sp->GetFrameIndex() == unwind_idx)
618 break;
619 frame_sp = GetFrameAtIndex (++frame_idx);
620 }
621 return frame_sp;
622}
623
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000624static bool
Jason Molendab57e4a12013-11-04 09:33:30 +0000625CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id)
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000626{
627 return stack_sp->GetStackID() < stack_id;
628}
629
Jason Molendab57e4a12013-11-04 09:33:30 +0000630StackFrameSP
Greg Claytoncc4d0142012-02-17 07:49:44 +0000631StackFrameList::GetFrameWithStackID (const StackID &stack_id)
Jim Ingham3a195b72011-03-31 00:15:49 +0000632{
Jason Molendab57e4a12013-11-04 09:33:30 +0000633 StackFrameSP frame_sp;
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000634
635 if (stack_id.IsValid())
Jim Ingham3a195b72011-03-31 00:15:49 +0000636 {
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000637 Mutex::Locker locker (m_mutex);
638 uint32_t frame_idx = 0;
639 // Do a binary search in case the stack frame is already in our cache
640 collection::const_iterator begin = m_frames.begin();
641 collection::const_iterator end = m_frames.end();
642 if (begin != end)
643 {
644 collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID);
Greg Clayton8012cad2014-11-17 19:39:20 +0000645 if (pos != end)
646 {
647 if ((*pos)->GetStackID() == stack_id)
648 return *pos;
649 }
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000650
Greg Clayton8012cad2014-11-17 19:39:20 +0000651// if (m_frames.back()->GetStackID() < stack_id)
652// frame_idx = m_frames.size();
Greg Clayton7bcb93d2013-05-24 00:58:29 +0000653 }
654 do
655 {
656 frame_sp = GetFrameAtIndex (frame_idx);
657 if (frame_sp && frame_sp->GetStackID() == stack_id)
658 break;
659 frame_idx++;
660 }
661 while (frame_sp);
Jim Ingham3a195b72011-03-31 00:15:49 +0000662 }
Jim Ingham3a195b72011-03-31 00:15:49 +0000663 return frame_sp;
664}
Greg Clayton5ccbd292011-01-06 22:15:06 +0000665
Greg Clayton12daf9462010-08-25 00:35:26 +0000666bool
Jason Molendab57e4a12013-11-04 09:33:30 +0000667StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
Greg Clayton12daf9462010-08-25 00:35:26 +0000668{
Greg Clayton5082c5f2010-08-27 18:24:16 +0000669 if (idx >= m_frames.size())
670 m_frames.resize(idx + 1);
Greg Clayton12daf9462010-08-25 00:35:26 +0000671 // Make sure allocation succeeded by checking bounds again
Greg Clayton5082c5f2010-08-27 18:24:16 +0000672 if (idx < m_frames.size())
Greg Clayton12daf9462010-08-25 00:35:26 +0000673 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000674 m_frames[idx] = frame_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000675 return true;
676 }
677 return false; // resize failed, out of memory?
678}
679
680uint32_t
Jim Ingham2976d002010-08-26 21:32:51 +0000681StackFrameList::GetSelectedFrameIndex () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682{
683 Mutex::Locker locker (m_mutex);
Jim Ingham2976d002010-08-26 21:32:51 +0000684 return m_selected_frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685}
686
687
688uint32_t
Jason Molendab57e4a12013-11-04 09:33:30 +0000689StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690{
691 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000692 const_iterator pos;
Greg Clayton5082c5f2010-08-27 18:24:16 +0000693 const_iterator begin = m_frames.begin();
694 const_iterator end = m_frames.end();
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000695 m_selected_frame_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 for (pos = begin; pos != end; ++pos)
697 {
698 if (pos->get() == frame)
699 {
Jim Ingham2976d002010-08-26 21:32:51 +0000700 m_selected_frame_idx = std::distance (begin, pos);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000701 uint32_t inlined_depth = GetCurrentInlinedDepth();
702 if (inlined_depth != UINT32_MAX)
703 m_selected_frame_idx -= inlined_depth;
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000704 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 }
706 }
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000707 SetDefaultFileAndLineToSelectedFrame();
Jim Ingham2976d002010-08-26 21:32:51 +0000708 return m_selected_frame_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709}
710
711// Mark a stack frame as the current frame using the frame index
Jim Inghamb0c72a52012-02-29 03:40:22 +0000712bool
Jim Ingham2976d002010-08-26 21:32:51 +0000713StackFrameList::SetSelectedFrameByIndex (uint32_t idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714{
715 Mutex::Locker locker (m_mutex);
Jason Molendab57e4a12013-11-04 09:33:30 +0000716 StackFrameSP frame_sp (GetFrameAtIndex (idx));
Jim Inghamb0c72a52012-02-29 03:40:22 +0000717 if (frame_sp)
718 {
719 SetSelectedFrame(frame_sp.get());
720 return true;
721 }
722 else
723 return false;
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000724}
725
726void
727StackFrameList::SetDefaultFileAndLineToSelectedFrame()
728{
Greg Clayton1ac04c32012-02-21 00:09:25 +0000729 if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID())
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000730 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000731 StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex()));
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000732 if (frame_sp)
733 {
Greg Clayton252d0ed2011-10-05 03:14:31 +0000734 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry);
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000735 if (sc.line_entry.file)
Greg Clayton1ac04c32012-02-21 00:09:25 +0000736 m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file,
Greg Clayton252d0ed2011-10-05 03:14:31 +0000737 sc.line_entry.line);
Jim Inghamb7f6b2f2011-09-08 22:13:49 +0000738 }
739 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740}
741
742// The thread has been run, reset the number stack frames to zero so we can
743// determine how many frames we have lazily.
744void
745StackFrameList::Clear ()
746{
747 Mutex::Locker locker (m_mutex);
Greg Clayton5082c5f2010-08-27 18:24:16 +0000748 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +0000749 m_concrete_frames_fetched = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750}
751
752void
753StackFrameList::InvalidateFrames (uint32_t start_idx)
754{
755 Mutex::Locker locker (m_mutex);
Greg Clayton12daf9462010-08-25 00:35:26 +0000756 if (m_show_inlined_frames)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 {
Greg Clayton12daf9462010-08-25 00:35:26 +0000758 Clear();
759 }
760 else
761 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000762 const size_t num_frames = m_frames.size();
Greg Clayton12daf9462010-08-25 00:35:26 +0000763 while (start_idx < num_frames)
764 {
Greg Clayton5082c5f2010-08-27 18:24:16 +0000765 m_frames[start_idx].reset();
Greg Clayton12daf9462010-08-25 00:35:26 +0000766 ++start_idx;
767 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768 }
769}
Greg Clayton2cad65a2010-09-03 17:10:42 +0000770
771void
Greg Clayton7b0992d2013-04-18 22:45:39 +0000772StackFrameList::Merge (std::unique_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
Greg Clayton2cad65a2010-09-03 17:10:42 +0000773{
Jim Ingham10ebffa2012-05-04 23:02:50 +0000774 Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL);
775 Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000776
777#if defined (DEBUG_STACK_FRAMES)
Johnny Chen2c595272011-08-25 17:27:02 +0000778 StreamFile s(stdout, false);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000779 s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n");
780 if (prev_sp.get())
781 prev_sp->Dump (&s);
782 else
783 s.PutCString ("NULL");
784 s.PutCString("\nCurr:\n");
785 if (curr_ap.get())
786 curr_ap->Dump (&s);
787 else
788 s.PutCString ("NULL");
789 s.EOL();
790#endif
791
792 if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0)
793 {
794#if defined (DEBUG_STACK_FRAMES)
795 s.PutCString("No current frames, leave previous frames alone...\n");
796#endif
797 curr_ap.release();
798 return;
799 }
800
801 if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0)
802 {
803#if defined (DEBUG_STACK_FRAMES)
804 s.PutCString("No previous frames, so use current frames...\n");
805#endif
806 // We either don't have any previous frames, or since we have more than
807 // one current frames it means we have all the frames and can safely
808 // replace our previous frames.
809 prev_sp.reset (curr_ap.release());
810 return;
811 }
812
813 const uint32_t num_curr_frames = curr_ap->GetNumFrames (false);
814
815 if (num_curr_frames > 1)
816 {
817#if defined (DEBUG_STACK_FRAMES)
818 s.PutCString("We have more than one current frame, so use current frames...\n");
819#endif
820 // We have more than one current frames it means we have all the frames
821 // and can safely replace our previous frames.
822 prev_sp.reset (curr_ap.release());
823
824#if defined (DEBUG_STACK_FRAMES)
825 s.PutCString("\nMerged:\n");
826 prev_sp->Dump (&s);
827#endif
828 return;
829 }
830
Jason Molendab57e4a12013-11-04 09:33:30 +0000831 StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0));
832 StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0));
Greg Clayton2cad65a2010-09-03 17:10:42 +0000833 StackID curr_stack_id (curr_frame_zero_sp->GetStackID());
834 StackID prev_stack_id (prev_frame_zero_sp->GetStackID());
835
Greg Clayton2cad65a2010-09-03 17:10:42 +0000836#if defined (DEBUG_STACK_FRAMES)
Johnny Chen2c595272011-08-25 17:27:02 +0000837 const uint32_t num_prev_frames = prev_sp->GetNumFrames (false);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000838 s.Printf("\n%u previous frames with one current frame\n", num_prev_frames);
839#endif
840
841 // We have only a single current frame
842 // Our previous stack frames only had a single frame as well...
843 if (curr_stack_id == prev_stack_id)
844 {
845#if defined (DEBUG_STACK_FRAMES)
846 s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n");
847#endif
848
849 curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp);
850// prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp);
851// prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp);
852 }
853 else if (curr_stack_id < prev_stack_id)
854 {
855#if defined (DEBUG_STACK_FRAMES)
856 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");
857#endif
858 prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp);
859 }
860
861 curr_ap.release();
862
863#if defined (DEBUG_STACK_FRAMES)
864 s.PutCString("\nMerged:\n");
865 prev_sp->Dump (&s);
866#endif
867
868
869}
Jim Inghame4284b72010-09-23 17:40:12 +0000870
Jason Molendab57e4a12013-11-04 09:33:30 +0000871lldb::StackFrameSP
872StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
Jim Inghame4284b72010-09-23 17:40:12 +0000873{
874 const_iterator pos;
875 const_iterator begin = m_frames.begin();
876 const_iterator end = m_frames.end();
Jason Molendab57e4a12013-11-04 09:33:30 +0000877 lldb::StackFrameSP ret_sp;
Jim Inghame4284b72010-09-23 17:40:12 +0000878
879 for (pos = begin; pos != end; ++pos)
880 {
881 if (pos->get() == stack_frame_ptr)
882 {
883 ret_sp = (*pos);
884 break;
885 }
886 }
887 return ret_sp;
888}
889
Greg Clayton7260f622011-04-18 08:33:37 +0000890size_t
891StackFrameList::GetStatus (Stream& strm,
892 uint32_t first_frame,
893 uint32_t num_frames,
894 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000895 uint32_t num_frames_with_source,
896 const char *selected_frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +0000897{
898 size_t num_frames_displayed = 0;
899
900 if (num_frames == 0)
901 return 0;
902
Jason Molendab57e4a12013-11-04 09:33:30 +0000903 StackFrameSP frame_sp;
Greg Clayton7260f622011-04-18 08:33:37 +0000904 uint32_t frame_idx = 0;
905 uint32_t last_frame;
906
907 // Don't let the last frame wrap around...
908 if (num_frames == UINT32_MAX)
909 last_frame = UINT32_MAX;
910 else
911 last_frame = first_frame + num_frames;
912
Jason Molendab57e4a12013-11-04 09:33:30 +0000913 StackFrameSP selected_frame_sp = m_thread.GetSelectedFrame();
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000914 const char *unselected_marker = NULL;
915 std::string buffer;
916 if (selected_frame_marker)
917 {
918 size_t len = strlen(selected_frame_marker);
919 buffer.insert(buffer.begin(), len, ' ');
920 unselected_marker = buffer.c_str();
921 }
922 const char *marker = NULL;
923
Greg Clayton7260f622011-04-18 08:33:37 +0000924 for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx)
925 {
926 frame_sp = GetFrameAtIndex(frame_idx);
927 if (frame_sp.get() == NULL)
928 break;
929
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000930 if (selected_frame_marker != NULL)
931 {
932 if (frame_sp == selected_frame_sp)
933 marker = selected_frame_marker;
934 else
935 marker = unselected_marker;
936 }
937
Greg Clayton7260f622011-04-18 08:33:37 +0000938 if (!frame_sp->GetStatus (strm,
939 show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +0000940 num_frames_with_source > (first_frame - frame_idx), marker))
Greg Clayton7260f622011-04-18 08:33:37 +0000941 break;
942 ++num_frames_displayed;
943 }
944
945 strm.IndentLess();
946 return num_frames_displayed;
947}
948