Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 1 | //===-- UnwindLLDB.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 | dc5eb69 | 2011-04-25 18:36:36 +0000 | [diff] [blame] | 10 | #include "lldb/Core/Module.h" |
| 11 | #include "lldb/Core/Log.h" |
| 12 | #include "lldb/Symbol/FuncUnwinders.h" |
| 13 | #include "lldb/Symbol/Function.h" |
| 14 | #include "lldb/Symbol/UnwindPlan.h" |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 15 | #include "lldb/Target/Thread.h" |
| 16 | #include "lldb/Target/Target.h" |
| 17 | #include "lldb/Target/Process.h" |
| 18 | #include "lldb/Target/RegisterContext.h" |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 19 | |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 20 | #include "UnwindLLDB.h" |
| 21 | #include "RegisterContextLLDB.h" |
| 22 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | UnwindLLDB::UnwindLLDB (Thread &thread) : |
| 27 | Unwind (thread), |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 28 | m_frames(), |
| 29 | m_unwind_complete(false) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
| 33 | uint32_t |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 34 | UnwindLLDB::DoGetFrameCount() |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 35 | { |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 36 | if (!m_unwind_complete) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 37 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 38 | //#define DEBUG_FRAME_SPEED 1 |
| 39 | #if DEBUG_FRAME_SPEED |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 40 | #define FRAME_COUNT 10000 |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 41 | TimeValue time_value (TimeValue::Now()); |
| 42 | #endif |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 43 | if (!AddFirstFrame ()) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 44 | return 0; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 45 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 46 | ProcessSP process_sp (m_thread.GetProcess()); |
| 47 | ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 48 | |
| 49 | while (AddOneMoreFrame (abi)) |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 50 | { |
| 51 | #if DEBUG_FRAME_SPEED |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 52 | if ((m_frames.size() % FRAME_COUNT) == 0) |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 53 | { |
| 54 | TimeValue now(TimeValue::Now()); |
| 55 | uint64_t delta_t = now - time_value; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 56 | printf ("%u frames in %" PRIu64 ".%09llu ms (%g frames/sec)\n", |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 57 | FRAME_COUNT, |
Peter Collingbourne | ba23ca0 | 2011-06-18 23:52:14 +0000 | [diff] [blame] | 58 | delta_t / TimeValue::NanoSecPerSec, |
| 59 | delta_t % TimeValue::NanoSecPerSec, |
| 60 | (float)FRAME_COUNT / ((float)delta_t / (float)TimeValue::NanoSecPerSec)); |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 61 | time_value = now; |
| 62 | } |
| 63 | #endif |
| 64 | } |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 65 | } |
| 66 | return m_frames.size (); |
| 67 | } |
| 68 | |
| 69 | bool |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 70 | UnwindLLDB::AddFirstFrame () |
| 71 | { |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 72 | if (m_frames.size() > 0) |
| 73 | return true; |
| 74 | |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 75 | // First, set up the 0th (initial) frame |
| 76 | CursorSP first_cursor_sp(new Cursor ()); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 77 | RegisterContextLLDBSP reg_ctx_sp (new RegisterContextLLDB (m_thread, |
| 78 | RegisterContextLLDBSP(), |
| 79 | first_cursor_sp->sctx, |
| 80 | 0, *this)); |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 81 | if (reg_ctx_sp.get() == NULL) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 82 | goto unwind_done; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 83 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 84 | if (!reg_ctx_sp->IsValid()) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 85 | goto unwind_done; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 86 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 87 | if (!reg_ctx_sp->GetCFA (first_cursor_sp->cfa)) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 88 | goto unwind_done; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 89 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 90 | if (!reg_ctx_sp->ReadPC (first_cursor_sp->start_pc)) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 91 | goto unwind_done; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 92 | |
| 93 | // Everything checks out, so release the auto pointer value and let the |
| 94 | // cursor own it in its shared pointer |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 95 | first_cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 96 | m_frames.push_back (first_cursor_sp); |
| 97 | return true; |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 98 | unwind_done: |
| 99 | m_unwind_complete = true; |
| 100 | return false; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // For adding a non-zero stack frame to m_frames. |
| 104 | bool |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 105 | UnwindLLDB::AddOneMoreFrame (ABI *abi) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 106 | { |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 107 | // If we've already gotten to the end of the stack, don't bother to try again... |
| 108 | if (m_unwind_complete) |
| 109 | return false; |
| 110 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame^] | 111 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 112 | CursorSP cursor_sp(new Cursor ()); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 113 | |
| 114 | // Frame zero is a little different |
| 115 | if (m_frames.size() == 0) |
| 116 | return false; |
| 117 | |
| 118 | uint32_t cur_idx = m_frames.size (); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 119 | RegisterContextLLDBSP reg_ctx_sp(new RegisterContextLLDB (m_thread, |
| 120 | m_frames[cur_idx - 1]->reg_ctx_lldb_sp, |
| 121 | cursor_sp->sctx, |
| 122 | cur_idx, |
| 123 | *this)); |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 124 | if (reg_ctx_sp.get() == NULL) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 125 | goto unwind_done; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 126 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 127 | if (!reg_ctx_sp->IsValid()) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 128 | { |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 129 | if (log) |
| 130 | { |
| 131 | log->Printf("%*sFrame %d invalid RegisterContext for this frame, stopping stack walk", |
| 132 | cur_idx < 100 ? cur_idx : 100, "", cur_idx); |
| 133 | } |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 134 | goto unwind_done; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 135 | } |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 136 | if (!reg_ctx_sp->GetCFA (cursor_sp->cfa)) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 137 | { |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 138 | if (log) |
| 139 | { |
| 140 | log->Printf("%*sFrame %d did not get CFA for this frame, stopping stack walk", |
| 141 | cur_idx < 100 ? cur_idx : 100, "", cur_idx); |
| 142 | } |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 143 | goto unwind_done; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 144 | } |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 145 | if (abi && !abi->CallFrameAddressIsValid(cursor_sp->cfa)) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 146 | { |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 147 | if (log) |
| 148 | { |
| 149 | log->Printf("%*sFrame %d did not get a valid CFA for this frame, stopping stack walk", |
| 150 | cur_idx < 100 ? cur_idx : 100, "", cur_idx); |
| 151 | } |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 152 | goto unwind_done; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 153 | } |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 154 | if (!reg_ctx_sp->ReadPC (cursor_sp->start_pc)) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 155 | { |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 156 | if (log) |
| 157 | { |
| 158 | log->Printf("%*sFrame %d did not get PC for this frame, stopping stack walk", |
| 159 | cur_idx < 100 ? cur_idx : 100, "", cur_idx); |
| 160 | } |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 161 | goto unwind_done; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 162 | } |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 163 | if (abi && !abi->CodeAddressIsValid (cursor_sp->start_pc)) |
| 164 | { |
| 165 | if (log) |
| 166 | { |
| 167 | log->Printf("%*sFrame %d did not get a valid PC, stopping stack walk", |
| 168 | cur_idx < 100 ? cur_idx : 100, "", cur_idx); |
| 169 | } |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 170 | goto unwind_done; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 171 | } |
Greg Clayton | fc75303 | 2011-01-17 21:03:33 +0000 | [diff] [blame] | 172 | if (!m_frames.empty()) |
| 173 | { |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 174 | if (m_frames.back()->start_pc == cursor_sp->start_pc) |
Greg Clayton | fc75303 | 2011-01-17 21:03:33 +0000 | [diff] [blame] | 175 | { |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 176 | if (m_frames.back()->cfa == cursor_sp->cfa) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 177 | goto unwind_done; // Infinite loop where the current cursor is the same as the previous one... |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 178 | else if (abi && abi->StackUsesFrames()) |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 179 | { |
Greg Clayton | 1cbc52c | 2011-05-25 17:56:20 +0000 | [diff] [blame] | 180 | // We might have a CFA that is not using the frame pointer and |
| 181 | // we want to validate that the frame pointer is valid. |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 182 | if (reg_ctx_sp->GetFP() == 0) |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 183 | goto unwind_done; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 184 | } |
Greg Clayton | fc75303 | 2011-01-17 21:03:33 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 187 | cursor_sp->reg_ctx_lldb_sp = reg_ctx_sp; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 188 | m_frames.push_back (cursor_sp); |
| 189 | return true; |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 190 | |
| 191 | unwind_done: |
| 192 | m_unwind_complete = true; |
| 193 | return false; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | bool |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 197 | UnwindLLDB::DoGetFrameInfoAtIndex (uint32_t idx, addr_t& cfa, addr_t& pc) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 198 | { |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 199 | if (m_frames.size() == 0) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 200 | { |
| 201 | if (!AddFirstFrame()) |
| 202 | return false; |
| 203 | } |
| 204 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 205 | ProcessSP process_sp (m_thread.GetProcess()); |
| 206 | ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 207 | |
| 208 | while (idx >= m_frames.size() && AddOneMoreFrame (abi)) |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 209 | ; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 210 | |
| 211 | if (idx < m_frames.size ()) |
| 212 | { |
Jason Molenda | 5976200 | 2010-11-04 00:53:20 +0000 | [diff] [blame] | 213 | cfa = m_frames[idx]->cfa; |
| 214 | pc = m_frames[idx]->start_pc; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 215 | return true; |
| 216 | } |
| 217 | return false; |
| 218 | } |
| 219 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 220 | lldb::RegisterContextSP |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 221 | UnwindLLDB::DoCreateRegisterContextForFrame (StackFrame *frame) |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 222 | { |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 223 | lldb::RegisterContextSP reg_ctx_sp; |
Greg Clayton | 671cabe | 2011-01-08 01:53:06 +0000 | [diff] [blame] | 224 | uint32_t idx = frame->GetConcreteFrameIndex (); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 225 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 226 | if (idx == 0) |
| 227 | { |
| 228 | return m_thread.GetRegisterContext(); |
| 229 | } |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 230 | |
| 231 | if (m_frames.size() == 0) |
| 232 | { |
| 233 | if (!AddFirstFrame()) |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 234 | return reg_ctx_sp; |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 237 | ProcessSP process_sp (m_thread.GetProcess()); |
| 238 | ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 239 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 240 | while (idx >= m_frames.size()) |
| 241 | { |
| 242 | if (!AddOneMoreFrame (abi)) |
| 243 | break; |
| 244 | } |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 245 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 246 | const uint32_t num_frames = m_frames.size(); |
| 247 | if (idx < num_frames) |
| 248 | { |
| 249 | Cursor *frame_cursor = m_frames[idx].get(); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 250 | reg_ctx_sp = frame_cursor->reg_ctx_lldb_sp; |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 251 | } |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 252 | return reg_ctx_sp; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 253 | } |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 254 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 255 | UnwindLLDB::RegisterContextLLDBSP |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 256 | UnwindLLDB::GetRegisterContextForFrameNum (uint32_t frame_num) |
| 257 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 258 | RegisterContextLLDBSP reg_ctx_sp; |
| 259 | if (frame_num < m_frames.size()) |
| 260 | reg_ctx_sp = m_frames[frame_num]->reg_ctx_lldb_sp; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 261 | return reg_ctx_sp; |
| 262 | } |
| 263 | |
| 264 | bool |
Jason Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 265 | UnwindLLDB::SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_or_return_address_reg) |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 266 | { |
| 267 | int64_t frame_num = starting_frame_num; |
| 268 | if (frame_num >= m_frames.size()) |
| 269 | return false; |
Jason Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 270 | |
| 271 | // Never interrogate more than one level while looking for the saved pc value. If the value |
| 272 | // isn't saved by frame_num, none of the frames lower on the stack will have a useful value. |
| 273 | if (pc_or_return_address_reg) |
| 274 | { |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 275 | UnwindLLDB::RegisterSearchResult result; |
| 276 | result = m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc); |
| 277 | if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound) |
Jason Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 278 | return true; |
| 279 | else |
| 280 | return false; |
| 281 | } |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 282 | while (frame_num >= 0) |
| 283 | { |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 284 | UnwindLLDB::RegisterSearchResult result; |
| 285 | result = m_frames[frame_num]->reg_ctx_lldb_sp->SavedLocationForRegister (lldb_regnum, regloc); |
Jason Molenda | 4c781fd7 | 2013-01-19 03:53:42 +0000 | [diff] [blame] | 286 | |
| 287 | // If we have unwind instructions saying that register N is saved in register M in the middle of |
| 288 | // the stack (and N can equal M here, meaning the register was not used in this function), then |
| 289 | // change the register number we're looking for to M and keep looking for a concrete location |
| 290 | // down the stack, or an actual value from a live RegisterContext at frame 0. |
| 291 | if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound |
| 292 | && regloc.type == UnwindLLDB::RegisterLocation::eRegisterInRegister |
| 293 | && frame_num > 0) |
| 294 | { |
| 295 | result = UnwindLLDB::RegisterSearchResult::eRegisterNotFound; |
| 296 | lldb_regnum = regloc.location.register_number; |
| 297 | } |
| 298 | |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 299 | if (result == UnwindLLDB::RegisterSearchResult::eRegisterFound) |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 300 | return true; |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 301 | if (result == UnwindLLDB::RegisterSearchResult::eRegisterIsVolatile) |
| 302 | return false; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 303 | frame_num--; |
| 304 | } |
| 305 | return false; |
| 306 | } |