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