1 //===-- StackFrameList.cpp --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/StackFrameList.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/BreakpointLocation.h"
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/StreamFile.h"
20 #include "lldb/Core/SourceManager.h"
21 #include "lldb/Symbol/Block.h"
22 #include "lldb/Symbol/Function.h"
23 #include "lldb/Symbol/Symbol.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Target/RegisterContext.h"
26 #include "lldb/Target/StackFrame.h"
27 #include "lldb/Target/StopInfo.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
30 #include "lldb/Target/Unwind.h"
32 //#define DEBUG_STACK_FRAMES 1
35 using namespace lldb_private;
37 //----------------------------------------------------------------------
38 // StackFrameList constructor
39 //----------------------------------------------------------------------
40 StackFrameList::StackFrameList
43 const lldb::StackFrameListSP &prev_frames_sp,
44 bool show_inline_frames
47 m_prev_frames_sp (prev_frames_sp),
48 m_mutex (Mutex::eMutexTypeRecursive),
50 m_selected_frame_idx (0),
51 m_concrete_frames_fetched (0),
52 m_current_inlined_depth (UINT32_MAX),
53 m_current_inlined_pc (LLDB_INVALID_ADDRESS),
54 m_show_inlined_frames (show_inline_frames)
58 m_current_inlined_depth = prev_frames_sp->m_current_inlined_depth;
59 m_current_inlined_pc = prev_frames_sp->m_current_inlined_pc;
63 //----------------------------------------------------------------------
65 //----------------------------------------------------------------------
66 StackFrameList::~StackFrameList()
68 // 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
74 StackFrameList::CalculateCurrentInlinedDepth()
76 uint32_t cur_inlined_depth = GetCurrentInlinedDepth();
77 if (cur_inlined_depth == UINT32_MAX)
79 ResetCurrentInlinedDepth();
84 StackFrameList::GetCurrentInlinedDepth ()
86 if (m_show_inlined_frames && m_current_inlined_pc != LLDB_INVALID_ADDRESS)
88 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
89 if (cur_pc != m_current_inlined_pc)
91 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
92 m_current_inlined_depth = UINT32_MAX;
93 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
94 if (log && log->GetVerbose())
95 log->Printf ("GetCurrentInlinedDepth: invalidating current inlined depth.\n");
97 return m_current_inlined_depth;
106 StackFrameList::ResetCurrentInlinedDepth ()
108 Mutex::Locker locker (m_mutex);
110 if (m_show_inlined_frames)
113 if (m_frames.size() == 0)
115 if (!m_frames[0]->IsInlined())
117 m_current_inlined_depth = UINT32_MAX;
118 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
119 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
120 if (log && log->GetVerbose())
121 log->Printf ("ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
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.
131 lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC();
132 Block *block_ptr = m_frames[0]->GetFrameBlock();
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))
140 if (pc_as_address == containing_range.GetBaseAddress())
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();
153 switch (stop_info_sp->GetStopReason())
155 case eStopReasonWatchpoint:
156 case eStopReasonException:
157 case eStopReasonExec:
158 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;
163 case eStopReasonBreakpoint:
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.
168 // 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;
177 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
178 for (uint32_t i = 0; i < num_owners; i++)
180 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
181 if (!bp_ref.IsInternal())
183 all_internal = false;
189 m_current_inlined_pc = curr_pc;
190 m_current_inlined_depth = 0;
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;
201 for (Block *container_ptr = block_ptr->GetInlinedParent();
202 container_ptr != NULL;
203 container_ptr = container_ptr->GetInlinedParent())
205 if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
207 if (pc_as_address != containing_range.GetBaseAddress())
210 num_inlined_functions++;
212 m_current_inlined_pc = curr_pc;
213 m_current_inlined_depth = num_inlined_functions + 1;
214 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
215 if (log && log->GetVerbose())
216 log->Printf ("ResetCurrentInlinedDepth: setting inlined depth: %d 0x%" PRIx64 ".\n", m_current_inlined_depth, curr_pc);
230 StackFrameList::DecrementCurrentInlinedDepth ()
232 if (m_show_inlined_frames)
234 uint32_t current_inlined_depth = GetCurrentInlinedDepth();
235 if (current_inlined_depth != UINT32_MAX)
237 if (current_inlined_depth > 0)
239 m_current_inlined_depth--;
248 StackFrameList::SetCurrentInlinedDepth (uint32_t new_depth)
250 m_current_inlined_depth = new_depth;
251 if (new_depth == UINT32_MAX)
252 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
254 m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
258 StackFrameList::GetFramesUpTo(uint32_t end_idx)
260 // this makes sure we do not fetch frames for an invalid thread
261 if (m_thread.IsValid() == false)
264 // We've already gotten more frames than asked for, or we've already finished unwinding, return.
265 if (m_frames.size() > end_idx || GetAllFramesFetched())
268 Unwind *unwinder = m_thread.GetUnwinder ();
270 if (m_show_inlined_frames)
272 #if defined (DEBUG_STACK_FRAMES)
273 StreamFile s(stdout, false);
275 // If we are hiding some frames from the outside world, we need to add those onto the total count of
276 // frames to fetch. However, we don't need to do that if end_idx is 0 since in that case we always
277 // 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...
280 uint32_t inlined_depth = 0;
281 if (end_idx > 0 && end_idx != UINT32_MAX)
283 inlined_depth = GetCurrentInlinedDepth();
284 if (inlined_depth != UINT32_MAX)
287 end_idx += inlined_depth;
291 StackFrameSP unwind_frame_sp;
294 uint32_t idx = m_concrete_frames_fetched++;
295 lldb::addr_t pc = LLDB_INVALID_ADDRESS;
296 lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
299 // We might have already created frame zero, only create it
301 if (m_frames.empty())
303 RegisterContextSP reg_ctx_sp (m_thread.GetRegisterContext());
308 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
309 // 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.
314 cfa = reg_ctx_sp->GetSP();
315 pc = reg_ctx_sp->GetPC();
318 unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(),
325 m_frames.push_back (unwind_frame_sp);
330 unwind_frame_sp = m_frames.front();
331 cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
336 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
339 // We've gotten to the end of the stack.
340 SetAllFramesFetched();
343 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));
347 m_frames.push_back (unwind_frame_sp);
350 assert(unwind_frame_sp);
351 SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction);
352 Block *unwind_block = unwind_sc.block;
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
363 if (curr_frame_address.GetOffset() == 0)
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();
369 addr_t load_addr = curr_frame_address.GetOpcodeLoadAddress(target.get(), eAddressClassCode);
370 curr_frame_address.SetOpcodeLoadAddress(load_addr - 1, target.get(), eAddressClassCode);
374 curr_frame_address.Slide(-1);
378 SymbolContext next_frame_sc;
379 Address next_frame_address;
381 while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address))
383 StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(),
386 unwind_frame_sp->GetRegisterContextSP (),
391 m_frames.push_back (frame_sp);
392 unwind_sc = next_frame_sc;
393 curr_frame_address = next_frame_address;
396 } while (m_frames.size() - 1 < end_idx);
398 // Don't try to merge till you've calculated all the frames in this stack.
399 if (GetAllFramesFetched() && m_prev_frames_sp)
401 StackFrameList *prev_frames = m_prev_frames_sp.get();
402 StackFrameList *curr_frames = this;
404 //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;
406 //printf ("GetFramesUpTo: Copying current inlined depth: %d 0x%" PRIx64 ".\n", curr_frames->m_current_inlined_depth, curr_frames->m_current_inlined_pc);
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);
415 size_t curr_frame_num, prev_frame_num;
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)
421 const size_t curr_frame_idx = curr_frame_num-1;
422 const size_t prev_frame_idx = prev_frame_num-1;
423 StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]);
424 StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]);
426 #if defined (DEBUG_STACK_FRAMES)
427 s.Printf("\n\nCurr frame #%u ", curr_frame_idx);
429 curr_frame_sp->Dump (&s, true, false);
431 s.PutCString("NULL");
432 s.Printf("\nPrev frame #%u ", prev_frame_idx);
434 prev_frame_sp->Dump (&s, true, false);
436 s.PutCString("NULL");
439 StackFrame *curr_frame = curr_frame_sp.get();
440 StackFrame *prev_frame = prev_frame_sp.get();
442 if (curr_frame == NULL || prev_frame == NULL)
445 // Check the stack ID to make sure they are equal
446 if (curr_frame->GetStackID() != prev_frame->GetStackID())
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);
455 #if defined (DEBUG_STACK_FRAMES)
456 s.Printf("\n Copying previous frame to current frame");
459 // We are done with the old stack frame list, we can release it now
460 m_prev_frames_sp.reset();
463 #if defined (DEBUG_STACK_FRAMES)
464 s.PutCString("\n\nNew frames:\n");
471 if (end_idx < m_concrete_frames_fetched)
476 uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
477 if (num_frames <= end_idx + 1)
480 m_concrete_frames_fetched = UINT32_MAX;
482 m_frames.resize(num_frames);
488 StackFrameList::GetNumFrames (bool can_create)
490 Mutex::Locker locker (m_mutex);
493 GetFramesUpTo (UINT32_MAX);
495 uint32_t inlined_depth = GetCurrentInlinedDepth();
496 if (inlined_depth == UINT32_MAX)
497 return m_frames.size();
499 return m_frames.size() - inlined_depth;
503 StackFrameList::Dump (Stream *s)
507 Mutex::Locker locker (m_mutex);
509 const_iterator pos, begin = m_frames.begin(), end = m_frames.end();
510 for (pos = begin; pos != end; ++pos)
512 StackFrame *frame = (*pos).get();
513 s->Printf("%p: ", static_cast<void*>(frame));
516 frame->GetStackID().Dump (s);
517 frame->DumpUsingSettingsFormat (s);
520 s->Printf("frame #%u", (uint32_t)std::distance (begin, pos));
527 StackFrameList::GetFrameAtIndex (uint32_t idx)
529 StackFrameSP frame_sp;
530 Mutex::Locker locker (m_mutex);
531 uint32_t original_idx = idx;
533 uint32_t inlined_depth = GetCurrentInlinedDepth();
534 if (inlined_depth != UINT32_MAX)
535 idx += inlined_depth;
537 if (idx < m_frames.size())
538 frame_sp = m_frames[idx];
543 // 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
547 if (idx < m_frames.size())
549 if (m_show_inlined_frames)
551 // When inline frames are enabled we actually create all the frames in GetFramesUpTo.
552 frame_sp = m_frames[idx];
556 Unwind *unwinder = m_thread.GetUnwinder ();
560 if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
562 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));
567 Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
570 // 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));
576 // Set the symbol scope from the symbol regardless if it is NULL or valid.
577 frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
579 SetFrameAtIndex(idx, frame_sp);
584 else if (original_idx == 0)
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)
591 ResetCurrentInlinedDepth();
592 frame_sp = m_frames[original_idx];
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.");
607 StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
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;
616 StackFrameSP frame_sp (GetFrameAtIndex (frame_idx));
619 if (frame_sp->GetFrameIndex() == unwind_idx)
621 frame_sp = GetFrameAtIndex (++frame_idx);
627 CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id)
629 return stack_sp->GetStackID() < stack_id;
633 StackFrameList::GetFrameWithStackID (const StackID &stack_id)
635 StackFrameSP frame_sp;
637 if (stack_id.IsValid())
639 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();
646 collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID);
649 if ((*pos)->GetStackID() == stack_id)
653 // if (m_frames.back()->GetStackID() < stack_id)
654 // frame_idx = m_frames.size();
658 frame_sp = GetFrameAtIndex (frame_idx);
659 if (frame_sp && frame_sp->GetStackID() == stack_id)
669 StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
671 if (idx >= m_frames.size())
672 m_frames.resize(idx + 1);
673 // Make sure allocation succeeded by checking bounds again
674 if (idx < m_frames.size())
676 m_frames[idx] = frame_sp;
679 return false; // resize failed, out of memory?
683 StackFrameList::GetSelectedFrameIndex () const
685 Mutex::Locker locker (m_mutex);
686 return m_selected_frame_idx;
691 StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame)
693 Mutex::Locker locker (m_mutex);
695 const_iterator begin = m_frames.begin();
696 const_iterator end = m_frames.end();
697 m_selected_frame_idx = 0;
698 for (pos = begin; pos != end; ++pos)
700 if (pos->get() == frame)
702 m_selected_frame_idx = std::distance (begin, pos);
703 uint32_t inlined_depth = GetCurrentInlinedDepth();
704 if (inlined_depth != UINT32_MAX)
705 m_selected_frame_idx -= inlined_depth;
709 SetDefaultFileAndLineToSelectedFrame();
710 return m_selected_frame_idx;
713 // Mark a stack frame as the current frame using the frame index
715 StackFrameList::SetSelectedFrameByIndex (uint32_t idx)
717 Mutex::Locker locker (m_mutex);
718 StackFrameSP frame_sp (GetFrameAtIndex (idx));
721 SetSelectedFrame(frame_sp.get());
729 StackFrameList::SetDefaultFileAndLineToSelectedFrame()
731 if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID())
733 StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex()));
736 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry);
737 if (sc.line_entry.file)
738 m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file,
744 // The thread has been run, reset the number stack frames to zero so we can
745 // determine how many frames we have lazily.
747 StackFrameList::Clear ()
749 Mutex::Locker locker (m_mutex);
751 m_concrete_frames_fetched = 0;
755 StackFrameList::InvalidateFrames (uint32_t start_idx)
757 Mutex::Locker locker (m_mutex);
758 if (m_show_inlined_frames)
764 const size_t num_frames = m_frames.size();
765 while (start_idx < num_frames)
767 m_frames[start_idx].reset();
774 StackFrameList::Merge (std::unique_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
776 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);
779 #if defined (DEBUG_STACK_FRAMES)
780 StreamFile s(stdout, false);
781 s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n");
785 s.PutCString ("NULL");
786 s.PutCString("\nCurr:\n");
790 s.PutCString ("NULL");
794 if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0)
796 #if defined (DEBUG_STACK_FRAMES)
797 s.PutCString("No current frames, leave previous frames alone...\n");
803 if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0)
805 #if defined (DEBUG_STACK_FRAMES)
806 s.PutCString("No previous frames, so use current frames...\n");
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());
815 const uint32_t num_curr_frames = curr_ap->GetNumFrames (false);
817 if (num_curr_frames > 1)
819 #if defined (DEBUG_STACK_FRAMES)
820 s.PutCString("We have more than one current frame, so use current frames...\n");
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());
826 #if defined (DEBUG_STACK_FRAMES)
827 s.PutCString("\nMerged:\n");
833 StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0));
834 StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0));
835 StackID curr_stack_id (curr_frame_zero_sp->GetStackID());
836 StackID prev_stack_id (prev_frame_zero_sp->GetStackID());
838 #if defined (DEBUG_STACK_FRAMES)
839 const uint32_t num_prev_frames = prev_sp->GetNumFrames (false);
840 s.Printf("\n%u previous frames with one current frame\n", num_prev_frames);
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)
847 #if defined (DEBUG_STACK_FRAMES)
848 s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n");
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);
855 else if (curr_stack_id < prev_stack_id)
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");
860 prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp);
865 #if defined (DEBUG_STACK_FRAMES)
866 s.PutCString("\nMerged:\n");
874 StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
877 const_iterator begin = m_frames.begin();
878 const_iterator end = m_frames.end();
879 lldb::StackFrameSP ret_sp;
881 for (pos = begin; pos != end; ++pos)
883 if (pos->get() == stack_frame_ptr)
893 StackFrameList::GetStatus (Stream& strm,
894 uint32_t first_frame,
896 bool show_frame_info,
897 uint32_t num_frames_with_source,
898 const char *selected_frame_marker)
900 size_t num_frames_displayed = 0;
905 StackFrameSP frame_sp;
906 uint32_t frame_idx = 0;
909 // Don't let the last frame wrap around...
910 if (num_frames == UINT32_MAX)
911 last_frame = UINT32_MAX;
913 last_frame = first_frame + num_frames;
915 StackFrameSP selected_frame_sp = m_thread.GetSelectedFrame();
916 const char *unselected_marker = NULL;
918 if (selected_frame_marker)
920 size_t len = strlen(selected_frame_marker);
921 buffer.insert(buffer.begin(), len, ' ');
922 unselected_marker = buffer.c_str();
924 const char *marker = NULL;
926 for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx)
928 frame_sp = GetFrameAtIndex(frame_idx);
929 if (frame_sp.get() == NULL)
932 if (selected_frame_marker != NULL)
934 if (frame_sp == selected_frame_sp)
935 marker = selected_frame_marker;
937 marker = unselected_marker;
940 if (!frame_sp->GetStatus (strm,
942 num_frames_with_source > (first_frame - frame_idx), marker))
944 ++num_frames_displayed;
948 return num_frames_displayed;