blob: e3e0b4468422cab6fbe8c23678b73db71af2c58e [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"
Enrico Granata46252392015-11-19 22:28:58 +000027#include "lldb/Symbol/Type.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000028#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/ExecutionContext.h"
30#include "lldb/Target/Process.h"
31#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38// The first bits in the flags are reserved for the SymbolContext::Scope bits
39// so we know if we have tried to look up information in our internal symbol
40// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000041#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000042#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000043#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
44#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000045#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046
Greg Claytond9e416c2012-02-18 05:35:26 +000047StackFrame::StackFrame (const ThreadSP &thread_sp,
48 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000049 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000050 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000051 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000052 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000053 uint32_t stop_id,
54 bool stop_id_is_valid,
55 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000056 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000057 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000058 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000059 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000060 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:10 +000061 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +000062 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000063 m_sc (),
64 m_flags (),
65 m_frame_base (),
66 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000067 m_cfa_is_valid (cfa_is_valid),
68 m_stop_id (stop_id),
69 m_stop_id_is_valid (stop_id_is_valid),
70 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000072 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +000073 m_disassembly (),
74 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075{
Jason Molenda99618472013-11-04 11:02:52 +000076 // If we don't have a CFA value, use the frame index for our StackID so that recursive
77 // functions properly aren't confused with one another on a history stack.
78 if (m_is_history_frame && m_cfa_is_valid == false)
79 {
80 m_id.SetCFA (m_frame_index);
81 }
82
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000084 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000086 m_flags.Set(m_sc.GetResolvedMask ());
87 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088}
89
Greg Claytond9e416c2012-02-18 05:35:26 +000090StackFrame::StackFrame (const ThreadSP &thread_sp,
91 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000092 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000093 const RegisterContextSP &reg_context_sp,
94 addr_t cfa,
95 addr_t pc,
96 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000097 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000098 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000099 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000100 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:10 +0000101 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +0000102 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000103 m_sc (),
104 m_flags (),
105 m_frame_base (),
106 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000107 m_cfa_is_valid (true),
108 m_stop_id (0),
109 m_stop_id_is_valid (false),
110 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000112 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000113 m_disassembly (),
114 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115{
116 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000117 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000119 m_flags.Set(m_sc.GetResolvedMask ());
120 }
121
122 if (reg_context_sp && !m_sc.target_sp)
123 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000124 m_sc.target_sp = reg_context_sp->CalculateTarget();
125 if (m_sc.target_sp)
126 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000127 }
128}
129
Greg Claytond9e416c2012-02-18 05:35:26 +0000130StackFrame::StackFrame (const ThreadSP &thread_sp,
131 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000132 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000133 const RegisterContextSP &reg_context_sp,
134 addr_t cfa,
135 const Address& pc_addr,
136 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000137 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000138 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000139 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000140 m_reg_context_sp (reg_context_sp),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000141 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000142 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000143 m_sc (),
144 m_flags (),
145 m_frame_base (),
146 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000147 m_cfa_is_valid (true),
148 m_stop_id (0),
149 m_stop_id_is_valid (false),
150 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000151 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000152 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000153 m_disassembly (),
154 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000155{
156 if (sc_ptr != NULL)
157 {
158 m_sc = *sc_ptr;
159 m_flags.Set(m_sc.GetResolvedMask ());
160 }
161
162 if (m_sc.target_sp.get() == NULL && reg_context_sp)
163 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000164 m_sc.target_sp = reg_context_sp->CalculateTarget();
165 if (m_sc.target_sp)
166 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000167 }
168
Greg Claytone72dfb32012-02-24 01:59:29 +0000169 ModuleSP pc_module_sp (pc_addr.GetModule());
170 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000171 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000172 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000173 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000174 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000175 m_flags.Set (eSymbolContextModule);
176 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000177 else
178 {
179 m_sc.module_sp.reset();
180 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000181 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182}
183
184
185//----------------------------------------------------------------------
186// Destructor
187//----------------------------------------------------------------------
188StackFrame::~StackFrame()
189{
190}
191
192StackID&
193StackFrame::GetStackID()
194{
Jason Molenda6a354702014-10-02 01:08:16 +0000195 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10 +0000196 // Make sure we have resolved the StackID object's symbol context scope if
197 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000199 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
200 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000201 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000202 {
Greg Clayton95897c62010-09-07 04:20:48 +0000203 // We already have a symbol context scope, we just don't have our
204 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000205 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
206 }
207 else
208 {
Greg Clayton95897c62010-09-07 04:20:48 +0000209 // Calculate the frame block and use this for the stack ID symbol
210 // context scope if we have one.
211 SymbolContextScope *scope = GetFrameBlock ();
212 if (scope == NULL)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000213 {
Greg Clayton95897c62010-09-07 04:20:48 +0000214 // We don't have a block, so use the symbol
215 if (m_flags.IsClear (eSymbolContextSymbol))
216 GetSymbolContext (eSymbolContextSymbol);
217
218 // It is ok if m_sc.symbol is NULL here
219 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000220 }
Greg Clayton95897c62010-09-07 04:20:48 +0000221 // Set the symbol context scope (the accessor will set the
222 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
223 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 }
226 return m_id;
227}
228
Jim Ingham513c6bb2012-09-01 01:02:41 +0000229uint32_t
230StackFrame::GetFrameIndex () const
231{
232 ThreadSP thread_sp = GetThread();
233 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000234 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000235 else
236 return m_frame_index;
237}
238
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000239void
240StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
241{
Jason Molenda6a354702014-10-02 01:08:16 +0000242 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000243 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
244 m_id.SetSymbolContextScope (symbol_scope);
245}
246
Greg Clayton34132752011-07-06 04:07:21 +0000247const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000248StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249{
Jason Molenda6a354702014-10-02 01:08:16 +0000250 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000251 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000253 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254
255 // Resolve the PC into a temporary address because if ResolveLoadAddress
256 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000257 ThreadSP thread_sp (GetThread());
258 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000260 TargetSP target_sp (thread_sp->CalculateTarget());
261 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262 {
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000263 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000265 ModuleSP module_sp (m_frame_code_addr.GetModule());
266 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000267 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000268 m_sc.module_sp = module_sp;
269 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000270 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 }
272 }
273 }
274 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000275 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276}
277
Jason Molenda99618472013-11-04 11:02:52 +0000278bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279StackFrame::ChangePC (addr_t pc)
280{
Jason Molenda6a354702014-10-02 01:08:16 +0000281 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000282 // We can't change the pc value of a history stack frame - it is immutable.
283 if (m_is_history_frame)
284 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000285 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47 +0000286 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59 +0000287 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26 +0000288 ThreadSP thread_sp (GetThread());
289 if (thread_sp)
290 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52 +0000291 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292}
293
294const char *
295StackFrame::Disassemble ()
296{
Jason Molenda6a354702014-10-02 01:08:16 +0000297 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 if (m_disassembly.GetSize() == 0)
299 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000300 ExecutionContext exe_ctx (shared_from_this());
301 Target *target = exe_ctx.GetTargetPtr();
302 if (target)
303 {
Jim Ingham0f063ba2013-03-02 00:26:47 +0000304 const char *plugin_name = NULL;
305 const char *flavor = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000306 Disassembler::Disassemble (target->GetDebugger(),
307 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000308 plugin_name,
309 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000310 exe_ctx,
311 0,
312 0,
313 0,
314 m_disassembly);
315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 if (m_disassembly.GetSize() == 0)
317 return NULL;
318 }
319 return m_disassembly.GetData();
320}
321
Greg Clayton95897c62010-09-07 04:20:48 +0000322Block *
323StackFrame::GetFrameBlock ()
324{
325 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
326 GetSymbolContext (eSymbolContextBlock);
327
328 if (m_sc.block)
329 {
330 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
331 if (inline_block)
332 {
333 // Use the block with the inlined function info
334 // as the frame block we want this frame to have only the variables
335 // for the inlined function and its non-inlined block child blocks.
336 return inline_block;
337 }
338 else
339 {
340 // This block is not contained withing any inlined function blocks
341 // with so we want to use the top most function block.
342 return &m_sc.function->GetBlock (false);
343 }
344 }
345 return NULL;
346}
347
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348//----------------------------------------------------------------------
349// Get the symbol context if we already haven't done so by resolving the
350// PC address as much as possible. This way when we pass around a
351// StackFrame object, everyone will have as much information as
352// possible and no one will ever have to look things up manually.
353//----------------------------------------------------------------------
354const SymbolContext&
355StackFrame::GetSymbolContext (uint32_t resolve_scope)
356{
Jason Molenda6a354702014-10-02 01:08:16 +0000357 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000359 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 {
Greg Clayton75a03332012-11-29 00:53:06 +0000361 uint32_t resolved = 0;
362
363 // If the target was requested add that:
364 if (!m_sc.target_sp)
365 {
366 m_sc.target_sp = CalculateTarget();
367 if (m_sc.target_sp)
368 resolved |= eSymbolContextTarget;
369 }
370
371
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000372 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 // and if we don't have a module. The resolved address section will
374 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000375 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000376 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377
378 // If this is not frame zero, then we need to subtract 1 from the PC
379 // value when doing address lookups since the PC will be on the
380 // instruction following the function call instruction...
381
Greg Clayton9da7bd02010-08-24 21:05:24 +0000382 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000383 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 {
385 addr_t offset = lookup_addr.GetOffset();
386 if (offset > 0)
Jason Molendacf296752014-11-08 05:38:17 +0000387 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17 +0000389
390 }
391 else
392 {
393 // lookup_addr is the start of a section. We need
394 // do the math on the actual load address and re-compute
395 // the section. We're working with a 'noreturn' function
396 // at the end of a section.
397 ThreadSP thread_sp (GetThread());
398 if (thread_sp)
399 {
400 TargetSP target_sp (thread_sp->CalculateTarget());
401 if (target_sp)
402 {
403 addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1;
404 lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get());
405 }
406 else
407 {
408 lookup_addr.SetOffset(offset - 1);
409 }
410 }
411 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 }
413
Greg Clayton9da7bd02010-08-24 21:05:24 +0000414
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 if (m_sc.module_sp)
416 {
417 // We have something in our stack frame symbol context, lets check
418 // if we haven't already tried to lookup one of those things. If we
419 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000420
421 uint32_t actual_resolve_scope = 0;
422
423 if (resolve_scope & eSymbolContextCompUnit)
424 {
425 if (m_flags.IsClear (eSymbolContextCompUnit))
426 {
427 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000428 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000429 else
430 actual_resolve_scope |= eSymbolContextCompUnit;
431 }
432 }
433
434 if (resolve_scope & eSymbolContextFunction)
435 {
436 if (m_flags.IsClear (eSymbolContextFunction))
437 {
438 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000439 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000440 else
441 actual_resolve_scope |= eSymbolContextFunction;
442 }
443 }
444
445 if (resolve_scope & eSymbolContextBlock)
446 {
447 if (m_flags.IsClear (eSymbolContextBlock))
448 {
449 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000450 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000451 else
452 actual_resolve_scope |= eSymbolContextBlock;
453 }
454 }
455
456 if (resolve_scope & eSymbolContextSymbol)
457 {
458 if (m_flags.IsClear (eSymbolContextSymbol))
459 {
460 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000461 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000462 else
463 actual_resolve_scope |= eSymbolContextSymbol;
464 }
465 }
466
467 if (resolve_scope & eSymbolContextLineEntry)
468 {
469 if (m_flags.IsClear (eSymbolContextLineEntry))
470 {
471 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000472 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000473 else
474 actual_resolve_scope |= eSymbolContextLineEntry;
475 }
476 }
477
478 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 {
480 // We might be resolving less information than what is already
481 // in our current symbol context so resolve into a temporary
482 // symbol context "sc" so we don't clear out data we have
483 // already found in "m_sc"
484 SymbolContext sc;
485 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000486 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000487 // Only replace what we didn't already have as we may have
488 // information for an inlined function scope that won't match
489 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000490 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
491 m_sc.comp_unit = sc.comp_unit;
492 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
493 m_sc.function = sc.function;
494 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
495 m_sc.block = sc.block;
496 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
497 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000498 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
499 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000500 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000501 if (m_sc.target_sp)
502 {
503 // Be sure to apply and file remappings to our file and line
504 // entries when handing out a line entry
505 FileSpec new_file_spec;
506 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
507 m_sc.line_entry.file = new_file_spec;
508 }
509 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 }
512 else
513 {
514 // If we don't have a module, then we can't have the compile unit,
515 // function, block, line entry or symbol, so we can safely call
516 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000517 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000518 {
Greg Clayton75a03332012-11-29 00:53:06 +0000519 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000520 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000521 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522
523 // Update our internal flags so we remember what we have tried to locate so
524 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000525 // We might have dug up more information that was requested (for example
526 // if we were asked to only get the block, we will have gotten the
527 // compile unit, and function) so set any additional bits that we resolved
528 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 }
530
531 // Return the symbol context with everything that was possible to resolve
532 // resolved.
533 return m_sc;
534}
535
536
537VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000538StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Jason Molenda6a354702014-10-02 01:08:16 +0000540 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 if (m_flags.IsClear(RESOLVED_VARIABLES))
542 {
543 m_flags.Set(RESOLVED_VARIABLES);
544
Greg Clayton95897c62010-09-07 04:20:48 +0000545 Block *frame_block = GetFrameBlock();
546
547 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
Greg Clayton95897c62010-09-07 04:20:48 +0000549 const bool get_child_variables = true;
550 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000551 const bool stop_if_child_block_is_inlined_function = true;
552 m_variable_list_sp.reset(new VariableList());
553 frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000555 }
556
557 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
558 get_file_globals)
559 {
560 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000561
Sean Callanan7c0962d2010-11-01 04:38:59 +0000562 if (m_flags.IsClear (eSymbolContextCompUnit))
563 GetSymbolContext (eSymbolContextCompUnit);
564
565 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000566 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000567 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
568 if (m_variable_list_sp)
569 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
570 else
571 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000572 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000574
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 return m_variable_list_sp.get();
576}
577
Greg Claytond41f0322011-08-02 23:35:43 +0000578VariableListSP
579StackFrame::GetInScopeVariableList (bool get_file_globals)
580{
Jason Molenda6a354702014-10-02 01:08:16 +0000581 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000582 // We can't fetch variable information for a history stack frame.
583 if (m_is_history_frame)
584 return VariableListSP();
585
Greg Claytond41f0322011-08-02 23:35:43 +0000586 VariableListSP var_list_sp(new VariableList);
587 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
588
589 if (m_sc.block)
590 {
591 const bool can_create = true;
592 const bool get_parent_variables = true;
593 const bool stop_if_block_is_inlined_function = true;
594 m_sc.block->AppendVariables (can_create,
595 get_parent_variables,
596 stop_if_block_is_inlined_function,
597 var_list_sp.get());
598 }
599
Siva Chandrab90168f2016-02-02 23:49:41 +0000600 if (m_sc.comp_unit && get_file_globals)
Greg Claytond41f0322011-08-02 23:35:43 +0000601 {
602 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
603 if (global_variable_list_sp)
604 var_list_sp->AddVariables (global_variable_list_sp.get());
605 }
606
607 return var_list_sp;
608}
609
610
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000611ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000612StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000613 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000614 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000615 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000616 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000617{
Jason Molenda99618472013-11-04 11:02:52 +0000618 // We can't fetch variable information for a history stack frame.
619 if (m_is_history_frame)
620 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000621
622 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000623 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000624 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
625 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000626 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000627 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000628 error.Clear();
629 bool deref = false;
630 bool address_of = false;
631 ValueObjectSP valobj_sp;
632 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000633 // When looking up a variable for an expression, we need only consider the
634 // variables that are in scope.
635 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
636 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000637
638 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000639 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000640 // If first character is a '*', then show pointer contents
641 const char *var_expr = var_expr_cstr;
642 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000643 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000644 deref = true;
645 var_expr++; // Skip the '*'
646 }
647 else if (var_expr[0] == '&')
648 {
649 address_of = true;
650 var_expr++; // Skip the '&'
651 }
652
653 std::string var_path (var_expr);
654 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
655 StreamString var_expr_path_strm;
656
657 ConstString name_const_string;
658 if (separator_idx == std::string::npos)
659 name_const_string.SetCString (var_path.c_str());
660 else
661 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
662
Paul Herman10bc1a42015-08-18 22:46:57 +0000663 var_sp = variable_list->FindVariable(name_const_string, false);
Greg Clayton685c88c2012-07-14 00:53:55 +0000664
665 bool synthetically_added_instance_object = false;
666
667 if (var_sp)
668 {
669 var_path.erase (0, name_const_string.GetLength ());
670 }
Enrico Granata46252392015-11-19 22:28:58 +0000671
672 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess))
Greg Clayton685c88c2012-07-14 00:53:55 +0000673 {
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 }
Enrico Granata46252392015-11-19 22:28:58 +0000694
695 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions))
696 {
697 // Check if any anonymous unions are there which contain a variable with the name we need
698 for (size_t i = 0;
699 i < variable_list->GetSize();
700 i++)
701 {
702 if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i))
703 {
704 if (variable_sp->GetName().IsEmpty())
705 {
706 if (Type *var_type = variable_sp->GetType())
707 {
708 if (var_type->GetForwardCompilerType().IsAnonymousType())
709 {
710 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
711 if (!valobj_sp)
712 return valobj_sp;
713 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true);
714 if (valobj_sp)
715 break;
716 }
717 }
718 }
719 }
720 }
721 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000722
Enrico Granata46252392015-11-19 22:28:58 +0000723 if (var_sp && !valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000724 {
Jim Ingham2837b762011-05-04 03:43:18 +0000725 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000726 if (!valobj_sp)
727 return valobj_sp;
Enrico Granata46252392015-11-19 22:28:58 +0000728 }
729 if (valobj_sp)
730 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000731 // We are dumping at least one child
732 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000733 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000734 // Calculate the next separator index ahead of time
735 ValueObjectSP child_valobj_sp;
736 const char separator_type = var_path[0];
737 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000738 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000739
740 case '-':
741 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000742 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000743
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000744 if (no_fragile_ivar)
745 {
746 // Make sure we aren't trying to deref an objective
747 // C ivar if this is not allowed
Greg Clayton99558cc42015-08-24 23:46:31 +0000748 const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo (NULL);
Enrico Granata622be232014-10-21 20:52:14 +0000749 if ((pointer_type_flags & eTypeIsObjC) &&
750 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000751 {
752 // This was an objective C object pointer and
753 // it was requested we skip any fragile ivars
754 // so return nothing here
755 return ValueObjectSP();
756 }
757 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000758 var_path.erase (0, 1); // Remove the '-'
Jason Molenda62e06812016-02-16 04:14:33 +0000759 LLVM_FALLTHROUGH;
Greg Clayton54979cd2010-12-15 05:08:08 +0000760 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000761 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000762 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000763
Greg Clayton54979cd2010-12-15 05:08:08 +0000764 var_path.erase (0, 1); // Remove the '.' or '>'
765 separator_idx = var_path.find_first_of(".-[");
766 ConstString child_name;
767 if (separator_idx == std::string::npos)
768 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000769 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000770 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
771
772 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000773 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000774 // We either have a pointer type and need to verify
775 // valobj_sp is a pointer, or we have a member of a
776 // class/union/struct being accessed with the . syntax
777 // and need to verify we don't have a pointer.
778 const bool actual_is_ptr = valobj_sp->IsPointerType ();
779
780 if (actual_is_ptr != expr_is_ptr)
781 {
782 // Incorrect use of "." with a pointer, or "->" with
783 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000784 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000785 if (actual_is_ptr)
786 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
787 var_expr_path_strm.GetString().c_str(),
788 child_name.GetCString(),
789 var_expr_path_strm.GetString().c_str(),
790 var_path.c_str());
791 else
792 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
793 var_expr_path_strm.GetString().c_str(),
794 child_name.GetCString(),
795 var_expr_path_strm.GetString().c_str(),
796 var_path.c_str());
797 return ValueObjectSP();
798 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000799 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000800 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000801 if (!child_valobj_sp)
802 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000803 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000804 {
805 child_valobj_sp = valobj_sp->GetSyntheticValue();
806 if (child_valobj_sp)
807 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
808 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000809
810 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000811 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000812 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000813 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000814 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000815 // We added a "this->" or "self->" to the beginning of the expression
816 // and this is the first pointer ivar access, so just return the normal
817 // error
818 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
819 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000820 }
821 else
822 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000823 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
824 if (child_name)
825 {
826 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
827 child_name.GetCString(),
828 valobj_sp->GetTypeName().AsCString("<invalid type>"),
829 var_expr_path_strm.GetString().c_str());
830 }
831 else
832 {
833 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
834 var_expr_path_strm.GetString().c_str(),
835 var_expr_cstr);
836 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000837 }
838 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000839 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000840 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000841 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000842 // Remove the child name from the path
843 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000844 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000845 {
Jim Ingham2837b762011-05-04 03:43:18 +0000846 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000847 if (dynamic_value_sp)
848 child_valobj_sp = dynamic_value_sp;
849 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000850 }
851 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000852
Greg Clayton54979cd2010-12-15 05:08:08 +0000853 case '[':
854 // Array member access, or treating pointer as an array
855 if (var_path.size() > 2) // Need at least two brackets and a number
856 {
857 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000858 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000859 if (end && *end == ']'
860 && *(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 +0000861 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000862 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000863 {
864 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
865 // and extract bit low out of it. reading array item low
866 // would be done by saying ptr[low], without a deref * sign
867 Error error;
868 ValueObjectSP temp(valobj_sp->Dereference(error));
869 if (error.Fail())
870 {
871 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
872 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
873 valobj_sp->GetTypeName().AsCString("<invalid type>"),
874 var_expr_path_strm.GetString().c_str());
875 return ValueObjectSP();
876 }
877 valobj_sp = temp;
878 deref = false;
879 }
Greg Clayton99558cc42015-08-24 23:46:31 +0000880 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000881 {
882 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
883 // (an operation that is equivalent to deref-ing arr)
884 // and extract bit low out of it. reading array item low
885 // would be done by saying arr[low], without a deref * sign
886 Error error;
887 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
888 if (error.Fail())
889 {
890 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
891 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
892 valobj_sp->GetTypeName().AsCString("<invalid type>"),
893 var_expr_path_strm.GetString().c_str());
894 return ValueObjectSP();
895 }
896 valobj_sp = temp;
897 deref = false;
898 }
899
Greg Clayton4ef877f2012-12-06 02:33:54 +0000900 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000901 if (valobj_sp->IsPointerType ())
902 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000903 bool is_objc_pointer = true;
904
Greg Clayton99558cc42015-08-24 23:46:31 +0000905 if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000906 is_objc_pointer = false;
Greg Clayton99558cc42015-08-24 23:46:31 +0000907 else if (!valobj_sp->GetCompilerType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000908 is_objc_pointer = false;
909
910 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000911 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000912 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
913 valobj_sp->GetTypeName().AsCString("<invalid type>"),
914 var_expr_path_strm.GetString().c_str());
915
916 return ValueObjectSP();
917 }
918 else if (is_objc_pointer)
919 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000920 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000921 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000922 if (synthetic.get() == NULL /* no synthetic */
923 || synthetic == valobj_sp) /* synthetic is the same as the original object */
924 {
925 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
926 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
927 valobj_sp->GetTypeName().AsCString("<invalid type>"),
928 var_expr_path_strm.GetString().c_str());
929 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000930 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000931 {
932 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000933 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000934 child_index,
935 valobj_sp->GetTypeName().AsCString("<invalid type>"),
936 var_expr_path_strm.GetString().c_str());
937 }
938 else
939 {
940 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
941 if (!child_valobj_sp)
942 {
943 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000944 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000945 child_index,
946 valobj_sp->GetTypeName().AsCString("<invalid type>"),
947 var_expr_path_strm.GetString().c_str());
948 }
949 }
950 }
951 else
952 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000953 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +0000954 if (!child_valobj_sp)
955 {
956 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000957 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000958 child_index,
959 valobj_sp->GetTypeName().AsCString("<invalid type>"),
960 var_expr_path_strm.GetString().c_str());
961 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000962 }
963 }
Greg Clayton99558cc42015-08-24 23:46:31 +0000964 else if (valobj_sp->GetCompilerType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000965 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000966 // Pass false to dynamic_value here so we can tell the difference between
967 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000968 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000969 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
970 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
971
Greg Clayton54979cd2010-12-15 05:08:08 +0000972 if (!child_valobj_sp)
973 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000974 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000975 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000976 child_index,
977 valobj_sp->GetTypeName().AsCString("<invalid type>"),
978 var_expr_path_strm.GetString().c_str());
979 }
980 }
Greg Clayton99558cc42015-08-24 23:46:31 +0000981 else if (valobj_sp->GetCompilerType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000982 {
983 // this is a bitfield asking to display just one bit
984 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, 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 ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000989 child_index, 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 else
995 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000996 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000997 if (no_synth_child /* synthetic is forbidden */ ||
998 synthetic.get() == NULL /* no synthetic */
999 || synthetic == valobj_sp) /* synthetic is the same as the original object */
1000 {
1001 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1002 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
1003 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1004 var_expr_path_strm.GetString().c_str());
1005 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +00001006 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +00001007 {
1008 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001009 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +00001010 child_index,
1011 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1012 var_expr_path_strm.GetString().c_str());
1013 }
1014 else
1015 {
1016 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
1017 if (!child_valobj_sp)
1018 {
1019 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001020 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +00001021 child_index,
1022 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1023 var_expr_path_strm.GetString().c_str());
1024 }
1025 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001026 }
1027
1028 if (!child_valobj_sp)
1029 {
1030 // Invalid array index...
1031 return ValueObjectSP();
1032 }
1033
1034 // Erase the array member specification '[%i]' where
1035 // %i is the array index
1036 var_path.erase(0, (end - var_path.c_str()) + 1);
1037 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001038 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001039 {
Jim Ingham2837b762011-05-04 03:43:18 +00001040 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +00001041 if (dynamic_value_sp)
1042 child_valobj_sp = dynamic_value_sp;
1043 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001044 // Break out early from the switch since we were
1045 // able to find the child member
1046 break;
1047 }
Enrico Granata20edcdb2011-07-19 18:03:25 +00001048 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +00001049 {
1050 // this is most probably a BitField, let's take a look
1051 char *real_end = NULL;
1052 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001053 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +00001054 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001055 {
1056 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001057 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001058 {
1059 long temp = child_index;
1060 child_index = final_index;
1061 final_index = temp;
1062 }
1063
Greg Clayton99558cc42015-08-24 23:46:31 +00001064 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001065 {
1066 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1067 // and extract bits low thru high out of it. reading array items low thru high
1068 // would be done by saying ptr[low-high], without a deref * sign
1069 Error error;
1070 ValueObjectSP temp(valobj_sp->Dereference(error));
1071 if (error.Fail())
1072 {
1073 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1074 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1075 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1076 var_expr_path_strm.GetString().c_str());
1077 return ValueObjectSP();
1078 }
1079 valobj_sp = temp;
1080 deref = false;
1081 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001082 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001083 {
1084 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1085 // (an operation that is equivalent to deref-ing arr)
1086 // and extract bits low thru high out of it. reading array items low thru high
1087 // would be done by saying arr[low-high], without a deref * sign
1088 Error error;
1089 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1090 if (error.Fail())
1091 {
1092 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1093 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1094 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1095 var_expr_path_strm.GetString().c_str());
1096 return ValueObjectSP();
1097 }
1098 valobj_sp = temp;
1099 deref = false;
1100 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001101 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001102 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001103 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1104 expand_bitfield = false;
1105 if (!child_valobj_sp)
1106 {
1107 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1108 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1109 child_index, final_index,
1110 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1111 var_expr_path_strm.GetString().c_str());
1112 }
1113 }*/
1114
1115 if (expand_bitfield)
1116 {
1117 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1118 if (!child_valobj_sp)
1119 {
1120 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001121 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001122 child_index, final_index,
1123 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1124 var_expr_path_strm.GetString().c_str());
1125 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001126 }
1127 }
1128
1129 if (!child_valobj_sp)
1130 {
1131 // Invalid bitfield range...
1132 return ValueObjectSP();
1133 }
1134
1135 // Erase the bitfield member specification '[%i-%i]' where
1136 // %i is the index
1137 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1138 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001139 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001140 {
1141 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1142 if (dynamic_value_sp)
1143 child_valobj_sp = dynamic_value_sp;
1144 }
1145 // Break out early from the switch since we were
1146 // able to find the child member
1147 break;
1148
1149 }
1150 }
1151 else
1152 {
1153 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1154 var_expr_path_strm.GetString().c_str(),
1155 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001156 }
1157 return ValueObjectSP();
1158
1159 default:
1160 // Failure...
1161 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001162 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001163 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1164 separator_type,
1165 var_expr_path_strm.GetString().c_str(),
1166 var_path.c_str());
1167
1168 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001169 }
1170 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001171
Greg Clayton54979cd2010-12-15 05:08:08 +00001172 if (child_valobj_sp)
1173 valobj_sp = child_valobj_sp;
1174
1175 if (var_path.empty())
1176 break;
1177
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001178 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001179 if (valobj_sp)
1180 {
1181 if (deref)
1182 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001183 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001184 valobj_sp = deref_valobj_sp;
1185 }
1186 else if (address_of)
1187 {
1188 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1189 valobj_sp = address_of_valobj_sp;
1190 }
1191 }
1192 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001193 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001194 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001195 {
Jim Ingham2837b762011-05-04 03:43:18 +00001196 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1197 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001198 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001199 }
1200 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001201 else
1202 {
1203 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1204 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001205 return ValueObjectSP();
1206}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207
1208bool
1209StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1210{
Jason Molenda6a354702014-10-02 01:08:16 +00001211 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001212 if (m_cfa_is_valid == false)
1213 {
1214 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1215 return false;
1216 }
1217
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 if (m_flags.IsClear(GOT_FRAME_BASE))
1219 {
1220 if (m_sc.function)
1221 {
1222 m_frame_base.Clear();
1223 m_frame_base_error.Clear();
1224
1225 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001226 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001228 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1229 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001230 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001231
Greg Clayton57ee3062013-07-11 22:46:58 +00001232 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 +00001233 {
1234 // We should really have an error if evaluate returns, but in case
1235 // we don't, lets set the error to something at least.
1236 if (m_frame_base_error.Success())
1237 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1238 }
1239 else
1240 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001241 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 }
1243 }
1244 else
1245 {
1246 m_frame_base_error.SetErrorString ("No function in symbol context.");
1247 }
1248 }
1249
1250 if (m_frame_base_error.Success())
1251 frame_base = m_frame_base;
1252
1253 if (error_ptr)
1254 *error_ptr = m_frame_base_error;
1255 return m_frame_base_error.Success();
1256}
1257
Greg Clayton5ccbd292011-01-06 22:15:06 +00001258RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001259StackFrame::GetRegisterContext ()
1260{
Jason Molenda6a354702014-10-02 01:08:16 +00001261 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001262 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001263 {
1264 ThreadSP thread_sp (GetThread());
1265 if (thread_sp)
1266 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1267 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001268 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269}
1270
1271bool
1272StackFrame::HasDebugInformation ()
1273{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001274 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 return m_sc.line_entry.IsValid();
1276}
1277
Greg Clayton288bdf92010-09-02 02:59:18 +00001278
1279ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001280StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281{
Jason Molenda6a354702014-10-02 01:08:16 +00001282 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001283 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001284 if (m_is_history_frame)
1285 {
1286 return valobj_sp;
1287 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001288 VariableList *var_list = GetVariableList (true);
1289 if (var_list)
1290 {
1291 // Make sure the variable is a frame variable
1292 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1293 const uint32_t num_variables = var_list->GetSize();
1294 if (var_idx < num_variables)
1295 {
1296 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1297 if (valobj_sp.get() == NULL)
1298 {
1299 if (m_variable_list_value_objects.GetSize() < num_variables)
1300 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001301 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001302 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1303 }
1304 }
1305 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001306 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001307 {
Jim Ingham2837b762011-05-04 03:43:18 +00001308 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001309 if (dynamic_sp)
1310 return dynamic_sp;
1311 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001312 return valobj_sp;
1313}
1314
1315ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001316StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001317{
Jason Molenda6a354702014-10-02 01:08:16 +00001318 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001319 if (m_is_history_frame)
1320 return ValueObjectSP();
1321
Greg Clayton288bdf92010-09-02 02:59:18 +00001322 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001323 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001324 if (!valobj_sp)
1325 {
1326 // We aren't already tracking this global
1327 VariableList *var_list = GetVariableList (true);
1328 // If this frame has no variables, create a new list
1329 if (var_list == NULL)
1330 m_variable_list_sp.reset (new VariableList());
1331
1332 // Add the global/static variable to this frame
1333 m_variable_list_sp->AddVariable (variable_sp);
1334
1335 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001336 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001337 }
1338 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339}
1340
Jim Ingham6b8379c2010-08-26 20:44:45 +00001341bool
1342StackFrame::IsInlined ()
1343{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001344 if (m_sc.block == NULL)
1345 GetSymbolContext (eSymbolContextBlock);
1346 if (m_sc.block)
1347 return m_sc.block->GetContainingInlinedBlock() != NULL;
1348 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001349}
1350
Dawn Perchik009d1102015-09-04 01:02:30 +00001351lldb::LanguageType
1352StackFrame::GetLanguage ()
1353{
1354 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1355 if (cu)
1356 return cu->GetLanguage();
1357 return lldb::eLanguageTypeUnknown;
1358}
1359
Greg Claytond9e416c2012-02-18 05:35:26 +00001360TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361StackFrame::CalculateTarget ()
1362{
Greg Claytond9e416c2012-02-18 05:35:26 +00001363 TargetSP target_sp;
1364 ThreadSP thread_sp(GetThread());
1365 if (thread_sp)
1366 {
1367 ProcessSP process_sp (thread_sp->CalculateProcess());
1368 if (process_sp)
1369 target_sp = process_sp->CalculateTarget();
1370 }
1371 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372}
1373
Greg Claytond9e416c2012-02-18 05:35:26 +00001374ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375StackFrame::CalculateProcess ()
1376{
Greg Claytond9e416c2012-02-18 05:35:26 +00001377 ProcessSP process_sp;
1378 ThreadSP thread_sp(GetThread());
1379 if (thread_sp)
1380 process_sp = thread_sp->CalculateProcess();
1381 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382}
1383
Greg Claytond9e416c2012-02-18 05:35:26 +00001384ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001385StackFrame::CalculateThread ()
1386{
Greg Claytond9e416c2012-02-18 05:35:26 +00001387 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388}
1389
Jason Molendab57e4a12013-11-04 09:33:30 +00001390StackFrameSP
1391StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392{
Greg Claytond9e416c2012-02-18 05:35:26 +00001393 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394}
1395
1396
1397void
Greg Clayton0603aa92010-10-04 01:05:56 +00001398StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001399{
Greg Claytond9e416c2012-02-18 05:35:26 +00001400 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001401}
1402
1403void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001404StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001405{
1406 if (strm == NULL)
1407 return;
1408
1409 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001410 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001411 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001412
1413 if (frame_marker)
1414 s.PutCString(frame_marker);
1415
Greg Clayton554f68d2015-02-04 22:00:53 +00001416 const FormatEntity::Entry *frame_format = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +00001417 Target *target = exe_ctx.GetTargetPtr();
1418 if (target)
1419 frame_format = target->GetDebugger().GetFrameFormat();
Greg Clayton554f68d2015-02-04 22:00:53 +00001420 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, NULL, NULL, false, false))
Greg Clayton0603aa92010-10-04 01:05:56 +00001421 {
1422 strm->Write(s.GetData(), s.GetSize());
1423 }
1424 else
1425 {
1426 Dump (strm, true, false);
1427 strm->EOL();
1428 }
1429}
1430
1431void
Greg Clayton6dadd502010-09-02 21:44:10 +00001432StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433{
1434 if (strm == NULL)
1435 return;
1436
1437 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001438 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001439 ExecutionContext exe_ctx (shared_from_this());
1440 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001441 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001442 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1443 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001444 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001445 const bool show_module = true;
1446 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001447 const bool show_function_arguments = true;
Jason Molendac980fa92015-02-13 23:24:21 +00001448 const bool show_function_name = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001449 m_sc.DumpStopContext (strm,
1450 exe_ctx.GetBestExecutionContextScope(),
1451 GetFrameCodeAddress(),
1452 show_fullpaths,
1453 show_module,
Jason Molendaaff1b352014-10-10 23:07:36 +00001454 show_inline,
Jason Molendac980fa92015-02-13 23:24:21 +00001455 show_function_arguments,
1456 show_function_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457}
1458
Greg Clayton5082c5f2010-08-27 18:24:16 +00001459void
Jason Molendab57e4a12013-11-04 09:33:30 +00001460StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001461{
Jason Molenda6a354702014-10-02 01:08:16 +00001462 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001463 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001464 m_variable_list_sp = prev_frame.m_variable_list_sp;
1465 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1466 if (!m_disassembly.GetString().empty())
1467 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001468}
Greg Clayton68275d52010-08-27 21:47:54 +00001469
1470
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001471void
Jason Molendab57e4a12013-11-04 09:33:30 +00001472StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001473{
Jason Molenda6a354702014-10-02 01:08:16 +00001474 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:42 +00001475 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001476 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1477 assert (GetThread() == curr_frame.GetThread());
1478 m_frame_index = curr_frame.m_frame_index;
1479 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1480 m_reg_context_sp = curr_frame.m_reg_context_sp;
1481 m_frame_code_addr = curr_frame.m_frame_code_addr;
1482 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());
1483 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());
1484 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1485 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1486 m_sc = curr_frame.m_sc;
1487 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1488 m_flags.Set (m_sc.GetResolvedMask());
1489 m_frame_base.Clear();
1490 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001491}
1492
1493
Greg Clayton2cad65a2010-09-03 17:10:42 +00001494bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001495StackFrame::HasCachedData () const
1496{
1497 if (m_variable_list_sp.get())
1498 return true;
1499 if (m_variable_list_value_objects.GetSize() > 0)
1500 return true;
1501 if (!m_disassembly.GetString().empty())
1502 return true;
1503 return false;
1504}
1505
1506bool
Greg Clayton7260f622011-04-18 08:33:37 +00001507StackFrame::GetStatus (Stream& strm,
1508 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001509 bool show_source,
1510 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001511{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001512
Greg Clayton7260f622011-04-18 08:33:37 +00001513 if (show_frame_info)
1514 {
1515 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001516 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001517 }
1518
1519 if (show_source)
1520 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001521 ExecutionContext exe_ctx (shared_from_this());
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001522 bool have_source = false, have_debuginfo = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001523 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001524 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001525 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001526 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001527 Debugger &debugger = target->GetDebugger();
1528 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1529 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1530 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001531
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001532 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1533 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001534 {
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001535 have_debuginfo = true;
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001536 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001537 {
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001538 size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001539 m_sc.line_entry.line,
1540 source_lines_before,
1541 source_lines_after,
1542 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001543 &strm);
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001544 if (num_lines != 0)
1545 have_source = true;
1546 // TODO: Give here a one time warning if source file is missing.
Greg Claytone372b982011-11-21 21:44:34 +00001547 }
1548 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001549 switch (disasm_display)
1550 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001551 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001552 break;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001553
1554 case Debugger::eStopDisassemblyTypeNoDebugInfo:
1555 if (have_debuginfo)
1556 break;
Jason Molenda62e06812016-02-16 04:14:33 +00001557 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001558
Greg Clayton67cc0632012-08-22 17:17:09 +00001559 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001560 if (have_source)
1561 break;
Jason Molenda62e06812016-02-16 04:14:33 +00001562 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001563
Greg Clayton67cc0632012-08-22 17:17:09 +00001564 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001565 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001566 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001567 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1568 if (disasm_lines > 0)
1569 {
1570 const ArchSpec &target_arch = target->GetArchitecture();
1571 AddressRange pc_range;
1572 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1573 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Jim Ingham0f063ba2013-03-02 00:26:47 +00001574 const char *plugin_name = NULL;
1575 const char *flavor = NULL;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001576 Disassembler::Disassemble (target->GetDebugger(),
1577 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001578 plugin_name,
1579 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001580 exe_ctx,
1581 pc_range,
1582 disasm_lines,
1583 0,
1584 Disassembler::eOptionMarkPCAddress,
1585 strm);
1586 }
Greg Claytone372b982011-11-21 21:44:34 +00001587 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001588 break;
Greg Claytone372b982011-11-21 21:44:34 +00001589 }
Greg Clayton7260f622011-04-18 08:33:37 +00001590 }
1591 }
1592 return true;
1593}
1594