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