blob: 01a8c9ab88f26319db70c3cfa3977e17d7842af3 [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"
Greg Clayton554f68d2015-02-04 22:00:53 +000021#include "lldb/Core/FormatEntity.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000023#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:08 +000024#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Symbol/Symbol.h"
28#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000029#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/ExecutionContext.h"
31#include "lldb/Target/Process.h"
32#include "lldb/Target/RegisterContext.h"
33#include "lldb/Target/Target.h"
34#include "lldb/Target/Thread.h"
35
36using namespace lldb;
37using namespace lldb_private;
38
39// The first bits in the flags are reserved for the SymbolContext::Scope bits
40// so we know if we have tried to look up information in our internal symbol
41// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000042#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000043#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000044#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
45#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000046#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Greg Claytond9e416c2012-02-18 05:35:26 +000048StackFrame::StackFrame (const ThreadSP &thread_sp,
49 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000050 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000051 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000052 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000053 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000054 uint32_t stop_id,
55 bool stop_id_is_valid,
56 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000057 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000058 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000059 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000060 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000061 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:10 +000062 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +000063 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000064 m_sc (),
65 m_flags (),
66 m_frame_base (),
67 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000068 m_cfa_is_valid (cfa_is_valid),
69 m_stop_id (stop_id),
70 m_stop_id_is_valid (stop_id_is_valid),
71 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000073 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +000074 m_disassembly (),
75 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076{
Jason Molenda99618472013-11-04 11:02:52 +000077 // If we don't have a CFA value, use the frame index for our StackID so that recursive
78 // functions properly aren't confused with one another on a history stack.
79 if (m_is_history_frame && m_cfa_is_valid == false)
80 {
81 m_id.SetCFA (m_frame_index);
82 }
83
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000085 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000087 m_flags.Set(m_sc.GetResolvedMask ());
88 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089}
90
Greg Claytond9e416c2012-02-18 05:35:26 +000091StackFrame::StackFrame (const ThreadSP &thread_sp,
92 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000093 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000094 const RegisterContextSP &reg_context_sp,
95 addr_t cfa,
96 addr_t pc,
97 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000098 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000099 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000100 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000101 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:10 +0000102 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +0000103 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000104 m_sc (),
105 m_flags (),
106 m_frame_base (),
107 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000108 m_cfa_is_valid (true),
109 m_stop_id (0),
110 m_stop_id_is_valid (false),
111 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000113 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000114 m_disassembly (),
115 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116{
117 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000118 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000120 m_flags.Set(m_sc.GetResolvedMask ());
121 }
122
123 if (reg_context_sp && !m_sc.target_sp)
124 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000125 m_sc.target_sp = reg_context_sp->CalculateTarget();
126 if (m_sc.target_sp)
127 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000128 }
129}
130
Greg Claytond9e416c2012-02-18 05:35:26 +0000131StackFrame::StackFrame (const ThreadSP &thread_sp,
132 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000133 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000134 const RegisterContextSP &reg_context_sp,
135 addr_t cfa,
136 const Address& pc_addr,
137 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000138 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000139 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000140 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000141 m_reg_context_sp (reg_context_sp),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000142 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000143 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000144 m_sc (),
145 m_flags (),
146 m_frame_base (),
147 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000148 m_cfa_is_valid (true),
149 m_stop_id (0),
150 m_stop_id_is_valid (false),
151 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000152 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000153 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000154 m_disassembly (),
155 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000156{
157 if (sc_ptr != NULL)
158 {
159 m_sc = *sc_ptr;
160 m_flags.Set(m_sc.GetResolvedMask ());
161 }
162
163 if (m_sc.target_sp.get() == NULL && reg_context_sp)
164 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000165 m_sc.target_sp = reg_context_sp->CalculateTarget();
166 if (m_sc.target_sp)
167 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000168 }
169
Greg Claytone72dfb32012-02-24 01:59:29 +0000170 ModuleSP pc_module_sp (pc_addr.GetModule());
171 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000172 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000173 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000174 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000175 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000176 m_flags.Set (eSymbolContextModule);
177 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000178 else
179 {
180 m_sc.module_sp.reset();
181 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000182 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183}
184
185
186//----------------------------------------------------------------------
187// Destructor
188//----------------------------------------------------------------------
189StackFrame::~StackFrame()
190{
191}
192
193StackID&
194StackFrame::GetStackID()
195{
Jason Molenda6a354702014-10-02 01:08:16 +0000196 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10 +0000197 // Make sure we have resolved the StackID object's symbol context scope if
198 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000200 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
201 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000202 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000203 {
Greg Clayton95897c62010-09-07 04:20:48 +0000204 // We already have a symbol context scope, we just don't have our
205 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000206 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
207 }
208 else
209 {
Greg Clayton95897c62010-09-07 04:20:48 +0000210 // Calculate the frame block and use this for the stack ID symbol
211 // context scope if we have one.
212 SymbolContextScope *scope = GetFrameBlock ();
213 if (scope == NULL)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000214 {
Greg Clayton95897c62010-09-07 04:20:48 +0000215 // We don't have a block, so use the symbol
216 if (m_flags.IsClear (eSymbolContextSymbol))
217 GetSymbolContext (eSymbolContextSymbol);
218
219 // It is ok if m_sc.symbol is NULL here
220 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000221 }
Greg Clayton95897c62010-09-07 04:20:48 +0000222 // Set the symbol context scope (the accessor will set the
223 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
224 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000225 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 }
227 return m_id;
228}
229
Jim Ingham513c6bb2012-09-01 01:02:41 +0000230uint32_t
231StackFrame::GetFrameIndex () const
232{
233 ThreadSP thread_sp = GetThread();
234 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000235 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000236 else
237 return m_frame_index;
238}
239
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000240void
241StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
242{
Jason Molenda6a354702014-10-02 01:08:16 +0000243 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000244 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
245 m_id.SetSymbolContextScope (symbol_scope);
246}
247
Greg Clayton34132752011-07-06 04:07:21 +0000248const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000249StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250{
Jason Molenda6a354702014-10-02 01:08:16 +0000251 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000252 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000254 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255
256 // Resolve the PC into a temporary address because if ResolveLoadAddress
257 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000258 ThreadSP thread_sp (GetThread());
259 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000260 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000261 TargetSP target_sp (thread_sp->CalculateTarget());
262 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000264 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000266 ModuleSP module_sp (m_frame_code_addr.GetModule());
267 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000268 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000269 m_sc.module_sp = module_sp;
270 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000271 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 }
273 }
274 }
275 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000276 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277}
278
Jason Molenda99618472013-11-04 11:02:52 +0000279bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280StackFrame::ChangePC (addr_t pc)
281{
Jason Molenda6a354702014-10-02 01:08:16 +0000282 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000283 // We can't change the pc value of a history stack frame - it is immutable.
284 if (m_is_history_frame)
285 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000286 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47 +0000287 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59 +0000288 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26 +0000289 ThreadSP thread_sp (GetThread());
290 if (thread_sp)
291 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52 +0000292 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293}
294
295const char *
296StackFrame::Disassemble ()
297{
Jason Molenda6a354702014-10-02 01:08:16 +0000298 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299 if (m_disassembly.GetSize() == 0)
300 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000301 ExecutionContext exe_ctx (shared_from_this());
302 Target *target = exe_ctx.GetTargetPtr();
303 if (target)
304 {
Jim Ingham0f063ba2013-03-02 00:26:47 +0000305 const char *plugin_name = NULL;
306 const char *flavor = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000307 Disassembler::Disassemble (target->GetDebugger(),
308 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000309 plugin_name,
310 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000311 exe_ctx,
312 0,
313 0,
314 0,
315 m_disassembly);
316 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317 if (m_disassembly.GetSize() == 0)
318 return NULL;
319 }
320 return m_disassembly.GetData();
321}
322
Greg Clayton95897c62010-09-07 04:20:48 +0000323Block *
324StackFrame::GetFrameBlock ()
325{
326 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
327 GetSymbolContext (eSymbolContextBlock);
328
329 if (m_sc.block)
330 {
331 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
332 if (inline_block)
333 {
334 // Use the block with the inlined function info
335 // as the frame block we want this frame to have only the variables
336 // for the inlined function and its non-inlined block child blocks.
337 return inline_block;
338 }
339 else
340 {
341 // This block is not contained withing any inlined function blocks
342 // with so we want to use the top most function block.
343 return &m_sc.function->GetBlock (false);
344 }
345 }
346 return NULL;
347}
348
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349//----------------------------------------------------------------------
350// Get the symbol context if we already haven't done so by resolving the
351// PC address as much as possible. This way when we pass around a
352// StackFrame object, everyone will have as much information as
353// possible and no one will ever have to look things up manually.
354//----------------------------------------------------------------------
355const SymbolContext&
356StackFrame::GetSymbolContext (uint32_t resolve_scope)
357{
Jason Molenda6a354702014-10-02 01:08:16 +0000358 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000360 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 {
Greg Clayton75a03332012-11-29 00:53:06 +0000362 uint32_t resolved = 0;
363
364 // If the target was requested add that:
365 if (!m_sc.target_sp)
366 {
367 m_sc.target_sp = CalculateTarget();
368 if (m_sc.target_sp)
369 resolved |= eSymbolContextTarget;
370 }
371
372
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000373 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 // and if we don't have a module. The resolved address section will
375 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000376 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000377 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378
379 // If this is not frame zero, then we need to subtract 1 from the PC
380 // value when doing address lookups since the PC will be on the
381 // instruction following the function call instruction...
382
Greg Clayton9da7bd02010-08-24 21:05:24 +0000383 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000384 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 {
386 addr_t offset = lookup_addr.GetOffset();
387 if (offset > 0)
Jason Molendacf296752014-11-08 05:38:17 +0000388 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17 +0000390
391 }
392 else
393 {
394 // lookup_addr is the start of a section. We need
395 // do the math on the actual load address and re-compute
396 // the section. We're working with a 'noreturn' function
397 // at the end of a section.
398 ThreadSP thread_sp (GetThread());
399 if (thread_sp)
400 {
401 TargetSP target_sp (thread_sp->CalculateTarget());
402 if (target_sp)
403 {
404 addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1;
405 lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get());
406 }
407 else
408 {
409 lookup_addr.SetOffset(offset - 1);
410 }
411 }
412 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 }
414
Greg Clayton9da7bd02010-08-24 21:05:24 +0000415
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 if (m_sc.module_sp)
417 {
418 // We have something in our stack frame symbol context, lets check
419 // if we haven't already tried to lookup one of those things. If we
420 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000421
422 uint32_t actual_resolve_scope = 0;
423
424 if (resolve_scope & eSymbolContextCompUnit)
425 {
426 if (m_flags.IsClear (eSymbolContextCompUnit))
427 {
428 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000429 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000430 else
431 actual_resolve_scope |= eSymbolContextCompUnit;
432 }
433 }
434
435 if (resolve_scope & eSymbolContextFunction)
436 {
437 if (m_flags.IsClear (eSymbolContextFunction))
438 {
439 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000440 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000441 else
442 actual_resolve_scope |= eSymbolContextFunction;
443 }
444 }
445
446 if (resolve_scope & eSymbolContextBlock)
447 {
448 if (m_flags.IsClear (eSymbolContextBlock))
449 {
450 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000451 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000452 else
453 actual_resolve_scope |= eSymbolContextBlock;
454 }
455 }
456
457 if (resolve_scope & eSymbolContextSymbol)
458 {
459 if (m_flags.IsClear (eSymbolContextSymbol))
460 {
461 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000462 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000463 else
464 actual_resolve_scope |= eSymbolContextSymbol;
465 }
466 }
467
468 if (resolve_scope & eSymbolContextLineEntry)
469 {
470 if (m_flags.IsClear (eSymbolContextLineEntry))
471 {
472 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000473 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000474 else
475 actual_resolve_scope |= eSymbolContextLineEntry;
476 }
477 }
478
479 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 {
481 // We might be resolving less information than what is already
482 // in our current symbol context so resolve into a temporary
483 // symbol context "sc" so we don't clear out data we have
484 // already found in "m_sc"
485 SymbolContext sc;
486 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000487 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000488 // Only replace what we didn't already have as we may have
489 // information for an inlined function scope that won't match
490 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000491 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
492 m_sc.comp_unit = sc.comp_unit;
493 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
494 m_sc.function = sc.function;
495 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
496 m_sc.block = sc.block;
497 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
498 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000499 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
500 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000501 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000502 if (m_sc.target_sp)
503 {
504 // Be sure to apply and file remappings to our file and line
505 // entries when handing out a line entry
506 FileSpec new_file_spec;
507 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
508 m_sc.line_entry.file = new_file_spec;
509 }
510 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 }
512 }
513 else
514 {
515 // If we don't have a module, then we can't have the compile unit,
516 // function, block, line entry or symbol, so we can safely call
517 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000518 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000519 {
Greg Clayton75a03332012-11-29 00:53:06 +0000520 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000521 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523
524 // Update our internal flags so we remember what we have tried to locate so
525 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000526 // We might have dug up more information that was requested (for example
527 // if we were asked to only get the block, we will have gotten the
528 // compile unit, and function) so set any additional bits that we resolved
529 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531
532 // Return the symbol context with everything that was possible to resolve
533 // resolved.
534 return m_sc;
535}
536
537
538VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000539StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540{
Jason Molenda6a354702014-10-02 01:08:16 +0000541 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 if (m_flags.IsClear(RESOLVED_VARIABLES))
543 {
544 m_flags.Set(RESOLVED_VARIABLES);
545
Greg Clayton95897c62010-09-07 04:20:48 +0000546 Block *frame_block = GetFrameBlock();
547
548 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 {
Greg Clayton95897c62010-09-07 04:20:48 +0000550 const bool get_child_variables = true;
551 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000552 const bool stop_if_child_block_is_inlined_function = true;
553 m_variable_list_sp.reset(new VariableList());
554 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 +0000555 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000556 }
557
558 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
559 get_file_globals)
560 {
561 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000562
Sean Callanan7c0962d2010-11-01 04:38:59 +0000563 if (m_flags.IsClear (eSymbolContextCompUnit))
564 GetSymbolContext (eSymbolContextCompUnit);
565
566 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000567 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000568 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
569 if (m_variable_list_sp)
570 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
571 else
572 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000573 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000575
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 return m_variable_list_sp.get();
577}
578
Greg Claytond41f0322011-08-02 23:35:43 +0000579VariableListSP
580StackFrame::GetInScopeVariableList (bool get_file_globals)
581{
Jason Molenda6a354702014-10-02 01:08:16 +0000582 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000583 // We can't fetch variable information for a history stack frame.
584 if (m_is_history_frame)
585 return VariableListSP();
586
Greg Claytond41f0322011-08-02 23:35:43 +0000587 VariableListSP var_list_sp(new VariableList);
588 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
589
590 if (m_sc.block)
591 {
592 const bool can_create = true;
593 const bool get_parent_variables = true;
594 const bool stop_if_block_is_inlined_function = true;
595 m_sc.block->AppendVariables (can_create,
596 get_parent_variables,
597 stop_if_block_is_inlined_function,
598 var_list_sp.get());
599 }
600
601 if (m_sc.comp_unit)
602 {
603 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
604 if (global_variable_list_sp)
605 var_list_sp->AddVariables (global_variable_list_sp.get());
606 }
607
608 return var_list_sp;
609}
610
611
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000612ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000613StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000614 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000615 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000616 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000617 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000618{
Jason Molenda99618472013-11-04 11:02:52 +0000619 // We can't fetch variable information for a history stack frame.
620 if (m_is_history_frame)
621 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000622
623 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000624 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000625 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
626 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000627 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000628 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000629 error.Clear();
630 bool deref = false;
631 bool address_of = false;
632 ValueObjectSP valobj_sp;
633 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000634 // When looking up a variable for an expression, we need only consider the
635 // variables that are in scope.
636 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
637 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000638
639 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000640 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000641 // If first character is a '*', then show pointer contents
642 const char *var_expr = var_expr_cstr;
643 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000644 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000645 deref = true;
646 var_expr++; // Skip the '*'
647 }
648 else if (var_expr[0] == '&')
649 {
650 address_of = true;
651 var_expr++; // Skip the '&'
652 }
653
654 std::string var_path (var_expr);
655 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
656 StreamString var_expr_path_strm;
657
658 ConstString name_const_string;
659 if (separator_idx == std::string::npos)
660 name_const_string.SetCString (var_path.c_str());
661 else
662 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
663
Jim Ingham2837b762011-05-04 03:43:18 +0000664 var_sp = variable_list->FindVariable(name_const_string);
Greg Clayton685c88c2012-07-14 00:53:55 +0000665
666 bool synthetically_added_instance_object = false;
667
668 if (var_sp)
669 {
670 var_path.erase (0, name_const_string.GetLength ());
671 }
672 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
673 {
674 // Check for direct ivars access which helps us with implicit
675 // access to ivars with the "this->" or "self->"
676 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
677 lldb::LanguageType method_language = eLanguageTypeUnknown;
678 bool is_instance_method = false;
679 ConstString method_object_name;
680 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
681 {
682 if (is_instance_method && method_object_name)
683 {
684 var_sp = variable_list->FindVariable(method_object_name);
685 if (var_sp)
686 {
687 separator_idx = 0;
688 var_path.insert(0, "->");
689 synthetically_added_instance_object = true;
690 }
691 }
692 }
693 }
694
Greg Clayton54979cd2010-12-15 05:08:08 +0000695 if (var_sp)
696 {
Jim Ingham2837b762011-05-04 03:43:18 +0000697 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000698 if (!valobj_sp)
699 return valobj_sp;
700
Greg Clayton54979cd2010-12-15 05:08:08 +0000701 // We are dumping at least one child
702 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000703 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000704 // Calculate the next separator index ahead of time
705 ValueObjectSP child_valobj_sp;
706 const char separator_type = var_path[0];
707 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000708 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000709
710 case '-':
711 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000712 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000713
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000714 if (no_fragile_ivar)
715 {
716 // Make sure we aren't trying to deref an objective
717 // C ivar if this is not allowed
Greg Clayton57ee3062013-07-11 22:46:58 +0000718 const uint32_t pointer_type_flags = valobj_sp->GetClangType().GetTypeInfo (NULL);
Enrico Granata622be232014-10-21 20:52:14 +0000719 if ((pointer_type_flags & eTypeIsObjC) &&
720 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000721 {
722 // This was an objective C object pointer and
723 // it was requested we skip any fragile ivars
724 // so return nothing here
725 return ValueObjectSP();
726 }
727 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000728 var_path.erase (0, 1); // Remove the '-'
729 // Fall through
730 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000731 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000732 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000733
Greg Clayton54979cd2010-12-15 05:08:08 +0000734 var_path.erase (0, 1); // Remove the '.' or '>'
735 separator_idx = var_path.find_first_of(".-[");
736 ConstString child_name;
737 if (separator_idx == std::string::npos)
738 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000739 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000740 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
741
742 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000743 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000744 // We either have a pointer type and need to verify
745 // valobj_sp is a pointer, or we have a member of a
746 // class/union/struct being accessed with the . syntax
747 // and need to verify we don't have a pointer.
748 const bool actual_is_ptr = valobj_sp->IsPointerType ();
749
750 if (actual_is_ptr != expr_is_ptr)
751 {
752 // Incorrect use of "." with a pointer, or "->" with
753 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000754 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000755 if (actual_is_ptr)
756 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
757 var_expr_path_strm.GetString().c_str(),
758 child_name.GetCString(),
759 var_expr_path_strm.GetString().c_str(),
760 var_path.c_str());
761 else
762 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
763 var_expr_path_strm.GetString().c_str(),
764 child_name.GetCString(),
765 var_expr_path_strm.GetString().c_str(),
766 var_path.c_str());
767 return ValueObjectSP();
768 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000769 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000770 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000771 if (!child_valobj_sp)
772 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000773 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000774 {
775 child_valobj_sp = valobj_sp->GetSyntheticValue();
776 if (child_valobj_sp)
777 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
778 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000779
780 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000781 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000782 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000783 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000784 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000785 // We added a "this->" or "self->" to the beginning of the expression
786 // and this is the first pointer ivar access, so just return the normal
787 // error
788 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
789 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000790 }
791 else
792 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000793 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
794 if (child_name)
795 {
796 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
797 child_name.GetCString(),
798 valobj_sp->GetTypeName().AsCString("<invalid type>"),
799 var_expr_path_strm.GetString().c_str());
800 }
801 else
802 {
803 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
804 var_expr_path_strm.GetString().c_str(),
805 var_expr_cstr);
806 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000807 }
808 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000809 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000810 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000811 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000812 // Remove the child name from the path
813 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000814 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000815 {
Jim Ingham2837b762011-05-04 03:43:18 +0000816 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000817 if (dynamic_value_sp)
818 child_valobj_sp = dynamic_value_sp;
819 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000820 }
821 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000822
Greg Clayton54979cd2010-12-15 05:08:08 +0000823 case '[':
824 // Array member access, or treating pointer as an array
825 if (var_path.size() > 2) // Need at least two brackets and a number
826 {
827 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000828 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000829 if (end && *end == ']'
830 && *(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 +0000831 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000832 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000833 {
834 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
835 // and extract bit low out of it. reading array item low
836 // would be done by saying ptr[low], without a deref * sign
837 Error error;
838 ValueObjectSP temp(valobj_sp->Dereference(error));
839 if (error.Fail())
840 {
841 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
842 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
843 valobj_sp->GetTypeName().AsCString("<invalid type>"),
844 var_expr_path_strm.GetString().c_str());
845 return ValueObjectSP();
846 }
847 valobj_sp = temp;
848 deref = false;
849 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000850 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000851 {
852 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
853 // (an operation that is equivalent to deref-ing arr)
854 // and extract bit low out of it. reading array item low
855 // would be done by saying arr[low], without a deref * sign
856 Error error;
857 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
858 if (error.Fail())
859 {
860 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
861 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
862 valobj_sp->GetTypeName().AsCString("<invalid type>"),
863 var_expr_path_strm.GetString().c_str());
864 return ValueObjectSP();
865 }
866 valobj_sp = temp;
867 deref = false;
868 }
869
Greg Clayton4ef877f2012-12-06 02:33:54 +0000870 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000871 if (valobj_sp->IsPointerType ())
872 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000873 bool is_objc_pointer = true;
874
Greg Clayton57ee3062013-07-11 22:46:58 +0000875 if (valobj_sp->GetClangType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000876 is_objc_pointer = false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000877 else if (!valobj_sp->GetClangType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000878 is_objc_pointer = false;
879
880 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000881 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000882 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
883 valobj_sp->GetTypeName().AsCString("<invalid type>"),
884 var_expr_path_strm.GetString().c_str());
885
886 return ValueObjectSP();
887 }
888 else if (is_objc_pointer)
889 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000890 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000891 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000892 if (synthetic.get() == NULL /* no synthetic */
893 || synthetic == valobj_sp) /* synthetic is the same as the original object */
894 {
895 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
896 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
897 valobj_sp->GetTypeName().AsCString("<invalid type>"),
898 var_expr_path_strm.GetString().c_str());
899 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000900 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000901 {
902 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000903 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000904 child_index,
905 valobj_sp->GetTypeName().AsCString("<invalid type>"),
906 var_expr_path_strm.GetString().c_str());
907 }
908 else
909 {
910 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
911 if (!child_valobj_sp)
912 {
913 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000914 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000915 child_index,
916 valobj_sp->GetTypeName().AsCString("<invalid type>"),
917 var_expr_path_strm.GetString().c_str());
918 }
919 }
920 }
921 else
922 {
923 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
924 if (!child_valobj_sp)
925 {
926 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000927 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000928 child_index,
929 valobj_sp->GetTypeName().AsCString("<invalid type>"),
930 var_expr_path_strm.GetString().c_str());
931 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000932 }
933 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000934 else if (valobj_sp->GetClangType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000935 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000936 // Pass false to dynamic_value here so we can tell the difference between
937 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000938 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000939 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
940 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
941
Greg Clayton54979cd2010-12-15 05:08:08 +0000942 if (!child_valobj_sp)
943 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000944 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000945 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000946 child_index,
947 valobj_sp->GetTypeName().AsCString("<invalid type>"),
948 var_expr_path_strm.GetString().c_str());
949 }
950 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000951 else if (valobj_sp->GetClangType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000952 {
953 // this is a bitfield asking to display just one bit
954 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
955 if (!child_valobj_sp)
956 {
957 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000958 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000959 child_index, child_index,
960 valobj_sp->GetTypeName().AsCString("<invalid type>"),
961 var_expr_path_strm.GetString().c_str());
962 }
963 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000964 else
965 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000966 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000967 if (no_synth_child /* synthetic is forbidden */ ||
968 synthetic.get() == NULL /* no synthetic */
969 || synthetic == valobj_sp) /* synthetic is the same as the original object */
970 {
971 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
972 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
973 valobj_sp->GetTypeName().AsCString("<invalid type>"),
974 var_expr_path_strm.GetString().c_str());
975 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000976 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000977 {
978 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000979 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000980 child_index,
981 valobj_sp->GetTypeName().AsCString("<invalid type>"),
982 var_expr_path_strm.GetString().c_str());
983 }
984 else
985 {
986 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
987 if (!child_valobj_sp)
988 {
989 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000990 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000991 child_index,
992 valobj_sp->GetTypeName().AsCString("<invalid type>"),
993 var_expr_path_strm.GetString().c_str());
994 }
995 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000996 }
997
998 if (!child_valobj_sp)
999 {
1000 // Invalid array index...
1001 return ValueObjectSP();
1002 }
1003
1004 // Erase the array member specification '[%i]' where
1005 // %i is the array index
1006 var_path.erase(0, (end - var_path.c_str()) + 1);
1007 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001008 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001009 {
Jim Ingham2837b762011-05-04 03:43:18 +00001010 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +00001011 if (dynamic_value_sp)
1012 child_valobj_sp = dynamic_value_sp;
1013 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001014 // Break out early from the switch since we were
1015 // able to find the child member
1016 break;
1017 }
Enrico Granata20edcdb2011-07-19 18:03:25 +00001018 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +00001019 {
1020 // this is most probably a BitField, let's take a look
1021 char *real_end = NULL;
1022 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001023 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +00001024 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001025 {
1026 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001027 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001028 {
1029 long temp = child_index;
1030 child_index = final_index;
1031 final_index = temp;
1032 }
1033
Greg Clayton57ee3062013-07-11 22:46:58 +00001034 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001035 {
1036 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1037 // and extract bits low thru high out of it. reading array items low thru high
1038 // would be done by saying ptr[low-high], without a deref * sign
1039 Error error;
1040 ValueObjectSP temp(valobj_sp->Dereference(error));
1041 if (error.Fail())
1042 {
1043 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1044 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1045 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1046 var_expr_path_strm.GetString().c_str());
1047 return ValueObjectSP();
1048 }
1049 valobj_sp = temp;
1050 deref = false;
1051 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001052 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001053 {
1054 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1055 // (an operation that is equivalent to deref-ing arr)
1056 // and extract bits low thru high out of it. reading array items low thru high
1057 // would be done by saying arr[low-high], without a deref * sign
1058 Error error;
1059 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1060 if (error.Fail())
1061 {
1062 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1063 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1064 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1065 var_expr_path_strm.GetString().c_str());
1066 return ValueObjectSP();
1067 }
1068 valobj_sp = temp;
1069 deref = false;
1070 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001071 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001072 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001073 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1074 expand_bitfield = false;
1075 if (!child_valobj_sp)
1076 {
1077 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1078 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1079 child_index, final_index,
1080 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1081 var_expr_path_strm.GetString().c_str());
1082 }
1083 }*/
1084
1085 if (expand_bitfield)
1086 {
1087 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1088 if (!child_valobj_sp)
1089 {
1090 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001091 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001092 child_index, final_index,
1093 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1094 var_expr_path_strm.GetString().c_str());
1095 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001096 }
1097 }
1098
1099 if (!child_valobj_sp)
1100 {
1101 // Invalid bitfield range...
1102 return ValueObjectSP();
1103 }
1104
1105 // Erase the bitfield member specification '[%i-%i]' where
1106 // %i is the index
1107 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1108 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001109 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001110 {
1111 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1112 if (dynamic_value_sp)
1113 child_valobj_sp = dynamic_value_sp;
1114 }
1115 // Break out early from the switch since we were
1116 // able to find the child member
1117 break;
1118
1119 }
1120 }
1121 else
1122 {
1123 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1124 var_expr_path_strm.GetString().c_str(),
1125 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001126 }
1127 return ValueObjectSP();
1128
1129 default:
1130 // Failure...
1131 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001132 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001133 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1134 separator_type,
1135 var_expr_path_strm.GetString().c_str(),
1136 var_path.c_str());
1137
1138 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001139 }
1140 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001141
Greg Clayton54979cd2010-12-15 05:08:08 +00001142 if (child_valobj_sp)
1143 valobj_sp = child_valobj_sp;
1144
1145 if (var_path.empty())
1146 break;
1147
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001148 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001149 if (valobj_sp)
1150 {
1151 if (deref)
1152 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001153 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001154 valobj_sp = deref_valobj_sp;
1155 }
1156 else if (address_of)
1157 {
1158 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1159 valobj_sp = address_of_valobj_sp;
1160 }
1161 }
1162 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001163 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001164 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001165 {
Jim Ingham2837b762011-05-04 03:43:18 +00001166 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1167 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001168 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001169 }
1170 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001171 else
1172 {
1173 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1174 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001175 return ValueObjectSP();
1176}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177
1178bool
1179StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1180{
Jason Molenda6a354702014-10-02 01:08:16 +00001181 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001182 if (m_cfa_is_valid == false)
1183 {
1184 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1185 return false;
1186 }
1187
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 if (m_flags.IsClear(GOT_FRAME_BASE))
1189 {
1190 if (m_sc.function)
1191 {
1192 m_frame_base.Clear();
1193 m_frame_base_error.Clear();
1194
1195 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001196 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001198 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1199 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001200 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001201
Greg Clayton57ee3062013-07-11 22:46:58 +00001202 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 +00001203 {
1204 // We should really have an error if evaluate returns, but in case
1205 // we don't, lets set the error to something at least.
1206 if (m_frame_base_error.Success())
1207 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1208 }
1209 else
1210 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001211 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 }
1214 else
1215 {
1216 m_frame_base_error.SetErrorString ("No function in symbol context.");
1217 }
1218 }
1219
1220 if (m_frame_base_error.Success())
1221 frame_base = m_frame_base;
1222
1223 if (error_ptr)
1224 *error_ptr = m_frame_base_error;
1225 return m_frame_base_error.Success();
1226}
1227
Greg Clayton5ccbd292011-01-06 22:15:06 +00001228RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229StackFrame::GetRegisterContext ()
1230{
Jason Molenda6a354702014-10-02 01:08:16 +00001231 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001232 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001233 {
1234 ThreadSP thread_sp (GetThread());
1235 if (thread_sp)
1236 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1237 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001238 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239}
1240
1241bool
1242StackFrame::HasDebugInformation ()
1243{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001244 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 return m_sc.line_entry.IsValid();
1246}
1247
Greg Clayton288bdf92010-09-02 02:59:18 +00001248
1249ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001250StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251{
Jason Molenda6a354702014-10-02 01:08:16 +00001252 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001253 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001254 if (m_is_history_frame)
1255 {
1256 return valobj_sp;
1257 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001258 VariableList *var_list = GetVariableList (true);
1259 if (var_list)
1260 {
1261 // Make sure the variable is a frame variable
1262 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1263 const uint32_t num_variables = var_list->GetSize();
1264 if (var_idx < num_variables)
1265 {
1266 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1267 if (valobj_sp.get() == NULL)
1268 {
1269 if (m_variable_list_value_objects.GetSize() < num_variables)
1270 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001271 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001272 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1273 }
1274 }
1275 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001276 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001277 {
Jim Ingham2837b762011-05-04 03:43:18 +00001278 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001279 if (dynamic_sp)
1280 return dynamic_sp;
1281 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001282 return valobj_sp;
1283}
1284
1285ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001286StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001287{
Jason Molenda6a354702014-10-02 01:08:16 +00001288 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001289 if (m_is_history_frame)
1290 return ValueObjectSP();
1291
Greg Clayton288bdf92010-09-02 02:59:18 +00001292 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001293 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001294 if (!valobj_sp)
1295 {
1296 // We aren't already tracking this global
1297 VariableList *var_list = GetVariableList (true);
1298 // If this frame has no variables, create a new list
1299 if (var_list == NULL)
1300 m_variable_list_sp.reset (new VariableList());
1301
1302 // Add the global/static variable to this frame
1303 m_variable_list_sp->AddVariable (variable_sp);
1304
1305 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001306 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001307 }
1308 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309}
1310
Jim Ingham6b8379c2010-08-26 20:44:45 +00001311bool
1312StackFrame::IsInlined ()
1313{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001314 if (m_sc.block == NULL)
1315 GetSymbolContext (eSymbolContextBlock);
1316 if (m_sc.block)
1317 return m_sc.block->GetContainingInlinedBlock() != NULL;
1318 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001319}
1320
Greg Claytond9e416c2012-02-18 05:35:26 +00001321TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322StackFrame::CalculateTarget ()
1323{
Greg Claytond9e416c2012-02-18 05:35:26 +00001324 TargetSP target_sp;
1325 ThreadSP thread_sp(GetThread());
1326 if (thread_sp)
1327 {
1328 ProcessSP process_sp (thread_sp->CalculateProcess());
1329 if (process_sp)
1330 target_sp = process_sp->CalculateTarget();
1331 }
1332 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333}
1334
Greg Claytond9e416c2012-02-18 05:35:26 +00001335ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336StackFrame::CalculateProcess ()
1337{
Greg Claytond9e416c2012-02-18 05:35:26 +00001338 ProcessSP process_sp;
1339 ThreadSP thread_sp(GetThread());
1340 if (thread_sp)
1341 process_sp = thread_sp->CalculateProcess();
1342 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343}
1344
Greg Claytond9e416c2012-02-18 05:35:26 +00001345ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001346StackFrame::CalculateThread ()
1347{
Greg Claytond9e416c2012-02-18 05:35:26 +00001348 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349}
1350
Jason Molendab57e4a12013-11-04 09:33:30 +00001351StackFrameSP
1352StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001353{
Greg Claytond9e416c2012-02-18 05:35:26 +00001354 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355}
1356
1357
1358void
Greg Clayton0603aa92010-10-04 01:05:56 +00001359StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360{
Greg Claytond9e416c2012-02-18 05:35:26 +00001361 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362}
1363
1364void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001365StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001366{
1367 if (strm == NULL)
1368 return;
1369
1370 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001371 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001372 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001373
1374 if (frame_marker)
1375 s.PutCString(frame_marker);
1376
Greg Clayton554f68d2015-02-04 22:00:53 +00001377 const FormatEntity::Entry *frame_format = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001378 Target *target = exe_ctx.GetTargetPtr();
1379 if (target)
1380 frame_format = target->GetDebugger().GetFrameFormat();
Greg Clayton554f68d2015-02-04 22:00:53 +00001381 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, NULL, NULL, false, false))
Greg Clayton0603aa92010-10-04 01:05:56 +00001382 {
1383 strm->Write(s.GetData(), s.GetSize());
1384 }
1385 else
1386 {
1387 Dump (strm, true, false);
1388 strm->EOL();
1389 }
1390}
1391
1392void
Greg Clayton6dadd502010-09-02 21:44:10 +00001393StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394{
1395 if (strm == NULL)
1396 return;
1397
1398 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001399 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001400 ExecutionContext exe_ctx (shared_from_this());
1401 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001402 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001403 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1404 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001405 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001406 const bool show_module = true;
1407 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001408 const bool show_function_arguments = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001409 m_sc.DumpStopContext (strm,
1410 exe_ctx.GetBestExecutionContextScope(),
1411 GetFrameCodeAddress(),
1412 show_fullpaths,
1413 show_module,
Jason Molendaaff1b352014-10-10 23:07:36 +00001414 show_inline,
1415 show_function_arguments);
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