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