blob: 3e6703531e7b42216d478057a6047ce4019e18a1 [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
10#include "lldb/Target/StackFrame.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Module.h"
Greg Clayton0603aa92010-10-04 01:05:56 +000017#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Core/Disassembler.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000019#include "lldb/Core/FormatEntity.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000021#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:08 +000022#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Symbol/Symbol.h"
26#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000027#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/ExecutionContext.h"
29#include "lldb/Target/Process.h"
30#include "lldb/Target/RegisterContext.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
37// The first bits in the flags are reserved for the SymbolContext::Scope bits
38// so we know if we have tried to look up information in our internal symbol
39// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000040#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000041#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000042#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
43#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000044#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045
Greg Claytond9e416c2012-02-18 05:35:26 +000046StackFrame::StackFrame (const ThreadSP &thread_sp,
47 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000048 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000049 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000050 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000051 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000052 uint32_t stop_id,
53 bool stop_id_is_valid,
54 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000055 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000056 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000057 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000058 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000059 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:10 +000060 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +000061 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000062 m_sc (),
63 m_flags (),
64 m_frame_base (),
65 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000066 m_cfa_is_valid (cfa_is_valid),
67 m_stop_id (stop_id),
68 m_stop_id_is_valid (stop_id_is_valid),
69 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000071 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +000072 m_disassembly (),
73 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074{
Jason Molenda99618472013-11-04 11:02:52 +000075 // If we don't have a CFA value, use the frame index for our StackID so that recursive
76 // functions properly aren't confused with one another on a history stack.
77 if (m_is_history_frame && m_cfa_is_valid == false)
78 {
79 m_id.SetCFA (m_frame_index);
80 }
81
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000083 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000085 m_flags.Set(m_sc.GetResolvedMask ());
86 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
Greg Claytond9e416c2012-02-18 05:35:26 +000089StackFrame::StackFrame (const ThreadSP &thread_sp,
90 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000091 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000092 const RegisterContextSP &reg_context_sp,
93 addr_t cfa,
94 addr_t pc,
95 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000096 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000097 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000098 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000099 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:10 +0000100 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +0000101 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000102 m_sc (),
103 m_flags (),
104 m_frame_base (),
105 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000106 m_cfa_is_valid (true),
107 m_stop_id (0),
108 m_stop_id_is_valid (false),
109 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000111 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000112 m_disassembly (),
113 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114{
115 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000116 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000118 m_flags.Set(m_sc.GetResolvedMask ());
119 }
120
121 if (reg_context_sp && !m_sc.target_sp)
122 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000123 m_sc.target_sp = reg_context_sp->CalculateTarget();
124 if (m_sc.target_sp)
125 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000126 }
127}
128
Greg Claytond9e416c2012-02-18 05:35:26 +0000129StackFrame::StackFrame (const ThreadSP &thread_sp,
130 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000131 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000132 const RegisterContextSP &reg_context_sp,
133 addr_t cfa,
134 const Address& pc_addr,
135 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000136 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000137 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000138 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000139 m_reg_context_sp (reg_context_sp),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000140 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000141 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000142 m_sc (),
143 m_flags (),
144 m_frame_base (),
145 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000146 m_cfa_is_valid (true),
147 m_stop_id (0),
148 m_stop_id_is_valid (false),
149 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000150 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000151 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000152 m_disassembly (),
153 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000154{
155 if (sc_ptr != NULL)
156 {
157 m_sc = *sc_ptr;
158 m_flags.Set(m_sc.GetResolvedMask ());
159 }
160
161 if (m_sc.target_sp.get() == NULL && reg_context_sp)
162 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000163 m_sc.target_sp = reg_context_sp->CalculateTarget();
164 if (m_sc.target_sp)
165 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000166 }
167
Greg Claytone72dfb32012-02-24 01:59:29 +0000168 ModuleSP pc_module_sp (pc_addr.GetModule());
169 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000170 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000171 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000172 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000173 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000174 m_flags.Set (eSymbolContextModule);
175 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000176 else
177 {
178 m_sc.module_sp.reset();
179 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000180 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181}
182
183
184//----------------------------------------------------------------------
185// Destructor
186//----------------------------------------------------------------------
187StackFrame::~StackFrame()
188{
189}
190
191StackID&
192StackFrame::GetStackID()
193{
Jason Molenda6a354702014-10-02 01:08:16 +0000194 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10 +0000195 // Make sure we have resolved the StackID object's symbol context scope if
196 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000198 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
199 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000200 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000201 {
Greg Clayton95897c62010-09-07 04:20:48 +0000202 // We already have a symbol context scope, we just don't have our
203 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000204 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
205 }
206 else
207 {
Greg Clayton95897c62010-09-07 04:20:48 +0000208 // Calculate the frame block and use this for the stack ID symbol
209 // context scope if we have one.
210 SymbolContextScope *scope = GetFrameBlock ();
211 if (scope == NULL)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000212 {
Greg Clayton95897c62010-09-07 04:20:48 +0000213 // We don't have a block, so use the symbol
214 if (m_flags.IsClear (eSymbolContextSymbol))
215 GetSymbolContext (eSymbolContextSymbol);
216
217 // It is ok if m_sc.symbol is NULL here
218 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000219 }
Greg Clayton95897c62010-09-07 04:20:48 +0000220 // Set the symbol context scope (the accessor will set the
221 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
222 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225 return m_id;
226}
227
Jim Ingham513c6bb2012-09-01 01:02:41 +0000228uint32_t
229StackFrame::GetFrameIndex () const
230{
231 ThreadSP thread_sp = GetThread();
232 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000233 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000234 else
235 return m_frame_index;
236}
237
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000238void
239StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
240{
Jason Molenda6a354702014-10-02 01:08:16 +0000241 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000242 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
243 m_id.SetSymbolContextScope (symbol_scope);
244}
245
Greg Clayton34132752011-07-06 04:07:21 +0000246const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000247StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248{
Jason Molenda6a354702014-10-02 01:08:16 +0000249 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000250 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000252 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253
254 // Resolve the PC into a temporary address because if ResolveLoadAddress
255 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000256 ThreadSP thread_sp (GetThread());
257 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000259 TargetSP target_sp (thread_sp->CalculateTarget());
260 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000262 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000264 ModuleSP module_sp (m_frame_code_addr.GetModule());
265 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000266 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000267 m_sc.module_sp = module_sp;
268 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000269 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 }
271 }
272 }
273 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000274 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275}
276
Jason Molenda99618472013-11-04 11:02:52 +0000277bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278StackFrame::ChangePC (addr_t pc)
279{
Jason Molenda6a354702014-10-02 01:08:16 +0000280 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000281 // We can't change the pc value of a history stack frame - it is immutable.
282 if (m_is_history_frame)
283 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000284 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47 +0000285 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59 +0000286 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26 +0000287 ThreadSP thread_sp (GetThread());
288 if (thread_sp)
289 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52 +0000290 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291}
292
293const char *
294StackFrame::Disassemble ()
295{
Jason Molenda6a354702014-10-02 01:08:16 +0000296 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297 if (m_disassembly.GetSize() == 0)
298 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000299 ExecutionContext exe_ctx (shared_from_this());
300 Target *target = exe_ctx.GetTargetPtr();
301 if (target)
302 {
Jim Ingham0f063ba2013-03-02 00:26:47 +0000303 const char *plugin_name = NULL;
304 const char *flavor = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000305 Disassembler::Disassemble (target->GetDebugger(),
306 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000307 plugin_name,
308 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000309 exe_ctx,
310 0,
311 0,
312 0,
313 m_disassembly);
314 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 if (m_disassembly.GetSize() == 0)
316 return NULL;
317 }
318 return m_disassembly.GetData();
319}
320
Greg Clayton95897c62010-09-07 04:20:48 +0000321Block *
322StackFrame::GetFrameBlock ()
323{
324 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
325 GetSymbolContext (eSymbolContextBlock);
326
327 if (m_sc.block)
328 {
329 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
330 if (inline_block)
331 {
332 // Use the block with the inlined function info
333 // as the frame block we want this frame to have only the variables
334 // for the inlined function and its non-inlined block child blocks.
335 return inline_block;
336 }
337 else
338 {
339 // This block is not contained withing any inlined function blocks
340 // with so we want to use the top most function block.
341 return &m_sc.function->GetBlock (false);
342 }
343 }
344 return NULL;
345}
346
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347//----------------------------------------------------------------------
348// Get the symbol context if we already haven't done so by resolving the
349// PC address as much as possible. This way when we pass around a
350// StackFrame object, everyone will have as much information as
351// possible and no one will ever have to look things up manually.
352//----------------------------------------------------------------------
353const SymbolContext&
354StackFrame::GetSymbolContext (uint32_t resolve_scope)
355{
Jason Molenda6a354702014-10-02 01:08:16 +0000356 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000358 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359 {
Greg Clayton75a03332012-11-29 00:53:06 +0000360 uint32_t resolved = 0;
361
362 // If the target was requested add that:
363 if (!m_sc.target_sp)
364 {
365 m_sc.target_sp = CalculateTarget();
366 if (m_sc.target_sp)
367 resolved |= eSymbolContextTarget;
368 }
369
370
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000371 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 // and if we don't have a module. The resolved address section will
373 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000374 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000375 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376
377 // If this is not frame zero, then we need to subtract 1 from the PC
378 // value when doing address lookups since the PC will be on the
379 // instruction following the function call instruction...
380
Greg Clayton9da7bd02010-08-24 21:05:24 +0000381 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000382 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 {
384 addr_t offset = lookup_addr.GetOffset();
385 if (offset > 0)
Jason Molendacf296752014-11-08 05:38:17 +0000386 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17 +0000388
389 }
390 else
391 {
392 // lookup_addr is the start of a section. We need
393 // do the math on the actual load address and re-compute
394 // the section. We're working with a 'noreturn' function
395 // at the end of a section.
396 ThreadSP thread_sp (GetThread());
397 if (thread_sp)
398 {
399 TargetSP target_sp (thread_sp->CalculateTarget());
400 if (target_sp)
401 {
402 addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1;
403 lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get());
404 }
405 else
406 {
407 lookup_addr.SetOffset(offset - 1);
408 }
409 }
410 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 }
412
Greg Clayton9da7bd02010-08-24 21:05:24 +0000413
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 if (m_sc.module_sp)
415 {
416 // We have something in our stack frame symbol context, lets check
417 // if we haven't already tried to lookup one of those things. If we
418 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000419
420 uint32_t actual_resolve_scope = 0;
421
422 if (resolve_scope & eSymbolContextCompUnit)
423 {
424 if (m_flags.IsClear (eSymbolContextCompUnit))
425 {
426 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000427 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000428 else
429 actual_resolve_scope |= eSymbolContextCompUnit;
430 }
431 }
432
433 if (resolve_scope & eSymbolContextFunction)
434 {
435 if (m_flags.IsClear (eSymbolContextFunction))
436 {
437 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000438 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000439 else
440 actual_resolve_scope |= eSymbolContextFunction;
441 }
442 }
443
444 if (resolve_scope & eSymbolContextBlock)
445 {
446 if (m_flags.IsClear (eSymbolContextBlock))
447 {
448 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000449 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000450 else
451 actual_resolve_scope |= eSymbolContextBlock;
452 }
453 }
454
455 if (resolve_scope & eSymbolContextSymbol)
456 {
457 if (m_flags.IsClear (eSymbolContextSymbol))
458 {
459 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000460 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000461 else
462 actual_resolve_scope |= eSymbolContextSymbol;
463 }
464 }
465
466 if (resolve_scope & eSymbolContextLineEntry)
467 {
468 if (m_flags.IsClear (eSymbolContextLineEntry))
469 {
470 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000471 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000472 else
473 actual_resolve_scope |= eSymbolContextLineEntry;
474 }
475 }
476
477 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 {
479 // We might be resolving less information than what is already
480 // in our current symbol context so resolve into a temporary
481 // symbol context "sc" so we don't clear out data we have
482 // already found in "m_sc"
483 SymbolContext sc;
484 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000485 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000486 // Only replace what we didn't already have as we may have
487 // information for an inlined function scope that won't match
488 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000489 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
490 m_sc.comp_unit = sc.comp_unit;
491 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
492 m_sc.function = sc.function;
493 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
494 m_sc.block = sc.block;
495 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
496 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000497 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
498 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000499 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000500 if (m_sc.target_sp)
501 {
502 // Be sure to apply and file remappings to our file and line
503 // entries when handing out a line entry
504 FileSpec new_file_spec;
505 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
506 m_sc.line_entry.file = new_file_spec;
507 }
508 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 }
510 }
511 else
512 {
513 // If we don't have a module, then we can't have the compile unit,
514 // function, block, line entry or symbol, so we can safely call
515 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000516 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000517 {
Greg Clayton75a03332012-11-29 00:53:06 +0000518 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000519 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000520 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521
522 // Update our internal flags so we remember what we have tried to locate so
523 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000524 // We might have dug up more information that was requested (for example
525 // if we were asked to only get the block, we will have gotten the
526 // compile unit, and function) so set any additional bits that we resolved
527 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528 }
529
530 // Return the symbol context with everything that was possible to resolve
531 // resolved.
532 return m_sc;
533}
534
535
536VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000537StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538{
Jason Molenda6a354702014-10-02 01:08:16 +0000539 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 if (m_flags.IsClear(RESOLVED_VARIABLES))
541 {
542 m_flags.Set(RESOLVED_VARIABLES);
543
Greg Clayton95897c62010-09-07 04:20:48 +0000544 Block *frame_block = GetFrameBlock();
545
546 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547 {
Greg Clayton95897c62010-09-07 04:20:48 +0000548 const bool get_child_variables = true;
549 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000550 const bool stop_if_child_block_is_inlined_function = true;
551 m_variable_list_sp.reset(new VariableList());
552 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 +0000553 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000554 }
555
556 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
557 get_file_globals)
558 {
559 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000560
Sean Callanan7c0962d2010-11-01 04:38:59 +0000561 if (m_flags.IsClear (eSymbolContextCompUnit))
562 GetSymbolContext (eSymbolContextCompUnit);
563
564 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000565 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000566 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
567 if (m_variable_list_sp)
568 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
569 else
570 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000571 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000573
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 return m_variable_list_sp.get();
575}
576
Greg Claytond41f0322011-08-02 23:35:43 +0000577VariableListSP
578StackFrame::GetInScopeVariableList (bool get_file_globals)
579{
Jason Molenda6a354702014-10-02 01:08:16 +0000580 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000581 // We can't fetch variable information for a history stack frame.
582 if (m_is_history_frame)
583 return VariableListSP();
584
Greg Claytond41f0322011-08-02 23:35:43 +0000585 VariableListSP var_list_sp(new VariableList);
586 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
587
588 if (m_sc.block)
589 {
590 const bool can_create = true;
591 const bool get_parent_variables = true;
592 const bool stop_if_block_is_inlined_function = true;
593 m_sc.block->AppendVariables (can_create,
594 get_parent_variables,
595 stop_if_block_is_inlined_function,
596 var_list_sp.get());
597 }
598
599 if (m_sc.comp_unit)
600 {
601 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
602 if (global_variable_list_sp)
603 var_list_sp->AddVariables (global_variable_list_sp.get());
604 }
605
606 return var_list_sp;
607}
608
609
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000610ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000611StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000612 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000613 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000614 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000615 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000616{
Jason Molenda99618472013-11-04 11:02:52 +0000617 // We can't fetch variable information for a history stack frame.
618 if (m_is_history_frame)
619 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000620
621 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000622 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000623 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
624 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000625 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000626 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000627 error.Clear();
628 bool deref = false;
629 bool address_of = false;
630 ValueObjectSP valobj_sp;
631 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000632 // When looking up a variable for an expression, we need only consider the
633 // variables that are in scope.
634 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
635 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000636
637 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000638 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000639 // If first character is a '*', then show pointer contents
640 const char *var_expr = var_expr_cstr;
641 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000642 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000643 deref = true;
644 var_expr++; // Skip the '*'
645 }
646 else if (var_expr[0] == '&')
647 {
648 address_of = true;
649 var_expr++; // Skip the '&'
650 }
651
652 std::string var_path (var_expr);
653 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
654 StreamString var_expr_path_strm;
655
656 ConstString name_const_string;
657 if (separator_idx == std::string::npos)
658 name_const_string.SetCString (var_path.c_str());
659 else
660 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
661
Paul Herman10bc1a42015-08-18 22:46:57 +0000662 var_sp = variable_list->FindVariable(name_const_string, false);
Greg Clayton685c88c2012-07-14 00:53:55 +0000663
664 bool synthetically_added_instance_object = false;
665
666 if (var_sp)
667 {
668 var_path.erase (0, name_const_string.GetLength ());
669 }
670 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
671 {
672 // Check for direct ivars access which helps us with implicit
673 // access to ivars with the "this->" or "self->"
674 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
675 lldb::LanguageType method_language = eLanguageTypeUnknown;
676 bool is_instance_method = false;
677 ConstString method_object_name;
678 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
679 {
680 if (is_instance_method && method_object_name)
681 {
682 var_sp = variable_list->FindVariable(method_object_name);
683 if (var_sp)
684 {
685 separator_idx = 0;
686 var_path.insert(0, "->");
687 synthetically_added_instance_object = true;
688 }
689 }
690 }
691 }
692
Greg Clayton54979cd2010-12-15 05:08:08 +0000693 if (var_sp)
694 {
Jim Ingham2837b762011-05-04 03:43:18 +0000695 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000696 if (!valobj_sp)
697 return valobj_sp;
698
Greg Clayton54979cd2010-12-15 05:08:08 +0000699 // We are dumping at least one child
700 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000701 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000702 // Calculate the next separator index ahead of time
703 ValueObjectSP child_valobj_sp;
704 const char separator_type = var_path[0];
705 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000706 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000707
708 case '-':
709 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000710 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000711
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000712 if (no_fragile_ivar)
713 {
714 // Make sure we aren't trying to deref an objective
715 // C ivar if this is not allowed
Greg Clayton57ee3062013-07-11 22:46:58 +0000716 const uint32_t pointer_type_flags = valobj_sp->GetClangType().GetTypeInfo (NULL);
Enrico Granata622be232014-10-21 20:52:14 +0000717 if ((pointer_type_flags & eTypeIsObjC) &&
718 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000719 {
720 // This was an objective C object pointer and
721 // it was requested we skip any fragile ivars
722 // so return nothing here
723 return ValueObjectSP();
724 }
725 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000726 var_path.erase (0, 1); // Remove the '-'
727 // Fall through
728 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000729 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000730 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000731
Greg Clayton54979cd2010-12-15 05:08:08 +0000732 var_path.erase (0, 1); // Remove the '.' or '>'
733 separator_idx = var_path.find_first_of(".-[");
734 ConstString child_name;
735 if (separator_idx == std::string::npos)
736 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000737 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000738 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
739
740 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000741 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000742 // We either have a pointer type and need to verify
743 // valobj_sp is a pointer, or we have a member of a
744 // class/union/struct being accessed with the . syntax
745 // and need to verify we don't have a pointer.
746 const bool actual_is_ptr = valobj_sp->IsPointerType ();
747
748 if (actual_is_ptr != expr_is_ptr)
749 {
750 // Incorrect use of "." with a pointer, or "->" with
751 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000752 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000753 if (actual_is_ptr)
754 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
755 var_expr_path_strm.GetString().c_str(),
756 child_name.GetCString(),
757 var_expr_path_strm.GetString().c_str(),
758 var_path.c_str());
759 else
760 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
761 var_expr_path_strm.GetString().c_str(),
762 child_name.GetCString(),
763 var_expr_path_strm.GetString().c_str(),
764 var_path.c_str());
765 return ValueObjectSP();
766 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000767 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000768 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000769 if (!child_valobj_sp)
770 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000771 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000772 {
773 child_valobj_sp = valobj_sp->GetSyntheticValue();
774 if (child_valobj_sp)
775 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
776 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000777
778 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000779 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000780 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000781 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000782 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000783 // We added a "this->" or "self->" to the beginning of the expression
784 // and this is the first pointer ivar access, so just return the normal
785 // error
786 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
787 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000788 }
789 else
790 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000791 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
792 if (child_name)
793 {
794 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
795 child_name.GetCString(),
796 valobj_sp->GetTypeName().AsCString("<invalid type>"),
797 var_expr_path_strm.GetString().c_str());
798 }
799 else
800 {
801 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
802 var_expr_path_strm.GetString().c_str(),
803 var_expr_cstr);
804 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000805 }
806 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000807 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000808 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000809 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000810 // Remove the child name from the path
811 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000812 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000813 {
Jim Ingham2837b762011-05-04 03:43:18 +0000814 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000815 if (dynamic_value_sp)
816 child_valobj_sp = dynamic_value_sp;
817 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000818 }
819 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000820
Greg Clayton54979cd2010-12-15 05:08:08 +0000821 case '[':
822 // Array member access, or treating pointer as an array
823 if (var_path.size() > 2) // Need at least two brackets and a number
824 {
825 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000826 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000827 if (end && *end == ']'
828 && *(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 +0000829 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000830 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000831 {
832 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
833 // and extract bit low out of it. reading array item low
834 // would be done by saying ptr[low], without a deref * sign
835 Error error;
836 ValueObjectSP temp(valobj_sp->Dereference(error));
837 if (error.Fail())
838 {
839 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
840 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
841 valobj_sp->GetTypeName().AsCString("<invalid type>"),
842 var_expr_path_strm.GetString().c_str());
843 return ValueObjectSP();
844 }
845 valobj_sp = temp;
846 deref = false;
847 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000848 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000849 {
850 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
851 // (an operation that is equivalent to deref-ing arr)
852 // and extract bit low out of it. reading array item low
853 // would be done by saying arr[low], without a deref * sign
854 Error error;
855 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
856 if (error.Fail())
857 {
858 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
859 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
860 valobj_sp->GetTypeName().AsCString("<invalid type>"),
861 var_expr_path_strm.GetString().c_str());
862 return ValueObjectSP();
863 }
864 valobj_sp = temp;
865 deref = false;
866 }
867
Greg Clayton4ef877f2012-12-06 02:33:54 +0000868 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000869 if (valobj_sp->IsPointerType ())
870 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000871 bool is_objc_pointer = true;
872
Greg Clayton57ee3062013-07-11 22:46:58 +0000873 if (valobj_sp->GetClangType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000874 is_objc_pointer = false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000875 else if (!valobj_sp->GetClangType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000876 is_objc_pointer = false;
877
878 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000879 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000880 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
881 valobj_sp->GetTypeName().AsCString("<invalid type>"),
882 var_expr_path_strm.GetString().c_str());
883
884 return ValueObjectSP();
885 }
886 else if (is_objc_pointer)
887 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000888 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000889 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000890 if (synthetic.get() == NULL /* no synthetic */
891 || synthetic == valobj_sp) /* synthetic is the same as the original object */
892 {
893 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
894 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
895 valobj_sp->GetTypeName().AsCString("<invalid type>"),
896 var_expr_path_strm.GetString().c_str());
897 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000898 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000899 {
900 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000901 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000902 child_index,
903 valobj_sp->GetTypeName().AsCString("<invalid type>"),
904 var_expr_path_strm.GetString().c_str());
905 }
906 else
907 {
908 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
909 if (!child_valobj_sp)
910 {
911 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000912 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000913 child_index,
914 valobj_sp->GetTypeName().AsCString("<invalid type>"),
915 var_expr_path_strm.GetString().c_str());
916 }
917 }
918 }
919 else
920 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000921 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +0000922 if (!child_valobj_sp)
923 {
924 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000925 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000926 child_index,
927 valobj_sp->GetTypeName().AsCString("<invalid type>"),
928 var_expr_path_strm.GetString().c_str());
929 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000930 }
931 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000932 else if (valobj_sp->GetClangType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000933 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000934 // Pass false to dynamic_value here so we can tell the difference between
935 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000936 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000937 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
938 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
939
Greg Clayton54979cd2010-12-15 05:08:08 +0000940 if (!child_valobj_sp)
941 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000942 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000943 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000944 child_index,
945 valobj_sp->GetTypeName().AsCString("<invalid type>"),
946 var_expr_path_strm.GetString().c_str());
947 }
948 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000949 else if (valobj_sp->GetClangType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000950 {
951 // this is a bitfield asking to display just one bit
952 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
953 if (!child_valobj_sp)
954 {
955 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000956 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000957 child_index, child_index,
958 valobj_sp->GetTypeName().AsCString("<invalid type>"),
959 var_expr_path_strm.GetString().c_str());
960 }
961 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000962 else
963 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000964 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000965 if (no_synth_child /* synthetic is forbidden */ ||
966 synthetic.get() == NULL /* no synthetic */
967 || synthetic == valobj_sp) /* synthetic is the same as the original object */
968 {
969 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
970 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
971 valobj_sp->GetTypeName().AsCString("<invalid type>"),
972 var_expr_path_strm.GetString().c_str());
973 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000974 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000975 {
976 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000977 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000978 child_index,
979 valobj_sp->GetTypeName().AsCString("<invalid type>"),
980 var_expr_path_strm.GetString().c_str());
981 }
982 else
983 {
984 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
985 if (!child_valobj_sp)
986 {
987 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000988 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000989 child_index,
990 valobj_sp->GetTypeName().AsCString("<invalid type>"),
991 var_expr_path_strm.GetString().c_str());
992 }
993 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000994 }
995
996 if (!child_valobj_sp)
997 {
998 // Invalid array index...
999 return ValueObjectSP();
1000 }
1001
1002 // Erase the array member specification '[%i]' where
1003 // %i is the array index
1004 var_path.erase(0, (end - var_path.c_str()) + 1);
1005 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001006 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001007 {
Jim Ingham2837b762011-05-04 03:43:18 +00001008 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +00001009 if (dynamic_value_sp)
1010 child_valobj_sp = dynamic_value_sp;
1011 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001012 // Break out early from the switch since we were
1013 // able to find the child member
1014 break;
1015 }
Enrico Granata20edcdb2011-07-19 18:03:25 +00001016 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +00001017 {
1018 // this is most probably a BitField, let's take a look
1019 char *real_end = NULL;
1020 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001021 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +00001022 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001023 {
1024 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001025 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001026 {
1027 long temp = child_index;
1028 child_index = final_index;
1029 final_index = temp;
1030 }
1031
Greg Clayton57ee3062013-07-11 22:46:58 +00001032 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001033 {
1034 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1035 // and extract bits low thru high out of it. reading array items low thru high
1036 // would be done by saying ptr[low-high], without a deref * sign
1037 Error error;
1038 ValueObjectSP temp(valobj_sp->Dereference(error));
1039 if (error.Fail())
1040 {
1041 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1042 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1043 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1044 var_expr_path_strm.GetString().c_str());
1045 return ValueObjectSP();
1046 }
1047 valobj_sp = temp;
1048 deref = false;
1049 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001050 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001051 {
1052 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1053 // (an operation that is equivalent to deref-ing arr)
1054 // and extract bits low thru high out of it. reading array items low thru high
1055 // would be done by saying arr[low-high], without a deref * sign
1056 Error error;
1057 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1058 if (error.Fail())
1059 {
1060 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1061 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1062 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1063 var_expr_path_strm.GetString().c_str());
1064 return ValueObjectSP();
1065 }
1066 valobj_sp = temp;
1067 deref = false;
1068 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001069 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001070 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001071 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1072 expand_bitfield = false;
1073 if (!child_valobj_sp)
1074 {
1075 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1076 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1077 child_index, final_index,
1078 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1079 var_expr_path_strm.GetString().c_str());
1080 }
1081 }*/
1082
1083 if (expand_bitfield)
1084 {
1085 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1086 if (!child_valobj_sp)
1087 {
1088 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001089 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001090 child_index, final_index,
1091 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1092 var_expr_path_strm.GetString().c_str());
1093 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001094 }
1095 }
1096
1097 if (!child_valobj_sp)
1098 {
1099 // Invalid bitfield range...
1100 return ValueObjectSP();
1101 }
1102
1103 // Erase the bitfield member specification '[%i-%i]' where
1104 // %i is the index
1105 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1106 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001107 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001108 {
1109 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1110 if (dynamic_value_sp)
1111 child_valobj_sp = dynamic_value_sp;
1112 }
1113 // Break out early from the switch since we were
1114 // able to find the child member
1115 break;
1116
1117 }
1118 }
1119 else
1120 {
1121 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1122 var_expr_path_strm.GetString().c_str(),
1123 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001124 }
1125 return ValueObjectSP();
1126
1127 default:
1128 // Failure...
1129 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001130 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001131 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1132 separator_type,
1133 var_expr_path_strm.GetString().c_str(),
1134 var_path.c_str());
1135
1136 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001137 }
1138 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001139
Greg Clayton54979cd2010-12-15 05:08:08 +00001140 if (child_valobj_sp)
1141 valobj_sp = child_valobj_sp;
1142
1143 if (var_path.empty())
1144 break;
1145
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001146 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001147 if (valobj_sp)
1148 {
1149 if (deref)
1150 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001151 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001152 valobj_sp = deref_valobj_sp;
1153 }
1154 else if (address_of)
1155 {
1156 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1157 valobj_sp = address_of_valobj_sp;
1158 }
1159 }
1160 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001161 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001162 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001163 {
Jim Ingham2837b762011-05-04 03:43:18 +00001164 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1165 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001166 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001167 }
1168 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001169 else
1170 {
1171 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1172 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001173 return ValueObjectSP();
1174}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175
1176bool
1177StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1178{
Jason Molenda6a354702014-10-02 01:08:16 +00001179 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001180 if (m_cfa_is_valid == false)
1181 {
1182 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1183 return false;
1184 }
1185
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 if (m_flags.IsClear(GOT_FRAME_BASE))
1187 {
1188 if (m_sc.function)
1189 {
1190 m_frame_base.Clear();
1191 m_frame_base_error.Clear();
1192
1193 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001194 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001195 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001196 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1197 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001198 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001199
Greg Clayton57ee3062013-07-11 22:46:58 +00001200 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 +00001201 {
1202 // We should really have an error if evaluate returns, but in case
1203 // we don't, lets set the error to something at least.
1204 if (m_frame_base_error.Success())
1205 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1206 }
1207 else
1208 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001209 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 }
1211 }
1212 else
1213 {
1214 m_frame_base_error.SetErrorString ("No function in symbol context.");
1215 }
1216 }
1217
1218 if (m_frame_base_error.Success())
1219 frame_base = m_frame_base;
1220
1221 if (error_ptr)
1222 *error_ptr = m_frame_base_error;
1223 return m_frame_base_error.Success();
1224}
1225
Greg Clayton5ccbd292011-01-06 22:15:06 +00001226RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227StackFrame::GetRegisterContext ()
1228{
Jason Molenda6a354702014-10-02 01:08:16 +00001229 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001230 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001231 {
1232 ThreadSP thread_sp (GetThread());
1233 if (thread_sp)
1234 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1235 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001236 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001237}
1238
1239bool
1240StackFrame::HasDebugInformation ()
1241{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001242 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 return m_sc.line_entry.IsValid();
1244}
1245
Greg Clayton288bdf92010-09-02 02:59:18 +00001246
1247ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001248StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249{
Jason Molenda6a354702014-10-02 01:08:16 +00001250 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001251 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001252 if (m_is_history_frame)
1253 {
1254 return valobj_sp;
1255 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001256 VariableList *var_list = GetVariableList (true);
1257 if (var_list)
1258 {
1259 // Make sure the variable is a frame variable
1260 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1261 const uint32_t num_variables = var_list->GetSize();
1262 if (var_idx < num_variables)
1263 {
1264 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1265 if (valobj_sp.get() == NULL)
1266 {
1267 if (m_variable_list_value_objects.GetSize() < num_variables)
1268 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001269 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001270 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1271 }
1272 }
1273 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001274 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001275 {
Jim Ingham2837b762011-05-04 03:43:18 +00001276 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001277 if (dynamic_sp)
1278 return dynamic_sp;
1279 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001280 return valobj_sp;
1281}
1282
1283ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001284StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001285{
Jason Molenda6a354702014-10-02 01:08:16 +00001286 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001287 if (m_is_history_frame)
1288 return ValueObjectSP();
1289
Greg Clayton288bdf92010-09-02 02:59:18 +00001290 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001291 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001292 if (!valobj_sp)
1293 {
1294 // We aren't already tracking this global
1295 VariableList *var_list = GetVariableList (true);
1296 // If this frame has no variables, create a new list
1297 if (var_list == NULL)
1298 m_variable_list_sp.reset (new VariableList());
1299
1300 // Add the global/static variable to this frame
1301 m_variable_list_sp->AddVariable (variable_sp);
1302
1303 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001304 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001305 }
1306 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307}
1308
Jim Ingham6b8379c2010-08-26 20:44:45 +00001309bool
1310StackFrame::IsInlined ()
1311{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001312 if (m_sc.block == NULL)
1313 GetSymbolContext (eSymbolContextBlock);
1314 if (m_sc.block)
1315 return m_sc.block->GetContainingInlinedBlock() != NULL;
1316 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001317}
1318
Greg Claytond9e416c2012-02-18 05:35:26 +00001319TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320StackFrame::CalculateTarget ()
1321{
Greg Claytond9e416c2012-02-18 05:35:26 +00001322 TargetSP target_sp;
1323 ThreadSP thread_sp(GetThread());
1324 if (thread_sp)
1325 {
1326 ProcessSP process_sp (thread_sp->CalculateProcess());
1327 if (process_sp)
1328 target_sp = process_sp->CalculateTarget();
1329 }
1330 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001331}
1332
Greg Claytond9e416c2012-02-18 05:35:26 +00001333ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334StackFrame::CalculateProcess ()
1335{
Greg Claytond9e416c2012-02-18 05:35:26 +00001336 ProcessSP process_sp;
1337 ThreadSP thread_sp(GetThread());
1338 if (thread_sp)
1339 process_sp = thread_sp->CalculateProcess();
1340 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341}
1342
Greg Claytond9e416c2012-02-18 05:35:26 +00001343ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001344StackFrame::CalculateThread ()
1345{
Greg Claytond9e416c2012-02-18 05:35:26 +00001346 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001347}
1348
Jason Molendab57e4a12013-11-04 09:33:30 +00001349StackFrameSP
1350StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001351{
Greg Claytond9e416c2012-02-18 05:35:26 +00001352 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001353}
1354
1355
1356void
Greg Clayton0603aa92010-10-04 01:05:56 +00001357StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358{
Greg Claytond9e416c2012-02-18 05:35:26 +00001359 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360}
1361
1362void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001363StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001364{
1365 if (strm == NULL)
1366 return;
1367
1368 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001369 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001370 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001371
1372 if (frame_marker)
1373 s.PutCString(frame_marker);
1374
Greg Clayton554f68d2015-02-04 22:00:53 +00001375 const FormatEntity::Entry *frame_format = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001376 Target *target = exe_ctx.GetTargetPtr();
1377 if (target)
1378 frame_format = target->GetDebugger().GetFrameFormat();
Greg Clayton554f68d2015-02-04 22:00:53 +00001379 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, NULL, NULL, false, false))
Greg Clayton0603aa92010-10-04 01:05:56 +00001380 {
1381 strm->Write(s.GetData(), s.GetSize());
1382 }
1383 else
1384 {
1385 Dump (strm, true, false);
1386 strm->EOL();
1387 }
1388}
1389
1390void
Greg Clayton6dadd502010-09-02 21:44:10 +00001391StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392{
1393 if (strm == NULL)
1394 return;
1395
1396 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001397 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001398 ExecutionContext exe_ctx (shared_from_this());
1399 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001400 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001401 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1402 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001403 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001404 const bool show_module = true;
1405 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001406 const bool show_function_arguments = true;
Jason Molendac980fa92015-02-13 23:24:21 +00001407 const bool show_function_name = 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,
Jason Molendac980fa92015-02-13 23:24:21 +00001414 show_function_arguments,
1415 show_function_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416}
1417
Greg Clayton5082c5f2010-08-27 18:24:16 +00001418void
Jason Molendab57e4a12013-11-04 09:33:30 +00001419StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001420{
Jason Molenda6a354702014-10-02 01:08:16 +00001421 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001422 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001423 m_variable_list_sp = prev_frame.m_variable_list_sp;
1424 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1425 if (!m_disassembly.GetString().empty())
1426 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001427}
Greg Clayton68275d52010-08-27 21:47:54 +00001428
1429
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001430void
Jason Molendab57e4a12013-11-04 09:33:30 +00001431StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001432{
Jason Molenda6a354702014-10-02 01:08:16 +00001433 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:42 +00001434 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001435 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1436 assert (GetThread() == curr_frame.GetThread());
1437 m_frame_index = curr_frame.m_frame_index;
1438 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1439 m_reg_context_sp = curr_frame.m_reg_context_sp;
1440 m_frame_code_addr = curr_frame.m_frame_code_addr;
1441 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());
1442 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());
1443 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1444 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1445 m_sc = curr_frame.m_sc;
1446 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1447 m_flags.Set (m_sc.GetResolvedMask());
1448 m_frame_base.Clear();
1449 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001450}
1451
1452
Greg Clayton2cad65a2010-09-03 17:10:42 +00001453bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001454StackFrame::HasCachedData () const
1455{
1456 if (m_variable_list_sp.get())
1457 return true;
1458 if (m_variable_list_value_objects.GetSize() > 0)
1459 return true;
1460 if (!m_disassembly.GetString().empty())
1461 return true;
1462 return false;
1463}
1464
1465bool
Greg Clayton7260f622011-04-18 08:33:37 +00001466StackFrame::GetStatus (Stream& strm,
1467 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001468 bool show_source,
1469 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001470{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001471
Greg Clayton7260f622011-04-18 08:33:37 +00001472 if (show_frame_info)
1473 {
1474 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001475 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001476 }
1477
1478 if (show_source)
1479 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001480 ExecutionContext exe_ctx (shared_from_this());
Greg Claytone372b982011-11-21 21:44:34 +00001481 bool have_source = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001482 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001483 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001484 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001485 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001486 Debugger &debugger = target->GetDebugger();
1487 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1488 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1489 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001490
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001491 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1492 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001493 {
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001494 have_source = true;
1495 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001496 {
Jason Molenda7cd81c52013-04-29 09:59:31 +00001497 target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001498 m_sc.line_entry.line,
1499 source_lines_before,
1500 source_lines_after,
1501 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001502 &strm);
Greg Claytone372b982011-11-21 21:44:34 +00001503 }
1504 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001505 switch (disasm_display)
1506 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001507 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001508 break;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001509
Greg Clayton67cc0632012-08-22 17:17:09 +00001510 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001511 if (have_source)
1512 break;
1513 // Fall through to next case
Greg Clayton67cc0632012-08-22 17:17:09 +00001514 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001515 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001516 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001517 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1518 if (disasm_lines > 0)
1519 {
1520 const ArchSpec &target_arch = target->GetArchitecture();
1521 AddressRange pc_range;
1522 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1523 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Jim Ingham0f063ba2013-03-02 00:26:47 +00001524 const char *plugin_name = NULL;
1525 const char *flavor = NULL;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001526 Disassembler::Disassemble (target->GetDebugger(),
1527 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001528 plugin_name,
1529 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001530 exe_ctx,
1531 pc_range,
1532 disasm_lines,
1533 0,
1534 Disassembler::eOptionMarkPCAddress,
1535 strm);
1536 }
Greg Claytone372b982011-11-21 21:44:34 +00001537 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001538 break;
Greg Claytone372b982011-11-21 21:44:34 +00001539 }
Greg Clayton7260f622011-04-18 08:33:37 +00001540 }
1541 }
1542 return true;
1543}
1544