blob: 1197586f66583e3318e61a5b3fc87b6ba546750b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Target/StackFrame.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/Module.h"
Greg Clayton0603aa92010-10-04 01:05:56 +000019#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Disassembler.h"
21#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000022#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:08 +000023#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Symbol/Symbol.h"
27#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000028#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/ExecutionContext.h"
30#include "lldb/Target/Process.h"
31#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38// The first bits in the flags are reserved for the SymbolContext::Scope bits
39// so we know if we have tried to look up information in our internal symbol
40// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000041#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000042#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000043#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
44#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000045#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046
Greg Claytond9e416c2012-02-18 05:35:26 +000047StackFrame::StackFrame (const ThreadSP &thread_sp,
48 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000049 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000050 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000051 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000052 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000053 uint32_t stop_id,
54 bool stop_id_is_valid,
55 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000056 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000057 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000058 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000059 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000060 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:10 +000061 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +000062 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000063 m_sc (),
64 m_flags (),
65 m_frame_base (),
66 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000067 m_cfa_is_valid (cfa_is_valid),
68 m_stop_id (stop_id),
69 m_stop_id_is_valid (stop_id_is_valid),
70 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000072 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +000073 m_disassembly (),
74 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075{
Jason Molenda99618472013-11-04 11:02:52 +000076 // If we don't have a CFA value, use the frame index for our StackID so that recursive
77 // functions properly aren't confused with one another on a history stack.
78 if (m_is_history_frame && m_cfa_is_valid == false)
79 {
80 m_id.SetCFA (m_frame_index);
81 }
82
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000084 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000086 m_flags.Set(m_sc.GetResolvedMask ());
87 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088}
89
Greg Claytond9e416c2012-02-18 05:35:26 +000090StackFrame::StackFrame (const ThreadSP &thread_sp,
91 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000092 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000093 const RegisterContextSP &reg_context_sp,
94 addr_t cfa,
95 addr_t pc,
96 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000097 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000098 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000099 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000100 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:10 +0000101 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +0000102 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000103 m_sc (),
104 m_flags (),
105 m_frame_base (),
106 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000107 m_cfa_is_valid (true),
108 m_stop_id (0),
109 m_stop_id_is_valid (false),
110 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000112 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000113 m_disassembly (),
114 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115{
116 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000117 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000119 m_flags.Set(m_sc.GetResolvedMask ());
120 }
121
122 if (reg_context_sp && !m_sc.target_sp)
123 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000124 m_sc.target_sp = reg_context_sp->CalculateTarget();
125 if (m_sc.target_sp)
126 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000127 }
128}
129
Greg Claytond9e416c2012-02-18 05:35:26 +0000130StackFrame::StackFrame (const ThreadSP &thread_sp,
131 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000132 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000133 const RegisterContextSP &reg_context_sp,
134 addr_t cfa,
135 const Address& pc_addr,
136 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000137 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000138 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000139 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000140 m_reg_context_sp (reg_context_sp),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000141 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000142 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000143 m_sc (),
144 m_flags (),
145 m_frame_base (),
146 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000147 m_cfa_is_valid (true),
148 m_stop_id (0),
149 m_stop_id_is_valid (false),
150 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000151 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000152 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000153 m_disassembly (),
154 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000155{
156 if (sc_ptr != NULL)
157 {
158 m_sc = *sc_ptr;
159 m_flags.Set(m_sc.GetResolvedMask ());
160 }
161
162 if (m_sc.target_sp.get() == NULL && reg_context_sp)
163 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000164 m_sc.target_sp = reg_context_sp->CalculateTarget();
165 if (m_sc.target_sp)
166 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000167 }
168
Greg Claytone72dfb32012-02-24 01:59:29 +0000169 ModuleSP pc_module_sp (pc_addr.GetModule());
170 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000171 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000172 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000173 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000174 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000175 m_flags.Set (eSymbolContextModule);
176 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000177 else
178 {
179 m_sc.module_sp.reset();
180 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000181 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182}
183
184
185//----------------------------------------------------------------------
186// Destructor
187//----------------------------------------------------------------------
188StackFrame::~StackFrame()
189{
190}
191
192StackID&
193StackFrame::GetStackID()
194{
Jason Molenda6a354702014-10-02 01:08:16 +0000195 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10 +0000196 // Make sure we have resolved the StackID object's symbol context scope if
197 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000199 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
200 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000201 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000202 {
Greg Clayton95897c62010-09-07 04:20:48 +0000203 // We already have a symbol context scope, we just don't have our
204 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000205 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
206 }
207 else
208 {
Greg Clayton95897c62010-09-07 04:20:48 +0000209 // Calculate the frame block and use this for the stack ID symbol
210 // context scope if we have one.
211 SymbolContextScope *scope = GetFrameBlock ();
212 if (scope == NULL)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000213 {
Greg Clayton95897c62010-09-07 04:20:48 +0000214 // We don't have a block, so use the symbol
215 if (m_flags.IsClear (eSymbolContextSymbol))
216 GetSymbolContext (eSymbolContextSymbol);
217
218 // It is ok if m_sc.symbol is NULL here
219 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000220 }
Greg Clayton95897c62010-09-07 04:20:48 +0000221 // Set the symbol context scope (the accessor will set the
222 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
223 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 }
226 return m_id;
227}
228
Jim Ingham513c6bb2012-09-01 01:02:41 +0000229uint32_t
230StackFrame::GetFrameIndex () const
231{
232 ThreadSP thread_sp = GetThread();
233 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000234 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000235 else
236 return m_frame_index;
237}
238
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000239void
240StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
241{
Jason Molenda6a354702014-10-02 01:08:16 +0000242 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000243 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
244 m_id.SetSymbolContextScope (symbol_scope);
245}
246
Greg Clayton34132752011-07-06 04:07:21 +0000247const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000248StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249{
Jason Molenda6a354702014-10-02 01:08:16 +0000250 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000251 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000253 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254
255 // Resolve the PC into a temporary address because if ResolveLoadAddress
256 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000257 ThreadSP thread_sp (GetThread());
258 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000260 TargetSP target_sp (thread_sp->CalculateTarget());
261 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000263 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000265 ModuleSP module_sp (m_frame_code_addr.GetModule());
266 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000267 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000268 m_sc.module_sp = module_sp;
269 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000270 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 }
272 }
273 }
274 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000275 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276}
277
Jason Molenda99618472013-11-04 11:02:52 +0000278bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279StackFrame::ChangePC (addr_t pc)
280{
Jason Molenda6a354702014-10-02 01:08:16 +0000281 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000282 // We can't change the pc value of a history stack frame - it is immutable.
283 if (m_is_history_frame)
284 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000285 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47 +0000286 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59 +0000287 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26 +0000288 ThreadSP thread_sp (GetThread());
289 if (thread_sp)
290 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52 +0000291 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292}
293
294const char *
295StackFrame::Disassemble ()
296{
Jason Molenda6a354702014-10-02 01:08:16 +0000297 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 if (m_disassembly.GetSize() == 0)
299 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000300 ExecutionContext exe_ctx (shared_from_this());
301 Target *target = exe_ctx.GetTargetPtr();
302 if (target)
303 {
Jim Ingham0f063ba2013-03-02 00:26:47 +0000304 const char *plugin_name = NULL;
305 const char *flavor = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000306 Disassembler::Disassemble (target->GetDebugger(),
307 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000308 plugin_name,
309 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000310 exe_ctx,
311 0,
312 0,
313 0,
314 m_disassembly);
315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 if (m_disassembly.GetSize() == 0)
317 return NULL;
318 }
319 return m_disassembly.GetData();
320}
321
Greg Clayton95897c62010-09-07 04:20:48 +0000322Block *
323StackFrame::GetFrameBlock ()
324{
325 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
326 GetSymbolContext (eSymbolContextBlock);
327
328 if (m_sc.block)
329 {
330 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
331 if (inline_block)
332 {
333 // Use the block with the inlined function info
334 // as the frame block we want this frame to have only the variables
335 // for the inlined function and its non-inlined block child blocks.
336 return inline_block;
337 }
338 else
339 {
340 // This block is not contained withing any inlined function blocks
341 // with so we want to use the top most function block.
342 return &m_sc.function->GetBlock (false);
343 }
344 }
345 return NULL;
346}
347
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348//----------------------------------------------------------------------
349// Get the symbol context if we already haven't done so by resolving the
350// PC address as much as possible. This way when we pass around a
351// StackFrame object, everyone will have as much information as
352// possible and no one will ever have to look things up manually.
353//----------------------------------------------------------------------
354const SymbolContext&
355StackFrame::GetSymbolContext (uint32_t resolve_scope)
356{
Jason Molenda6a354702014-10-02 01:08:16 +0000357 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000359 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 {
Greg Clayton75a03332012-11-29 00:53:06 +0000361 uint32_t resolved = 0;
362
363 // If the target was requested add that:
364 if (!m_sc.target_sp)
365 {
366 m_sc.target_sp = CalculateTarget();
367 if (m_sc.target_sp)
368 resolved |= eSymbolContextTarget;
369 }
370
371
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000372 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 // and if we don't have a module. The resolved address section will
374 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000375 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000376 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377
378 // If this is not frame zero, then we need to subtract 1 from the PC
379 // value when doing address lookups since the PC will be on the
380 // instruction following the function call instruction...
381
Greg Clayton9da7bd02010-08-24 21:05:24 +0000382 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000383 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 {
385 addr_t offset = lookup_addr.GetOffset();
386 if (offset > 0)
387 lookup_addr.SetOffset(offset - 1);
388 }
389
Greg Clayton9da7bd02010-08-24 21:05:24 +0000390
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391 if (m_sc.module_sp)
392 {
393 // We have something in our stack frame symbol context, lets check
394 // if we haven't already tried to lookup one of those things. If we
395 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000396
397 uint32_t actual_resolve_scope = 0;
398
399 if (resolve_scope & eSymbolContextCompUnit)
400 {
401 if (m_flags.IsClear (eSymbolContextCompUnit))
402 {
403 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000404 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000405 else
406 actual_resolve_scope |= eSymbolContextCompUnit;
407 }
408 }
409
410 if (resolve_scope & eSymbolContextFunction)
411 {
412 if (m_flags.IsClear (eSymbolContextFunction))
413 {
414 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000415 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000416 else
417 actual_resolve_scope |= eSymbolContextFunction;
418 }
419 }
420
421 if (resolve_scope & eSymbolContextBlock)
422 {
423 if (m_flags.IsClear (eSymbolContextBlock))
424 {
425 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000426 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000427 else
428 actual_resolve_scope |= eSymbolContextBlock;
429 }
430 }
431
432 if (resolve_scope & eSymbolContextSymbol)
433 {
434 if (m_flags.IsClear (eSymbolContextSymbol))
435 {
436 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000437 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000438 else
439 actual_resolve_scope |= eSymbolContextSymbol;
440 }
441 }
442
443 if (resolve_scope & eSymbolContextLineEntry)
444 {
445 if (m_flags.IsClear (eSymbolContextLineEntry))
446 {
447 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000448 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000449 else
450 actual_resolve_scope |= eSymbolContextLineEntry;
451 }
452 }
453
454 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
456 // We might be resolving less information than what is already
457 // in our current symbol context so resolve into a temporary
458 // symbol context "sc" so we don't clear out data we have
459 // already found in "m_sc"
460 SymbolContext sc;
461 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000462 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000463 // Only replace what we didn't already have as we may have
464 // information for an inlined function scope that won't match
465 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000466 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
467 m_sc.comp_unit = sc.comp_unit;
468 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
469 m_sc.function = sc.function;
470 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
471 m_sc.block = sc.block;
472 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
473 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000474 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
475 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000476 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000477 if (m_sc.target_sp)
478 {
479 // Be sure to apply and file remappings to our file and line
480 // entries when handing out a line entry
481 FileSpec new_file_spec;
482 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
483 m_sc.line_entry.file = new_file_spec;
484 }
485 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 }
487 }
488 else
489 {
490 // If we don't have a module, then we can't have the compile unit,
491 // function, block, line entry or symbol, so we can safely call
492 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000493 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000494 {
Greg Clayton75a03332012-11-29 00:53:06 +0000495 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000496 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000497 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498
499 // Update our internal flags so we remember what we have tried to locate so
500 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000501 // We might have dug up more information that was requested (for example
502 // if we were asked to only get the block, we will have gotten the
503 // compile unit, and function) so set any additional bits that we resolved
504 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 }
506
507 // Return the symbol context with everything that was possible to resolve
508 // resolved.
509 return m_sc;
510}
511
512
513VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000514StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515{
Jason Molenda6a354702014-10-02 01:08:16 +0000516 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 if (m_flags.IsClear(RESOLVED_VARIABLES))
518 {
519 m_flags.Set(RESOLVED_VARIABLES);
520
Greg Clayton95897c62010-09-07 04:20:48 +0000521 Block *frame_block = GetFrameBlock();
522
523 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 {
Greg Clayton95897c62010-09-07 04:20:48 +0000525 const bool get_child_variables = true;
526 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000527 const bool stop_if_child_block_is_inlined_function = true;
528 m_variable_list_sp.reset(new VariableList());
529 frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000531 }
532
533 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
534 get_file_globals)
535 {
536 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000537
Sean Callanan7c0962d2010-11-01 04:38:59 +0000538 if (m_flags.IsClear (eSymbolContextCompUnit))
539 GetSymbolContext (eSymbolContextCompUnit);
540
541 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000542 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000543 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
544 if (m_variable_list_sp)
545 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
546 else
547 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000548 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000550
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 return m_variable_list_sp.get();
552}
553
Greg Claytond41f0322011-08-02 23:35:43 +0000554VariableListSP
555StackFrame::GetInScopeVariableList (bool get_file_globals)
556{
Jason Molenda6a354702014-10-02 01:08:16 +0000557 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000558 // We can't fetch variable information for a history stack frame.
559 if (m_is_history_frame)
560 return VariableListSP();
561
Greg Claytond41f0322011-08-02 23:35:43 +0000562 VariableListSP var_list_sp(new VariableList);
563 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
564
565 if (m_sc.block)
566 {
567 const bool can_create = true;
568 const bool get_parent_variables = true;
569 const bool stop_if_block_is_inlined_function = true;
570 m_sc.block->AppendVariables (can_create,
571 get_parent_variables,
572 stop_if_block_is_inlined_function,
573 var_list_sp.get());
574 }
575
576 if (m_sc.comp_unit)
577 {
578 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
579 if (global_variable_list_sp)
580 var_list_sp->AddVariables (global_variable_list_sp.get());
581 }
582
583 return var_list_sp;
584}
585
586
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000587ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000588StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000589 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000590 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000591 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000592 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000593{
Jason Molenda99618472013-11-04 11:02:52 +0000594 // We can't fetch variable information for a history stack frame.
595 if (m_is_history_frame)
596 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000597
598 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000599 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000600 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
601 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000602 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000603 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000604 error.Clear();
605 bool deref = false;
606 bool address_of = false;
607 ValueObjectSP valobj_sp;
608 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000609 // When looking up a variable for an expression, we need only consider the
610 // variables that are in scope.
611 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
612 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000613
614 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000615 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000616 // If first character is a '*', then show pointer contents
617 const char *var_expr = var_expr_cstr;
618 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000619 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000620 deref = true;
621 var_expr++; // Skip the '*'
622 }
623 else if (var_expr[0] == '&')
624 {
625 address_of = true;
626 var_expr++; // Skip the '&'
627 }
628
629 std::string var_path (var_expr);
630 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
631 StreamString var_expr_path_strm;
632
633 ConstString name_const_string;
634 if (separator_idx == std::string::npos)
635 name_const_string.SetCString (var_path.c_str());
636 else
637 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
638
Jim Ingham2837b762011-05-04 03:43:18 +0000639 var_sp = variable_list->FindVariable(name_const_string);
Greg Clayton685c88c2012-07-14 00:53:55 +0000640
641 bool synthetically_added_instance_object = false;
642
643 if (var_sp)
644 {
645 var_path.erase (0, name_const_string.GetLength ());
646 }
647 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
648 {
649 // Check for direct ivars access which helps us with implicit
650 // access to ivars with the "this->" or "self->"
651 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
652 lldb::LanguageType method_language = eLanguageTypeUnknown;
653 bool is_instance_method = false;
654 ConstString method_object_name;
655 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
656 {
657 if (is_instance_method && method_object_name)
658 {
659 var_sp = variable_list->FindVariable(method_object_name);
660 if (var_sp)
661 {
662 separator_idx = 0;
663 var_path.insert(0, "->");
664 synthetically_added_instance_object = true;
665 }
666 }
667 }
668 }
669
Greg Clayton54979cd2010-12-15 05:08:08 +0000670 if (var_sp)
671 {
Jim Ingham2837b762011-05-04 03:43:18 +0000672 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000673 if (!valobj_sp)
674 return valobj_sp;
675
Greg Clayton54979cd2010-12-15 05:08:08 +0000676 // We are dumping at least one child
677 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000678 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000679 // Calculate the next separator index ahead of time
680 ValueObjectSP child_valobj_sp;
681 const char separator_type = var_path[0];
682 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000683 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000684
685 case '-':
686 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000687 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000688
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000689 if (no_fragile_ivar)
690 {
691 // Make sure we aren't trying to deref an objective
692 // C ivar if this is not allowed
Greg Clayton57ee3062013-07-11 22:46:58 +0000693 const uint32_t pointer_type_flags = valobj_sp->GetClangType().GetTypeInfo (NULL);
694 if ((pointer_type_flags & ClangASTType::eTypeIsObjC) &&
695 (pointer_type_flags & ClangASTType::eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000696 {
697 // This was an objective C object pointer and
698 // it was requested we skip any fragile ivars
699 // so return nothing here
700 return ValueObjectSP();
701 }
702 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000703 var_path.erase (0, 1); // Remove the '-'
704 // Fall through
705 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000706 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000707 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000708
Greg Clayton54979cd2010-12-15 05:08:08 +0000709 var_path.erase (0, 1); // Remove the '.' or '>'
710 separator_idx = var_path.find_first_of(".-[");
711 ConstString child_name;
712 if (separator_idx == std::string::npos)
713 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000714 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000715 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
716
717 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000718 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000719 // We either have a pointer type and need to verify
720 // valobj_sp is a pointer, or we have a member of a
721 // class/union/struct being accessed with the . syntax
722 // and need to verify we don't have a pointer.
723 const bool actual_is_ptr = valobj_sp->IsPointerType ();
724
725 if (actual_is_ptr != expr_is_ptr)
726 {
727 // Incorrect use of "." with a pointer, or "->" with
728 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000729 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000730 if (actual_is_ptr)
731 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
732 var_expr_path_strm.GetString().c_str(),
733 child_name.GetCString(),
734 var_expr_path_strm.GetString().c_str(),
735 var_path.c_str());
736 else
737 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
738 var_expr_path_strm.GetString().c_str(),
739 child_name.GetCString(),
740 var_expr_path_strm.GetString().c_str(),
741 var_path.c_str());
742 return ValueObjectSP();
743 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000744 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000745 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000746 if (!child_valobj_sp)
747 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000748 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000749 {
750 child_valobj_sp = valobj_sp->GetSyntheticValue();
751 if (child_valobj_sp)
752 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
753 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000754
755 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000756 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000757 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000758 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000759 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000760 // We added a "this->" or "self->" to the beginning of the expression
761 // and this is the first pointer ivar access, so just return the normal
762 // error
763 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
764 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000765 }
766 else
767 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000768 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
769 if (child_name)
770 {
771 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
772 child_name.GetCString(),
773 valobj_sp->GetTypeName().AsCString("<invalid type>"),
774 var_expr_path_strm.GetString().c_str());
775 }
776 else
777 {
778 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
779 var_expr_path_strm.GetString().c_str(),
780 var_expr_cstr);
781 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000782 }
783 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000784 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000785 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000786 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000787 // Remove the child name from the path
788 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000789 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000790 {
Jim Ingham2837b762011-05-04 03:43:18 +0000791 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000792 if (dynamic_value_sp)
793 child_valobj_sp = dynamic_value_sp;
794 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000795 }
796 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000797
Greg Clayton54979cd2010-12-15 05:08:08 +0000798 case '[':
799 // Array member access, or treating pointer as an array
800 if (var_path.size() > 2) // Need at least two brackets and a number
801 {
802 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000803 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000804 if (end && *end == ']'
805 && *(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 Clayton54979cd2010-12-15 05:08:08 +0000806 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000807 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000808 {
809 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
810 // and extract bit low out of it. reading array item low
811 // would be done by saying ptr[low], without a deref * sign
812 Error error;
813 ValueObjectSP temp(valobj_sp->Dereference(error));
814 if (error.Fail())
815 {
816 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
817 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
818 valobj_sp->GetTypeName().AsCString("<invalid type>"),
819 var_expr_path_strm.GetString().c_str());
820 return ValueObjectSP();
821 }
822 valobj_sp = temp;
823 deref = false;
824 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000825 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000826 {
827 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
828 // (an operation that is equivalent to deref-ing arr)
829 // and extract bit low out of it. reading array item low
830 // would be done by saying arr[low], without a deref * sign
831 Error error;
832 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
833 if (error.Fail())
834 {
835 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
836 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
837 valobj_sp->GetTypeName().AsCString("<invalid type>"),
838 var_expr_path_strm.GetString().c_str());
839 return ValueObjectSP();
840 }
841 valobj_sp = temp;
842 deref = false;
843 }
844
Greg Clayton4ef877f2012-12-06 02:33:54 +0000845 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000846 if (valobj_sp->IsPointerType ())
847 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000848 bool is_objc_pointer = true;
849
Greg Clayton57ee3062013-07-11 22:46:58 +0000850 if (valobj_sp->GetClangType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000851 is_objc_pointer = false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000852 else if (!valobj_sp->GetClangType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000853 is_objc_pointer = false;
854
855 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000856 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000857 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
858 valobj_sp->GetTypeName().AsCString("<invalid type>"),
859 var_expr_path_strm.GetString().c_str());
860
861 return ValueObjectSP();
862 }
863 else if (is_objc_pointer)
864 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000865 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000866 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000867 if (synthetic.get() == NULL /* no synthetic */
868 || synthetic == valobj_sp) /* synthetic is the same as the original object */
869 {
870 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
871 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
872 valobj_sp->GetTypeName().AsCString("<invalid type>"),
873 var_expr_path_strm.GetString().c_str());
874 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000875 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000876 {
877 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000878 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000879 child_index,
880 valobj_sp->GetTypeName().AsCString("<invalid type>"),
881 var_expr_path_strm.GetString().c_str());
882 }
883 else
884 {
885 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
886 if (!child_valobj_sp)
887 {
888 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000889 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000890 child_index,
891 valobj_sp->GetTypeName().AsCString("<invalid type>"),
892 var_expr_path_strm.GetString().c_str());
893 }
894 }
895 }
896 else
897 {
898 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
899 if (!child_valobj_sp)
900 {
901 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000902 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000903 child_index,
904 valobj_sp->GetTypeName().AsCString("<invalid type>"),
905 var_expr_path_strm.GetString().c_str());
906 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000907 }
908 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000909 else if (valobj_sp->GetClangType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000910 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000911 // Pass false to dynamic_value here so we can tell the difference between
912 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000913 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000914 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
915 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
916
Greg Clayton54979cd2010-12-15 05:08:08 +0000917 if (!child_valobj_sp)
918 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000919 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000920 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000921 child_index,
922 valobj_sp->GetTypeName().AsCString("<invalid type>"),
923 var_expr_path_strm.GetString().c_str());
924 }
925 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000926 else if (valobj_sp->GetClangType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000927 {
928 // this is a bitfield asking to display just one bit
929 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
930 if (!child_valobj_sp)
931 {
932 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000933 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000934 child_index, child_index,
935 valobj_sp->GetTypeName().AsCString("<invalid type>"),
936 var_expr_path_strm.GetString().c_str());
937 }
938 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000939 else
940 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000941 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000942 if (no_synth_child /* synthetic is forbidden */ ||
943 synthetic.get() == NULL /* no synthetic */
944 || synthetic == valobj_sp) /* synthetic is the same as the original object */
945 {
946 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
947 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
948 valobj_sp->GetTypeName().AsCString("<invalid type>"),
949 var_expr_path_strm.GetString().c_str());
950 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000951 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000952 {
953 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000954 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000955 child_index,
956 valobj_sp->GetTypeName().AsCString("<invalid type>"),
957 var_expr_path_strm.GetString().c_str());
958 }
959 else
960 {
961 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
962 if (!child_valobj_sp)
963 {
964 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000965 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000966 child_index,
967 valobj_sp->GetTypeName().AsCString("<invalid type>"),
968 var_expr_path_strm.GetString().c_str());
969 }
970 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000971 }
972
973 if (!child_valobj_sp)
974 {
975 // Invalid array index...
976 return ValueObjectSP();
977 }
978
979 // Erase the array member specification '[%i]' where
980 // %i is the array index
981 var_path.erase(0, (end - var_path.c_str()) + 1);
982 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +0000983 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000984 {
Jim Ingham2837b762011-05-04 03:43:18 +0000985 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000986 if (dynamic_value_sp)
987 child_valobj_sp = dynamic_value_sp;
988 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000989 // Break out early from the switch since we were
990 // able to find the child member
991 break;
992 }
Enrico Granata20edcdb2011-07-19 18:03:25 +0000993 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +0000994 {
995 // this is most probably a BitField, let's take a look
996 char *real_end = NULL;
997 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000998 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +0000999 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001000 {
1001 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001002 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001003 {
1004 long temp = child_index;
1005 child_index = final_index;
1006 final_index = temp;
1007 }
1008
Greg Clayton57ee3062013-07-11 22:46:58 +00001009 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001010 {
1011 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1012 // and extract bits low thru high out of it. reading array items low thru high
1013 // would be done by saying ptr[low-high], without a deref * sign
1014 Error error;
1015 ValueObjectSP temp(valobj_sp->Dereference(error));
1016 if (error.Fail())
1017 {
1018 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1019 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1020 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1021 var_expr_path_strm.GetString().c_str());
1022 return ValueObjectSP();
1023 }
1024 valobj_sp = temp;
1025 deref = false;
1026 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001027 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001028 {
1029 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1030 // (an operation that is equivalent to deref-ing arr)
1031 // and extract bits low thru high out of it. reading array items low thru high
1032 // would be done by saying arr[low-high], without a deref * sign
1033 Error error;
1034 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1035 if (error.Fail())
1036 {
1037 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1038 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1039 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1040 var_expr_path_strm.GetString().c_str());
1041 return ValueObjectSP();
1042 }
1043 valobj_sp = temp;
1044 deref = false;
1045 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001046 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001047 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001048 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1049 expand_bitfield = false;
1050 if (!child_valobj_sp)
1051 {
1052 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1053 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1054 child_index, final_index,
1055 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1056 var_expr_path_strm.GetString().c_str());
1057 }
1058 }*/
1059
1060 if (expand_bitfield)
1061 {
1062 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1063 if (!child_valobj_sp)
1064 {
1065 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001066 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001067 child_index, final_index,
1068 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1069 var_expr_path_strm.GetString().c_str());
1070 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001071 }
1072 }
1073
1074 if (!child_valobj_sp)
1075 {
1076 // Invalid bitfield range...
1077 return ValueObjectSP();
1078 }
1079
1080 // Erase the bitfield member specification '[%i-%i]' where
1081 // %i is the index
1082 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1083 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001084 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001085 {
1086 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1087 if (dynamic_value_sp)
1088 child_valobj_sp = dynamic_value_sp;
1089 }
1090 // Break out early from the switch since we were
1091 // able to find the child member
1092 break;
1093
1094 }
1095 }
1096 else
1097 {
1098 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1099 var_expr_path_strm.GetString().c_str(),
1100 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001101 }
1102 return ValueObjectSP();
1103
1104 default:
1105 // Failure...
1106 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001107 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001108 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1109 separator_type,
1110 var_expr_path_strm.GetString().c_str(),
1111 var_path.c_str());
1112
1113 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001114 }
1115 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001116
Greg Clayton54979cd2010-12-15 05:08:08 +00001117 if (child_valobj_sp)
1118 valobj_sp = child_valobj_sp;
1119
1120 if (var_path.empty())
1121 break;
1122
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001123 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001124 if (valobj_sp)
1125 {
1126 if (deref)
1127 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001128 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001129 valobj_sp = deref_valobj_sp;
1130 }
1131 else if (address_of)
1132 {
1133 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1134 valobj_sp = address_of_valobj_sp;
1135 }
1136 }
1137 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001138 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001139 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001140 {
Jim Ingham2837b762011-05-04 03:43:18 +00001141 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1142 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001143 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001144 }
1145 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001146 else
1147 {
1148 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1149 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001150 return ValueObjectSP();
1151}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152
1153bool
1154StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1155{
Jason Molenda6a354702014-10-02 01:08:16 +00001156 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001157 if (m_cfa_is_valid == false)
1158 {
1159 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1160 return false;
1161 }
1162
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163 if (m_flags.IsClear(GOT_FRAME_BASE))
1164 {
1165 if (m_sc.function)
1166 {
1167 m_frame_base.Clear();
1168 m_frame_base_error.Clear();
1169
1170 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001171 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001172 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001173 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1174 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001175 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001176
Greg Clayton57ee3062013-07-11 22:46:58 +00001177 if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178 {
1179 // We should really have an error if evaluate returns, but in case
1180 // we don't, lets set the error to something at least.
1181 if (m_frame_base_error.Success())
1182 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1183 }
1184 else
1185 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001186 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 }
1188 }
1189 else
1190 {
1191 m_frame_base_error.SetErrorString ("No function in symbol context.");
1192 }
1193 }
1194
1195 if (m_frame_base_error.Success())
1196 frame_base = m_frame_base;
1197
1198 if (error_ptr)
1199 *error_ptr = m_frame_base_error;
1200 return m_frame_base_error.Success();
1201}
1202
Greg Clayton5ccbd292011-01-06 22:15:06 +00001203RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204StackFrame::GetRegisterContext ()
1205{
Jason Molenda6a354702014-10-02 01:08:16 +00001206 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001207 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001208 {
1209 ThreadSP thread_sp (GetThread());
1210 if (thread_sp)
1211 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1212 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001213 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214}
1215
1216bool
1217StackFrame::HasDebugInformation ()
1218{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001219 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220 return m_sc.line_entry.IsValid();
1221}
1222
Greg Clayton288bdf92010-09-02 02:59:18 +00001223
1224ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001225StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226{
Jason Molenda6a354702014-10-02 01:08:16 +00001227 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001228 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001229 if (m_is_history_frame)
1230 {
1231 return valobj_sp;
1232 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001233 VariableList *var_list = GetVariableList (true);
1234 if (var_list)
1235 {
1236 // Make sure the variable is a frame variable
1237 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1238 const uint32_t num_variables = var_list->GetSize();
1239 if (var_idx < num_variables)
1240 {
1241 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1242 if (valobj_sp.get() == NULL)
1243 {
1244 if (m_variable_list_value_objects.GetSize() < num_variables)
1245 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001246 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001247 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1248 }
1249 }
1250 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001251 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001252 {
Jim Ingham2837b762011-05-04 03:43:18 +00001253 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001254 if (dynamic_sp)
1255 return dynamic_sp;
1256 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001257 return valobj_sp;
1258}
1259
1260ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001261StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001262{
Jason Molenda6a354702014-10-02 01:08:16 +00001263 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001264 if (m_is_history_frame)
1265 return ValueObjectSP();
1266
Greg Clayton288bdf92010-09-02 02:59:18 +00001267 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001268 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001269 if (!valobj_sp)
1270 {
1271 // We aren't already tracking this global
1272 VariableList *var_list = GetVariableList (true);
1273 // If this frame has no variables, create a new list
1274 if (var_list == NULL)
1275 m_variable_list_sp.reset (new VariableList());
1276
1277 // Add the global/static variable to this frame
1278 m_variable_list_sp->AddVariable (variable_sp);
1279
1280 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001281 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001282 }
1283 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284}
1285
Jim Ingham6b8379c2010-08-26 20:44:45 +00001286bool
1287StackFrame::IsInlined ()
1288{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001289 if (m_sc.block == NULL)
1290 GetSymbolContext (eSymbolContextBlock);
1291 if (m_sc.block)
1292 return m_sc.block->GetContainingInlinedBlock() != NULL;
1293 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001294}
1295
Greg Claytond9e416c2012-02-18 05:35:26 +00001296TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297StackFrame::CalculateTarget ()
1298{
Greg Claytond9e416c2012-02-18 05:35:26 +00001299 TargetSP target_sp;
1300 ThreadSP thread_sp(GetThread());
1301 if (thread_sp)
1302 {
1303 ProcessSP process_sp (thread_sp->CalculateProcess());
1304 if (process_sp)
1305 target_sp = process_sp->CalculateTarget();
1306 }
1307 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308}
1309
Greg Claytond9e416c2012-02-18 05:35:26 +00001310ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311StackFrame::CalculateProcess ()
1312{
Greg Claytond9e416c2012-02-18 05:35:26 +00001313 ProcessSP process_sp;
1314 ThreadSP thread_sp(GetThread());
1315 if (thread_sp)
1316 process_sp = thread_sp->CalculateProcess();
1317 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318}
1319
Greg Claytond9e416c2012-02-18 05:35:26 +00001320ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321StackFrame::CalculateThread ()
1322{
Greg Claytond9e416c2012-02-18 05:35:26 +00001323 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324}
1325
Jason Molendab57e4a12013-11-04 09:33:30 +00001326StackFrameSP
1327StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328{
Greg Claytond9e416c2012-02-18 05:35:26 +00001329 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330}
1331
1332
1333void
Greg Clayton0603aa92010-10-04 01:05:56 +00001334StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001335{
Greg Claytond9e416c2012-02-18 05:35:26 +00001336 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337}
1338
1339void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001340StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001341{
1342 if (strm == NULL)
1343 return;
1344
1345 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001346 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001347 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001348
1349 if (frame_marker)
1350 s.PutCString(frame_marker);
1351
Greg Claytond9e416c2012-02-18 05:35:26 +00001352 const char *frame_format = NULL;
1353 Target *target = exe_ctx.GetTargetPtr();
1354 if (target)
1355 frame_format = target->GetDebugger().GetFrameFormat();
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001356 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s))
Greg Clayton0603aa92010-10-04 01:05:56 +00001357 {
1358 strm->Write(s.GetData(), s.GetSize());
1359 }
1360 else
1361 {
1362 Dump (strm, true, false);
1363 strm->EOL();
1364 }
1365}
1366
1367void
Greg Clayton6dadd502010-09-02 21:44:10 +00001368StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369{
1370 if (strm == NULL)
1371 return;
1372
1373 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001374 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001375 ExecutionContext exe_ctx (shared_from_this());
1376 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001377 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001378 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1379 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001380 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001381 const bool show_module = true;
1382 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001383 const bool show_function_arguments = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001384 m_sc.DumpStopContext (strm,
1385 exe_ctx.GetBestExecutionContextScope(),
1386 GetFrameCodeAddress(),
1387 show_fullpaths,
1388 show_module,
Jason Molendaaff1b352014-10-10 23:07:36 +00001389 show_inline,
1390 show_function_arguments);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391}
1392
Greg Clayton5082c5f2010-08-27 18:24:16 +00001393void
Jason Molendab57e4a12013-11-04 09:33:30 +00001394StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001395{
Jason Molenda6a354702014-10-02 01:08:16 +00001396 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001397 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001398 m_variable_list_sp = prev_frame.m_variable_list_sp;
1399 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1400 if (!m_disassembly.GetString().empty())
1401 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001402}
Greg Clayton68275d52010-08-27 21:47:54 +00001403
1404
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001405void
Jason Molendab57e4a12013-11-04 09:33:30 +00001406StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001407{
Jason Molenda6a354702014-10-02 01:08:16 +00001408 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:42 +00001409 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001410 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1411 assert (GetThread() == curr_frame.GetThread());
1412 m_frame_index = curr_frame.m_frame_index;
1413 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1414 m_reg_context_sp = curr_frame.m_reg_context_sp;
1415 m_frame_code_addr = curr_frame.m_frame_code_addr;
1416 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());
1417 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());
1418 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1419 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1420 m_sc = curr_frame.m_sc;
1421 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1422 m_flags.Set (m_sc.GetResolvedMask());
1423 m_frame_base.Clear();
1424 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001425}
1426
1427
Greg Clayton2cad65a2010-09-03 17:10:42 +00001428bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001429StackFrame::HasCachedData () const
1430{
1431 if (m_variable_list_sp.get())
1432 return true;
1433 if (m_variable_list_value_objects.GetSize() > 0)
1434 return true;
1435 if (!m_disassembly.GetString().empty())
1436 return true;
1437 return false;
1438}
1439
1440bool
Greg Clayton7260f622011-04-18 08:33:37 +00001441StackFrame::GetStatus (Stream& strm,
1442 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001443 bool show_source,
1444 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001445{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001446
Greg Clayton7260f622011-04-18 08:33:37 +00001447 if (show_frame_info)
1448 {
1449 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001450 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001451 }
1452
1453 if (show_source)
1454 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001455 ExecutionContext exe_ctx (shared_from_this());
Greg Claytone372b982011-11-21 21:44:34 +00001456 bool have_source = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001457 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001458 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001459 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001460 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001461 Debugger &debugger = target->GetDebugger();
1462 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1463 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1464 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001465
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001466 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1467 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001468 {
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001469 have_source = true;
1470 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001471 {
Jason Molenda7cd81c52013-04-29 09:59:31 +00001472 target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001473 m_sc.line_entry.line,
1474 source_lines_before,
1475 source_lines_after,
1476 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001477 &strm);
Greg Claytone372b982011-11-21 21:44:34 +00001478 }
1479 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001480 switch (disasm_display)
1481 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001482 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001483 break;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001484
Greg Clayton67cc0632012-08-22 17:17:09 +00001485 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001486 if (have_source)
1487 break;
1488 // Fall through to next case
Greg Clayton67cc0632012-08-22 17:17:09 +00001489 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001490 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001491 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001492 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1493 if (disasm_lines > 0)
1494 {
1495 const ArchSpec &target_arch = target->GetArchitecture();
1496 AddressRange pc_range;
1497 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1498 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Jim Ingham0f063ba2013-03-02 00:26:47 +00001499 const char *plugin_name = NULL;
1500 const char *flavor = NULL;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001501 Disassembler::Disassemble (target->GetDebugger(),
1502 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001503 plugin_name,
1504 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001505 exe_ctx,
1506 pc_range,
1507 disasm_lines,
1508 0,
1509 Disassembler::eOptionMarkPCAddress,
1510 strm);
1511 }
Greg Claytone372b982011-11-21 21:44:34 +00001512 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001513 break;
Greg Claytone372b982011-11-21 21:44:34 +00001514 }
Greg Clayton7260f622011-04-18 08:33:37 +00001515 }
1516 }
1517 return true;
1518}
1519