Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 10 | #include "lldb/Target/StackFrameList.h" |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 16 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 17 | #include "lldb/Core/SourceManager.h" |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/Block.h" |
| 19 | #include "lldb/Symbol/Function.h" |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/Symbol.h" |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Process.h" |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 22 | #include "lldb/Target/RegisterContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StackFrame.h" |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StopInfo.h" |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Thread.h" |
| 27 | #include "lldb/Target/Unwind.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 29 | //#define DEBUG_STACK_FRAMES 1 |
| 30 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | using namespace lldb; |
| 32 | using namespace lldb_private; |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // StackFrameList constructor |
| 36 | //---------------------------------------------------------------------- |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 37 | StackFrameList::StackFrameList |
| 38 | ( |
| 39 | Thread &thread, |
| 40 | const lldb::StackFrameListSP &prev_frames_sp, |
| 41 | bool show_inline_frames |
| 42 | ) : |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 43 | m_thread (thread), |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 44 | m_prev_frames_sp (prev_frames_sp), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | m_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 46 | m_frames (), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 47 | m_selected_frame_idx (0), |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 48 | m_concrete_frames_fetched (0), |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 49 | m_current_inlined_depth (UINT32_MAX), |
| 50 | m_current_inlined_pc (LLDB_INVALID_ADDRESS), |
Stephen Wilson | dbeb3e1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 51 | m_show_inlined_frames (show_inline_frames) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | { |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 53 | if (prev_frames_sp) |
| 54 | { |
| 55 | m_current_inlined_depth = prev_frames_sp->m_current_inlined_depth; |
| 56 | m_current_inlined_pc = prev_frames_sp->m_current_inlined_pc; |
| 57 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | //---------------------------------------------------------------------- |
| 61 | // Destructor |
| 62 | //---------------------------------------------------------------------- |
| 63 | StackFrameList::~StackFrameList() |
| 64 | { |
| 65 | } |
| 66 | |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 67 | void |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 68 | StackFrameList::CalculateCurrentInlinedDepth() |
| 69 | { |
| 70 | uint32_t cur_inlined_depth = GetCurrentInlinedDepth(); |
| 71 | if (cur_inlined_depth == UINT32_MAX) |
| 72 | { |
| 73 | ResetCurrentInlinedDepth(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | uint32_t |
| 78 | StackFrameList::GetCurrentInlinedDepth () |
| 79 | { |
| 80 | if (m_show_inlined_frames) |
| 81 | { |
| 82 | lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC(); |
| 83 | if (cur_pc != m_current_inlined_pc) |
| 84 | { |
| 85 | m_current_inlined_pc = LLDB_INVALID_ADDRESS; |
| 86 | m_current_inlined_depth = UINT32_MAX; |
| 87 | } |
| 88 | return m_current_inlined_depth; |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | return UINT32_MAX; |
| 93 | } |
| 94 | } |
| 95 | |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 96 | void |
| 97 | StackFrameList::ResetCurrentInlinedDepth () |
| 98 | { |
Jim Ingham | 1cc0c05 | 2012-09-05 21:14:28 +0000 | [diff] [blame^] | 99 | if (m_show_inlined_frames) |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 100 | { |
| 101 | GetFramesUpTo(0); |
| 102 | if (!m_frames[0]->IsInlined()) |
| 103 | { |
| 104 | m_current_inlined_depth = UINT32_MAX; |
| 105 | m_current_inlined_pc = LLDB_INVALID_ADDRESS; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | // We only need to do something special about inlined blocks when we |
| 110 | // are at the beginning of an inlined function: |
| 111 | // FIXME: We probably also have to do something special if the PC is at the END |
| 112 | // of an inlined function, which coincides with the end of either its containing |
| 113 | // function or another inlined function. |
| 114 | |
| 115 | lldb::addr_t curr_pc = m_thread.GetRegisterContext()->GetPC(); |
| 116 | Block *block_ptr = m_frames[0]->GetFrameBlock(); |
| 117 | if (block_ptr) |
| 118 | { |
| 119 | Address pc_as_address; |
| 120 | pc_as_address.SetLoadAddress(curr_pc, &(m_thread.GetProcess()->GetTarget())); |
| 121 | AddressRange containing_range; |
| 122 | if (block_ptr->GetRangeContainingAddress(pc_as_address, containing_range)) |
| 123 | { |
| 124 | if (pc_as_address == containing_range.GetBaseAddress()) |
| 125 | { |
| 126 | // If we got here because of a breakpoint hit, then set the inlined depth depending on where |
| 127 | // the breakpoint was set. |
| 128 | // If we got here because of a crash, then set the inlined depth to the deepest most block. |
| 129 | // Otherwise, we stopped here naturally as the result of a step, so set ourselves in the |
| 130 | // containing frame of the whole set of nested inlines, so the user can then "virtually" |
| 131 | // step into the frames one by one, or next over the whole mess. |
| 132 | // Note: We don't have to handle being somewhere in the middle of the stack here, since |
| 133 | // ResetCurrentInlinedDepth doesn't get called if there is a valid inlined depth set. |
| 134 | StopInfoSP stop_info_sp = m_thread.GetStopInfo(); |
| 135 | if (stop_info_sp) |
| 136 | { |
| 137 | switch (stop_info_sp->GetStopReason()) |
| 138 | { |
| 139 | case eStopReasonBreakpoint: |
| 140 | { |
| 141 | |
| 142 | } |
| 143 | break; |
| 144 | case eStopReasonWatchpoint: |
| 145 | case eStopReasonException: |
| 146 | case eStopReasonSignal: |
| 147 | // In all these cases we want to stop in the deepest most frame. |
| 148 | m_current_inlined_pc = curr_pc; |
| 149 | m_current_inlined_depth = 0; |
| 150 | break; |
| 151 | default: |
| 152 | { |
| 153 | // Otherwise, we should set ourselves at the container of the inlining, so that the |
| 154 | // user can descend into them. |
| 155 | // So first we check whether we have more than one inlined block sharing this PC: |
| 156 | int num_inlined_functions = 0; |
| 157 | |
| 158 | for (Block *container_ptr = block_ptr->GetInlinedParent(); |
| 159 | container_ptr != NULL; |
| 160 | container_ptr = container_ptr->GetInlinedParent()) |
| 161 | { |
| 162 | if (!container_ptr->GetRangeContainingAddress(pc_as_address, containing_range)) |
| 163 | break; |
| 164 | if (pc_as_address != containing_range.GetBaseAddress()) |
| 165 | break; |
| 166 | |
| 167 | num_inlined_functions++; |
| 168 | } |
| 169 | m_current_inlined_pc = curr_pc; |
| 170 | m_current_inlined_depth = num_inlined_functions + 1; |
| 171 | |
| 172 | } |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | bool |
| 184 | StackFrameList::DecrementCurrentInlinedDepth () |
| 185 | { |
| 186 | if (m_show_inlined_frames) |
| 187 | { |
| 188 | uint32_t current_inlined_depth = GetCurrentInlinedDepth(); |
| 189 | if (current_inlined_depth != UINT32_MAX) |
| 190 | { |
| 191 | if (current_inlined_depth > 0) |
| 192 | m_current_inlined_depth--; |
| 193 | return true; |
| 194 | } |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | void |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 200 | StackFrameList::GetFramesUpTo(uint32_t end_idx) |
| 201 | { |
| 202 | // We've already gotten more frames than asked for, or we've already finished unwinding, return. |
| 203 | if (m_frames.size() > end_idx || GetAllFramesFetched()) |
| 204 | return; |
| 205 | |
| 206 | Unwind *unwinder = m_thread.GetUnwinder (); |
| 207 | |
| 208 | if (m_show_inlined_frames) |
| 209 | { |
| 210 | #if defined (DEBUG_STACK_FRAMES) |
| 211 | StreamFile s(stdout, false); |
| 212 | #endif |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 213 | // If we are hiding some frames from the outside world, we need to add those onto the total count of |
| 214 | // frames to fetch. However, we don't need ot do that if end_idx is 0 since in that case we always |
| 215 | // get the first concrete frame and all the inlined frames below it... |
| 216 | |
| 217 | uint32_t inlined_depth = 0; |
| 218 | if (end_idx > 0) |
| 219 | { |
| 220 | inlined_depth = GetCurrentInlinedDepth(); |
| 221 | if (inlined_depth != UINT32_MAX) |
| 222 | { |
| 223 | if (end_idx > 0) |
| 224 | end_idx += inlined_depth; |
| 225 | } |
| 226 | else |
| 227 | inlined_depth = 0; |
| 228 | } |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 229 | |
| 230 | StackFrameSP unwind_frame_sp; |
| 231 | do |
| 232 | { |
| 233 | uint32_t idx = m_concrete_frames_fetched++; |
| 234 | lldb::addr_t pc; |
| 235 | lldb::addr_t cfa; |
| 236 | if (idx == 0) |
| 237 | { |
| 238 | // We might have already created frame zero, only create it |
| 239 | // if we need to |
| 240 | if (m_frames.empty()) |
| 241 | { |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 242 | m_thread.GetRegisterContext(); |
Jim Ingham | c92468f | 2012-02-29 19:58:25 +0000 | [diff] [blame] | 243 | assert (m_thread.m_reg_context_sp.get()); |
Jim Ingham | 6252ea8 | 2012-03-01 02:53:40 +0000 | [diff] [blame] | 244 | |
| 245 | const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc); |
| 246 | // There shouldn't be any way not to get the frame info for frame 0. |
| 247 | // But if the unwinder can't make one, lets make one by hand with the |
| 248 | // SP as the CFA and see if that gets any further. |
| 249 | if (!success) |
| 250 | { |
| 251 | cfa = m_thread.GetRegisterContext()->GetSP(); |
| 252 | pc = m_thread.GetRegisterContext()->GetPC(); |
| 253 | } |
| 254 | |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 255 | unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), |
| 256 | m_frames.size(), |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 257 | idx, |
Jim Ingham | c92468f | 2012-02-29 19:58:25 +0000 | [diff] [blame] | 258 | m_thread.m_reg_context_sp, |
Jim Ingham | 6252ea8 | 2012-03-01 02:53:40 +0000 | [diff] [blame] | 259 | cfa, |
Jim Ingham | c92468f | 2012-02-29 19:58:25 +0000 | [diff] [blame] | 260 | pc, |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 261 | NULL)); |
| 262 | m_frames.push_back (unwind_frame_sp); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | unwind_frame_sp = m_frames.front(); |
| 267 | cfa = unwind_frame_sp->m_id.GetCallFrameAddress(); |
| 268 | } |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc); |
| 273 | if (!success) |
| 274 | { |
| 275 | // We've gotten to the end of the stack. |
| 276 | SetAllFramesFetched(); |
| 277 | break; |
| 278 | } |
| 279 | unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), m_frames.size(), idx, cfa, pc, NULL)); |
| 280 | m_frames.push_back (unwind_frame_sp); |
| 281 | } |
| 282 | |
| 283 | SymbolContext unwind_sc = unwind_frame_sp->GetSymbolContext (eSymbolContextBlock | eSymbolContextFunction); |
| 284 | Block *unwind_block = unwind_sc.block; |
| 285 | if (unwind_block) |
| 286 | { |
| 287 | Address curr_frame_address (unwind_frame_sp->GetFrameCodeAddress()); |
| 288 | // Be sure to adjust the frame address to match the address |
| 289 | // that was used to lookup the symbol context above. If we are |
| 290 | // in the first concrete frame, then we lookup using the current |
| 291 | // address, else we decrement the address by one to get the correct |
| 292 | // location. |
| 293 | if (idx > 0) |
| 294 | curr_frame_address.Slide(-1); |
| 295 | |
| 296 | SymbolContext next_frame_sc; |
| 297 | Address next_frame_address; |
| 298 | |
| 299 | while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address)) |
| 300 | { |
| 301 | StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(), |
| 302 | m_frames.size(), |
| 303 | idx, |
| 304 | unwind_frame_sp->GetRegisterContextSP (), |
| 305 | cfa, |
| 306 | next_frame_address, |
| 307 | &next_frame_sc)); |
| 308 | |
| 309 | m_frames.push_back (frame_sp); |
| 310 | unwind_sc = next_frame_sc; |
| 311 | curr_frame_address = next_frame_address; |
| 312 | } |
| 313 | } |
| 314 | } while (m_frames.size() - 1 < end_idx); |
| 315 | |
| 316 | // Don't try to merge till you've calculated all the frames in this stack. |
| 317 | if (GetAllFramesFetched() && m_prev_frames_sp) |
| 318 | { |
| 319 | StackFrameList *prev_frames = m_prev_frames_sp.get(); |
| 320 | StackFrameList *curr_frames = this; |
| 321 | |
| 322 | #if defined (DEBUG_STACK_FRAMES) |
| 323 | s.PutCString("\nprev_frames:\n"); |
| 324 | prev_frames->Dump (&s); |
| 325 | s.PutCString("\ncurr_frames:\n"); |
| 326 | curr_frames->Dump (&s); |
| 327 | s.EOL(); |
| 328 | #endif |
| 329 | size_t curr_frame_num, prev_frame_num; |
| 330 | |
| 331 | for (curr_frame_num = curr_frames->m_frames.size(), prev_frame_num = prev_frames->m_frames.size(); |
| 332 | curr_frame_num > 0 && prev_frame_num > 0; |
| 333 | --curr_frame_num, --prev_frame_num) |
| 334 | { |
| 335 | const size_t curr_frame_idx = curr_frame_num-1; |
| 336 | const size_t prev_frame_idx = prev_frame_num-1; |
| 337 | StackFrameSP curr_frame_sp (curr_frames->m_frames[curr_frame_idx]); |
| 338 | StackFrameSP prev_frame_sp (prev_frames->m_frames[prev_frame_idx]); |
| 339 | |
| 340 | #if defined (DEBUG_STACK_FRAMES) |
| 341 | s.Printf("\n\nCurr frame #%u ", curr_frame_idx); |
| 342 | if (curr_frame_sp) |
| 343 | curr_frame_sp->Dump (&s, true, false); |
| 344 | else |
| 345 | s.PutCString("NULL"); |
| 346 | s.Printf("\nPrev frame #%u ", prev_frame_idx); |
| 347 | if (prev_frame_sp) |
| 348 | prev_frame_sp->Dump (&s, true, false); |
| 349 | else |
| 350 | s.PutCString("NULL"); |
| 351 | #endif |
| 352 | |
| 353 | StackFrame *curr_frame = curr_frame_sp.get(); |
| 354 | StackFrame *prev_frame = prev_frame_sp.get(); |
| 355 | |
| 356 | if (curr_frame == NULL || prev_frame == NULL) |
| 357 | break; |
| 358 | |
| 359 | // Check the stack ID to make sure they are equal |
| 360 | if (curr_frame->GetStackID() != prev_frame->GetStackID()) |
| 361 | break; |
| 362 | |
| 363 | prev_frame->UpdatePreviousFrameFromCurrentFrame (*curr_frame); |
| 364 | // Now copy the fixed up previous frame into the current frames |
| 365 | // so the pointer doesn't change |
| 366 | m_frames[curr_frame_idx] = prev_frame_sp; |
| 367 | //curr_frame->UpdateCurrentFrameFromPreviousFrame (*prev_frame); |
| 368 | |
| 369 | #if defined (DEBUG_STACK_FRAMES) |
| 370 | s.Printf("\n Copying previous frame to current frame"); |
| 371 | #endif |
| 372 | } |
| 373 | // We are done with the old stack frame list, we can release it now |
| 374 | m_prev_frames_sp.reset(); |
| 375 | } |
| 376 | |
| 377 | #if defined (DEBUG_STACK_FRAMES) |
| 378 | s.PutCString("\n\nNew frames:\n"); |
| 379 | Dump (&s); |
| 380 | s.EOL(); |
| 381 | #endif |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | if (end_idx < m_concrete_frames_fetched) |
| 386 | return; |
| 387 | |
| 388 | uint32_t num_frames = unwinder->GetFramesUpTo(end_idx); |
| 389 | if (num_frames <= end_idx + 1) |
| 390 | { |
| 391 | //Done unwinding. |
| 392 | m_concrete_frames_fetched = UINT32_MAX; |
| 393 | } |
| 394 | m_frames.resize(num_frames); |
| 395 | } |
| 396 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | |
| 398 | uint32_t |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 399 | StackFrameList::GetNumFrames (bool can_create) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 400 | { |
| 401 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 402 | |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 403 | if (can_create) |
| 404 | GetFramesUpTo (UINT32_MAX); |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 405 | |
| 406 | uint32_t inlined_depth = GetCurrentInlinedDepth(); |
| 407 | if (inlined_depth == UINT32_MAX) |
| 408 | return m_frames.size(); |
| 409 | else |
| 410 | return m_frames.size() - inlined_depth; |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | void |
| 414 | StackFrameList::Dump (Stream *s) |
| 415 | { |
| 416 | if (s == NULL) |
| 417 | return; |
| 418 | Mutex::Locker locker (m_mutex); |
| 419 | |
| 420 | const_iterator pos, begin = m_frames.begin(), end = m_frames.end(); |
| 421 | for (pos = begin; pos != end; ++pos) |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 422 | { |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 423 | StackFrame *frame = (*pos).get(); |
| 424 | s->Printf("%p: ", frame); |
| 425 | if (frame) |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 426 | { |
| 427 | frame->GetStackID().Dump (s); |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 428 | frame->DumpUsingSettingsFormat (s); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 429 | } |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 430 | else |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 431 | s->Printf("frame #%u", (uint32_t)std::distance (begin, pos)); |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 432 | s->EOL(); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 433 | } |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 434 | s->EOL(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | StackFrameSP |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 438 | StackFrameList::GetFrameAtIndex (uint32_t idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | { |
| 440 | StackFrameSP frame_sp; |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 441 | Mutex::Locker locker (m_mutex); |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 442 | uint32_t inlined_depth = GetCurrentInlinedDepth(); |
| 443 | if (inlined_depth != UINT32_MAX) |
| 444 | idx += inlined_depth; |
| 445 | |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 446 | if (idx < m_frames.size()) |
| 447 | frame_sp = m_frames[idx]; |
| 448 | |
| 449 | if (frame_sp) |
| 450 | return frame_sp; |
Greg Clayton | f40e308 | 2010-08-26 02:28:22 +0000 | [diff] [blame] | 451 | |
Jim Ingham | c92468f | 2012-02-29 19:58:25 +0000 | [diff] [blame] | 452 | // GetFramesUpTo will fill m_frames with as many frames as you asked for, |
| 453 | // if there are that many. If there weren't then you asked for too many |
| 454 | // frames. |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 455 | GetFramesUpTo (idx); |
| 456 | if (idx < m_frames.size()) |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 457 | { |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 458 | if (m_show_inlined_frames) |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 459 | { |
Jim Ingham | c92468f | 2012-02-29 19:58:25 +0000 | [diff] [blame] | 460 | // When inline frames are enabled we actually create all the frames in GetFramesUpTo. |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 461 | frame_sp = m_frames[idx]; |
| 462 | } |
| 463 | else |
| 464 | { |
| 465 | Unwind *unwinder = m_thread.GetUnwinder (); |
| 466 | if (unwinder) |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 467 | { |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 468 | addr_t pc, cfa; |
| 469 | if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc)) |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 470 | { |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 471 | frame_sp.reset (new StackFrame (m_thread.shared_from_this(), idx, idx, cfa, pc, NULL)); |
| 472 | |
| 473 | Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function; |
| 474 | if (function) |
| 475 | { |
| 476 | // When we aren't showing inline functions we always use |
| 477 | // the top most function block as the scope. |
| 478 | frame_sp->SetSymbolContextScope (&function->GetBlock(false)); |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | // Set the symbol scope from the symbol regardless if it is NULL or valid. |
| 483 | frame_sp->SetSymbolContextScope (frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol); |
| 484 | } |
| 485 | SetFrameAtIndex(idx, frame_sp); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 486 | } |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 487 | } |
| 488 | } |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 489 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | return frame_sp; |
| 491 | } |
| 492 | |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 493 | StackFrameSP |
| 494 | StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 495 | { |
| 496 | // First try assuming the unwind index is the same as the frame index. The |
| 497 | // unwind index is always greater than or equal to the frame index, so it |
| 498 | // is a good place to start. If we have inlined frames we might have 5 |
| 499 | // concrete frames (frame unwind indexes go from 0-4), but we might have 15 |
| 500 | // frames after we make all the inlined frames. Most of the time the unwind |
| 501 | // frame index (or the concrete frame index) is the same as the frame index. |
| 502 | uint32_t frame_idx = unwind_idx; |
| 503 | StackFrameSP frame_sp (GetFrameAtIndex (frame_idx)); |
| 504 | while (frame_sp) |
| 505 | { |
| 506 | if (frame_sp->GetFrameIndex() == unwind_idx) |
| 507 | break; |
| 508 | frame_sp = GetFrameAtIndex (++frame_idx); |
| 509 | } |
| 510 | return frame_sp; |
| 511 | } |
| 512 | |
Jim Ingham | 5c4b160 | 2011-03-31 00:15:49 +0000 | [diff] [blame] | 513 | StackFrameSP |
Greg Clayton | b4d7fc0 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 514 | StackFrameList::GetFrameWithStackID (const StackID &stack_id) |
Jim Ingham | 5c4b160 | 2011-03-31 00:15:49 +0000 | [diff] [blame] | 515 | { |
| 516 | uint32_t frame_idx = 0; |
| 517 | StackFrameSP frame_sp; |
| 518 | do |
| 519 | { |
| 520 | frame_sp = GetFrameAtIndex (frame_idx); |
| 521 | if (frame_sp && frame_sp->GetStackID() == stack_id) |
| 522 | break; |
| 523 | frame_idx++; |
| 524 | } |
| 525 | while (frame_sp); |
| 526 | return frame_sp; |
| 527 | } |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 528 | |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 529 | bool |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 530 | StackFrameList::SetFrameAtIndex (uint32_t idx, StackFrameSP &frame_sp) |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 531 | { |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 532 | if (idx >= m_frames.size()) |
| 533 | m_frames.resize(idx + 1); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 534 | // Make sure allocation succeeded by checking bounds again |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 535 | if (idx < m_frames.size()) |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 536 | { |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 537 | m_frames[idx] = frame_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | return true; |
| 539 | } |
| 540 | return false; // resize failed, out of memory? |
| 541 | } |
| 542 | |
| 543 | uint32_t |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 544 | StackFrameList::GetSelectedFrameIndex () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 545 | { |
| 546 | Mutex::Locker locker (m_mutex); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 547 | return m_selected_frame_idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
| 551 | uint32_t |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 552 | StackFrameList::SetSelectedFrame (lldb_private::StackFrame *frame) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 553 | { |
| 554 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 555 | const_iterator pos; |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 556 | const_iterator begin = m_frames.begin(); |
| 557 | const_iterator end = m_frames.end(); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 558 | m_selected_frame_idx = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | for (pos = begin; pos != end; ++pos) |
| 560 | { |
| 561 | if (pos->get() == frame) |
| 562 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 563 | m_selected_frame_idx = std::distance (begin, pos); |
Jim Ingham | 0c8fa2d | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 564 | uint32_t inlined_depth = GetCurrentInlinedDepth(); |
| 565 | if (inlined_depth != UINT32_MAX) |
| 566 | m_selected_frame_idx -= inlined_depth; |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 567 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 570 | SetDefaultFileAndLineToSelectedFrame(); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 571 | return m_selected_frame_idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | // Mark a stack frame as the current frame using the frame index |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 575 | bool |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 576 | StackFrameList::SetSelectedFrameByIndex (uint32_t idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | { |
| 578 | Mutex::Locker locker (m_mutex); |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 579 | StackFrameSP frame_sp (GetFrameAtIndex (idx)); |
| 580 | if (frame_sp) |
| 581 | { |
| 582 | SetSelectedFrame(frame_sp.get()); |
| 583 | return true; |
| 584 | } |
| 585 | else |
| 586 | return false; |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | void |
| 590 | StackFrameList::SetDefaultFileAndLineToSelectedFrame() |
| 591 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 592 | if (m_thread.GetID() == m_thread.GetProcess()->GetThreadList().GetSelectedThread()->GetID()) |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 593 | { |
Greg Clayton | 840a992 | 2011-10-05 03:14:31 +0000 | [diff] [blame] | 594 | StackFrameSP frame_sp (GetFrameAtIndex (GetSelectedFrameIndex())); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 595 | if (frame_sp) |
| 596 | { |
Greg Clayton | 840a992 | 2011-10-05 03:14:31 +0000 | [diff] [blame] | 597 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextLineEntry); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 598 | if (sc.line_entry.file) |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 599 | m_thread.CalculateTarget()->GetSourceManager().SetDefaultFileAndLine (sc.line_entry.file, |
Greg Clayton | 840a992 | 2011-10-05 03:14:31 +0000 | [diff] [blame] | 600 | sc.line_entry.line); |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 601 | } |
| 602 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | // The thread has been run, reset the number stack frames to zero so we can |
| 606 | // determine how many frames we have lazily. |
| 607 | void |
| 608 | StackFrameList::Clear () |
| 609 | { |
| 610 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 611 | m_frames.clear(); |
Jim Ingham | bf97d74 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 612 | m_concrete_frames_fetched = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | void |
| 616 | StackFrameList::InvalidateFrames (uint32_t start_idx) |
| 617 | { |
| 618 | Mutex::Locker locker (m_mutex); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 619 | if (m_show_inlined_frames) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | { |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 621 | Clear(); |
| 622 | } |
| 623 | else |
| 624 | { |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 625 | const size_t num_frames = m_frames.size(); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 626 | while (start_idx < num_frames) |
| 627 | { |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 628 | m_frames[start_idx].reset(); |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 629 | ++start_idx; |
| 630 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 633 | |
| 634 | void |
| 635 | StackFrameList::Merge (std::auto_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp) |
| 636 | { |
Jim Ingham | 1b584eb | 2012-05-04 23:02:50 +0000 | [diff] [blame] | 637 | Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL); |
| 638 | Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 639 | |
| 640 | #if defined (DEBUG_STACK_FRAMES) |
Johnny Chen | 0a77f90 | 2011-08-25 17:27:02 +0000 | [diff] [blame] | 641 | StreamFile s(stdout, false); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 642 | s.PutCString("\n\nStackFrameList::Merge():\nPrev:\n"); |
| 643 | if (prev_sp.get()) |
| 644 | prev_sp->Dump (&s); |
| 645 | else |
| 646 | s.PutCString ("NULL"); |
| 647 | s.PutCString("\nCurr:\n"); |
| 648 | if (curr_ap.get()) |
| 649 | curr_ap->Dump (&s); |
| 650 | else |
| 651 | s.PutCString ("NULL"); |
| 652 | s.EOL(); |
| 653 | #endif |
| 654 | |
| 655 | if (curr_ap.get() == NULL || curr_ap->GetNumFrames (false) == 0) |
| 656 | { |
| 657 | #if defined (DEBUG_STACK_FRAMES) |
| 658 | s.PutCString("No current frames, leave previous frames alone...\n"); |
| 659 | #endif |
| 660 | curr_ap.release(); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | if (prev_sp.get() == NULL || prev_sp->GetNumFrames (false) == 0) |
| 665 | { |
| 666 | #if defined (DEBUG_STACK_FRAMES) |
| 667 | s.PutCString("No previous frames, so use current frames...\n"); |
| 668 | #endif |
| 669 | // We either don't have any previous frames, or since we have more than |
| 670 | // one current frames it means we have all the frames and can safely |
| 671 | // replace our previous frames. |
| 672 | prev_sp.reset (curr_ap.release()); |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | const uint32_t num_curr_frames = curr_ap->GetNumFrames (false); |
| 677 | |
| 678 | if (num_curr_frames > 1) |
| 679 | { |
| 680 | #if defined (DEBUG_STACK_FRAMES) |
| 681 | s.PutCString("We have more than one current frame, so use current frames...\n"); |
| 682 | #endif |
| 683 | // We have more than one current frames it means we have all the frames |
| 684 | // and can safely replace our previous frames. |
| 685 | prev_sp.reset (curr_ap.release()); |
| 686 | |
| 687 | #if defined (DEBUG_STACK_FRAMES) |
| 688 | s.PutCString("\nMerged:\n"); |
| 689 | prev_sp->Dump (&s); |
| 690 | #endif |
| 691 | return; |
| 692 | } |
| 693 | |
| 694 | StackFrameSP prev_frame_zero_sp(prev_sp->GetFrameAtIndex (0)); |
| 695 | StackFrameSP curr_frame_zero_sp(curr_ap->GetFrameAtIndex (0)); |
| 696 | StackID curr_stack_id (curr_frame_zero_sp->GetStackID()); |
| 697 | StackID prev_stack_id (prev_frame_zero_sp->GetStackID()); |
| 698 | |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 699 | #if defined (DEBUG_STACK_FRAMES) |
Johnny Chen | 0a77f90 | 2011-08-25 17:27:02 +0000 | [diff] [blame] | 700 | const uint32_t num_prev_frames = prev_sp->GetNumFrames (false); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 701 | s.Printf("\n%u previous frames with one current frame\n", num_prev_frames); |
| 702 | #endif |
| 703 | |
| 704 | // We have only a single current frame |
| 705 | // Our previous stack frames only had a single frame as well... |
| 706 | if (curr_stack_id == prev_stack_id) |
| 707 | { |
| 708 | #if defined (DEBUG_STACK_FRAMES) |
| 709 | s.Printf("\nPrevious frame #0 is same as current frame #0, merge the cached data\n"); |
| 710 | #endif |
| 711 | |
| 712 | curr_frame_zero_sp->UpdateCurrentFrameFromPreviousFrame (*prev_frame_zero_sp); |
| 713 | // prev_frame_zero_sp->UpdatePreviousFrameFromCurrentFrame (*curr_frame_zero_sp); |
| 714 | // prev_sp->SetFrameAtIndex (0, prev_frame_zero_sp); |
| 715 | } |
| 716 | else if (curr_stack_id < prev_stack_id) |
| 717 | { |
| 718 | #if defined (DEBUG_STACK_FRAMES) |
| 719 | 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"); |
| 720 | #endif |
| 721 | prev_sp->m_frames.insert (prev_sp->m_frames.begin(), curr_frame_zero_sp); |
| 722 | } |
| 723 | |
| 724 | curr_ap.release(); |
| 725 | |
| 726 | #if defined (DEBUG_STACK_FRAMES) |
| 727 | s.PutCString("\nMerged:\n"); |
| 728 | prev_sp->Dump (&s); |
| 729 | #endif |
| 730 | |
| 731 | |
| 732 | } |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 733 | |
| 734 | lldb::StackFrameSP |
| 735 | StackFrameList::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 736 | { |
| 737 | const_iterator pos; |
| 738 | const_iterator begin = m_frames.begin(); |
| 739 | const_iterator end = m_frames.end(); |
| 740 | lldb::StackFrameSP ret_sp; |
| 741 | |
| 742 | for (pos = begin; pos != end; ++pos) |
| 743 | { |
| 744 | if (pos->get() == stack_frame_ptr) |
| 745 | { |
| 746 | ret_sp = (*pos); |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | return ret_sp; |
| 751 | } |
| 752 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 753 | size_t |
| 754 | StackFrameList::GetStatus (Stream& strm, |
| 755 | uint32_t first_frame, |
| 756 | uint32_t num_frames, |
| 757 | bool show_frame_info, |
Greg Clayton | a7d3dc7 | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 758 | uint32_t num_frames_with_source) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 759 | { |
| 760 | size_t num_frames_displayed = 0; |
| 761 | |
| 762 | if (num_frames == 0) |
| 763 | return 0; |
| 764 | |
| 765 | StackFrameSP frame_sp; |
| 766 | uint32_t frame_idx = 0; |
| 767 | uint32_t last_frame; |
| 768 | |
| 769 | // Don't let the last frame wrap around... |
| 770 | if (num_frames == UINT32_MAX) |
| 771 | last_frame = UINT32_MAX; |
| 772 | else |
| 773 | last_frame = first_frame + num_frames; |
| 774 | |
| 775 | for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx) |
| 776 | { |
| 777 | frame_sp = GetFrameAtIndex(frame_idx); |
| 778 | if (frame_sp.get() == NULL) |
| 779 | break; |
| 780 | |
| 781 | if (!frame_sp->GetStatus (strm, |
| 782 | show_frame_info, |
Greg Clayton | a7d3dc7 | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 783 | num_frames_with_source > (first_frame - frame_idx))) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 784 | break; |
| 785 | ++num_frames_displayed; |
| 786 | } |
| 787 | |
| 788 | strm.IndentLess(); |
| 789 | return num_frames_displayed; |
| 790 | } |
| 791 | |