130fdc8d8SChris Lattner //===-- StackFrameList.cpp --------------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1012daf946SGreg Clayton #include "lldb/Target/StackFrameList.h" 1112daf946SGreg Clayton 1230fdc8d8SChris Lattner // C Includes 1330fdc8d8SChris Lattner // C++ Includes 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 16*6cd41da7SJim Ingham #include "lldb/Core/Log.h" 175082c5fdSGreg Clayton #include "lldb/Core/StreamFile.h" 18b7f6b2faSJim Ingham #include "lldb/Core/SourceManager.h" 1912daf946SGreg Clayton #include "lldb/Symbol/Block.h" 2012daf946SGreg Clayton #include "lldb/Symbol/Function.h" 2159e8fc1cSGreg Clayton #include "lldb/Symbol/Symbol.h" 22b7f6b2faSJim Ingham #include "lldb/Target/Process.h" 2312daf946SGreg Clayton #include "lldb/Target/RegisterContext.h" 2430fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h" 25513c6bb8SJim Ingham #include "lldb/Target/StopInfo.h" 26b7f6b2faSJim Ingham #include "lldb/Target/Target.h" 2712daf946SGreg Clayton #include "lldb/Target/Thread.h" 2812daf946SGreg Clayton #include "lldb/Target/Unwind.h" 2930fdc8d8SChris Lattner 305082c5fdSGreg Clayton //#define DEBUG_STACK_FRAMES 1 315082c5fdSGreg Clayton 3230fdc8d8SChris Lattner using namespace lldb; 3330fdc8d8SChris Lattner using namespace lldb_private; 3430fdc8d8SChris Lattner 3530fdc8d8SChris Lattner //---------------------------------------------------------------------- 3630fdc8d8SChris Lattner // StackFrameList constructor 3730fdc8d8SChris Lattner //---------------------------------------------------------------------- 382cad65a5SGreg Clayton StackFrameList::StackFrameList 392cad65a5SGreg Clayton ( 402cad65a5SGreg Clayton Thread &thread, 412cad65a5SGreg Clayton const lldb::StackFrameListSP &prev_frames_sp, 422cad65a5SGreg Clayton bool show_inline_frames 432cad65a5SGreg Clayton ) : 4412daf946SGreg Clayton m_thread (thread), 452cad65a5SGreg Clayton m_prev_frames_sp (prev_frames_sp), 4630fdc8d8SChris Lattner m_mutex (Mutex::eMutexTypeRecursive), 475082c5fdSGreg Clayton m_frames (), 4871c21d18SStephen Wilson m_selected_frame_idx (0), 49b0c72a5fSJim Ingham m_concrete_frames_fetched (0), 50513c6bb8SJim Ingham m_current_inlined_depth (UINT32_MAX), 51513c6bb8SJim Ingham m_current_inlined_pc (LLDB_INVALID_ADDRESS), 5271c21d18SStephen Wilson m_show_inlined_frames (show_inline_frames) 5330fdc8d8SChris Lattner { 54513c6bb8SJim Ingham if (prev_frames_sp) 55513c6bb8SJim Ingham { 56513c6bb8SJim Ingham m_current_inlined_depth = prev_frames_sp->m_current_inlined_depth; 57513c6bb8SJim Ingham m_current_inlined_pc = prev_frames_sp->m_current_inlined_pc; 58513c6bb8SJim Ingham } 5930fdc8d8SChris Lattner } 6030fdc8d8SChris Lattner 6130fdc8d8SChris Lattner //---------------------------------------------------------------------- 6230fdc8d8SChris Lattner // Destructor 6330fdc8d8SChris Lattner //---------------------------------------------------------------------- 6430fdc8d8SChris Lattner StackFrameList::~StackFrameList() 6530fdc8d8SChris Lattner { 6630fdc8d8SChris Lattner } 6730fdc8d8SChris Lattner 68b0c72a5fSJim Ingham void 69513c6bb8SJim Ingham StackFrameList::CalculateCurrentInlinedDepth() 70513c6bb8SJim Ingham { 71513c6bb8SJim Ingham uint32_t cur_inlined_depth = GetCurrentInlinedDepth(); 72513c6bb8SJim Ingham if (cur_inlined_depth == UINT32_MAX) 73513c6bb8SJim Ingham { 74513c6bb8SJim Ingham ResetCurrentInlinedDepth(); 75513c6bb8SJim Ingham } 76513c6bb8SJim Ingham } 77513c6bb8SJim Ingham 78513c6bb8SJim Ingham uint32_t 79513c6bb8SJim Ingham StackFrameList::GetCurrentInlinedDepth () 80513c6bb8SJim Ingham { 81*6cd41da7SJim Ingham if (m_show_inlined_frames && m_current_inlined_pc != LLDB_INVALID_ADDRESS) 82513c6bb8SJim Ingham { 83513c6bb8SJim Ingham lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC(); 84513c6bb8SJim Ingham if (cur_pc != m_current_inlined_pc) 85513c6bb8SJim Ingham { 86513c6bb8SJim Ingham m_current_inlined_pc = LLDB_INVALID_ADDRESS; 87513c6bb8SJim Ingham m_current_inlined_depth = UINT32_MAX; 88*6cd41da7SJim Ingham LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 89*6cd41da7SJim Ingham if (log && log->GetVerbose()) 90*6cd41da7SJim Ingham log->Printf ("GetCurrentInlinedDepth: invalidating current inlined depth.\n"); 91513c6bb8SJim Ingham } 92513c6bb8SJim Ingham return m_current_inlined_depth; 93513c6bb8SJim Ingham } 94513c6bb8SJim Ingham else 95513c6bb8SJim Ingham { 96513c6bb8SJim Ingham return UINT32_MAX; 97513c6bb8SJim Ingham } 98513c6bb8SJim Ingham } 99513c6bb8SJim Ingham 100513c6bb8SJim Ingham void 101513c6bb8SJim Ingham StackFrameList::ResetCurrentInlinedDepth () 102513c6bb8SJim Ingham { 103e7e6ffc6SJim Ingham if (m_show_inlined_frames) 104513c6bb8SJim Ingham { 105513c6bb8SJim Ingham GetFramesUpTo(0); 106513c6bb8SJim Ingham if (!m_frames[0]->IsInlined()) 107513c6bb8SJim Ingham { 108513c6bb8SJim Ingham m_current_inlined_depth = UINT32_MAX; 109513c6bb8SJim Ingham m_current_inlined_pc = LLDB_INVALID_ADDRESS; 110*6cd41da7SJim Ingham LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 111*6cd41da7SJim Ingham if (log && log->GetVerbose()) 112*6cd41da7SJim Ingham log->Printf ("ResetCurrentInlinedDepth: Invalidating current inlined depth.\n"); 113513c6bb8SJim Ingham } 114513c6bb8SJim Ingham else 115513c6bb8SJim Ingham { 116513c6bb8SJim Ingham // We only need to do something special about inlined blocks when we 117513c6bb8SJim Ingham // are at the beginning of an inlined function: 118513c6bb8SJim Ingham // FIXME: We probably also have to do something special if the PC is at the END 119513c6bb8SJim Ingham // of an inlined function, which coincides with the end of either its containing 120513c6bb8SJim Ingham // function or another inlined function. 121513c6bb8SJim Ingham 122513c6bb8SJim Ingham lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC(); 123513c6bb8SJim Ingham Block *block_ptr = m_frames[0]->GetFrameBlock(); 124513c6bb8SJim Ingham if (block_ptr) 125513c6bb8SJim Ingham { 126513c6bb8SJim Ingham Address pc_as_address; 127513c6bb8SJim Ingham pc_as_address.SetLoadAddress(curr_pc, &(m_thread.GetProcess()->GetTarget())); 128513c6bb8SJim Ingham AddressRange containing_range; 129513c6bb8SJim Ingham if (block_ptr->GetRangeContainingAddress(pc_as_address, containing_range)) 130513c6bb8SJim Ingham { 131513c6bb8SJim Ingham if (pc_as_address == containing_range.GetBaseAddress()) 132513c6bb8SJim Ingham { 133513c6bb8SJim Ingham // If we got here because of a breakpoint hit, then set the inlined depth depending on where 134513c6bb8SJim Ingham // the breakpoint was set. 135513c6bb8SJim Ingham // If we got here because of a crash, then set the inlined depth to the deepest most block. 136513c6bb8SJim Ingham // Otherwise, we stopped here naturally as the result of a step, so set ourselves in the 137513c6bb8SJim Ingham // containing frame of the whole set of nested inlines, so the user can then "virtually" 138513c6bb8SJim Ingham // step into the frames one by one, or next over the whole mess. 139513c6bb8SJim Ingham // Note: We don't have to handle being somewhere in the middle of the stack here, since 140513c6bb8SJim Ingham // ResetCurrentInlinedDepth doesn't get called if there is a valid inlined depth set. 141513c6bb8SJim Ingham StopInfoSP stop_info_sp = m_thread.GetStopInfo(); 142513c6bb8SJim Ingham if (stop_info_sp) 143513c6bb8SJim Ingham { 144513c6bb8SJim Ingham switch (stop_info_sp->GetStopReason()) 145513c6bb8SJim Ingham { 146513c6bb8SJim Ingham case eStopReasonWatchpoint: 147513c6bb8SJim Ingham case eStopReasonException: 148513c6bb8SJim Ingham case eStopReasonSignal: 149513c6bb8SJim Ingham // In all these cases we want to stop in the deepest most frame. 150513c6bb8SJim Ingham m_current_inlined_pc = curr_pc; 151513c6bb8SJim Ingham m_current_inlined_depth = 0; 152513c6bb8SJim Ingham break; 1537da851a3SJim Ingham case eStopReasonBreakpoint: 1547da851a3SJim Ingham { 1557da851a3SJim Ingham // FIXME: Figure out what this break point is doing, and set the inline depth 1567da851a3SJim Ingham // appropriately. Be careful to take into account breakpoints that implement 1577da851a3SJim Ingham // step over prologue, since that should do the default calculation. 1587da851a3SJim Ingham } 159513c6bb8SJim Ingham default: 160513c6bb8SJim Ingham { 161513c6bb8SJim Ingham // Otherwise, we should set ourselves at the container of the inlining, so that the 162513c6bb8SJim Ingham // user can descend into them. 163513c6bb8SJim Ingham // So first we check whether we have more than one inlined block sharing this PC: 164513c6bb8SJim Ingham int num_inlined_functions = 0; 165513c6bb8SJim Ingham 166513c6bb8SJim Ingham for (Block *container_ptr = block_ptr->GetInlinedParent(); 167513c6bb8SJim Ingham container_ptr != NULL; 168513c6bb8SJim Ingham container_ptr = container_ptr->GetInlinedParent()) 169513c6bb8SJim Ingham { 170513c6bb8SJim Ingham if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range)) 171513c6bb8SJim Ingham break; 172513c6bb8SJim Ingham if (pc_as_address != containing_range.GetBaseAddress()) 173513c6bb8SJim Ingham break; 174513c6bb8SJim Ingham 175513c6bb8SJim Ingham num_inlined_functions++; 176513c6bb8SJim Ingham } 177513c6bb8SJim Ingham m_current_inlined_pc = curr_pc; 178513c6bb8SJim Ingham m_current_inlined_depth = num_inlined_functions + 1; 179*6cd41da7SJim Ingham LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); 180*6cd41da7SJim Ingham if (log && log->GetVerbose()) 181*6cd41da7SJim Ingham log->Printf ("ResetCurrentInlinedDepth: setting inlined depth: %d 0x%llx.\n", m_current_inlined_depth, curr_pc); 182513c6bb8SJim Ingham 183513c6bb8SJim Ingham } 184513c6bb8SJim Ingham break; 185513c6bb8SJim Ingham } 186513c6bb8SJim Ingham } 187513c6bb8SJim Ingham } 188513c6bb8SJim Ingham } 189513c6bb8SJim Ingham } 190513c6bb8SJim Ingham } 191513c6bb8SJim Ingham } 192513c6bb8SJim Ingham } 193513c6bb8SJim Ingham 194513c6bb8SJim Ingham bool 195513c6bb8SJim Ingham StackFrameList::DecrementCurrentInlinedDepth () 196513c6bb8SJim Ingham { 197513c6bb8SJim Ingham if (m_show_inlined_frames) 198513c6bb8SJim Ingham { 199513c6bb8SJim Ingham uint32_t current_inlined_depth = GetCurrentInlinedDepth(); 200513c6bb8SJim Ingham if (current_inlined_depth != UINT32_MAX) 201513c6bb8SJim Ingham { 202513c6bb8SJim Ingham if (current_inlined_depth > 0) 2039786eeebSJim Ingham { 204513c6bb8SJim Ingham m_current_inlined_depth--; 205513c6bb8SJim Ingham return true; 206513c6bb8SJim Ingham } 207513c6bb8SJim Ingham } 2089786eeebSJim Ingham } 209513c6bb8SJim Ingham return false; 210513c6bb8SJim Ingham } 211513c6bb8SJim Ingham 212513c6bb8SJim Ingham void 213*6cd41da7SJim Ingham StackFrameList::SetCurrentInlinedDepth (uint32_t new_depth) 214*6cd41da7SJim Ingham { 215*6cd41da7SJim Ingham m_current_inlined_depth = new_depth; 216*6cd41da7SJim Ingham if (new_depth == UINT32_MAX) 217*6cd41da7SJim Ingham m_current_inlined_pc = LLDB_INVALID_ADDRESS; 218*6cd41da7SJim Ingham else 219*6cd41da7SJim Ingham m_current_inlined_pc = m_thread.GetRegisterContext()->GetPC(); 220*6cd41da7SJim Ingham } 221*6cd41da7SJim Ingham 222*6cd41da7SJim Ingham void 223b0c72a5fSJim Ingham StackFrameList::GetFramesUpTo(uint32_t end_idx) 22430fdc8d8SChris Lattner { 225b0c72a5fSJim Ingham // We've already gotten more frames than asked for, or we've already finished unwinding, return. 226b0c72a5fSJim Ingham if (m_frames.size() > end_idx || GetAllFramesFetched()) 227b0c72a5fSJim Ingham return; 22812daf946SGreg Clayton 229b0c72a5fSJim Ingham Unwind *unwinder = m_thread.GetUnwinder (); 230b0c72a5fSJim Ingham 23112daf946SGreg Clayton if (m_show_inlined_frames) 23212daf946SGreg Clayton { 2335082c5fdSGreg Clayton #if defined (DEBUG_STACK_FRAMES) 2342c595273SJohnny Chen StreamFile s(stdout, false); 2355082c5fdSGreg Clayton #endif 236513c6bb8SJim Ingham // If we are hiding some frames from the outside world, we need to add those onto the total count of 237513c6bb8SJim Ingham // frames to fetch. However, we don't need ot do that if end_idx is 0 since in that case we always 238*6cd41da7SJim Ingham // get the first concrete frame and all the inlined frames below it... And of course, if end_idx is 239*6cd41da7SJim Ingham // UINT32_MAX that means get all, so just do that... 240513c6bb8SJim Ingham 241513c6bb8SJim Ingham uint32_t inlined_depth = 0; 242*6cd41da7SJim Ingham if (end_idx > 0 && end_idx != UINT32_MAX) 243513c6bb8SJim Ingham { 244513c6bb8SJim Ingham inlined_depth = GetCurrentInlinedDepth(); 245513c6bb8SJim Ingham if (inlined_depth != UINT32_MAX) 246513c6bb8SJim Ingham { 247513c6bb8SJim Ingham if (end_idx > 0) 248513c6bb8SJim Ingham end_idx += inlined_depth; 249513c6bb8SJim Ingham } 250513c6bb8SJim Ingham else 251513c6bb8SJim Ingham inlined_depth = 0; 252513c6bb8SJim Ingham } 25312daf946SGreg Clayton 2545082c5fdSGreg Clayton StackFrameSP unwind_frame_sp; 255b0c72a5fSJim Ingham do 25612daf946SGreg Clayton { 257b0c72a5fSJim Ingham uint32_t idx = m_concrete_frames_fetched++; 258b0c72a5fSJim Ingham lldb::addr_t pc; 259b0c72a5fSJim Ingham lldb::addr_t cfa; 26012daf946SGreg Clayton if (idx == 0) 26112daf946SGreg Clayton { 2625082c5fdSGreg Clayton // We might have already created frame zero, only create it 2635082c5fdSGreg Clayton // if we need to 2645082c5fdSGreg Clayton if (m_frames.empty()) 2655082c5fdSGreg Clayton { 26612daf946SGreg Clayton m_thread.GetRegisterContext(); 2671692b901SJim Ingham assert (m_thread.m_reg_context_sp.get()); 268376c4854SJim Ingham 269376c4854SJim Ingham const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc); 270376c4854SJim Ingham // There shouldn't be any way not to get the frame info for frame 0. 271376c4854SJim Ingham // But if the unwinder can't make one, lets make one by hand with the 272376c4854SJim Ingham // SP as the CFA and see if that gets any further. 273376c4854SJim Ingham if (!success) 274376c4854SJim Ingham { 275376c4854SJim Ingham cfa = m_thread.GetRegisterContext()->GetSP(); 276376c4854SJim Ingham pc = m_thread.GetRegisterContext()->GetPC(); 277376c4854SJim Ingham } 278376c4854SJim Ingham 279d9e416c0SGreg Clayton unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), 280d9e416c0SGreg Clayton m_frames.size(), 2815082c5fdSGreg Clayton idx, 28212daf946SGreg Clayton m_thread.m_reg_context_sp, 28359e8fc1cSGreg Clayton cfa, 2841692b901SJim Ingham pc, 28512daf946SGreg Clayton NULL)); 2865082c5fdSGreg Clayton m_frames.push_back (unwind_frame_sp); 2875082c5fdSGreg Clayton } 2885082c5fdSGreg Clayton else 2895082c5fdSGreg Clayton { 2905082c5fdSGreg Clayton unwind_frame_sp = m_frames.front(); 29159e8fc1cSGreg Clayton cfa = unwind_frame_sp->m_id.GetCallFrameAddress(); 2925082c5fdSGreg Clayton } 29312daf946SGreg Clayton } 29412daf946SGreg Clayton else 29512daf946SGreg Clayton { 29612daf946SGreg Clayton const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc); 297b0c72a5fSJim Ingham if (!success) 298b0c72a5fSJim Ingham { 299b0c72a5fSJim Ingham // We've gotten to the end of the stack. 300b0c72a5fSJim Ingham SetAllFramesFetched(); 301b0c72a5fSJim Ingham break; 302b0c72a5fSJim Ingham } 303d9e416c0SGreg Clayton unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), m_frames.size(), idx, cfa, pc, NULL)); 3045082c5fdSGreg Clayton m_frames.push_back (unwind_frame_sp); 30512daf946SGreg Clayton } 30612daf946SGreg Clayton 3071ed54f50SGreg Clayton SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction); 3081ed54f50SGreg Clayton Block *unwind_block = unwind_sc.block; 30959e8fc1cSGreg Clayton if (unwind_block) 31012daf946SGreg Clayton { 3115f4c61e2SGreg Clayton Address curr_frame_address (unwind_frame_sp->GetFrameCodeAddress()); 3125f4c61e2SGreg Clayton // Be sure to adjust the frame address to match the address 3135f4c61e2SGreg Clayton // that was used to lookup the symbol context above. If we are 3145f4c61e2SGreg Clayton // in the first concrete frame, then we lookup using the current 3155f4c61e2SGreg Clayton // address, else we decrement the address by one to get the correct 3165f4c61e2SGreg Clayton // location. 3175f4c61e2SGreg Clayton if (idx > 0) 3185f4c61e2SGreg Clayton curr_frame_address.Slide(-1); 3195f4c61e2SGreg Clayton 3201ed54f50SGreg Clayton SymbolContext next_frame_sc; 3211ed54f50SGreg Clayton Address next_frame_address; 3221ed54f50SGreg Clayton 3231ed54f50SGreg Clayton while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address)) 32459e8fc1cSGreg Clayton { 325d9e416c0SGreg Clayton StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(), 326d9e416c0SGreg Clayton m_frames.size(), 3275082c5fdSGreg Clayton idx, 3285082c5fdSGreg Clayton unwind_frame_sp->GetRegisterContextSP (), 32959e8fc1cSGreg Clayton cfa, 3301ed54f50SGreg Clayton next_frame_address, 3311ed54f50SGreg Clayton &next_frame_sc)); 3325082c5fdSGreg Clayton 3335082c5fdSGreg Clayton m_frames.push_back (frame_sp); 3341ed54f50SGreg Clayton unwind_sc = next_frame_sc; 3351ed54f50SGreg Clayton curr_frame_address = next_frame_address; 336b0c72a5fSJim Ingham } 337b0c72a5fSJim Ingham } 338b0c72a5fSJim Ingham } while (m_frames.size() - 1 < end_idx); 3391ed54f50SGreg Clayton 340b0c72a5fSJim Ingham // Don't try to merge till you've calculated all the frames in this stack. 341b0c72a5fSJim Ingham if (GetAllFramesFetched() && m_prev_frames_sp) 34212daf946SGreg Clayton { 3432cad65a5SGreg Clayton StackFrameList *prev_frames = m_prev_frames_sp.get(); 3445082c5fdSGreg Clayton StackFrameList *curr_frames = this; 3455082c5fdSGreg Clayton 346*6cd41da7SJim Ingham //curr_frames->m_current_inlined_depth = prev_frames->m_current_inlined_depth; 347*6cd41da7SJim Ingham //curr_frames->m_current_inlined_pc = prev_frames->m_current_inlined_pc; 348*6cd41da7SJim Ingham //printf ("GetFramesUpTo: Copying current inlined depth: %d 0x%llx.\n", curr_frames->m_current_inlined_depth, curr_frames->m_current_inlined_pc); 3499786eeebSJim Ingham 3505082c5fdSGreg Clayton #if defined (DEBUG_STACK_FRAMES) 35168275d5eSGreg Clayton s.PutCString("\nprev_frames:\n"); 3525082c5fdSGreg Clayton prev_frames->Dump (&s); 35368275d5eSGreg Clayton s.PutCString("\ncurr_frames:\n"); 3545082c5fdSGreg Clayton curr_frames->Dump (&s); 3555082c5fdSGreg Clayton s.EOL(); 3565082c5fdSGreg Clayton #endif 3575082c5fdSGreg Clayton size_t curr_frame_num, prev_frame_num; 3585082c5fdSGreg Clayton 3595082c5fdSGreg Clayton for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size(); 3605082c5fdSGreg Clayton curr_frame_num > 0 && prev_frame_num > 0; 3615082c5fdSGreg Clayton --curr_frame_num, --prev_frame_num) 3625082c5fdSGreg Clayton { 3635082c5fdSGreg Clayton const size_t curr_frame_idx = curr_frame_num-1; 3645082c5fdSGreg Clayton const size_t prev_frame_idx = prev_frame_num-1; 3655082c5fdSGreg Clayton StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]); 3665082c5fdSGreg Clayton StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]); 3675082c5fdSGreg Clayton 3685082c5fdSGreg Clayton #if defined (DEBUG_STACK_FRAMES) 3692cad65a5SGreg Clayton s.Printf("\n\nCurr frame #%u ", curr_frame_idx); 3705082c5fdSGreg Clayton if (curr_frame_sp) 3712cad65a5SGreg Clayton curr_frame_sp->Dump (&s, true, false); 3725082c5fdSGreg Clayton else 3735082c5fdSGreg Clayton s.PutCString("NULL"); 3742cad65a5SGreg Clayton s.Printf("\nPrev frame #%u ", prev_frame_idx); 3755082c5fdSGreg Clayton if (prev_frame_sp) 3762cad65a5SGreg Clayton prev_frame_sp->Dump (&s, true, false); 3775082c5fdSGreg Clayton else 3785082c5fdSGreg Clayton s.PutCString("NULL"); 3795082c5fdSGreg Clayton #endif 3805082c5fdSGreg Clayton 3815082c5fdSGreg Clayton StackFrame *curr_frame = curr_frame_sp.get(); 3825082c5fdSGreg Clayton StackFrame *prev_frame = prev_frame_sp.get(); 3835082c5fdSGreg Clayton 3845082c5fdSGreg Clayton if (curr_frame == NULL || prev_frame == NULL) 3855082c5fdSGreg Clayton break; 3865082c5fdSGreg Clayton 38759e8fc1cSGreg Clayton // Check the stack ID to make sure they are equal 38859e8fc1cSGreg Clayton if (curr_frame->GetStackID() != prev_frame->GetStackID()) 3895082c5fdSGreg Clayton break; 3905082c5fdSGreg Clayton 39159e8fc1cSGreg Clayton prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame); 39259e8fc1cSGreg Clayton // Now copy the fixed up previous frame into the current frames 39359e8fc1cSGreg Clayton // so the pointer doesn't change 39459e8fc1cSGreg Clayton m_frames[curr_frame_idx] = prev_frame_sp; 39559e8fc1cSGreg Clayton //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame); 3965082c5fdSGreg Clayton 3975082c5fdSGreg Clayton #if defined (DEBUG_STACK_FRAMES) 39868275d5eSGreg Clayton s.Printf("\n Copying previous frame to current frame"); 3995082c5fdSGreg Clayton #endif 4005082c5fdSGreg Clayton } 4015082c5fdSGreg Clayton // We are done with the old stack frame list, we can release it now 4022cad65a5SGreg Clayton m_prev_frames_sp.reset(); 4035082c5fdSGreg Clayton } 40468275d5eSGreg Clayton 40568275d5eSGreg Clayton #if defined (DEBUG_STACK_FRAMES) 40668275d5eSGreg Clayton s.PutCString("\n\nNew frames:\n"); 40768275d5eSGreg Clayton Dump (&s); 40868275d5eSGreg Clayton s.EOL(); 40968275d5eSGreg Clayton #endif 41012daf946SGreg Clayton } 41112daf946SGreg Clayton else 41212daf946SGreg Clayton { 413b0c72a5fSJim Ingham if (end_idx < m_concrete_frames_fetched) 414b0c72a5fSJim Ingham return; 415b0c72a5fSJim Ingham 416b0c72a5fSJim Ingham uint32_t num_frames = unwinder->GetFramesUpTo(end_idx); 417b0c72a5fSJim Ingham if (num_frames <= end_idx + 1) 418b0c72a5fSJim Ingham { 419b0c72a5fSJim Ingham //Done unwinding. 420b0c72a5fSJim Ingham m_concrete_frames_fetched = UINT32_MAX; 421b0c72a5fSJim Ingham } 422b0c72a5fSJim Ingham m_frames.resize(num_frames); 42312daf946SGreg Clayton } 4245082c5fdSGreg Clayton } 425b0c72a5fSJim Ingham 426b0c72a5fSJim Ingham uint32_t 427b0c72a5fSJim Ingham StackFrameList::GetNumFrames (bool can_create) 428b0c72a5fSJim Ingham { 429b0c72a5fSJim Ingham Mutex::Locker locker (m_mutex); 430b0c72a5fSJim Ingham 431b0c72a5fSJim Ingham if (can_create) 432b0c72a5fSJim Ingham GetFramesUpTo (UINT32_MAX); 433513c6bb8SJim Ingham 434513c6bb8SJim Ingham uint32_t inlined_depth = GetCurrentInlinedDepth(); 435513c6bb8SJim Ingham if (inlined_depth == UINT32_MAX) 4365082c5fdSGreg Clayton return m_frames.size(); 437513c6bb8SJim Ingham else 438513c6bb8SJim Ingham return m_frames.size() - inlined_depth; 43930fdc8d8SChris Lattner } 44030fdc8d8SChris Lattner 4415082c5fdSGreg Clayton void 4425082c5fdSGreg Clayton StackFrameList::Dump (Stream *s) 44330fdc8d8SChris Lattner { 4445082c5fdSGreg Clayton if (s == NULL) 4455082c5fdSGreg Clayton return; 4465082c5fdSGreg Clayton Mutex::Locker locker (m_mutex); 44730fdc8d8SChris Lattner 4485082c5fdSGreg Clayton const_iterator pos, begin = m_frames.begin(), end = m_frames.end(); 4495082c5fdSGreg Clayton for (pos = begin; pos != end; ++pos) 45012daf946SGreg Clayton { 4515082c5fdSGreg Clayton StackFrame *frame = (*pos).get(); 4525082c5fdSGreg Clayton s->Printf("%p: ", frame); 4535082c5fdSGreg Clayton if (frame) 45459e8fc1cSGreg Clayton { 45559e8fc1cSGreg Clayton frame->GetStackID().Dump (s); 4560603aa9dSGreg Clayton frame->DumpUsingSettingsFormat (s); 45759e8fc1cSGreg Clayton } 4585082c5fdSGreg Clayton else 459dce502edSGreg Clayton s->Printf("frame #%u", (uint32_t)std::distance (begin, pos)); 4605082c5fdSGreg Clayton s->EOL(); 46112daf946SGreg Clayton } 4625082c5fdSGreg Clayton s->EOL(); 4635082c5fdSGreg Clayton } 46412daf946SGreg Clayton 46530fdc8d8SChris Lattner StackFrameSP 46612daf946SGreg Clayton StackFrameList::GetFrameAtIndex (uint32_t idx) 46730fdc8d8SChris Lattner { 46830fdc8d8SChris Lattner StackFrameSP frame_sp; 46930fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 470513c6bb8SJim Ingham uint32_t inlined_depth = GetCurrentInlinedDepth(); 471513c6bb8SJim Ingham if (inlined_depth != UINT32_MAX) 472513c6bb8SJim Ingham idx += inlined_depth; 473513c6bb8SJim Ingham 4745082c5fdSGreg Clayton if (idx < m_frames.size()) 4755082c5fdSGreg Clayton frame_sp = m_frames[idx]; 47612daf946SGreg Clayton 4775082c5fdSGreg Clayton if (frame_sp) 47812daf946SGreg Clayton return frame_sp; 47912daf946SGreg Clayton 4801692b901SJim Ingham // GetFramesUpTo will fill m_frames with as many frames as you asked for, 4811692b901SJim Ingham // if there are that many. If there weren't then you asked for too many 4821692b901SJim Ingham // frames. 483b0c72a5fSJim Ingham GetFramesUpTo (idx); 484b0c72a5fSJim Ingham if (idx < m_frames.size()) 48512daf946SGreg Clayton { 48612daf946SGreg Clayton if (m_show_inlined_frames) 48712daf946SGreg Clayton { 4881692b901SJim Ingham // When inline frames are enabled we actually create all the frames in GetFramesUpTo. 4895082c5fdSGreg Clayton frame_sp = m_frames[idx]; 49012daf946SGreg Clayton } 49112daf946SGreg Clayton else 49212daf946SGreg Clayton { 49312daf946SGreg Clayton Unwind *unwinder = m_thread.GetUnwinder (); 49412daf946SGreg Clayton if (unwinder) 49512daf946SGreg Clayton { 49612daf946SGreg Clayton addr_t pc, cfa; 49712daf946SGreg Clayton if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc)) 4985082c5fdSGreg Clayton { 499d9e416c0SGreg Clayton frame_sp.reset (new StackFrame (m_thread.shared_from_this(), idx, idx, cfa, pc, NULL)); 50059e8fc1cSGreg Clayton 50159e8fc1cSGreg Clayton Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function; 50259e8fc1cSGreg Clayton if (function) 50359e8fc1cSGreg Clayton { 50459e8fc1cSGreg Clayton // When we aren't showing inline functions we always use 50559e8fc1cSGreg Clayton // the top most function block as the scope. 50659e8fc1cSGreg Clayton frame_sp->SetSymbolContextScope (&function->GetBlock(false)); 50759e8fc1cSGreg Clayton } 50859e8fc1cSGreg Clayton else 50959e8fc1cSGreg Clayton { 51059e8fc1cSGreg Clayton // Set the symbol scope from the symbol regardless if it is NULL or valid. 51159e8fc1cSGreg Clayton frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol); 51259e8fc1cSGreg Clayton } 5135082c5fdSGreg Clayton SetFrameAtIndex(idx, frame_sp); 51412daf946SGreg Clayton } 51512daf946SGreg Clayton } 51612daf946SGreg Clayton } 51730fdc8d8SChris Lattner } 51830fdc8d8SChris Lattner return frame_sp; 51930fdc8d8SChris Lattner } 52030fdc8d8SChris Lattner 5215ccbd294SGreg Clayton StackFrameSP 5225ccbd294SGreg Clayton StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) 5235ccbd294SGreg Clayton { 5245ccbd294SGreg Clayton // First try assuming the unwind index is the same as the frame index. The 5255ccbd294SGreg Clayton // unwind index is always greater than or equal to the frame index, so it 5265ccbd294SGreg Clayton // is a good place to start. If we have inlined frames we might have 5 5275ccbd294SGreg Clayton // concrete frames (frame unwind indexes go from 0-4), but we might have 15 5285ccbd294SGreg Clayton // frames after we make all the inlined frames. Most of the time the unwind 5295ccbd294SGreg Clayton // frame index (or the concrete frame index) is the same as the frame index. 5305ccbd294SGreg Clayton uint32_t frame_idx = unwind_idx; 5315ccbd294SGreg Clayton StackFrameSP frame_sp (GetFrameAtIndex (frame_idx)); 5325ccbd294SGreg Clayton while (frame_sp) 5335ccbd294SGreg Clayton { 5345ccbd294SGreg Clayton if (frame_sp->GetFrameIndex() == unwind_idx) 5355ccbd294SGreg Clayton break; 5365ccbd294SGreg Clayton frame_sp = GetFrameAtIndex (++frame_idx); 5375ccbd294SGreg Clayton } 5385ccbd294SGreg Clayton return frame_sp; 5395ccbd294SGreg Clayton } 5405ccbd294SGreg Clayton 5413a195b7eSJim Ingham StackFrameSP 542cc4d0146SGreg Clayton StackFrameList::GetFrameWithStackID (const StackID &stack_id) 5433a195b7eSJim Ingham { 5443a195b7eSJim Ingham uint32_t frame_idx = 0; 5453a195b7eSJim Ingham StackFrameSP frame_sp; 5463a195b7eSJim Ingham do 5473a195b7eSJim Ingham { 5483a195b7eSJim Ingham frame_sp = GetFrameAtIndex (frame_idx); 5493a195b7eSJim Ingham if (frame_sp && frame_sp->GetStackID() == stack_id) 5503a195b7eSJim Ingham break; 5513a195b7eSJim Ingham frame_idx++; 5523a195b7eSJim Ingham } 5533a195b7eSJim Ingham while (frame_sp); 5543a195b7eSJim Ingham return frame_sp; 5553a195b7eSJim Ingham } 5565ccbd294SGreg Clayton 55712daf946SGreg Clayton bool 5585082c5fdSGreg Clayton StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp) 55912daf946SGreg Clayton { 5605082c5fdSGreg Clayton if (idx >= m_frames.size()) 5615082c5fdSGreg Clayton m_frames.resize(idx + 1); 56212daf946SGreg Clayton // Make sure allocation succeeded by checking bounds again 5635082c5fdSGreg Clayton if (idx < m_frames.size()) 56412daf946SGreg Clayton { 5655082c5fdSGreg Clayton m_frames[idx] = frame_sp; 56630fdc8d8SChris Lattner return true; 56730fdc8d8SChris Lattner } 56830fdc8d8SChris Lattner return false; // resize failed, out of memory? 56930fdc8d8SChris Lattner } 57030fdc8d8SChris Lattner 57130fdc8d8SChris Lattner uint32_t 5722976d00aSJim Ingham StackFrameList::GetSelectedFrameIndex () const 57330fdc8d8SChris Lattner { 57430fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 5752976d00aSJim Ingham return m_selected_frame_idx; 57630fdc8d8SChris Lattner } 57730fdc8d8SChris Lattner 57830fdc8d8SChris Lattner 57930fdc8d8SChris Lattner uint32_t 5802976d00aSJim Ingham StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame) 58130fdc8d8SChris Lattner { 58230fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 58312daf946SGreg Clayton const_iterator pos; 5845082c5fdSGreg Clayton const_iterator begin = m_frames.begin(); 5855082c5fdSGreg Clayton const_iterator end = m_frames.end(); 586b7f6b2faSJim Ingham m_selected_frame_idx = 0; 58730fdc8d8SChris Lattner for (pos = begin; pos != end; ++pos) 58830fdc8d8SChris Lattner { 58930fdc8d8SChris Lattner if (pos->get() == frame) 59030fdc8d8SChris Lattner { 5912976d00aSJim Ingham m_selected_frame_idx = std::distance (begin, pos); 592513c6bb8SJim Ingham uint32_t inlined_depth = GetCurrentInlinedDepth(); 593513c6bb8SJim Ingham if (inlined_depth != UINT32_MAX) 594513c6bb8SJim Ingham m_selected_frame_idx -= inlined_depth; 595b7f6b2faSJim Ingham break; 59630fdc8d8SChris Lattner } 59730fdc8d8SChris Lattner } 598b7f6b2faSJim Ingham SetDefaultFileAndLineToSelectedFrame(); 5992976d00aSJim Ingham return m_selected_frame_idx; 60030fdc8d8SChris Lattner } 60130fdc8d8SChris Lattner 60230fdc8d8SChris Lattner // Mark a stack frame as the current frame using the frame index 603b0c72a5fSJim Ingham bool 6042976d00aSJim Ingham StackFrameList::SetSelectedFrameByIndex (uint32_t idx) 60530fdc8d8SChris Lattner { 60630fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 607b0c72a5fSJim Ingham StackFrameSP frame_sp (GetFrameAtIndex (idx)); 608b0c72a5fSJim Ingham if (frame_sp) 609b0c72a5fSJim Ingham { 610b0c72a5fSJim Ingham SetSelectedFrame(frame_sp.get()); 611b0c72a5fSJim Ingham return true; 612b0c72a5fSJim Ingham } 613b0c72a5fSJim Ingham else 614b0c72a5fSJim Ingham return false; 615b7f6b2faSJim Ingham } 616b7f6b2faSJim Ingham 617b7f6b2faSJim Ingham void 618b7f6b2faSJim Ingham StackFrameList::SetDefaultFileAndLineToSelectedFrame() 619b7f6b2faSJim Ingham { 6201ac04c30SGreg Clayton if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID()) 621b7f6b2faSJim Ingham { 622252d0edeSGreg Clayton StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex())); 623b7f6b2faSJim Ingham if (frame_sp) 624b7f6b2faSJim Ingham { 625252d0edeSGreg Clayton SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry); 626b7f6b2faSJim Ingham if (sc.line_entry.file) 6271ac04c30SGreg Clayton m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file, 628252d0edeSGreg Clayton sc.line_entry.line); 629b7f6b2faSJim Ingham } 630b7f6b2faSJim Ingham } 63130fdc8d8SChris Lattner } 63230fdc8d8SChris Lattner 63330fdc8d8SChris Lattner // The thread has been run, reset the number stack frames to zero so we can 63430fdc8d8SChris Lattner // determine how many frames we have lazily. 63530fdc8d8SChris Lattner void 63630fdc8d8SChris Lattner StackFrameList::Clear () 63730fdc8d8SChris Lattner { 63830fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 6395082c5fdSGreg Clayton m_frames.clear(); 640b0c72a5fSJim Ingham m_concrete_frames_fetched = 0; 64130fdc8d8SChris Lattner } 64230fdc8d8SChris Lattner 64330fdc8d8SChris Lattner void 64430fdc8d8SChris Lattner StackFrameList::InvalidateFrames (uint32_t start_idx) 64530fdc8d8SChris Lattner { 64630fdc8d8SChris Lattner Mutex::Locker locker (m_mutex); 64712daf946SGreg Clayton if (m_show_inlined_frames) 64812daf946SGreg Clayton { 64912daf946SGreg Clayton Clear(); 65012daf946SGreg Clayton } 65112daf946SGreg Clayton else 65212daf946SGreg Clayton { 6535082c5fdSGreg Clayton const size_t num_frames = m_frames.size(); 65430fdc8d8SChris Lattner while (start_idx < num_frames) 65530fdc8d8SChris Lattner { 6565082c5fdSGreg Clayton m_frames[start_idx].reset(); 65730fdc8d8SChris Lattner ++start_idx; 65830fdc8d8SChris Lattner } 65930fdc8d8SChris Lattner } 66012daf946SGreg Clayton } 6612cad65a5SGreg Clayton 6622cad65a5SGreg Clayton void 6632cad65a5SGreg Clayton StackFrameList::Merge (std::auto_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp) 6642cad65a5SGreg Clayton { 66510ebffa4SJim Ingham Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL); 66610ebffa4SJim Ingham Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL); 6672cad65a5SGreg Clayton 6682cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 6692c595273SJohnny Chen StreamFile s(stdout, false); 6702cad65a5SGreg Clayton s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n"); 6712cad65a5SGreg Clayton if (prev_sp.get()) 6722cad65a5SGreg Clayton prev_sp->Dump (&s); 6732cad65a5SGreg Clayton else 6742cad65a5SGreg Clayton s.PutCString ("NULL"); 6752cad65a5SGreg Clayton s.PutCString("\nCurr:\n"); 6762cad65a5SGreg Clayton if (curr_ap.get()) 6772cad65a5SGreg Clayton curr_ap->Dump (&s); 6782cad65a5SGreg Clayton else 6792cad65a5SGreg Clayton s.PutCString ("NULL"); 6802cad65a5SGreg Clayton s.EOL(); 6812cad65a5SGreg Clayton #endif 6822cad65a5SGreg Clayton 6832cad65a5SGreg Clayton if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0) 6842cad65a5SGreg Clayton { 6852cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 6862cad65a5SGreg Clayton s.PutCString("No current frames, leave previous frames alone...\n"); 6872cad65a5SGreg Clayton #endif 6882cad65a5SGreg Clayton curr_ap.release(); 6892cad65a5SGreg Clayton return; 6902cad65a5SGreg Clayton } 6912cad65a5SGreg Clayton 6922cad65a5SGreg Clayton if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0) 6932cad65a5SGreg Clayton { 6942cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 6952cad65a5SGreg Clayton s.PutCString("No previous frames, so use current frames...\n"); 6962cad65a5SGreg Clayton #endif 6972cad65a5SGreg Clayton // We either don't have any previous frames, or since we have more than 6982cad65a5SGreg Clayton // one current frames it means we have all the frames and can safely 6992cad65a5SGreg Clayton // replace our previous frames. 7002cad65a5SGreg Clayton prev_sp.reset (curr_ap.release()); 7012cad65a5SGreg Clayton return; 7022cad65a5SGreg Clayton } 7032cad65a5SGreg Clayton 7042cad65a5SGreg Clayton const uint32_t num_curr_frames = curr_ap->GetNumFrames (false); 7052cad65a5SGreg Clayton 7062cad65a5SGreg Clayton if (num_curr_frames > 1) 7072cad65a5SGreg Clayton { 7082cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7092cad65a5SGreg Clayton s.PutCString("We have more than one current frame, so use current frames...\n"); 7102cad65a5SGreg Clayton #endif 7112cad65a5SGreg Clayton // We have more than one current frames it means we have all the frames 7122cad65a5SGreg Clayton // and can safely replace our previous frames. 7132cad65a5SGreg Clayton prev_sp.reset (curr_ap.release()); 7142cad65a5SGreg Clayton 7152cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7162cad65a5SGreg Clayton s.PutCString("\nMerged:\n"); 7172cad65a5SGreg Clayton prev_sp->Dump (&s); 7182cad65a5SGreg Clayton #endif 7192cad65a5SGreg Clayton return; 7202cad65a5SGreg Clayton } 7212cad65a5SGreg Clayton 7222cad65a5SGreg Clayton StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0)); 7232cad65a5SGreg Clayton StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0)); 7242cad65a5SGreg Clayton StackID curr_stack_id (curr_frame_zero_sp->GetStackID()); 7252cad65a5SGreg Clayton StackID prev_stack_id (prev_frame_zero_sp->GetStackID()); 7262cad65a5SGreg Clayton 7272cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7282c595273SJohnny Chen const uint32_t num_prev_frames = prev_sp->GetNumFrames (false); 7292cad65a5SGreg Clayton s.Printf("\n%u previous frames with one current frame\n", num_prev_frames); 7302cad65a5SGreg Clayton #endif 7312cad65a5SGreg Clayton 7322cad65a5SGreg Clayton // We have only a single current frame 7332cad65a5SGreg Clayton // Our previous stack frames only had a single frame as well... 7342cad65a5SGreg Clayton if (curr_stack_id == prev_stack_id) 7352cad65a5SGreg Clayton { 7362cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7372cad65a5SGreg Clayton s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n"); 7382cad65a5SGreg Clayton #endif 7392cad65a5SGreg Clayton 7402cad65a5SGreg Clayton curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp); 7412cad65a5SGreg Clayton // prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp); 7422cad65a5SGreg Clayton // prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp); 7432cad65a5SGreg Clayton } 7442cad65a5SGreg Clayton else if (curr_stack_id < prev_stack_id) 7452cad65a5SGreg Clayton { 7462cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7472cad65a5SGreg Clayton 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"); 7482cad65a5SGreg Clayton #endif 7492cad65a5SGreg Clayton prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp); 7502cad65a5SGreg Clayton } 7512cad65a5SGreg Clayton 7522cad65a5SGreg Clayton curr_ap.release(); 7532cad65a5SGreg Clayton 7542cad65a5SGreg Clayton #if defined (DEBUG_STACK_FRAMES) 7552cad65a5SGreg Clayton s.PutCString("\nMerged:\n"); 7562cad65a5SGreg Clayton prev_sp->Dump (&s); 7572cad65a5SGreg Clayton #endif 7582cad65a5SGreg Clayton 7592cad65a5SGreg Clayton 7602cad65a5SGreg Clayton } 761e4284b71SJim Ingham 762e4284b71SJim Ingham lldb::StackFrameSP 763e4284b71SJim Ingham StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) 764e4284b71SJim Ingham { 765e4284b71SJim Ingham const_iterator pos; 766e4284b71SJim Ingham const_iterator begin = m_frames.begin(); 767e4284b71SJim Ingham const_iterator end = m_frames.end(); 768e4284b71SJim Ingham lldb::StackFrameSP ret_sp; 769e4284b71SJim Ingham 770e4284b71SJim Ingham for (pos = begin; pos != end; ++pos) 771e4284b71SJim Ingham { 772e4284b71SJim Ingham if (pos->get() == stack_frame_ptr) 773e4284b71SJim Ingham { 774e4284b71SJim Ingham ret_sp = (*pos); 775e4284b71SJim Ingham break; 776e4284b71SJim Ingham } 777e4284b71SJim Ingham } 778e4284b71SJim Ingham return ret_sp; 779e4284b71SJim Ingham } 780e4284b71SJim Ingham 7817260f620SGreg Clayton size_t 7827260f620SGreg Clayton StackFrameList::GetStatus (Stream& strm, 7837260f620SGreg Clayton uint32_t first_frame, 7847260f620SGreg Clayton uint32_t num_frames, 7857260f620SGreg Clayton bool show_frame_info, 78653eb7ad2SGreg Clayton uint32_t num_frames_with_source) 7877260f620SGreg Clayton { 7887260f620SGreg Clayton size_t num_frames_displayed = 0; 7897260f620SGreg Clayton 7907260f620SGreg Clayton if (num_frames == 0) 7917260f620SGreg Clayton return 0; 7927260f620SGreg Clayton 7937260f620SGreg Clayton StackFrameSP frame_sp; 7947260f620SGreg Clayton uint32_t frame_idx = 0; 7957260f620SGreg Clayton uint32_t last_frame; 7967260f620SGreg Clayton 7977260f620SGreg Clayton // Don't let the last frame wrap around... 7987260f620SGreg Clayton if (num_frames == UINT32_MAX) 7997260f620SGreg Clayton last_frame = UINT32_MAX; 8007260f620SGreg Clayton else 8017260f620SGreg Clayton last_frame = first_frame + num_frames; 8027260f620SGreg Clayton 8037260f620SGreg Clayton for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx) 8047260f620SGreg Clayton { 8057260f620SGreg Clayton frame_sp = GetFrameAtIndex(frame_idx); 8067260f620SGreg Clayton if (frame_sp.get() == NULL) 8077260f620SGreg Clayton break; 8087260f620SGreg Clayton 8097260f620SGreg Clayton if (!frame_sp->GetStatus (strm, 8107260f620SGreg Clayton show_frame_info, 81153eb7ad2SGreg Clayton num_frames_with_source > (first_frame - frame_idx))) 8127260f620SGreg Clayton break; 8137260f620SGreg Clayton ++num_frames_displayed; 8147260f620SGreg Clayton } 8157260f620SGreg Clayton 8167260f620SGreg Clayton strm.IndentLess(); 8177260f620SGreg Clayton return num_frames_displayed; 8187260f620SGreg Clayton } 8197260f620SGreg Clayton 820