Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- StackFrame.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 | |
| 10 | #include "lldb/Target/StackFrame.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Module.h" |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Disassembler.h" |
| 19 | #include "lldb/Core/Value.h" |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 21 | #include "lldb/Core/ValueObjectConstResult.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/Function.h" |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/ExecutionContext.h" |
| 25 | #include "lldb/Target/Process.h" |
| 26 | #include "lldb/Target/RegisterContext.h" |
| 27 | #include "lldb/Target/Target.h" |
| 28 | #include "lldb/Target/Thread.h" |
| 29 | |
| 30 | using namespace lldb; |
| 31 | using namespace lldb_private; |
| 32 | |
| 33 | // The first bits in the flags are reserved for the SymbolContext::Scope bits |
| 34 | // so we know if we have tried to look up information in our internal symbol |
| 35 | // context (m_sc) already. |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 36 | #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 37 | #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 38 | #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) |
| 39 | #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 40 | #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 42 | StackFrame::StackFrame |
| 43 | ( |
| 44 | lldb::user_id_t frame_idx, |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 45 | lldb::user_id_t unwind_frame_index, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 46 | Thread &thread, |
| 47 | lldb::addr_t cfa, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 48 | lldb::addr_t pc, |
| 49 | const SymbolContext *sc_ptr |
| 50 | ) : |
| 51 | m_frame_index (frame_idx), |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 52 | m_unwind_frame_index (unwind_frame_index), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | m_thread (thread), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 54 | m_reg_context_sp (), |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 55 | m_id (pc, cfa, NULL), |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 56 | m_frame_code_addr (NULL, pc), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 57 | m_sc (), |
| 58 | m_flags (), |
| 59 | m_frame_base (), |
| 60 | m_frame_base_error (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | m_variable_list_sp (), |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 62 | m_variable_list_value_objects () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | { |
| 64 | if (sc_ptr != NULL) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 65 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | m_sc = *sc_ptr; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 67 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 68 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 71 | StackFrame::StackFrame |
| 72 | ( |
| 73 | lldb::user_id_t frame_idx, |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 74 | lldb::user_id_t unwind_frame_index, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 75 | Thread &thread, |
| 76 | const RegisterContextSP ®_context_sp, |
| 77 | lldb::addr_t cfa, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 78 | lldb::addr_t pc, |
| 79 | const SymbolContext *sc_ptr |
| 80 | ) : |
| 81 | m_frame_index (frame_idx), |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 82 | m_unwind_frame_index (unwind_frame_index), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | m_thread (thread), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 84 | m_reg_context_sp (reg_context_sp), |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 85 | m_id (pc, cfa, NULL), |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 86 | m_frame_code_addr (NULL, pc), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 87 | m_sc (), |
| 88 | m_flags (), |
| 89 | m_frame_base (), |
| 90 | m_frame_base_error (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | m_variable_list_sp (), |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 92 | m_variable_list_value_objects () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | { |
| 94 | if (sc_ptr != NULL) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 95 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | m_sc = *sc_ptr; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 97 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 98 | } |
| 99 | |
| 100 | if (reg_context_sp && !m_sc.target_sp) |
| 101 | { |
| 102 | m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP(); |
| 103 | m_flags.Set (eSymbolContextTarget); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | StackFrame::StackFrame |
| 108 | ( |
| 109 | lldb::user_id_t frame_idx, |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 110 | lldb::user_id_t unwind_frame_index, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 111 | Thread &thread, |
| 112 | const RegisterContextSP ®_context_sp, |
| 113 | lldb::addr_t cfa, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 114 | const Address& pc_addr, |
| 115 | const SymbolContext *sc_ptr |
| 116 | ) : |
| 117 | m_frame_index (frame_idx), |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 118 | m_unwind_frame_index (unwind_frame_index), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 119 | m_thread (thread), |
| 120 | m_reg_context_sp (reg_context_sp), |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 121 | m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL), |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 122 | m_frame_code_addr (pc_addr), |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 123 | m_sc (), |
| 124 | m_flags (), |
| 125 | m_frame_base (), |
| 126 | m_frame_base_error (), |
| 127 | m_variable_list_sp (), |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 128 | m_variable_list_value_objects () |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 129 | { |
| 130 | if (sc_ptr != NULL) |
| 131 | { |
| 132 | m_sc = *sc_ptr; |
| 133 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 134 | } |
| 135 | |
| 136 | if (m_sc.target_sp.get() == NULL && reg_context_sp) |
| 137 | { |
| 138 | m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP(); |
| 139 | m_flags.Set (eSymbolContextTarget); |
| 140 | } |
| 141 | |
Greg Clayton | e2c5e45 | 2010-09-13 04:34:30 +0000 | [diff] [blame] | 142 | Module *pc_module = pc_addr.GetModule(); |
| 143 | if (m_sc.module_sp.get() == NULL || m_sc.module_sp.get() != pc_module) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 144 | { |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 145 | if (pc_module) |
| 146 | { |
| 147 | m_sc.module_sp = pc_module->GetSP(); |
| 148 | m_flags.Set (eSymbolContextModule); |
| 149 | } |
Greg Clayton | e2c5e45 | 2010-09-13 04:34:30 +0000 | [diff] [blame] | 150 | else |
| 151 | { |
| 152 | m_sc.module_sp.reset(); |
| 153 | } |
| 154 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 155 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | //---------------------------------------------------------------------- |
| 160 | // Destructor |
| 161 | //---------------------------------------------------------------------- |
| 162 | StackFrame::~StackFrame() |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | StackID& |
| 167 | StackFrame::GetStackID() |
| 168 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 169 | // Make sure we have resolved the StackID object's symbol context scope if |
| 170 | // we already haven't looked it up. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 172 | if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) |
| 173 | { |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 174 | if (m_id.GetSymbolContextScope ()) |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 175 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 176 | // We already have a symbol context scope, we just don't have our |
| 177 | // flag bit set. |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 178 | m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 179 | } |
| 180 | else |
| 181 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 182 | // Calculate the frame block and use this for the stack ID symbol |
| 183 | // context scope if we have one. |
| 184 | SymbolContextScope *scope = GetFrameBlock (); |
| 185 | if (scope == NULL) |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 186 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 187 | // We don't have a block, so use the symbol |
| 188 | if (m_flags.IsClear (eSymbolContextSymbol)) |
| 189 | GetSymbolContext (eSymbolContextSymbol); |
| 190 | |
| 191 | // It is ok if m_sc.symbol is NULL here |
| 192 | scope = m_sc.symbol; |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 193 | } |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 194 | // Set the symbol context scope (the accessor will set the |
| 195 | // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). |
| 196 | SetSymbolContextScope (scope); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 197 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | } |
| 199 | return m_id; |
| 200 | } |
| 201 | |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 202 | void |
| 203 | StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) |
| 204 | { |
| 205 | m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 206 | m_id.SetSymbolContextScope (symbol_scope); |
| 207 | } |
| 208 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | Address& |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 210 | StackFrame::GetFrameCodeAddress() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 212 | if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 213 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 214 | m_flags.Set (RESOLVED_FRAME_CODE_ADDR); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | |
| 216 | // Resolve the PC into a temporary address because if ResolveLoadAddress |
| 217 | // fails to resolve the address, it will clear the address object... |
| 218 | Address resolved_pc; |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 219 | if (m_thread.GetProcess().GetTarget().GetSectionLoadList().ResolveLoadAddress(m_frame_code_addr.GetOffset(), resolved_pc)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 220 | { |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 221 | m_frame_code_addr = resolved_pc; |
| 222 | const Section *section = m_frame_code_addr.GetSection(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | if (section) |
| 224 | { |
| 225 | Module *module = section->GetModule(); |
| 226 | if (module) |
| 227 | { |
| 228 | m_sc.module_sp = module->GetSP(); |
| 229 | if (m_sc.module_sp) |
| 230 | m_flags.Set(eSymbolContextModule); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | } |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 235 | return m_frame_code_addr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void |
| 239 | StackFrame::ChangePC (addr_t pc) |
| 240 | { |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 241 | m_frame_code_addr.SetOffset(pc); |
| 242 | m_frame_code_addr.SetSection(NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | m_sc.Clear(); |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 244 | m_flags.Reset(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | m_thread.ClearStackFrames (); |
| 246 | } |
| 247 | |
| 248 | const char * |
| 249 | StackFrame::Disassemble () |
| 250 | { |
| 251 | if (m_disassembly.GetSize() == 0) |
| 252 | { |
| 253 | ExecutionContext exe_ctx; |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 254 | CalculateExecutionContext(exe_ctx); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 255 | Target &target = m_thread.GetProcess().GetTarget(); |
| 256 | Disassembler::Disassemble (target.GetDebugger(), |
| 257 | target.GetArchitecture(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | exe_ctx, |
| 259 | 0, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 260 | false, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | m_disassembly); |
| 262 | if (m_disassembly.GetSize() == 0) |
| 263 | return NULL; |
| 264 | } |
| 265 | return m_disassembly.GetData(); |
| 266 | } |
| 267 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 268 | Block * |
| 269 | StackFrame::GetFrameBlock () |
| 270 | { |
| 271 | if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock)) |
| 272 | GetSymbolContext (eSymbolContextBlock); |
| 273 | |
| 274 | if (m_sc.block) |
| 275 | { |
| 276 | Block *inline_block = m_sc.block->GetContainingInlinedBlock(); |
| 277 | if (inline_block) |
| 278 | { |
| 279 | // Use the block with the inlined function info |
| 280 | // as the frame block we want this frame to have only the variables |
| 281 | // for the inlined function and its non-inlined block child blocks. |
| 282 | return inline_block; |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | // This block is not contained withing any inlined function blocks |
| 287 | // with so we want to use the top most function block. |
| 288 | return &m_sc.function->GetBlock (false); |
| 289 | } |
| 290 | } |
| 291 | return NULL; |
| 292 | } |
| 293 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 294 | //---------------------------------------------------------------------- |
| 295 | // Get the symbol context if we already haven't done so by resolving the |
| 296 | // PC address as much as possible. This way when we pass around a |
| 297 | // StackFrame object, everyone will have as much information as |
| 298 | // possible and no one will ever have to look things up manually. |
| 299 | //---------------------------------------------------------------------- |
| 300 | const SymbolContext& |
| 301 | StackFrame::GetSymbolContext (uint32_t resolve_scope) |
| 302 | { |
| 303 | // Copy our internal symbol context into "sc". |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 304 | if ((m_flags.Get() & resolve_scope) != resolve_scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | { |
| 306 | // Resolve our PC to section offset if we haven't alreday done so |
| 307 | // and if we don't have a module. The resolved address section will |
| 308 | // contain the module to which it belongs |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 309 | if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 310 | GetFrameCodeAddress(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 311 | |
| 312 | // If this is not frame zero, then we need to subtract 1 from the PC |
| 313 | // value when doing address lookups since the PC will be on the |
| 314 | // instruction following the function call instruction... |
| 315 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 316 | Address lookup_addr(GetFrameCodeAddress()); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 317 | if (m_frame_index > 0 && lookup_addr.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | { |
| 319 | addr_t offset = lookup_addr.GetOffset(); |
| 320 | if (offset > 0) |
| 321 | lookup_addr.SetOffset(offset - 1); |
| 322 | } |
| 323 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 324 | |
| 325 | uint32_t resolved = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | if (m_sc.module_sp) |
| 327 | { |
| 328 | // We have something in our stack frame symbol context, lets check |
| 329 | // if we haven't already tried to lookup one of those things. If we |
| 330 | // haven't then we will do the query. |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 331 | |
| 332 | uint32_t actual_resolve_scope = 0; |
| 333 | |
| 334 | if (resolve_scope & eSymbolContextCompUnit) |
| 335 | { |
| 336 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 337 | { |
| 338 | if (m_sc.comp_unit) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 339 | resolved |= eSymbolContextCompUnit; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 340 | else |
| 341 | actual_resolve_scope |= eSymbolContextCompUnit; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if (resolve_scope & eSymbolContextFunction) |
| 346 | { |
| 347 | if (m_flags.IsClear (eSymbolContextFunction)) |
| 348 | { |
| 349 | if (m_sc.function) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 350 | resolved |= eSymbolContextFunction; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 351 | else |
| 352 | actual_resolve_scope |= eSymbolContextFunction; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if (resolve_scope & eSymbolContextBlock) |
| 357 | { |
| 358 | if (m_flags.IsClear (eSymbolContextBlock)) |
| 359 | { |
| 360 | if (m_sc.block) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 361 | resolved |= eSymbolContextBlock; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 362 | else |
| 363 | actual_resolve_scope |= eSymbolContextBlock; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (resolve_scope & eSymbolContextSymbol) |
| 368 | { |
| 369 | if (m_flags.IsClear (eSymbolContextSymbol)) |
| 370 | { |
| 371 | if (m_sc.symbol) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 372 | resolved |= eSymbolContextSymbol; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 373 | else |
| 374 | actual_resolve_scope |= eSymbolContextSymbol; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (resolve_scope & eSymbolContextLineEntry) |
| 379 | { |
| 380 | if (m_flags.IsClear (eSymbolContextLineEntry)) |
| 381 | { |
| 382 | if (m_sc.line_entry.IsValid()) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 383 | resolved |= eSymbolContextLineEntry; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 384 | else |
| 385 | actual_resolve_scope |= eSymbolContextLineEntry; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if (actual_resolve_scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 390 | { |
| 391 | // We might be resolving less information than what is already |
| 392 | // in our current symbol context so resolve into a temporary |
| 393 | // symbol context "sc" so we don't clear out data we have |
| 394 | // already found in "m_sc" |
| 395 | SymbolContext sc; |
| 396 | // Set flags that indicate what we have tried to resolve |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 397 | resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 398 | // Only replace what we didn't already have as we may have |
| 399 | // information for an inlined function scope that won't match |
| 400 | // what a standard lookup by address would match |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 401 | if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL) |
| 402 | m_sc.comp_unit = sc.comp_unit; |
| 403 | if ((resolved & eSymbolContextFunction) && m_sc.function == NULL) |
| 404 | m_sc.function = sc.function; |
| 405 | if ((resolved & eSymbolContextBlock) && m_sc.block == NULL) |
| 406 | m_sc.block = sc.block; |
| 407 | if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL) |
| 408 | m_sc.symbol = sc.symbol; |
| 409 | if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) |
| 410 | m_sc.line_entry = sc.line_entry; |
| 411 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | // If we don't have a module, then we can't have the compile unit, |
| 417 | // function, block, line entry or symbol, so we can safely call |
| 418 | // ResolveSymbolContextForAddress with our symbol context member m_sc. |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 419 | resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | // If the target was requested add that: |
| 423 | if (m_sc.target_sp.get() == NULL) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 424 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | m_sc.target_sp = CalculateProcess()->GetTarget().GetSP(); |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 426 | if (m_sc.target_sp) |
| 427 | resolved |= eSymbolContextTarget; |
| 428 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | |
| 430 | // Update our internal flags so we remember what we have tried to locate so |
| 431 | // we don't have to keep trying when more calls to this function are made. |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 432 | // We might have dug up more information that was requested (for example |
| 433 | // if we were asked to only get the block, we will have gotten the |
| 434 | // compile unit, and function) so set any additional bits that we resolved |
| 435 | m_flags.Set (resolve_scope | resolved); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | // Return the symbol context with everything that was possible to resolve |
| 439 | // resolved. |
| 440 | return m_sc; |
| 441 | } |
| 442 | |
| 443 | |
| 444 | VariableList * |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 445 | StackFrame::GetVariableList (bool get_file_globals) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | { |
| 447 | if (m_flags.IsClear(RESOLVED_VARIABLES)) |
| 448 | { |
| 449 | m_flags.Set(RESOLVED_VARIABLES); |
| 450 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 451 | Block *frame_block = GetFrameBlock(); |
| 452 | |
| 453 | if (frame_block) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 455 | const bool get_child_variables = true; |
| 456 | const bool can_create = true; |
| 457 | m_variable_list_sp = frame_block->GetVariableList (get_child_variables, can_create); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | } |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && |
| 462 | get_file_globals) |
| 463 | { |
| 464 | m_flags.Set(RESOLVED_GLOBAL_VARIABLES); |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 465 | |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 466 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 467 | GetSymbolContext (eSymbolContextCompUnit); |
| 468 | |
| 469 | if (m_sc.comp_unit) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 470 | { |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 471 | VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); |
| 472 | if (m_variable_list_sp) |
| 473 | m_variable_list_sp->AddVariables (global_variable_list_sp.get()); |
| 474 | else |
| 475 | m_variable_list_sp = global_variable_list_sp; |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 476 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | } |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 478 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 479 | return m_variable_list_sp.get(); |
| 480 | } |
| 481 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 482 | ValueObjectSP |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 483 | StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, bool check_ptr_vs_member, Error &error) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 484 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 485 | |
| 486 | if (var_expr_cstr && var_expr_cstr[0]) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 487 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 488 | error.Clear(); |
| 489 | bool deref = false; |
| 490 | bool address_of = false; |
| 491 | ValueObjectSP valobj_sp; |
| 492 | const bool get_file_globals = true; |
| 493 | VariableList *variable_list = GetVariableList (get_file_globals); |
| 494 | |
| 495 | if (variable_list) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 496 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 497 | // If first character is a '*', then show pointer contents |
| 498 | const char *var_expr = var_expr_cstr; |
| 499 | if (var_expr[0] == '*') |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 500 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 501 | deref = true; |
| 502 | var_expr++; // Skip the '*' |
| 503 | } |
| 504 | else if (var_expr[0] == '&') |
| 505 | { |
| 506 | address_of = true; |
| 507 | var_expr++; // Skip the '&' |
| 508 | } |
| 509 | |
| 510 | std::string var_path (var_expr); |
| 511 | size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); |
| 512 | StreamString var_expr_path_strm; |
| 513 | |
| 514 | ConstString name_const_string; |
| 515 | if (separator_idx == std::string::npos) |
| 516 | name_const_string.SetCString (var_path.c_str()); |
| 517 | else |
| 518 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 519 | |
| 520 | VariableSP var_sp (variable_list->FindVariable(name_const_string)); |
| 521 | if (var_sp) |
| 522 | { |
| 523 | valobj_sp = GetValueObjectForFrameVariable (var_sp); |
| 524 | |
| 525 | var_path.erase (0, name_const_string.GetLength ()); |
| 526 | // We are dumping at least one child |
| 527 | while (separator_idx != std::string::npos) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 528 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 529 | // Calculate the next separator index ahead of time |
| 530 | ValueObjectSP child_valobj_sp; |
| 531 | const char separator_type = var_path[0]; |
| 532 | switch (separator_type) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 533 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 534 | |
| 535 | case '-': |
| 536 | if (var_path.size() >= 2 && var_path[1] != '>') |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 537 | return ValueObjectSP(); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 538 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 539 | var_path.erase (0, 1); // Remove the '-' |
| 540 | // Fall through |
| 541 | case '.': |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 542 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 543 | const bool expr_is_ptr = var_path[0] == '>'; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 544 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 545 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 546 | separator_idx = var_path.find_first_of(".-["); |
| 547 | ConstString child_name; |
| 548 | if (separator_idx == std::string::npos) |
| 549 | child_name.SetCString (var_path.c_str()); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 550 | else |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 551 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
| 552 | |
| 553 | if (check_ptr_vs_member) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 554 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 555 | // We either have a pointer type and need to verify |
| 556 | // valobj_sp is a pointer, or we have a member of a |
| 557 | // class/union/struct being accessed with the . syntax |
| 558 | // and need to verify we don't have a pointer. |
| 559 | const bool actual_is_ptr = valobj_sp->IsPointerType (); |
| 560 | |
| 561 | if (actual_is_ptr != expr_is_ptr) |
| 562 | { |
| 563 | // Incorrect use of "." with a pointer, or "->" with |
| 564 | // a class/union/struct instance or reference. |
| 565 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 566 | if (actual_is_ptr) |
| 567 | error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", |
| 568 | var_expr_path_strm.GetString().c_str(), |
| 569 | child_name.GetCString(), |
| 570 | var_expr_path_strm.GetString().c_str(), |
| 571 | var_path.c_str()); |
| 572 | else |
| 573 | error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", |
| 574 | var_expr_path_strm.GetString().c_str(), |
| 575 | child_name.GetCString(), |
| 576 | var_expr_path_strm.GetString().c_str(), |
| 577 | var_path.c_str()); |
| 578 | return ValueObjectSP(); |
| 579 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 582 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 583 | if (!child_valobj_sp) |
| 584 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 585 | // No child member with name "child_name" |
| 586 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 587 | if (child_name) |
| 588 | { |
| 589 | error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", |
| 590 | child_name.GetCString(), |
| 591 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 592 | var_expr_path_strm.GetString().c_str()); |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", |
| 597 | var_expr_path_strm.GetString().c_str(), |
| 598 | var_expr_cstr); |
| 599 | } |
| 600 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 601 | return ValueObjectSP(); |
| 602 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 603 | // Remove the child name from the path |
| 604 | var_path.erase(0, child_name.GetLength()); |
| 605 | } |
| 606 | break; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 607 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 608 | case '[': |
| 609 | // Array member access, or treating pointer as an array |
| 610 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 611 | { |
| 612 | char *end = NULL; |
| 613 | int32_t child_index = ::strtol (&var_path[1], &end, 0); |
| 614 | if (end && *end == ']') |
| 615 | { |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 616 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 617 | if (valobj_sp->IsPointerType ()) |
| 618 | { |
| 619 | child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); |
| 620 | if (!child_valobj_sp) |
| 621 | { |
| 622 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 623 | error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"", |
| 624 | child_index, |
| 625 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 626 | var_expr_path_strm.GetString().c_str()); |
| 627 | } |
| 628 | } |
| 629 | else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL)) |
| 630 | { |
| 631 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
| 632 | if (!child_valobj_sp) |
| 633 | { |
| 634 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 635 | error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"", |
| 636 | child_index, |
| 637 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 638 | var_expr_path_strm.GetString().c_str()); |
| 639 | } |
| 640 | } |
| 641 | else |
| 642 | { |
| 643 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 644 | error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", |
| 645 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 646 | var_expr_path_strm.GetString().c_str()); |
| 647 | } |
| 648 | |
| 649 | if (!child_valobj_sp) |
| 650 | { |
| 651 | // Invalid array index... |
| 652 | return ValueObjectSP(); |
| 653 | } |
| 654 | |
| 655 | // Erase the array member specification '[%i]' where |
| 656 | // %i is the array index |
| 657 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 658 | separator_idx = var_path.find_first_of(".-["); |
| 659 | |
| 660 | // Break out early from the switch since we were |
| 661 | // able to find the child member |
| 662 | break; |
| 663 | } |
| 664 | } |
| 665 | return ValueObjectSP(); |
| 666 | |
| 667 | default: |
| 668 | // Failure... |
| 669 | { |
| 670 | valobj_sp->GetExpressionPath (var_expr_path_strm); |
| 671 | error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", |
| 672 | separator_type, |
| 673 | var_expr_path_strm.GetString().c_str(), |
| 674 | var_path.c_str()); |
| 675 | |
| 676 | return ValueObjectSP(); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 679 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 680 | if (child_valobj_sp) |
| 681 | valobj_sp = child_valobj_sp; |
| 682 | |
| 683 | if (var_path.empty()) |
| 684 | break; |
| 685 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 686 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 687 | if (valobj_sp) |
| 688 | { |
| 689 | if (deref) |
| 690 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame^] | 691 | ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 692 | valobj_sp = deref_valobj_sp; |
| 693 | } |
| 694 | else if (address_of) |
| 695 | { |
| 696 | ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); |
| 697 | valobj_sp = address_of_valobj_sp; |
| 698 | } |
| 699 | } |
| 700 | return valobj_sp; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 701 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 702 | else |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 703 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 704 | error.SetErrorStringWithFormat("no variable named '%s' found in this frame", name_const_string.GetCString()); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 705 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 706 | } |
| 707 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 708 | else |
| 709 | { |
| 710 | error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); |
| 711 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 712 | return ValueObjectSP(); |
| 713 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | |
| 715 | bool |
| 716 | StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) |
| 717 | { |
| 718 | if (m_flags.IsClear(GOT_FRAME_BASE)) |
| 719 | { |
| 720 | if (m_sc.function) |
| 721 | { |
| 722 | m_frame_base.Clear(); |
| 723 | m_frame_base_error.Clear(); |
| 724 | |
| 725 | m_flags.Set(GOT_FRAME_BASE); |
| 726 | ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this); |
| 727 | Value expr_value; |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 728 | addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; |
| 729 | if (m_sc.function->GetFrameBaseExpression().IsLocationList()) |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 730 | loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget()); |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 731 | |
Jason Molenda | 8e69de4 | 2010-11-20 01:28:30 +0000 | [diff] [blame] | 732 | if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 733 | { |
| 734 | // We should really have an error if evaluate returns, but in case |
| 735 | // we don't, lets set the error to something at least. |
| 736 | if (m_frame_base_error.Success()) |
| 737 | m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); |
| 738 | } |
| 739 | else |
| 740 | { |
| 741 | m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL); |
| 742 | } |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | m_frame_base_error.SetErrorString ("No function in symbol context."); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | if (m_frame_base_error.Success()) |
| 751 | frame_base = m_frame_base; |
| 752 | |
| 753 | if (error_ptr) |
| 754 | *error_ptr = m_frame_base_error; |
| 755 | return m_frame_base_error.Success(); |
| 756 | } |
| 757 | |
| 758 | RegisterContext * |
| 759 | StackFrame::GetRegisterContext () |
| 760 | { |
| 761 | if (m_reg_context_sp.get() == NULL) |
| 762 | m_reg_context_sp.reset (m_thread.CreateRegisterContextForFrame (this)); |
| 763 | return m_reg_context_sp.get(); |
| 764 | } |
| 765 | |
| 766 | bool |
| 767 | StackFrame::HasDebugInformation () |
| 768 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 769 | GetSymbolContext (eSymbolContextLineEntry); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 770 | return m_sc.line_entry.IsValid(); |
| 771 | } |
| 772 | |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 773 | |
| 774 | ValueObjectSP |
| 775 | StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 776 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 777 | ValueObjectSP valobj_sp; |
| 778 | VariableList *var_list = GetVariableList (true); |
| 779 | if (var_list) |
| 780 | { |
| 781 | // Make sure the variable is a frame variable |
| 782 | const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); |
| 783 | const uint32_t num_variables = var_list->GetSize(); |
| 784 | if (var_idx < num_variables) |
| 785 | { |
| 786 | valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); |
| 787 | if (valobj_sp.get() == NULL) |
| 788 | { |
| 789 | if (m_variable_list_value_objects.GetSize() < num_variables) |
| 790 | m_variable_list_value_objects.Resize(num_variables); |
| 791 | valobj_sp.reset (new ValueObjectVariable (variable_sp)); |
| 792 | m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | return valobj_sp; |
| 797 | } |
| 798 | |
| 799 | ValueObjectSP |
| 800 | StackFrame::TrackGlobalVariable (const VariableSP &variable_sp) |
| 801 | { |
| 802 | // Check to make sure we aren't already tracking this variable? |
| 803 | ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp)); |
| 804 | if (!valobj_sp) |
| 805 | { |
| 806 | // We aren't already tracking this global |
| 807 | VariableList *var_list = GetVariableList (true); |
| 808 | // If this frame has no variables, create a new list |
| 809 | if (var_list == NULL) |
| 810 | m_variable_list_sp.reset (new VariableList()); |
| 811 | |
| 812 | // Add the global/static variable to this frame |
| 813 | m_variable_list_sp->AddVariable (variable_sp); |
| 814 | |
| 815 | // Now make a value object for it so we can track its changes |
| 816 | valobj_sp = GetValueObjectForFrameVariable (variable_sp); |
| 817 | } |
| 818 | return valobj_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jim Ingham | 2154da4 | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 821 | bool |
| 822 | StackFrame::IsInlined () |
| 823 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 824 | if (m_sc.block == NULL) |
| 825 | GetSymbolContext (eSymbolContextBlock); |
| 826 | if (m_sc.block) |
| 827 | return m_sc.block->GetContainingInlinedBlock() != NULL; |
| 828 | return false; |
Jim Ingham | 2154da4 | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 831 | Target * |
| 832 | StackFrame::CalculateTarget () |
| 833 | { |
| 834 | return m_thread.CalculateTarget(); |
| 835 | } |
| 836 | |
| 837 | Process * |
| 838 | StackFrame::CalculateProcess () |
| 839 | { |
| 840 | return m_thread.CalculateProcess(); |
| 841 | } |
| 842 | |
| 843 | Thread * |
| 844 | StackFrame::CalculateThread () |
| 845 | { |
| 846 | return &m_thread; |
| 847 | } |
| 848 | |
| 849 | StackFrame * |
| 850 | StackFrame::CalculateStackFrame () |
| 851 | { |
| 852 | return this; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 857 | StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 858 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 859 | m_thread.CalculateExecutionContext (exe_ctx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 860 | exe_ctx.frame = this; |
| 861 | } |
| 862 | |
| 863 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 864 | StackFrame::DumpUsingSettingsFormat (Stream *strm) |
| 865 | { |
| 866 | if (strm == NULL) |
| 867 | return; |
| 868 | |
| 869 | GetSymbolContext(eSymbolContextEverything); |
| 870 | ExecutionContext exe_ctx; |
| 871 | CalculateExecutionContext(exe_ctx); |
| 872 | const char *end = NULL; |
| 873 | StreamString s; |
| 874 | const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat(); |
| 875 | if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end)) |
| 876 | { |
| 877 | strm->Write(s.GetData(), s.GetSize()); |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | Dump (strm, true, false); |
| 882 | strm->EOL(); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 887 | StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 888 | { |
| 889 | if (strm == NULL) |
| 890 | return; |
| 891 | |
| 892 | if (show_frame_index) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 893 | strm->Printf("frame #%u: ", m_frame_index); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 894 | strm->Printf("0x%0*llx ", m_thread.GetProcess().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget())); |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 895 | GetSymbolContext(eSymbolContextEverything); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 896 | const bool show_module = true; |
| 897 | const bool show_inline = true; |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 898 | m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 901 | void |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 902 | StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 903 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 904 | assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing |
| 905 | m_variable_list_sp = prev_frame.m_variable_list_sp; |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 906 | m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); |
Greg Clayton | 870a1cd | 2010-08-27 21:47:54 +0000 | [diff] [blame] | 907 | if (!m_disassembly.GetString().empty()) |
| 908 | m_disassembly.GetString().swap (m_disassembly.GetString()); |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 909 | } |
Greg Clayton | 870a1cd | 2010-08-27 21:47:54 +0000 | [diff] [blame] | 910 | |
| 911 | |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 912 | void |
| 913 | StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) |
| 914 | { |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 915 | assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing |
| 916 | m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 917 | assert (&m_thread == &curr_frame.m_thread); |
| 918 | m_frame_index = curr_frame.m_frame_index; |
| 919 | m_unwind_frame_index = curr_frame.m_unwind_frame_index; |
| 920 | m_reg_context_sp = curr_frame.m_reg_context_sp; |
| 921 | m_frame_code_addr = curr_frame.m_frame_code_addr; |
| 922 | assert (m_sc.target_sp.get() == NULL || curr_frame.m_sc.target_sp.get() == NULL || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get()); |
| 923 | assert (m_sc.module_sp.get() == NULL || curr_frame.m_sc.module_sp.get() == NULL || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get()); |
| 924 | assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); |
| 925 | assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function); |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 926 | m_sc = curr_frame.m_sc; |
| 927 | m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); |
| 928 | m_flags.Set (m_sc.GetResolvedMask()); |
| 929 | m_frame_base.Clear(); |
| 930 | m_frame_base_error.Clear(); |
| 931 | } |
| 932 | |
| 933 | |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 934 | bool |
| 935 | StackFrame::HasCachedData () const |
| 936 | { |
| 937 | if (m_variable_list_sp.get()) |
| 938 | return true; |
| 939 | if (m_variable_list_value_objects.GetSize() > 0) |
| 940 | return true; |
| 941 | if (!m_disassembly.GetString().empty()) |
| 942 | return true; |
| 943 | return false; |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | lldb::StackFrameSP |
| 947 | StackFrame::GetSP () |
| 948 | { |
| 949 | return m_thread.GetStackFrameSPForStackFramePtr (this); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 950 | } |