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 | |
Greg Clayton | 107e53d | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 212 | const 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... |
Greg Clayton | 107e53d | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 221 | |
| 222 | if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), &m_thread.GetProcess().GetTarget())) |
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 | const Section *section = m_frame_code_addr.GetSection(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | if (section) |
| 226 | { |
| 227 | Module *module = section->GetModule(); |
| 228 | if (module) |
| 229 | { |
| 230 | m_sc.module_sp = module->GetSP(); |
| 231 | if (m_sc.module_sp) |
| 232 | m_flags.Set(eSymbolContextModule); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 237 | return m_frame_code_addr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void |
| 241 | StackFrame::ChangePC (addr_t pc) |
| 242 | { |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 243 | m_frame_code_addr.SetOffset(pc); |
| 244 | m_frame_code_addr.SetSection(NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | m_sc.Clear(); |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 246 | m_flags.Reset(0); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | m_thread.ClearStackFrames (); |
| 248 | } |
| 249 | |
| 250 | const char * |
| 251 | StackFrame::Disassemble () |
| 252 | { |
| 253 | if (m_disassembly.GetSize() == 0) |
| 254 | { |
| 255 | ExecutionContext exe_ctx; |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 256 | CalculateExecutionContext(exe_ctx); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 257 | Target &target = m_thread.GetProcess().GetTarget(); |
| 258 | Disassembler::Disassemble (target.GetDebugger(), |
| 259 | target.GetArchitecture(), |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 260 | NULL, |
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 | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 264 | 0, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | m_disassembly); |
| 266 | if (m_disassembly.GetSize() == 0) |
| 267 | return NULL; |
| 268 | } |
| 269 | return m_disassembly.GetData(); |
| 270 | } |
| 271 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 272 | Block * |
| 273 | StackFrame::GetFrameBlock () |
| 274 | { |
| 275 | if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock)) |
| 276 | GetSymbolContext (eSymbolContextBlock); |
| 277 | |
| 278 | if (m_sc.block) |
| 279 | { |
| 280 | Block *inline_block = m_sc.block->GetContainingInlinedBlock(); |
| 281 | if (inline_block) |
| 282 | { |
| 283 | // Use the block with the inlined function info |
| 284 | // as the frame block we want this frame to have only the variables |
| 285 | // for the inlined function and its non-inlined block child blocks. |
| 286 | return inline_block; |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | // This block is not contained withing any inlined function blocks |
| 291 | // with so we want to use the top most function block. |
| 292 | return &m_sc.function->GetBlock (false); |
| 293 | } |
| 294 | } |
| 295 | return NULL; |
| 296 | } |
| 297 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | //---------------------------------------------------------------------- |
| 299 | // Get the symbol context if we already haven't done so by resolving the |
| 300 | // PC address as much as possible. This way when we pass around a |
| 301 | // StackFrame object, everyone will have as much information as |
| 302 | // possible and no one will ever have to look things up manually. |
| 303 | //---------------------------------------------------------------------- |
| 304 | const SymbolContext& |
| 305 | StackFrame::GetSymbolContext (uint32_t resolve_scope) |
| 306 | { |
| 307 | // Copy our internal symbol context into "sc". |
Greg Clayton | f3d0b0c | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 308 | if ((m_flags.Get() & resolve_scope) != resolve_scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | { |
| 310 | // Resolve our PC to section offset if we haven't alreday done so |
| 311 | // and if we don't have a module. The resolved address section will |
| 312 | // contain the module to which it belongs |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 313 | if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 314 | GetFrameCodeAddress(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | |
| 316 | // If this is not frame zero, then we need to subtract 1 from the PC |
| 317 | // value when doing address lookups since the PC will be on the |
| 318 | // instruction following the function call instruction... |
| 319 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 320 | Address lookup_addr(GetFrameCodeAddress()); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 321 | if (m_frame_index > 0 && lookup_addr.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | { |
| 323 | addr_t offset = lookup_addr.GetOffset(); |
| 324 | if (offset > 0) |
| 325 | lookup_addr.SetOffset(offset - 1); |
| 326 | } |
| 327 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 328 | |
| 329 | uint32_t resolved = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | if (m_sc.module_sp) |
| 331 | { |
| 332 | // We have something in our stack frame symbol context, lets check |
| 333 | // if we haven't already tried to lookup one of those things. If we |
| 334 | // haven't then we will do the query. |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 335 | |
| 336 | uint32_t actual_resolve_scope = 0; |
| 337 | |
| 338 | if (resolve_scope & eSymbolContextCompUnit) |
| 339 | { |
| 340 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 341 | { |
| 342 | if (m_sc.comp_unit) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 343 | resolved |= eSymbolContextCompUnit; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 344 | else |
| 345 | actual_resolve_scope |= eSymbolContextCompUnit; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if (resolve_scope & eSymbolContextFunction) |
| 350 | { |
| 351 | if (m_flags.IsClear (eSymbolContextFunction)) |
| 352 | { |
| 353 | if (m_sc.function) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 354 | resolved |= eSymbolContextFunction; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 355 | else |
| 356 | actual_resolve_scope |= eSymbolContextFunction; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if (resolve_scope & eSymbolContextBlock) |
| 361 | { |
| 362 | if (m_flags.IsClear (eSymbolContextBlock)) |
| 363 | { |
| 364 | if (m_sc.block) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 365 | resolved |= eSymbolContextBlock; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 366 | else |
| 367 | actual_resolve_scope |= eSymbolContextBlock; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (resolve_scope & eSymbolContextSymbol) |
| 372 | { |
| 373 | if (m_flags.IsClear (eSymbolContextSymbol)) |
| 374 | { |
| 375 | if (m_sc.symbol) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 376 | resolved |= eSymbolContextSymbol; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 377 | else |
| 378 | actual_resolve_scope |= eSymbolContextSymbol; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (resolve_scope & eSymbolContextLineEntry) |
| 383 | { |
| 384 | if (m_flags.IsClear (eSymbolContextLineEntry)) |
| 385 | { |
| 386 | if (m_sc.line_entry.IsValid()) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 387 | resolved |= eSymbolContextLineEntry; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 388 | else |
| 389 | actual_resolve_scope |= eSymbolContextLineEntry; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | if (actual_resolve_scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | { |
| 395 | // We might be resolving less information than what is already |
| 396 | // in our current symbol context so resolve into a temporary |
| 397 | // symbol context "sc" so we don't clear out data we have |
| 398 | // already found in "m_sc" |
| 399 | SymbolContext sc; |
| 400 | // Set flags that indicate what we have tried to resolve |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 401 | resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 402 | // Only replace what we didn't already have as we may have |
| 403 | // information for an inlined function scope that won't match |
| 404 | // what a standard lookup by address would match |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 405 | if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL) |
| 406 | m_sc.comp_unit = sc.comp_unit; |
| 407 | if ((resolved & eSymbolContextFunction) && m_sc.function == NULL) |
| 408 | m_sc.function = sc.function; |
| 409 | if ((resolved & eSymbolContextBlock) && m_sc.block == NULL) |
| 410 | m_sc.block = sc.block; |
| 411 | if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL) |
| 412 | m_sc.symbol = sc.symbol; |
| 413 | if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) |
| 414 | m_sc.line_entry = sc.line_entry; |
| 415 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | // If we don't have a module, then we can't have the compile unit, |
| 421 | // function, block, line entry or symbol, so we can safely call |
| 422 | // ResolveSymbolContextForAddress with our symbol context member m_sc. |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 423 | 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] | 424 | } |
| 425 | |
| 426 | // If the target was requested add that: |
| 427 | if (m_sc.target_sp.get() == NULL) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 428 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | m_sc.target_sp = CalculateProcess()->GetTarget().GetSP(); |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 430 | if (m_sc.target_sp) |
| 431 | resolved |= eSymbolContextTarget; |
| 432 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | |
| 434 | // Update our internal flags so we remember what we have tried to locate so |
| 435 | // 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] | 436 | // We might have dug up more information that was requested (for example |
| 437 | // if we were asked to only get the block, we will have gotten the |
| 438 | // compile unit, and function) so set any additional bits that we resolved |
| 439 | m_flags.Set (resolve_scope | resolved); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | // Return the symbol context with everything that was possible to resolve |
| 443 | // resolved. |
| 444 | return m_sc; |
| 445 | } |
| 446 | |
| 447 | |
| 448 | VariableList * |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 449 | StackFrame::GetVariableList (bool get_file_globals) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | { |
| 451 | if (m_flags.IsClear(RESOLVED_VARIABLES)) |
| 452 | { |
| 453 | m_flags.Set(RESOLVED_VARIABLES); |
| 454 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 455 | Block *frame_block = GetFrameBlock(); |
| 456 | |
| 457 | if (frame_block) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 459 | const bool get_child_variables = true; |
| 460 | const bool can_create = true; |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 461 | const bool stop_if_child_block_is_inlined_function = true; |
| 462 | m_variable_list_sp.reset(new VariableList()); |
| 463 | frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 464 | } |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && |
| 468 | get_file_globals) |
| 469 | { |
| 470 | m_flags.Set(RESOLVED_GLOBAL_VARIABLES); |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 471 | |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 472 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 473 | GetSymbolContext (eSymbolContextCompUnit); |
| 474 | |
| 475 | if (m_sc.comp_unit) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 476 | { |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 477 | VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); |
| 478 | if (m_variable_list_sp) |
| 479 | m_variable_list_sp->AddVariables (global_variable_list_sp.get()); |
| 480 | else |
| 481 | m_variable_list_sp = global_variable_list_sp; |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 482 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | } |
Sean Callanan | 8936359 | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 484 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | return m_variable_list_sp.get(); |
| 486 | } |
| 487 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 488 | ValueObjectSP |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 489 | StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, |
| 490 | lldb::DynamicValueType use_dynamic, |
| 491 | uint32_t options, |
| 492 | lldb::VariableSP &var_sp, |
| 493 | Error &error) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 494 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 495 | |
| 496 | if (var_expr_cstr && var_expr_cstr[0]) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 497 | { |
Greg Clayton | c67efa4 | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 498 | const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; |
| 499 | const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 500 | error.Clear(); |
| 501 | bool deref = false; |
| 502 | bool address_of = false; |
| 503 | ValueObjectSP valobj_sp; |
| 504 | const bool get_file_globals = true; |
| 505 | VariableList *variable_list = GetVariableList (get_file_globals); |
| 506 | |
| 507 | if (variable_list) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 508 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 509 | // If first character is a '*', then show pointer contents |
| 510 | const char *var_expr = var_expr_cstr; |
| 511 | if (var_expr[0] == '*') |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 512 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 513 | deref = true; |
| 514 | var_expr++; // Skip the '*' |
| 515 | } |
| 516 | else if (var_expr[0] == '&') |
| 517 | { |
| 518 | address_of = true; |
| 519 | var_expr++; // Skip the '&' |
| 520 | } |
| 521 | |
| 522 | std::string var_path (var_expr); |
| 523 | size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); |
| 524 | StreamString var_expr_path_strm; |
| 525 | |
| 526 | ConstString name_const_string; |
| 527 | if (separator_idx == std::string::npos) |
| 528 | name_const_string.SetCString (var_path.c_str()); |
| 529 | else |
| 530 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 531 | |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 532 | var_sp = variable_list->FindVariable(name_const_string); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 533 | if (var_sp) |
| 534 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 535 | valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 536 | if (!valobj_sp) |
| 537 | return valobj_sp; |
| 538 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 539 | var_path.erase (0, name_const_string.GetLength ()); |
| 540 | // We are dumping at least one child |
| 541 | while (separator_idx != std::string::npos) |
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 | // Calculate the next separator index ahead of time |
| 544 | ValueObjectSP child_valobj_sp; |
| 545 | const char separator_type = var_path[0]; |
| 546 | switch (separator_type) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 547 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 548 | |
| 549 | case '-': |
| 550 | if (var_path.size() >= 2 && var_path[1] != '>') |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 551 | return ValueObjectSP(); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 552 | |
Greg Clayton | c67efa4 | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 553 | if (no_fragile_ivar) |
| 554 | { |
| 555 | // Make sure we aren't trying to deref an objective |
| 556 | // C ivar if this is not allowed |
| 557 | const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL); |
| 558 | if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) && |
| 559 | (pointer_type_flags & ClangASTContext::eTypeIsPointer)) |
| 560 | { |
| 561 | // This was an objective C object pointer and |
| 562 | // it was requested we skip any fragile ivars |
| 563 | // so return nothing here |
| 564 | return ValueObjectSP(); |
| 565 | } |
| 566 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 567 | var_path.erase (0, 1); // Remove the '-' |
| 568 | // Fall through |
| 569 | case '.': |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 570 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 571 | const bool expr_is_ptr = var_path[0] == '>'; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 572 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 573 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 574 | separator_idx = var_path.find_first_of(".-["); |
| 575 | ConstString child_name; |
| 576 | if (separator_idx == std::string::npos) |
| 577 | child_name.SetCString (var_path.c_str()); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 578 | else |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 579 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
| 580 | |
| 581 | if (check_ptr_vs_member) |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 582 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 583 | // We either have a pointer type and need to verify |
| 584 | // valobj_sp is a pointer, or we have a member of a |
| 585 | // class/union/struct being accessed with the . syntax |
| 586 | // and need to verify we don't have a pointer. |
| 587 | const bool actual_is_ptr = valobj_sp->IsPointerType (); |
| 588 | |
| 589 | if (actual_is_ptr != expr_is_ptr) |
| 590 | { |
| 591 | // Incorrect use of "." with a pointer, or "->" with |
| 592 | // a class/union/struct instance or reference. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 593 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 594 | if (actual_is_ptr) |
| 595 | error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", |
| 596 | var_expr_path_strm.GetString().c_str(), |
| 597 | child_name.GetCString(), |
| 598 | var_expr_path_strm.GetString().c_str(), |
| 599 | var_path.c_str()); |
| 600 | else |
| 601 | error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", |
| 602 | var_expr_path_strm.GetString().c_str(), |
| 603 | child_name.GetCString(), |
| 604 | var_expr_path_strm.GetString().c_str(), |
| 605 | var_path.c_str()); |
| 606 | return ValueObjectSP(); |
| 607 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 608 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 609 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 610 | if (!child_valobj_sp) |
| 611 | { |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 612 | // No child member with name "child_name" |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 613 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 614 | if (child_name) |
| 615 | { |
| 616 | error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", |
| 617 | child_name.GetCString(), |
| 618 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 619 | var_expr_path_strm.GetString().c_str()); |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", |
| 624 | var_expr_path_strm.GetString().c_str(), |
| 625 | var_expr_cstr); |
| 626 | } |
| 627 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 628 | return ValueObjectSP(); |
| 629 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 630 | // Remove the child name from the path |
| 631 | var_path.erase(0, child_name.GetLength()); |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 632 | if (use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 633 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 634 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 635 | if (dynamic_value_sp) |
| 636 | child_valobj_sp = dynamic_value_sp; |
| 637 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 638 | } |
| 639 | break; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 640 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 641 | case '[': |
| 642 | // Array member access, or treating pointer as an array |
| 643 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 644 | { |
| 645 | char *end = NULL; |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 646 | long child_index = ::strtol (&var_path[1], &end, 0); |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 647 | if (end && *end == ']' |
| 648 | && *(end-1) != '[') // this code forces an error in the case of arr[]. as bitfield[] is not a good syntax we're good to go |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 649 | { |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 650 | if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) |
| 651 | { |
| 652 | // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr |
| 653 | // and extract bit low out of it. reading array item low |
| 654 | // would be done by saying ptr[low], without a deref * sign |
| 655 | Error error; |
| 656 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 657 | if (error.Fail()) |
| 658 | { |
| 659 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 660 | error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", |
| 661 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 662 | var_expr_path_strm.GetString().c_str()); |
| 663 | return ValueObjectSP(); |
| 664 | } |
| 665 | valobj_sp = temp; |
| 666 | deref = false; |
| 667 | } |
| 668 | else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) |
| 669 | { |
| 670 | // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] |
| 671 | // (an operation that is equivalent to deref-ing arr) |
| 672 | // and extract bit low out of it. reading array item low |
| 673 | // would be done by saying arr[low], without a deref * sign |
| 674 | Error error; |
| 675 | ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); |
| 676 | if (error.Fail()) |
| 677 | { |
| 678 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 679 | error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", |
| 680 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 681 | var_expr_path_strm.GetString().c_str()); |
| 682 | return ValueObjectSP(); |
| 683 | } |
| 684 | valobj_sp = temp; |
| 685 | deref = false; |
| 686 | } |
| 687 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 688 | if (valobj_sp->IsPointerType ()) |
| 689 | { |
| 690 | child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); |
| 691 | if (!child_valobj_sp) |
| 692 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 693 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 694 | error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"", |
| 695 | child_index, |
| 696 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 697 | var_expr_path_strm.GetString().c_str()); |
| 698 | } |
| 699 | } |
| 700 | else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL)) |
| 701 | { |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 702 | // Pass false to dynamic_value here so we can tell the difference between |
| 703 | // no dynamic value and no member of this type... |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 704 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
| 705 | if (!child_valobj_sp) |
| 706 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 707 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 708 | error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"", |
| 709 | child_index, |
| 710 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 711 | var_expr_path_strm.GetString().c_str()); |
| 712 | } |
| 713 | } |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 714 | else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType())) |
| 715 | { |
| 716 | // this is a bitfield asking to display just one bit |
| 717 | child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); |
| 718 | if (!child_valobj_sp) |
| 719 | { |
| 720 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 721 | error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"", |
| 722 | child_index, child_index, |
| 723 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 724 | var_expr_path_strm.GetString().c_str()); |
| 725 | } |
| 726 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 727 | else |
| 728 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 729 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 730 | error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", |
| 731 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 732 | var_expr_path_strm.GetString().c_str()); |
| 733 | } |
| 734 | |
| 735 | if (!child_valobj_sp) |
| 736 | { |
| 737 | // Invalid array index... |
| 738 | return ValueObjectSP(); |
| 739 | } |
| 740 | |
| 741 | // Erase the array member specification '[%i]' where |
| 742 | // %i is the array index |
| 743 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 744 | separator_idx = var_path.find_first_of(".-["); |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 745 | if (use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 746 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 747 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 748 | if (dynamic_value_sp) |
| 749 | child_valobj_sp = dynamic_value_sp; |
| 750 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 751 | // Break out early from the switch since we were |
| 752 | // able to find the child member |
| 753 | break; |
| 754 | } |
Enrico Granata | 4c3fb4b | 2011-07-19 18:03:25 +0000 | [diff] [blame^] | 755 | else if (end && *end == '-') |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 756 | { |
| 757 | // this is most probably a BitField, let's take a look |
| 758 | char *real_end = NULL; |
| 759 | long final_index = ::strtol (end+1, &real_end, 0); |
Enrico Granata | 4c3fb4b | 2011-07-19 18:03:25 +0000 | [diff] [blame^] | 760 | if (real_end && *real_end == ']') |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 761 | { |
| 762 | // if the format given is [high-low], swap range |
Enrico Granata | 4c3fb4b | 2011-07-19 18:03:25 +0000 | [diff] [blame^] | 763 | if (child_index > final_index) |
Enrico Granata | 9762e10 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 764 | { |
| 765 | long temp = child_index; |
| 766 | child_index = final_index; |
| 767 | final_index = temp; |
| 768 | } |
| 769 | |
| 770 | if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) |
| 771 | { |
| 772 | // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr |
| 773 | // and extract bits low thru high out of it. reading array items low thru high |
| 774 | // would be done by saying ptr[low-high], without a deref * sign |
| 775 | Error error; |
| 776 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 777 | if (error.Fail()) |
| 778 | { |
| 779 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 780 | error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", |
| 781 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 782 | var_expr_path_strm.GetString().c_str()); |
| 783 | return ValueObjectSP(); |
| 784 | } |
| 785 | valobj_sp = temp; |
| 786 | deref = false; |
| 787 | } |
| 788 | else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) |
| 789 | { |
| 790 | // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] |
| 791 | // (an operation that is equivalent to deref-ing arr) |
| 792 | // and extract bits low thru high out of it. reading array items low thru high |
| 793 | // would be done by saying arr[low-high], without a deref * sign |
| 794 | Error error; |
| 795 | ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); |
| 796 | if (error.Fail()) |
| 797 | { |
| 798 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 799 | error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", |
| 800 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 801 | var_expr_path_strm.GetString().c_str()); |
| 802 | return ValueObjectSP(); |
| 803 | } |
| 804 | valobj_sp = temp; |
| 805 | deref = false; |
| 806 | } |
| 807 | |
| 808 | child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); |
| 809 | if (!child_valobj_sp) |
| 810 | { |
| 811 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 812 | error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"", |
| 813 | child_index, final_index, |
| 814 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 815 | var_expr_path_strm.GetString().c_str()); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | if (!child_valobj_sp) |
| 820 | { |
| 821 | // Invalid bitfield range... |
| 822 | return ValueObjectSP(); |
| 823 | } |
| 824 | |
| 825 | // Erase the bitfield member specification '[%i-%i]' where |
| 826 | // %i is the index |
| 827 | var_path.erase(0, (real_end - var_path.c_str()) + 1); |
| 828 | separator_idx = var_path.find_first_of(".-["); |
| 829 | if (use_dynamic != lldb::eNoDynamicValues) |
| 830 | { |
| 831 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
| 832 | if (dynamic_value_sp) |
| 833 | child_valobj_sp = dynamic_value_sp; |
| 834 | } |
| 835 | // Break out early from the switch since we were |
| 836 | // able to find the child member |
| 837 | break; |
| 838 | |
| 839 | } |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", |
| 844 | var_expr_path_strm.GetString().c_str(), |
| 845 | var_path.c_str()); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 846 | } |
| 847 | return ValueObjectSP(); |
| 848 | |
| 849 | default: |
| 850 | // Failure... |
| 851 | { |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 852 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 853 | error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", |
| 854 | separator_type, |
| 855 | var_expr_path_strm.GetString().c_str(), |
| 856 | var_path.c_str()); |
| 857 | |
| 858 | return ValueObjectSP(); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 859 | } |
| 860 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 861 | |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 862 | if (child_valobj_sp) |
| 863 | valobj_sp = child_valobj_sp; |
| 864 | |
| 865 | if (var_path.empty()) |
| 866 | break; |
| 867 | |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 868 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 869 | if (valobj_sp) |
| 870 | { |
| 871 | if (deref) |
| 872 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 873 | ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 874 | valobj_sp = deref_valobj_sp; |
| 875 | } |
| 876 | else if (address_of) |
| 877 | { |
| 878 | ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); |
| 879 | valobj_sp = address_of_valobj_sp; |
| 880 | } |
| 881 | } |
| 882 | return valobj_sp; |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 883 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 884 | else |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 885 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 886 | error.SetErrorStringWithFormat("no variable named '%s' found in this frame", |
| 887 | name_const_string.GetCString()); |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 888 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 891 | else |
| 892 | { |
| 893 | error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); |
| 894 | } |
Greg Clayton | 427f290 | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 895 | return ValueObjectSP(); |
| 896 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | |
| 898 | bool |
| 899 | StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) |
| 900 | { |
| 901 | if (m_flags.IsClear(GOT_FRAME_BASE)) |
| 902 | { |
| 903 | if (m_sc.function) |
| 904 | { |
| 905 | m_frame_base.Clear(); |
| 906 | m_frame_base_error.Clear(); |
| 907 | |
| 908 | m_flags.Set(GOT_FRAME_BASE); |
| 909 | ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this); |
| 910 | Value expr_value; |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 911 | addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; |
| 912 | if (m_sc.function->GetFrameBaseExpression().IsLocationList()) |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 913 | 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] | 914 | |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 915 | 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] | 916 | { |
| 917 | // We should really have an error if evaluate returns, but in case |
| 918 | // we don't, lets set the error to something at least. |
| 919 | if (m_frame_base_error.Success()) |
| 920 | m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL); |
| 925 | } |
| 926 | } |
| 927 | else |
| 928 | { |
| 929 | m_frame_base_error.SetErrorString ("No function in symbol context."); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | if (m_frame_base_error.Success()) |
| 934 | frame_base = m_frame_base; |
| 935 | |
| 936 | if (error_ptr) |
| 937 | *error_ptr = m_frame_base_error; |
| 938 | return m_frame_base_error.Success(); |
| 939 | } |
| 940 | |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 941 | RegisterContextSP |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 942 | StackFrame::GetRegisterContext () |
| 943 | { |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 944 | if (!m_reg_context_sp) |
| 945 | m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this); |
| 946 | return m_reg_context_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | bool |
| 950 | StackFrame::HasDebugInformation () |
| 951 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 952 | GetSymbolContext (eSymbolContextLineEntry); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | return m_sc.line_entry.IsValid(); |
| 954 | } |
| 955 | |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 956 | |
| 957 | ValueObjectSP |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 958 | StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 959 | { |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 960 | ValueObjectSP valobj_sp; |
| 961 | VariableList *var_list = GetVariableList (true); |
| 962 | if (var_list) |
| 963 | { |
| 964 | // Make sure the variable is a frame variable |
| 965 | const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); |
| 966 | const uint32_t num_variables = var_list->GetSize(); |
| 967 | if (var_idx < num_variables) |
| 968 | { |
| 969 | valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); |
| 970 | if (valobj_sp.get() == NULL) |
| 971 | { |
| 972 | if (m_variable_list_value_objects.GetSize() < num_variables) |
| 973 | m_variable_list_value_objects.Resize(num_variables); |
Jim Ingham | 47da810 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 974 | valobj_sp = ValueObjectVariable::Create (this, variable_sp); |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 975 | m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); |
| 976 | } |
| 977 | } |
| 978 | } |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 979 | if (use_dynamic != lldb::eNoDynamicValues && valobj_sp) |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 980 | { |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 981 | ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 982 | if (dynamic_sp) |
| 983 | return dynamic_sp; |
| 984 | } |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 985 | return valobj_sp; |
| 986 | } |
| 987 | |
| 988 | ValueObjectSP |
Jim Ingham | 10de7d1 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 989 | StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 990 | { |
| 991 | // Check to make sure we aren't already tracking this variable? |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 992 | ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 993 | if (!valobj_sp) |
| 994 | { |
| 995 | // We aren't already tracking this global |
| 996 | VariableList *var_list = GetVariableList (true); |
| 997 | // If this frame has no variables, create a new list |
| 998 | if (var_list == NULL) |
| 999 | m_variable_list_sp.reset (new VariableList()); |
| 1000 | |
| 1001 | // Add the global/static variable to this frame |
| 1002 | m_variable_list_sp->AddVariable (variable_sp); |
| 1003 | |
| 1004 | // Now make a value object for it so we can track its changes |
Jim Ingham | e41494a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1005 | valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1006 | } |
| 1007 | return valobj_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Jim Ingham | 2154da4 | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 1010 | bool |
| 1011 | StackFrame::IsInlined () |
| 1012 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1013 | if (m_sc.block == NULL) |
| 1014 | GetSymbolContext (eSymbolContextBlock); |
| 1015 | if (m_sc.block) |
| 1016 | return m_sc.block->GetContainingInlinedBlock() != NULL; |
| 1017 | return false; |
Jim Ingham | 2154da4 | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | Target * |
| 1021 | StackFrame::CalculateTarget () |
| 1022 | { |
| 1023 | return m_thread.CalculateTarget(); |
| 1024 | } |
| 1025 | |
| 1026 | Process * |
| 1027 | StackFrame::CalculateProcess () |
| 1028 | { |
| 1029 | return m_thread.CalculateProcess(); |
| 1030 | } |
| 1031 | |
| 1032 | Thread * |
| 1033 | StackFrame::CalculateThread () |
| 1034 | { |
| 1035 | return &m_thread; |
| 1036 | } |
| 1037 | |
| 1038 | StackFrame * |
| 1039 | StackFrame::CalculateStackFrame () |
| 1040 | { |
| 1041 | return this; |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1046 | StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1048 | m_thread.CalculateExecutionContext (exe_ctx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1049 | exe_ctx.frame = this; |
| 1050 | } |
| 1051 | |
| 1052 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1053 | StackFrame::DumpUsingSettingsFormat (Stream *strm) |
| 1054 | { |
| 1055 | if (strm == NULL) |
| 1056 | return; |
| 1057 | |
| 1058 | GetSymbolContext(eSymbolContextEverything); |
| 1059 | ExecutionContext exe_ctx; |
| 1060 | CalculateExecutionContext(exe_ctx); |
| 1061 | const char *end = NULL; |
| 1062 | StreamString s; |
| 1063 | const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat(); |
| 1064 | if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end)) |
| 1065 | { |
| 1066 | strm->Write(s.GetData(), s.GetSize()); |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | Dump (strm, true, false); |
| 1071 | strm->EOL(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | void |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 1076 | StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1077 | { |
| 1078 | if (strm == NULL) |
| 1079 | return; |
| 1080 | |
| 1081 | if (show_frame_index) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 1082 | strm->Printf("frame #%u: ", m_frame_index); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 1083 | 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] | 1084 | GetSymbolContext(eSymbolContextEverything); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 1085 | const bool show_module = true; |
| 1086 | const bool show_inline = true; |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 1087 | 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] | 1088 | } |
| 1089 | |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1090 | void |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1091 | StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1093 | assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing |
| 1094 | m_variable_list_sp = prev_frame.m_variable_list_sp; |
Greg Clayton | 17dae08 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1095 | 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] | 1096 | if (!m_disassembly.GetString().empty()) |
| 1097 | m_disassembly.GetString().swap (m_disassembly.GetString()); |
Greg Clayton | 1d66ef5 | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1098 | } |
Greg Clayton | 870a1cd | 2010-08-27 21:47:54 +0000 | [diff] [blame] | 1099 | |
| 1100 | |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1101 | void |
| 1102 | StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) |
| 1103 | { |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1104 | assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing |
| 1105 | 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] | 1106 | assert (&m_thread == &curr_frame.m_thread); |
| 1107 | m_frame_index = curr_frame.m_frame_index; |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1108 | m_concrete_frame_index = curr_frame.m_concrete_frame_index; |
Greg Clayton | 4fb0815 | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1109 | m_reg_context_sp = curr_frame.m_reg_context_sp; |
| 1110 | m_frame_code_addr = curr_frame.m_frame_code_addr; |
| 1111 | 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()); |
| 1112 | 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()); |
| 1113 | assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); |
| 1114 | 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] | 1115 | m_sc = curr_frame.m_sc; |
| 1116 | m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); |
| 1117 | m_flags.Set (m_sc.GetResolvedMask()); |
| 1118 | m_frame_base.Clear(); |
| 1119 | m_frame_base_error.Clear(); |
| 1120 | } |
| 1121 | |
| 1122 | |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1123 | bool |
| 1124 | StackFrame::HasCachedData () const |
| 1125 | { |
| 1126 | if (m_variable_list_sp.get()) |
| 1127 | return true; |
| 1128 | if (m_variable_list_value_objects.GetSize() > 0) |
| 1129 | return true; |
| 1130 | if (!m_disassembly.GetString().empty()) |
| 1131 | return true; |
| 1132 | return false; |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | lldb::StackFrameSP |
| 1136 | StackFrame::GetSP () |
| 1137 | { |
| 1138 | return m_thread.GetStackFrameSPForStackFramePtr (this); |
Greg Clayton | bdcb6ab | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 1139 | } |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1140 | |
| 1141 | |
| 1142 | |
| 1143 | bool |
| 1144 | StackFrame::GetStatus (Stream& strm, |
| 1145 | bool show_frame_info, |
| 1146 | bool show_source, |
| 1147 | uint32_t source_lines_before, |
| 1148 | uint32_t source_lines_after) |
| 1149 | { |
| 1150 | if (show_frame_info) |
| 1151 | { |
| 1152 | strm.Indent(); |
| 1153 | DumpUsingSettingsFormat (&strm); |
| 1154 | } |
| 1155 | |
| 1156 | if (show_source) |
| 1157 | { |
| 1158 | GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); |
| 1159 | |
| 1160 | if (m_sc.comp_unit && m_sc.line_entry.IsValid()) |
| 1161 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 1162 | Target &target = GetThread().GetProcess().GetTarget(); |
| 1163 | target.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers ( |
| 1164 | &target, |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1165 | m_sc.line_entry.file, |
| 1166 | m_sc.line_entry.line, |
| 1167 | 3, |
| 1168 | 3, |
| 1169 | "->", |
| 1170 | &strm); |
| 1171 | |
| 1172 | } |
| 1173 | } |
| 1174 | return true; |
| 1175 | } |
| 1176 | |