blob: c46db4cfadf9b375bc67225263792a021052bd1f [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)
Jason Molendacf296752014-11-08 05:38:17 +0000387 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17 +0000389
390 }
391 else
392 {
393 // lookup_addr is the start of a section. We need
394 // do the math on the actual load address and re-compute
395 // the section. We're working with a 'noreturn' function
396 // at the end of a section.
397 ThreadSP thread_sp (GetThread());
398 if (thread_sp)
399 {
400 TargetSP target_sp (thread_sp->CalculateTarget());
401 if (target_sp)
402 {
403 addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1;
404 lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get());
405 }
406 else
407 {
408 lookup_addr.SetOffset(offset - 1);
409 }
410 }
411 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 }
413
Greg Clayton9da7bd02010-08-24 21:05:24 +0000414
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 if (m_sc.module_sp)
416 {
417 // We have something in our stack frame symbol context, lets check
418 // if we haven't already tried to lookup one of those things. If we
419 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000420
421 uint32_t actual_resolve_scope = 0;
422
423 if (resolve_scope & eSymbolContextCompUnit)
424 {
425 if (m_flags.IsClear (eSymbolContextCompUnit))
426 {
427 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000428 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000429 else
430 actual_resolve_scope |= eSymbolContextCompUnit;
431 }
432 }
433
434 if (resolve_scope & eSymbolContextFunction)
435 {
436 if (m_flags.IsClear (eSymbolContextFunction))
437 {
438 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000439 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000440 else
441 actual_resolve_scope |= eSymbolContextFunction;
442 }
443 }
444
445 if (resolve_scope & eSymbolContextBlock)
446 {
447 if (m_flags.IsClear (eSymbolContextBlock))
448 {
449 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000450 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000451 else
452 actual_resolve_scope |= eSymbolContextBlock;
453 }
454 }
455
456 if (resolve_scope & eSymbolContextSymbol)
457 {
458 if (m_flags.IsClear (eSymbolContextSymbol))
459 {
460 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000461 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000462 else
463 actual_resolve_scope |= eSymbolContextSymbol;
464 }
465 }
466
467 if (resolve_scope & eSymbolContextLineEntry)
468 {
469 if (m_flags.IsClear (eSymbolContextLineEntry))
470 {
471 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000472 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000473 else
474 actual_resolve_scope |= eSymbolContextLineEntry;
475 }
476 }
477
478 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 {
480 // We might be resolving less information than what is already
481 // in our current symbol context so resolve into a temporary
482 // symbol context "sc" so we don't clear out data we have
483 // already found in "m_sc"
484 SymbolContext sc;
485 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000486 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000487 // Only replace what we didn't already have as we may have
488 // information for an inlined function scope that won't match
489 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000490 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
491 m_sc.comp_unit = sc.comp_unit;
492 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
493 m_sc.function = sc.function;
494 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
495 m_sc.block = sc.block;
496 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
497 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000498 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
499 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000500 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000501 if (m_sc.target_sp)
502 {
503 // Be sure to apply and file remappings to our file and line
504 // entries when handing out a line entry
505 FileSpec new_file_spec;
506 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
507 m_sc.line_entry.file = new_file_spec;
508 }
509 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 }
512 else
513 {
514 // If we don't have a module, then we can't have the compile unit,
515 // function, block, line entry or symbol, so we can safely call
516 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000517 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000518 {
Greg Clayton75a03332012-11-29 00:53:06 +0000519 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000520 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000521 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522
523 // Update our internal flags so we remember what we have tried to locate so
524 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000525 // We might have dug up more information that was requested (for example
526 // if we were asked to only get the block, we will have gotten the
527 // compile unit, and function) so set any additional bits that we resolved
528 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 }
530
531 // Return the symbol context with everything that was possible to resolve
532 // resolved.
533 return m_sc;
534}
535
536
537VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000538StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Jason Molenda6a354702014-10-02 01:08:16 +0000540 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 if (m_flags.IsClear(RESOLVED_VARIABLES))
542 {
543 m_flags.Set(RESOLVED_VARIABLES);
544
Greg Clayton95897c62010-09-07 04:20:48 +0000545 Block *frame_block = GetFrameBlock();
546
547 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
Greg Clayton95897c62010-09-07 04:20:48 +0000549 const bool get_child_variables = true;
550 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000551 const bool stop_if_child_block_is_inlined_function = true;
552 m_variable_list_sp.reset(new VariableList());
553 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 +0000554 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000555 }
556
557 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
558 get_file_globals)
559 {
560 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000561
Sean Callanan7c0962d2010-11-01 04:38:59 +0000562 if (m_flags.IsClear (eSymbolContextCompUnit))
563 GetSymbolContext (eSymbolContextCompUnit);
564
565 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000566 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000567 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
568 if (m_variable_list_sp)
569 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
570 else
571 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000572 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000574
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 return m_variable_list_sp.get();
576}
577
Greg Claytond41f0322011-08-02 23:35:43 +0000578VariableListSP
579StackFrame::GetInScopeVariableList (bool get_file_globals)
580{
Jason Molenda6a354702014-10-02 01:08:16 +0000581 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000582 // We can't fetch variable information for a history stack frame.
583 if (m_is_history_frame)
584 return VariableListSP();
585
Greg Claytond41f0322011-08-02 23:35:43 +0000586 VariableListSP var_list_sp(new VariableList);
587 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
588
589 if (m_sc.block)
590 {
591 const bool can_create = true;
592 const bool get_parent_variables = true;
593 const bool stop_if_block_is_inlined_function = true;
594 m_sc.block->AppendVariables (can_create,
595 get_parent_variables,
596 stop_if_block_is_inlined_function,
597 var_list_sp.get());
598 }
599
600 if (m_sc.comp_unit)
601 {
602 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
603 if (global_variable_list_sp)
604 var_list_sp->AddVariables (global_variable_list_sp.get());
605 }
606
607 return var_list_sp;
608}
609
610
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000611ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000612StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000613 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000614 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000615 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000616 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000617{
Jason Molenda99618472013-11-04 11:02:52 +0000618 // We can't fetch variable information for a history stack frame.
619 if (m_is_history_frame)
620 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000621
622 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000623 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000624 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
625 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000626 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000627 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000628 error.Clear();
629 bool deref = false;
630 bool address_of = false;
631 ValueObjectSP valobj_sp;
632 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000633 // When looking up a variable for an expression, we need only consider the
634 // variables that are in scope.
635 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
636 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000637
638 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000639 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000640 // If first character is a '*', then show pointer contents
641 const char *var_expr = var_expr_cstr;
642 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000643 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000644 deref = true;
645 var_expr++; // Skip the '*'
646 }
647 else if (var_expr[0] == '&')
648 {
649 address_of = true;
650 var_expr++; // Skip the '&'
651 }
652
653 std::string var_path (var_expr);
654 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
655 StreamString var_expr_path_strm;
656
657 ConstString name_const_string;
658 if (separator_idx == std::string::npos)
659 name_const_string.SetCString (var_path.c_str());
660 else
661 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
662
Jim Ingham2837b762011-05-04 03:43:18 +0000663 var_sp = variable_list->FindVariable(name_const_string);
Greg Clayton685c88c2012-07-14 00:53:55 +0000664
665 bool synthetically_added_instance_object = false;
666
667 if (var_sp)
668 {
669 var_path.erase (0, name_const_string.GetLength ());
670 }
671 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
672 {
673 // Check for direct ivars access which helps us with implicit
674 // access to ivars with the "this->" or "self->"
675 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
676 lldb::LanguageType method_language = eLanguageTypeUnknown;
677 bool is_instance_method = false;
678 ConstString method_object_name;
679 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
680 {
681 if (is_instance_method && method_object_name)
682 {
683 var_sp = variable_list->FindVariable(method_object_name);
684 if (var_sp)
685 {
686 separator_idx = 0;
687 var_path.insert(0, "->");
688 synthetically_added_instance_object = true;
689 }
690 }
691 }
692 }
693
Greg Clayton54979cd2010-12-15 05:08:08 +0000694 if (var_sp)
695 {
Jim Ingham2837b762011-05-04 03:43:18 +0000696 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000697 if (!valobj_sp)
698 return valobj_sp;
699
Greg Clayton54979cd2010-12-15 05:08:08 +0000700 // We are dumping at least one child
701 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000702 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000703 // Calculate the next separator index ahead of time
704 ValueObjectSP child_valobj_sp;
705 const char separator_type = var_path[0];
706 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000707 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000708
709 case '-':
710 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000711 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000712
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000713 if (no_fragile_ivar)
714 {
715 // Make sure we aren't trying to deref an objective
716 // C ivar if this is not allowed
Greg Clayton57ee3062013-07-11 22:46:58 +0000717 const uint32_t pointer_type_flags = valobj_sp->GetClangType().GetTypeInfo (NULL);
Enrico Granata622be232014-10-21 20:52:14 +0000718 if ((pointer_type_flags & eTypeIsObjC) &&
719 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000720 {
721 // This was an objective C object pointer and
722 // it was requested we skip any fragile ivars
723 // so return nothing here
724 return ValueObjectSP();
725 }
726 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000727 var_path.erase (0, 1); // Remove the '-'
728 // Fall through
729 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000730 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000731 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000732
Greg Clayton54979cd2010-12-15 05:08:08 +0000733 var_path.erase (0, 1); // Remove the '.' or '>'
734 separator_idx = var_path.find_first_of(".-[");
735 ConstString child_name;
736 if (separator_idx == std::string::npos)
737 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000738 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000739 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
740
741 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000742 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000743 // We either have a pointer type and need to verify
744 // valobj_sp is a pointer, or we have a member of a
745 // class/union/struct being accessed with the . syntax
746 // and need to verify we don't have a pointer.
747 const bool actual_is_ptr = valobj_sp->IsPointerType ();
748
749 if (actual_is_ptr != expr_is_ptr)
750 {
751 // Incorrect use of "." with a pointer, or "->" with
752 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000753 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000754 if (actual_is_ptr)
755 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
756 var_expr_path_strm.GetString().c_str(),
757 child_name.GetCString(),
758 var_expr_path_strm.GetString().c_str(),
759 var_path.c_str());
760 else
761 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
762 var_expr_path_strm.GetString().c_str(),
763 child_name.GetCString(),
764 var_expr_path_strm.GetString().c_str(),
765 var_path.c_str());
766 return ValueObjectSP();
767 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000768 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000769 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000770 if (!child_valobj_sp)
771 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000772 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000773 {
774 child_valobj_sp = valobj_sp->GetSyntheticValue();
775 if (child_valobj_sp)
776 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
777 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000778
779 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000780 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000781 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000782 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000783 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000784 // We added a "this->" or "self->" to the beginning of the expression
785 // and this is the first pointer ivar access, so just return the normal
786 // error
787 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
788 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000789 }
790 else
791 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000792 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
793 if (child_name)
794 {
795 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
796 child_name.GetCString(),
797 valobj_sp->GetTypeName().AsCString("<invalid type>"),
798 var_expr_path_strm.GetString().c_str());
799 }
800 else
801 {
802 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
803 var_expr_path_strm.GetString().c_str(),
804 var_expr_cstr);
805 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000806 }
807 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000808 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000809 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000810 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000811 // Remove the child name from the path
812 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000813 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000814 {
Jim Ingham2837b762011-05-04 03:43:18 +0000815 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000816 if (dynamic_value_sp)
817 child_valobj_sp = dynamic_value_sp;
818 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000819 }
820 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000821
Greg Clayton54979cd2010-12-15 05:08:08 +0000822 case '[':
823 // Array member access, or treating pointer as an array
824 if (var_path.size() > 2) // Need at least two brackets and a number
825 {
826 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000827 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000828 if (end && *end == ']'
829 && *(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 +0000830 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000831 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000832 {
833 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
834 // and extract bit low out of it. reading array item low
835 // would be done by saying ptr[low], without a deref * sign
836 Error error;
837 ValueObjectSP temp(valobj_sp->Dereference(error));
838 if (error.Fail())
839 {
840 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
841 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
842 valobj_sp->GetTypeName().AsCString("<invalid type>"),
843 var_expr_path_strm.GetString().c_str());
844 return ValueObjectSP();
845 }
846 valobj_sp = temp;
847 deref = false;
848 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000849 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000850 {
851 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
852 // (an operation that is equivalent to deref-ing arr)
853 // and extract bit low out of it. reading array item low
854 // would be done by saying arr[low], without a deref * sign
855 Error error;
856 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
857 if (error.Fail())
858 {
859 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
860 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
861 valobj_sp->GetTypeName().AsCString("<invalid type>"),
862 var_expr_path_strm.GetString().c_str());
863 return ValueObjectSP();
864 }
865 valobj_sp = temp;
866 deref = false;
867 }
868
Greg Clayton4ef877f2012-12-06 02:33:54 +0000869 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000870 if (valobj_sp->IsPointerType ())
871 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000872 bool is_objc_pointer = true;
873
Greg Clayton57ee3062013-07-11 22:46:58 +0000874 if (valobj_sp->GetClangType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000875 is_objc_pointer = false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000876 else if (!valobj_sp->GetClangType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000877 is_objc_pointer = false;
878
879 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000880 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000881 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
882 valobj_sp->GetTypeName().AsCString("<invalid type>"),
883 var_expr_path_strm.GetString().c_str());
884
885 return ValueObjectSP();
886 }
887 else if (is_objc_pointer)
888 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000889 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000890 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000891 if (synthetic.get() == NULL /* no synthetic */
892 || synthetic == valobj_sp) /* synthetic is the same as the original object */
893 {
894 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
895 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
896 valobj_sp->GetTypeName().AsCString("<invalid type>"),
897 var_expr_path_strm.GetString().c_str());
898 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000899 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000900 {
901 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000902 error.SetErrorStringWithFormat ("array index %ld is not valid 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 }
907 else
908 {
909 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
910 if (!child_valobj_sp)
911 {
912 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000913 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000914 child_index,
915 valobj_sp->GetTypeName().AsCString("<invalid type>"),
916 var_expr_path_strm.GetString().c_str());
917 }
918 }
919 }
920 else
921 {
922 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
923 if (!child_valobj_sp)
924 {
925 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000926 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000927 child_index,
928 valobj_sp->GetTypeName().AsCString("<invalid type>"),
929 var_expr_path_strm.GetString().c_str());
930 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000931 }
932 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000933 else if (valobj_sp->GetClangType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000934 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000935 // Pass false to dynamic_value here so we can tell the difference between
936 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000937 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000938 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
939 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
940
Greg Clayton54979cd2010-12-15 05:08:08 +0000941 if (!child_valobj_sp)
942 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000943 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000944 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000945 child_index,
946 valobj_sp->GetTypeName().AsCString("<invalid type>"),
947 var_expr_path_strm.GetString().c_str());
948 }
949 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000950 else if (valobj_sp->GetClangType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000951 {
952 // this is a bitfield asking to display just one bit
953 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
954 if (!child_valobj_sp)
955 {
956 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000957 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000958 child_index, child_index,
959 valobj_sp->GetTypeName().AsCString("<invalid type>"),
960 var_expr_path_strm.GetString().c_str());
961 }
962 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000963 else
964 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000965 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000966 if (no_synth_child /* synthetic is forbidden */ ||
967 synthetic.get() == NULL /* no synthetic */
968 || synthetic == valobj_sp) /* synthetic is the same as the original object */
969 {
970 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
971 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
972 valobj_sp->GetTypeName().AsCString("<invalid type>"),
973 var_expr_path_strm.GetString().c_str());
974 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000975 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000976 {
977 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000978 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000979 child_index,
980 valobj_sp->GetTypeName().AsCString("<invalid type>"),
981 var_expr_path_strm.GetString().c_str());
982 }
983 else
984 {
985 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
986 if (!child_valobj_sp)
987 {
988 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000989 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000990 child_index,
991 valobj_sp->GetTypeName().AsCString("<invalid type>"),
992 var_expr_path_strm.GetString().c_str());
993 }
994 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000995 }
996
997 if (!child_valobj_sp)
998 {
999 // Invalid array index...
1000 return ValueObjectSP();
1001 }
1002
1003 // Erase the array member specification '[%i]' where
1004 // %i is the array index
1005 var_path.erase(0, (end - var_path.c_str()) + 1);
1006 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001007 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001008 {
Jim Ingham2837b762011-05-04 03:43:18 +00001009 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +00001010 if (dynamic_value_sp)
1011 child_valobj_sp = dynamic_value_sp;
1012 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001013 // Break out early from the switch since we were
1014 // able to find the child member
1015 break;
1016 }
Enrico Granata20edcdb2011-07-19 18:03:25 +00001017 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +00001018 {
1019 // this is most probably a BitField, let's take a look
1020 char *real_end = NULL;
1021 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001022 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +00001023 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001024 {
1025 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001026 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001027 {
1028 long temp = child_index;
1029 child_index = final_index;
1030 final_index = temp;
1031 }
1032
Greg Clayton57ee3062013-07-11 22:46:58 +00001033 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001034 {
1035 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1036 // and extract bits low thru high out of it. reading array items low thru high
1037 // would be done by saying ptr[low-high], without a deref * sign
1038 Error error;
1039 ValueObjectSP temp(valobj_sp->Dereference(error));
1040 if (error.Fail())
1041 {
1042 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1043 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1044 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1045 var_expr_path_strm.GetString().c_str());
1046 return ValueObjectSP();
1047 }
1048 valobj_sp = temp;
1049 deref = false;
1050 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001051 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001052 {
1053 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1054 // (an operation that is equivalent to deref-ing arr)
1055 // and extract bits low thru high out of it. reading array items low thru high
1056 // would be done by saying arr[low-high], without a deref * sign
1057 Error error;
1058 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1059 if (error.Fail())
1060 {
1061 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1062 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1063 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1064 var_expr_path_strm.GetString().c_str());
1065 return ValueObjectSP();
1066 }
1067 valobj_sp = temp;
1068 deref = false;
1069 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001070 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001071 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001072 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1073 expand_bitfield = false;
1074 if (!child_valobj_sp)
1075 {
1076 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1077 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1078 child_index, final_index,
1079 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1080 var_expr_path_strm.GetString().c_str());
1081 }
1082 }*/
1083
1084 if (expand_bitfield)
1085 {
1086 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1087 if (!child_valobj_sp)
1088 {
1089 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001090 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001091 child_index, final_index,
1092 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1093 var_expr_path_strm.GetString().c_str());
1094 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001095 }
1096 }
1097
1098 if (!child_valobj_sp)
1099 {
1100 // Invalid bitfield range...
1101 return ValueObjectSP();
1102 }
1103
1104 // Erase the bitfield member specification '[%i-%i]' where
1105 // %i is the index
1106 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1107 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001108 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001109 {
1110 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1111 if (dynamic_value_sp)
1112 child_valobj_sp = dynamic_value_sp;
1113 }
1114 // Break out early from the switch since we were
1115 // able to find the child member
1116 break;
1117
1118 }
1119 }
1120 else
1121 {
1122 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1123 var_expr_path_strm.GetString().c_str(),
1124 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001125 }
1126 return ValueObjectSP();
1127
1128 default:
1129 // Failure...
1130 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001131 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001132 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1133 separator_type,
1134 var_expr_path_strm.GetString().c_str(),
1135 var_path.c_str());
1136
1137 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001138 }
1139 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001140
Greg Clayton54979cd2010-12-15 05:08:08 +00001141 if (child_valobj_sp)
1142 valobj_sp = child_valobj_sp;
1143
1144 if (var_path.empty())
1145 break;
1146
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001147 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001148 if (valobj_sp)
1149 {
1150 if (deref)
1151 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001152 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001153 valobj_sp = deref_valobj_sp;
1154 }
1155 else if (address_of)
1156 {
1157 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1158 valobj_sp = address_of_valobj_sp;
1159 }
1160 }
1161 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001162 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001163 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001164 {
Jim Ingham2837b762011-05-04 03:43:18 +00001165 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1166 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001167 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001168 }
1169 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001170 else
1171 {
1172 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1173 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001174 return ValueObjectSP();
1175}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176
1177bool
1178StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1179{
Jason Molenda6a354702014-10-02 01:08:16 +00001180 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001181 if (m_cfa_is_valid == false)
1182 {
1183 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1184 return false;
1185 }
1186
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 if (m_flags.IsClear(GOT_FRAME_BASE))
1188 {
1189 if (m_sc.function)
1190 {
1191 m_frame_base.Clear();
1192 m_frame_base_error.Clear();
1193
1194 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001195 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001197 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1198 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001199 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001200
Greg Clayton57ee3062013-07-11 22:46:58 +00001201 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 +00001202 {
1203 // We should really have an error if evaluate returns, but in case
1204 // we don't, lets set the error to something at least.
1205 if (m_frame_base_error.Success())
1206 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1207 }
1208 else
1209 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001210 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211 }
1212 }
1213 else
1214 {
1215 m_frame_base_error.SetErrorString ("No function in symbol context.");
1216 }
1217 }
1218
1219 if (m_frame_base_error.Success())
1220 frame_base = m_frame_base;
1221
1222 if (error_ptr)
1223 *error_ptr = m_frame_base_error;
1224 return m_frame_base_error.Success();
1225}
1226
Greg Clayton5ccbd292011-01-06 22:15:06 +00001227RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228StackFrame::GetRegisterContext ()
1229{
Jason Molenda6a354702014-10-02 01:08:16 +00001230 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001231 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001232 {
1233 ThreadSP thread_sp (GetThread());
1234 if (thread_sp)
1235 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1236 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001237 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238}
1239
1240bool
1241StackFrame::HasDebugInformation ()
1242{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001243 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244 return m_sc.line_entry.IsValid();
1245}
1246
Greg Clayton288bdf92010-09-02 02:59:18 +00001247
1248ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001249StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250{
Jason Molenda6a354702014-10-02 01:08:16 +00001251 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001252 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001253 if (m_is_history_frame)
1254 {
1255 return valobj_sp;
1256 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001257 VariableList *var_list = GetVariableList (true);
1258 if (var_list)
1259 {
1260 // Make sure the variable is a frame variable
1261 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1262 const uint32_t num_variables = var_list->GetSize();
1263 if (var_idx < num_variables)
1264 {
1265 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1266 if (valobj_sp.get() == NULL)
1267 {
1268 if (m_variable_list_value_objects.GetSize() < num_variables)
1269 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001270 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001271 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1272 }
1273 }
1274 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001275 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001276 {
Jim Ingham2837b762011-05-04 03:43:18 +00001277 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001278 if (dynamic_sp)
1279 return dynamic_sp;
1280 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001281 return valobj_sp;
1282}
1283
1284ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001285StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001286{
Jason Molenda6a354702014-10-02 01:08:16 +00001287 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001288 if (m_is_history_frame)
1289 return ValueObjectSP();
1290
Greg Clayton288bdf92010-09-02 02:59:18 +00001291 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001292 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001293 if (!valobj_sp)
1294 {
1295 // We aren't already tracking this global
1296 VariableList *var_list = GetVariableList (true);
1297 // If this frame has no variables, create a new list
1298 if (var_list == NULL)
1299 m_variable_list_sp.reset (new VariableList());
1300
1301 // Add the global/static variable to this frame
1302 m_variable_list_sp->AddVariable (variable_sp);
1303
1304 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001305 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001306 }
1307 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308}
1309
Jim Ingham6b8379c2010-08-26 20:44:45 +00001310bool
1311StackFrame::IsInlined ()
1312{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001313 if (m_sc.block == NULL)
1314 GetSymbolContext (eSymbolContextBlock);
1315 if (m_sc.block)
1316 return m_sc.block->GetContainingInlinedBlock() != NULL;
1317 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001318}
1319
Greg Claytond9e416c2012-02-18 05:35:26 +00001320TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321StackFrame::CalculateTarget ()
1322{
Greg Claytond9e416c2012-02-18 05:35:26 +00001323 TargetSP target_sp;
1324 ThreadSP thread_sp(GetThread());
1325 if (thread_sp)
1326 {
1327 ProcessSP process_sp (thread_sp->CalculateProcess());
1328 if (process_sp)
1329 target_sp = process_sp->CalculateTarget();
1330 }
1331 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001332}
1333
Greg Claytond9e416c2012-02-18 05:35:26 +00001334ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001335StackFrame::CalculateProcess ()
1336{
Greg Claytond9e416c2012-02-18 05:35:26 +00001337 ProcessSP process_sp;
1338 ThreadSP thread_sp(GetThread());
1339 if (thread_sp)
1340 process_sp = thread_sp->CalculateProcess();
1341 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342}
1343
Greg Claytond9e416c2012-02-18 05:35:26 +00001344ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001345StackFrame::CalculateThread ()
1346{
Greg Claytond9e416c2012-02-18 05:35:26 +00001347 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001348}
1349
Jason Molendab57e4a12013-11-04 09:33:30 +00001350StackFrameSP
1351StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001352{
Greg Claytond9e416c2012-02-18 05:35:26 +00001353 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354}
1355
1356
1357void
Greg Clayton0603aa92010-10-04 01:05:56 +00001358StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001359{
Greg Claytond9e416c2012-02-18 05:35:26 +00001360 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361}
1362
1363void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001364StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001365{
1366 if (strm == NULL)
1367 return;
1368
1369 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001370 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001371 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001372
1373 if (frame_marker)
1374 s.PutCString(frame_marker);
1375
Greg Claytond9e416c2012-02-18 05:35:26 +00001376 const char *frame_format = NULL;
1377 Target *target = exe_ctx.GetTargetPtr();
1378 if (target)
1379 frame_format = target->GetDebugger().GetFrameFormat();
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001380 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s))
Greg Clayton0603aa92010-10-04 01:05:56 +00001381 {
1382 strm->Write(s.GetData(), s.GetSize());
1383 }
1384 else
1385 {
1386 Dump (strm, true, false);
1387 strm->EOL();
1388 }
1389}
1390
1391void
Greg Clayton6dadd502010-09-02 21:44:10 +00001392StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001393{
1394 if (strm == NULL)
1395 return;
1396
1397 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001398 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001399 ExecutionContext exe_ctx (shared_from_this());
1400 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001401 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001402 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1403 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001404 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001405 const bool show_module = true;
1406 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001407 const bool show_function_arguments = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001408 m_sc.DumpStopContext (strm,
1409 exe_ctx.GetBestExecutionContextScope(),
1410 GetFrameCodeAddress(),
1411 show_fullpaths,
1412 show_module,
Jason Molendaaff1b352014-10-10 23:07:36 +00001413 show_inline,
1414 show_function_arguments);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001415}
1416
Greg Clayton5082c5f2010-08-27 18:24:16 +00001417void
Jason Molendab57e4a12013-11-04 09:33:30 +00001418StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001419{
Jason Molenda6a354702014-10-02 01:08:16 +00001420 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001421 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001422 m_variable_list_sp = prev_frame.m_variable_list_sp;
1423 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1424 if (!m_disassembly.GetString().empty())
1425 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001426}
Greg Clayton68275d52010-08-27 21:47:54 +00001427
1428
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001429void
Jason Molendab57e4a12013-11-04 09:33:30 +00001430StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001431{
Jason Molenda6a354702014-10-02 01:08:16 +00001432 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:42 +00001433 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001434 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1435 assert (GetThread() == curr_frame.GetThread());
1436 m_frame_index = curr_frame.m_frame_index;
1437 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1438 m_reg_context_sp = curr_frame.m_reg_context_sp;
1439 m_frame_code_addr = curr_frame.m_frame_code_addr;
1440 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());
1441 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());
1442 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1443 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1444 m_sc = curr_frame.m_sc;
1445 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1446 m_flags.Set (m_sc.GetResolvedMask());
1447 m_frame_base.Clear();
1448 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001449}
1450
1451
Greg Clayton2cad65a2010-09-03 17:10:42 +00001452bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001453StackFrame::HasCachedData () const
1454{
1455 if (m_variable_list_sp.get())
1456 return true;
1457 if (m_variable_list_value_objects.GetSize() > 0)
1458 return true;
1459 if (!m_disassembly.GetString().empty())
1460 return true;
1461 return false;
1462}
1463
1464bool
Greg Clayton7260f622011-04-18 08:33:37 +00001465StackFrame::GetStatus (Stream& strm,
1466 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001467 bool show_source,
1468 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001469{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001470
Greg Clayton7260f622011-04-18 08:33:37 +00001471 if (show_frame_info)
1472 {
1473 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001474 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001475 }
1476
1477 if (show_source)
1478 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001479 ExecutionContext exe_ctx (shared_from_this());
Greg Claytone372b982011-11-21 21:44:34 +00001480 bool have_source = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001481 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001482 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001483 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001484 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001485 Debugger &debugger = target->GetDebugger();
1486 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1487 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1488 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001489
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001490 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1491 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001492 {
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001493 have_source = true;
1494 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001495 {
Jason Molenda7cd81c52013-04-29 09:59:31 +00001496 target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001497 m_sc.line_entry.line,
1498 source_lines_before,
1499 source_lines_after,
1500 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001501 &strm);
Greg Claytone372b982011-11-21 21:44:34 +00001502 }
1503 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001504 switch (disasm_display)
1505 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001506 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001507 break;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001508
Greg Clayton67cc0632012-08-22 17:17:09 +00001509 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001510 if (have_source)
1511 break;
1512 // Fall through to next case
Greg Clayton67cc0632012-08-22 17:17:09 +00001513 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001514 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001515 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001516 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1517 if (disasm_lines > 0)
1518 {
1519 const ArchSpec &target_arch = target->GetArchitecture();
1520 AddressRange pc_range;
1521 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1522 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Jim Ingham0f063ba2013-03-02 00:26:47 +00001523 const char *plugin_name = NULL;
1524 const char *flavor = NULL;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001525 Disassembler::Disassemble (target->GetDebugger(),
1526 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001527 plugin_name,
1528 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001529 exe_ctx,
1530 pc_range,
1531 disasm_lines,
1532 0,
1533 Disassembler::eOptionMarkPCAddress,
1534 strm);
1535 }
Greg Claytone372b982011-11-21 21:44:34 +00001536 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001537 break;
Greg Claytone372b982011-11-21 21:44:34 +00001538 }
Greg Clayton7260f622011-04-18 08:33:37 +00001539 }
1540 }
1541 return true;
1542}
1543