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 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/Target/StackFrameList.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Breakpoint/Breakpoint.h"
17 #include "lldb/Core/Log.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Core/SourceManager.h"
20 #include "lldb/Symbol/Block.h"
21 #include "lldb/Symbol/Function.h"
22 #include "lldb/Symbol/Symbol.h"
23 #include "lldb/Target/Process.h"
24 #include "lldb/Target/RegisterContext.h"
25 #include "lldb/Target/StackFrame.h"
26 #include "lldb/Target/StopInfo.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/Thread.h"
29 #include "lldb/Target/Unwind.h"
31 //#define DEBUG_STACK_FRAMES 1
34 using namespace lldb_private;
36 //----------------------------------------------------------------------
37 // StackFrameList constructor
38 //----------------------------------------------------------------------
39 StackFrameList::StackFrameList(Thread &thread, const lldb::StackFrameListSP &prev_frames_sp, bool show_inline_frames)
41 m_prev_frames_sp(prev_frames_sp),
44 m_selected_frame_idx(0),
45 m_concrete_frames_fetched(0),
46 m_current_inlined_depth(UINT32_MAX),
47 m_current_inlined_pc(LLDB_INVALID_ADDRESS),
48 m_show_inlined_frames(show_inline_frames)
52 m_current_inlined_depth = prev_frames_sp->m_current_inlined_depth;
53 m_current_inlined_pc = prev_frames_sp->m_current_inlined_pc;
57 StackFrameList::~StackFrameList()
59 // Call clear since this takes a lock and clears the stack frame list
60 // in case another thread is currently using this stack frame list
65 StackFrameList::CalculateCurrentInlinedDepth()
67 uint32_t cur_inlined_depth = GetCurrentInlinedDepth();
68 if (cur_inlined_depth == UINT32_MAX)
70 ResetCurrentInlinedDepth();
75 StackFrameList::GetCurrentInlinedDepth ()
77 if (m_show_inlined_frames && m_current_inlined_pc != LLDB_INVALID_ADDRESS)
79 lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
80 if (cur_pc != m_current_inlined_pc)
82 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
83 m_current_inlined_depth = UINT32_MAX;
84 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
85 if (log && log->GetVerbose())
86 log->Printf ("GetCurrentInlinedDepth: invalidating current inlined depth.\n");
88 return m_current_inlined_depth;
97 StackFrameList::ResetCurrentInlinedDepth ()
99 std::lock_guard<std::recursive_mutex> guard(m_mutex);
101 if (m_show_inlined_frames)
104 if (m_frames.empty())
106 if (!m_frames[0]->IsInlined())
108 m_current_inlined_depth = UINT32_MAX;
109 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
110 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
111 if (log && log->GetVerbose())
112 log->Printf ("ResetCurrentInlinedDepth: Invalidating current inlined depth.\n");
116 // We only need to do something special about inlined blocks when we
117 // are at the beginning of an inlined function:
118 // FIXME: We probably also have to do something special if the PC is at the END
119 // of an inlined function, which coincides with the end of either its containing
120 // function or another inlined function.
122 lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC();
123 Block *block_ptr = m_frames[0]->GetFrameBlock();
126 Address pc_as_address;
127 pc_as_address.SetLoadAddress(curr_pc, &(m_thread.GetProcess()->GetTarget()));
128 AddressRange containing_range;
129 if (block_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
131 if (pc_as_address == containing_range.GetBaseAddress())
133 // If we got here because of a breakpoint hit, then set the inlined depth depending on where
134 // the breakpoint was set.
135 // If we got here because of a crash, then set the inlined depth to the deepest most block.
136 // Otherwise, we stopped here naturally as the result of a step, so set ourselves in the
137 // containing frame of the whole set of nested inlines, so the user can then "virtually"
138 // step into the frames one by one, or next over the whole mess.
139 // Note: We don't have to handle being somewhere in the middle of the stack here, since
140 // ResetCurrentInlinedDepth doesn't get called if there is a valid inlined depth set.
141 StopInfoSP stop_info_sp = m_thread.GetStopInfo();
144 switch (stop_info_sp->GetStopReason())
146 case eStopReasonWatchpoint:
147 case eStopReasonException:
148 case eStopReasonExec:
149 case eStopReasonSignal:
150 // In all these cases we want to stop in the deepest most frame.
151 m_current_inlined_pc = curr_pc;
152 m_current_inlined_depth = 0;
154 case eStopReasonBreakpoint:
156 // FIXME: Figure out what this break point is doing, and set the inline depth
157 // appropriately. Be careful to take into account breakpoints that implement
158 // step over prologue, since that should do the default calculation.
159 // For now, if the breakpoints corresponding to this hit are all internal,
160 // I set the stop location to the top of the inlined stack, since that will make
161 // things like stepping over prologues work right. But if there are any non-internal
162 // breakpoints I do to the bottom of the stack, since that was the old behavior.
163 uint32_t bp_site_id = stop_info_sp->GetValue();
164 BreakpointSiteSP bp_site_sp(m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id));
165 bool all_internal = true;
168 uint32_t num_owners = bp_site_sp->GetNumberOfOwners();
169 for (uint32_t i = 0; i < num_owners; i++)
171 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
172 if (!bp_ref.IsInternal())
174 all_internal = false;
180 m_current_inlined_pc = curr_pc;
181 m_current_inlined_depth = 0;
188 // Otherwise, we should set ourselves at the container of the inlining, so that the
189 // user can descend into them.
190 // So first we check whether we have more than one inlined block sharing this PC:
191 int num_inlined_functions = 0;
193 for (Block *container_ptr = block_ptr->GetInlinedParent();
194 container_ptr != nullptr;
195 container_ptr = container_ptr->GetInlinedParent())
197 if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range))
199 if (pc_as_address != containing_range.GetBaseAddress())
202 num_inlined_functions++;
204 m_current_inlined_pc = curr_pc;
205 m_current_inlined_depth = num_inlined_functions + 1;
206 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
207 if (log && log->GetVerbose())
208 log->Printf ("ResetCurrentInlinedDepth: setting inlined depth: %d 0x%" PRIx64 ".\n", m_current_inlined_depth, curr_pc);
222 StackFrameList::DecrementCurrentInlinedDepth ()
224 if (m_show_inlined_frames)
226 uint32_t current_inlined_depth = GetCurrentInlinedDepth();
227 if (current_inlined_depth != UINT32_MAX)
229 if (current_inlined_depth > 0)
231 m_current_inlined_depth--;
240 StackFrameList::SetCurrentInlinedDepth (uint32_t new_depth)
242 m_current_inlined_depth = new_depth;
243 if (new_depth == UINT32_MAX)
244 m_current_inlined_pc = LLDB_INVALID_ADDRESS;
246 m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC();
250 StackFrameList::GetFramesUpTo(uint32_t end_idx)
252 // this makes sure we do not fetch frames for an invalid thread
253 if (!m_thread.IsValid())
256 // We've already gotten more frames than asked for, or we've already finished unwinding, return.
257 if (m_frames.size() > end_idx || GetAllFramesFetched())
260 Unwind *unwinder = m_thread.GetUnwinder ();
262 if (m_show_inlined_frames)
264 #if defined (DEBUG_STACK_FRAMES)
265 StreamFile s(stdout, false);
267 // If we are hiding some frames from the outside world, we need to add those onto the total count of
268 // frames to fetch. However, we don't need to do that if end_idx is 0 since in that case we always
269 // get the first concrete frame and all the inlined frames below it... And of course, if end_idx is
270 // UINT32_MAX that means get all, so just do that...
272 uint32_t inlined_depth = 0;
273 if (end_idx > 0 && end_idx != UINT32_MAX)
275 inlined_depth = GetCurrentInlinedDepth();
276 if (inlined_depth != UINT32_MAX)
279 end_idx += inlined_depth;
283 StackFrameSP unwind_frame_sp;
286 uint32_t idx = m_concrete_frames_fetched++;
287 lldb::addr_t pc = LLDB_INVALID_ADDRESS;
288 lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
291 // We might have already created frame zero, only create it
293 if (m_frames.empty())
295 RegisterContextSP reg_ctx_sp (m_thread.GetRegisterContext());
299 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
300 // There shouldn't be any way not to get the frame info for frame 0.
301 // But if the unwinder can't make one, lets make one by hand with the
302 // SP as the CFA and see if that gets any further.
305 cfa = reg_ctx_sp->GetSP();
306 pc = reg_ctx_sp->GetPC();
309 unwind_frame_sp.reset(new StackFrame(m_thread.shared_from_this(),
316 m_frames.push_back (unwind_frame_sp);
321 unwind_frame_sp = m_frames.front();
322 cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
327 const bool success = unwinder && unwinder->GetFrameInfoAtIndex(idx, cfa, pc);
330 // We've gotten to the end of the stack.
331 SetAllFramesFetched();
334 const bool cfa_is_valid = true;
335 const bool stop_id_is_valid = false;
336 const bool is_history_frame = false;
337 unwind_frame_sp.reset(new StackFrame(m_thread.shared_from_this(), m_frames.size(), idx, cfa, cfa_is_valid, pc,
338 0, stop_id_is_valid, is_history_frame, nullptr));
339 m_frames.push_back (unwind_frame_sp);
342 assert(unwind_frame_sp);
343 SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction);
344 Block *unwind_block = unwind_sc.block;
347 Address curr_frame_address (unwind_frame_sp->GetFrameCodeAddress());
348 TargetSP target_sp = m_thread.CalculateTarget();
349 // Be sure to adjust the frame address to match the address
350 // that was used to lookup the symbol context above. If we are
351 // in the first concrete frame, then we lookup using the current
352 // address, else we decrement the address by one to get the correct
356 if (curr_frame_address.GetOffset() == 0)
358 // If curr_frame_address points to the first address in a section then after
359 // adjustment it will point to an other section. In that case resolve the
360 // address again to the correct section plus offset form.
361 addr_t load_addr = curr_frame_address.GetOpcodeLoadAddress(target_sp.get(), eAddressClassCode);
362 curr_frame_address.SetOpcodeLoadAddress(load_addr - 1, target_sp.get(), eAddressClassCode);
366 curr_frame_address.Slide(-1);
370 SymbolContext next_frame_sc;
371 Address next_frame_address;
373 while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address))
375 next_frame_sc.line_entry.ApplyFileMappings(target_sp);
\r
376 StackFrameSP frame_sp(new StackFrame(m_thread.shared_from_this(),
379 unwind_frame_sp->GetRegisterContextSP (),
384 m_frames.push_back (frame_sp);
385 unwind_sc = next_frame_sc;
386 curr_frame_address = next_frame_address;
389 } while (m_frames.size() - 1 < end_idx);
391 // Don't try to merge till you've calculated all the frames in this stack.
392 if (GetAllFramesFetched() && m_prev_frames_sp)
394 StackFrameList *prev_frames = m_prev_frames_sp.get();
395 StackFrameList *curr_frames = this;
397 //curr_frames->m_current_inlined_depth = prev_frames->m_current_inlined_depth;
398 //curr_frames->m_current_inlined_pc = prev_frames->m_current_inlined_pc;
399 //printf ("GetFramesUpTo: Copying current inlined depth: %d 0x%" PRIx64 ".\n", curr_frames->m_current_inlined_depth, curr_frames->m_current_inlined_pc);
401 #if defined (DEBUG_STACK_FRAMES)
402 s.PutCString("\nprev_frames:\n");
403 prev_frames->Dump (&s);
404 s.PutCString("\ncurr_frames:\n");
405 curr_frames->Dump (&s);
408 size_t curr_frame_num, prev_frame_num;
410 for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size();
411 curr_frame_num > 0 && prev_frame_num > 0;
412 --curr_frame_num, --prev_frame_num)
414 const size_t curr_frame_idx = curr_frame_num-1;
415 const size_t prev_frame_idx = prev_frame_num-1;
416 StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]);
417 StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]);
419 #if defined (DEBUG_STACK_FRAMES)
420 s.Printf("\n\nCurr frame #%u ", curr_frame_idx);
422 curr_frame_sp->Dump (&s, true, false);
424 s.PutCString("NULL");
425 s.Printf("\nPrev frame #%u ", prev_frame_idx);
427 prev_frame_sp->Dump (&s, true, false);
429 s.PutCString("NULL");
432 StackFrame *curr_frame = curr_frame_sp.get();
433 StackFrame *prev_frame = prev_frame_sp.get();
435 if (curr_frame == nullptr || prev_frame == nullptr)
438 // Check the stack ID to make sure they are equal
439 if (curr_frame->GetStackID() != prev_frame->GetStackID())
442 prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame);
443 // Now copy the fixed up previous frame into the current frames
444 // so the pointer doesn't change
445 m_frames[curr_frame_idx] = prev_frame_sp;
446 //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame);
448 #if defined (DEBUG_STACK_FRAMES)
449 s.Printf("\n Copying previous frame to current frame");
452 // We are done with the old stack frame list, we can release it now
453 m_prev_frames_sp.reset();
456 #if defined (DEBUG_STACK_FRAMES)
457 s.PutCString("\n\nNew frames:\n");
464 if (end_idx < m_concrete_frames_fetched)
469 uint32_t num_frames = unwinder->GetFramesUpTo(end_idx);
470 if (num_frames <= end_idx + 1)
473 m_concrete_frames_fetched = UINT32_MAX;
475 m_frames.resize(num_frames);
481 StackFrameList::GetNumFrames (bool can_create)
483 std::lock_guard<std::recursive_mutex> guard(m_mutex);
486 GetFramesUpTo (UINT32_MAX);
488 uint32_t inlined_depth = GetCurrentInlinedDepth();
489 if (inlined_depth == UINT32_MAX)
490 return m_frames.size();
492 return m_frames.size() - inlined_depth;
496 StackFrameList::Dump (Stream *s)
501 std::lock_guard<std::recursive_mutex> guard(m_mutex);
503 const_iterator pos, begin = m_frames.begin(), end = m_frames.end();
504 for (pos = begin; pos != end; ++pos)
506 StackFrame *frame = (*pos).get();
507 s->Printf("%p: ", static_cast<void*>(frame));
510 frame->GetStackID().Dump (s);
511 frame->DumpUsingSettingsFormat (s);
514 s->Printf("frame #%u", (uint32_t)std::distance (begin, pos));
521 StackFrameList::GetFrameAtIndex (uint32_t idx)
523 StackFrameSP frame_sp;
524 std::lock_guard<std::recursive_mutex> guard(m_mutex);
525 uint32_t original_idx = idx;
527 uint32_t inlined_depth = GetCurrentInlinedDepth();
528 if (inlined_depth != UINT32_MAX)
529 idx += inlined_depth;
531 if (idx < m_frames.size())
532 frame_sp = m_frames[idx];
537 // GetFramesUpTo will fill m_frames with as many frames as you asked for,
538 // if there are that many. If there weren't then you asked for too many
541 if (idx < m_frames.size())
543 if (m_show_inlined_frames)
545 // When inline frames are enabled we actually create all the frames in GetFramesUpTo.
546 frame_sp = m_frames[idx];
550 Unwind *unwinder = m_thread.GetUnwinder ();
554 if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc))
556 const bool cfa_is_valid = true;
557 const bool stop_id_is_valid = false;
558 const bool is_history_frame = false;
559 frame_sp.reset(new StackFrame(m_thread.shared_from_this(), idx, idx, cfa, cfa_is_valid, pc, 0,
560 stop_id_is_valid, is_history_frame, nullptr));
562 Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function;
565 // When we aren't showing inline functions we always use
566 // the top most function block as the scope.
567 frame_sp->SetSymbolContextScope (&function->GetBlock(false));
571 // Set the symbol scope from the symbol regardless if it is nullptr or valid.
572 frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
574 SetFrameAtIndex(idx, frame_sp);
579 else if (original_idx == 0)
581 // There should ALWAYS be a frame at index 0. If something went wrong with the CurrentInlinedDepth such that
582 // there weren't as many frames as we thought taking that into account, then reset the current inlined depth
583 // and return the real zeroth frame.
584 if (m_frames.empty())
586 // Why do we have a thread with zero frames, that should not ever happen...
587 if (m_thread.IsValid())
588 assert ("A valid thread has no frames.");
592 ResetCurrentInlinedDepth();
593 frame_sp = m_frames[original_idx];
601 StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
603 // First try assuming the unwind index is the same as the frame index. The
604 // unwind index is always greater than or equal to the frame index, so it
605 // is a good place to start. If we have inlined frames we might have 5
606 // concrete frames (frame unwind indexes go from 0-4), but we might have 15
607 // frames after we make all the inlined frames. Most of the time the unwind
608 // frame index (or the concrete frame index) is the same as the frame index.
609 uint32_t frame_idx = unwind_idx;
610 StackFrameSP frame_sp (GetFrameAtIndex (frame_idx));
613 if (frame_sp->GetFrameIndex() == unwind_idx)
615 frame_sp = GetFrameAtIndex (++frame_idx);
621 CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id)
623 return stack_sp->GetStackID() < stack_id;
627 StackFrameList::GetFrameWithStackID (const StackID &stack_id)
629 StackFrameSP frame_sp;
631 if (stack_id.IsValid())
633 std::lock_guard<std::recursive_mutex> guard(m_mutex);
634 uint32_t frame_idx = 0;
635 // Do a binary search in case the stack frame is already in our cache
636 collection::const_iterator begin = m_frames.begin();
637 collection::const_iterator end = m_frames.end();
640 collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID);
643 if ((*pos)->GetStackID() == stack_id)
647 // if (m_frames.back()->GetStackID() < stack_id)
648 // frame_idx = m_frames.size();
652 frame_sp = GetFrameAtIndex (frame_idx);
653 if (frame_sp && frame_sp->GetStackID() == stack_id)
663 StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp)
665 if (idx >= m_frames.size())
666 m_frames.resize(idx + 1);
667 // Make sure allocation succeeded by checking bounds again
668 if (idx < m_frames.size())
670 m_frames[idx] = frame_sp;
673 return false; // resize failed, out of memory?
677 StackFrameList::GetSelectedFrameIndex () const
679 std::lock_guard<std::recursive_mutex> guard(m_mutex);
680 return m_selected_frame_idx;
684 StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame)
686 std::lock_guard<std::recursive_mutex> guard(m_mutex);
688 const_iterator begin = m_frames.begin();
689 const_iterator end = m_frames.end();
690 m_selected_frame_idx = 0;
691 for (pos = begin; pos != end; ++pos)
693 if (pos->get() == frame)
695 m_selected_frame_idx = std::distance (begin, pos);
696 uint32_t inlined_depth = GetCurrentInlinedDepth();
697 if (inlined_depth != UINT32_MAX)
698 m_selected_frame_idx -= inlined_depth;
702 SetDefaultFileAndLineToSelectedFrame();
703 return m_selected_frame_idx;
706 // Mark a stack frame as the current frame using the frame index
708 StackFrameList::SetSelectedFrameByIndex (uint32_t idx)
710 std::lock_guard<std::recursive_mutex> guard(m_mutex);
711 StackFrameSP frame_sp (GetFrameAtIndex (idx));
714 SetSelectedFrame(frame_sp.get());
722 StackFrameList::SetDefaultFileAndLineToSelectedFrame()
724 if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID())
726 StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex()));
729 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry);
730 if (sc.line_entry.file)
731 m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file,
737 // The thread has been run, reset the number stack frames to zero so we can
738 // determine how many frames we have lazily.
740 StackFrameList::Clear ()
742 std::lock_guard<std::recursive_mutex> guard(m_mutex);
744 m_concrete_frames_fetched = 0;
748 StackFrameList::InvalidateFrames (uint32_t start_idx)
750 std::lock_guard<std::recursive_mutex> guard(m_mutex);
751 if (m_show_inlined_frames)
757 const size_t num_frames = m_frames.size();
758 while (start_idx < num_frames)
760 m_frames[start_idx].reset();
767 StackFrameList::Merge (std::unique_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
769 std::unique_lock<std::recursive_mutex> current_lock, previous_lock;
771 current_lock = std::unique_lock<std::recursive_mutex>(curr_ap->m_mutex);
773 previous_lock = std::unique_lock<std::recursive_mutex>(prev_sp->m_mutex);
775 #if defined (DEBUG_STACK_FRAMES)
776 StreamFile s(stdout, false);
777 s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n");
781 s.PutCString ("NULL");
782 s.PutCString("\nCurr:\n");
786 s.PutCString ("NULL");
790 if (!curr_ap || curr_ap->GetNumFrames(false) == 0)
792 #if defined (DEBUG_STACK_FRAMES)
793 s.PutCString("No current frames, leave previous frames alone...\n");
799 if (!prev_sp || prev_sp->GetNumFrames(false) == 0)
801 #if defined (DEBUG_STACK_FRAMES)
802 s.PutCString("No previous frames, so use current frames...\n");
804 // We either don't have any previous frames, or since we have more than
805 // one current frames it means we have all the frames and can safely
806 // replace our previous frames.
807 prev_sp.reset (curr_ap.release());
811 const uint32_t num_curr_frames = curr_ap->GetNumFrames (false);
813 if (num_curr_frames > 1)
815 #if defined (DEBUG_STACK_FRAMES)
816 s.PutCString("We have more than one current frame, so use current frames...\n");
818 // We have more than one current frames it means we have all the frames
819 // and can safely replace our previous frames.
820 prev_sp.reset (curr_ap.release());
822 #if defined (DEBUG_STACK_FRAMES)
823 s.PutCString("\nMerged:\n");
829 StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0));
830 StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0));
831 StackID curr_stack_id (curr_frame_zero_sp->GetStackID());
832 StackID prev_stack_id (prev_frame_zero_sp->GetStackID());
834 #if defined (DEBUG_STACK_FRAMES)
835 const uint32_t num_prev_frames = prev_sp->GetNumFrames (false);
836 s.Printf("\n%u previous frames with one current frame\n", num_prev_frames);
839 // We have only a single current frame
840 // Our previous stack frames only had a single frame as well...
841 if (curr_stack_id == prev_stack_id)
843 #if defined (DEBUG_STACK_FRAMES)
844 s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n");
847 curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp);
848 // prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp);
849 // prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp);
851 else if (curr_stack_id < prev_stack_id)
853 #if defined (DEBUG_STACK_FRAMES)
854 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");
856 prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp);
861 #if defined (DEBUG_STACK_FRAMES)
862 s.PutCString("\nMerged:\n");
868 StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
871 const_iterator begin = m_frames.begin();
872 const_iterator end = m_frames.end();
873 lldb::StackFrameSP ret_sp;
875 for (pos = begin; pos != end; ++pos)
877 if (pos->get() == stack_frame_ptr)
887 StackFrameList::GetStatus (Stream& strm,
888 uint32_t first_frame,
890 bool show_frame_info,
891 uint32_t num_frames_with_source,
892 const char *selected_frame_marker)
894 size_t num_frames_displayed = 0;
899 StackFrameSP frame_sp;
900 uint32_t frame_idx = 0;
903 // Don't let the last frame wrap around...
904 if (num_frames == UINT32_MAX)
905 last_frame = UINT32_MAX;
907 last_frame = first_frame + num_frames;
909 StackFrameSP selected_frame_sp = m_thread.GetSelectedFrame();
910 const char *unselected_marker = nullptr;
912 if (selected_frame_marker)
914 size_t len = strlen(selected_frame_marker);
915 buffer.insert(buffer.begin(), len, ' ');
916 unselected_marker = buffer.c_str();
918 const char *marker = nullptr;
920 for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx)
922 frame_sp = GetFrameAtIndex(frame_idx);
926 if (selected_frame_marker != nullptr)
928 if (frame_sp == selected_frame_sp)
929 marker = selected_frame_marker;
931 marker = unselected_marker;
934 if (!frame_sp->GetStatus (strm,
936 num_frames_with_source > (first_frame - frame_idx), marker))
938 ++num_frames_displayed;
942 return num_frames_displayed;