blob: 43ca4b3f97ae62ac601b5ff0e038087588991d96 [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000014#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
Greg Clayton0603aa92010-10-04 01:05:56 +000016#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Disassembler.h"
Greg Clayton554f68d2015-02-04 22:00:53 +000018#include "lldb/Core/FormatEntity.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000020#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:08 +000021#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Symbol/Symbol.h"
25#include "lldb/Symbol/SymbolContextScope.h"
Enrico Granata46252392015-11-19 22:28:58 +000026#include "lldb/Symbol/Type.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000027#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Target/ExecutionContext.h"
29#include "lldb/Target/Process.h"
30#include "lldb/Target/RegisterContext.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
37// The first bits in the flags are reserved for the SymbolContext::Scope bits
38// so we know if we have tried to look up information in our internal symbol
39// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000040#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000041#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000042#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
43#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000044#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045
Greg Claytond9e416c2012-02-18 05:35:26 +000046StackFrame::StackFrame (const ThreadSP &thread_sp,
47 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000048 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000049 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000050 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000051 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000052 uint32_t stop_id,
53 bool stop_id_is_valid,
54 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000055 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000056 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000057 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000058 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000059 m_reg_context_sp (),
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000060 m_id(pc, cfa, nullptr),
Greg Claytone72dfb32012-02-24 01:59:29 +000061 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000062 m_sc (),
63 m_flags (),
64 m_frame_base (),
65 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000066 m_cfa_is_valid (cfa_is_valid),
67 m_stop_id (stop_id),
68 m_stop_id_is_valid (stop_id_is_valid),
69 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000071 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +000072 m_disassembly (),
73 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074{
Jason Molenda99618472013-11-04 11:02:52 +000075 // If we don't have a CFA value, use the frame index for our StackID so that recursive
76 // functions properly aren't confused with one another on a history stack.
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000077 if (m_is_history_frame && !m_cfa_is_valid)
Jason Molenda99618472013-11-04 11:02:52 +000078 {
79 m_id.SetCFA (m_frame_index);
80 }
81
Eugene Zelenkod70a6e72016-02-18 18:52:47 +000082 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000083 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000085 m_flags.Set(m_sc.GetResolvedMask ());
86 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
Greg Claytond9e416c2012-02-18 05:35:26 +000089StackFrame::StackFrame (const ThreadSP &thread_sp,
90 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000091 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000092 const RegisterContextSP &reg_context_sp,
93 addr_t cfa,
94 addr_t pc,
95 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000096 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000097 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000098 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000099 m_reg_context_sp (reg_context_sp),
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000100 m_id(pc, cfa, nullptr),
Greg Claytone72dfb32012-02-24 01:59:29 +0000101 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000102 m_sc (),
103 m_flags (),
104 m_frame_base (),
105 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000106 m_cfa_is_valid (true),
107 m_stop_id (0),
108 m_stop_id_is_valid (false),
109 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000111 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000112 m_disassembly (),
113 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000115 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000116 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000118 m_flags.Set(m_sc.GetResolvedMask ());
119 }
120
121 if (reg_context_sp && !m_sc.target_sp)
122 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000123 m_sc.target_sp = reg_context_sp->CalculateTarget();
124 if (m_sc.target_sp)
125 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000126 }
127}
128
Greg Claytond9e416c2012-02-18 05:35:26 +0000129StackFrame::StackFrame (const ThreadSP &thread_sp,
130 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000131 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000132 const RegisterContextSP &reg_context_sp,
133 addr_t cfa,
134 const Address& pc_addr,
135 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000136 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000137 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000138 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000139 m_reg_context_sp (reg_context_sp),
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000140 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa, nullptr),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000141 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000142 m_sc (),
143 m_flags (),
144 m_frame_base (),
145 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000146 m_cfa_is_valid (true),
147 m_stop_id (0),
148 m_stop_id_is_valid (false),
149 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000150 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000151 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16 +0000152 m_disassembly (),
153 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000154{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000155 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000156 {
157 m_sc = *sc_ptr;
158 m_flags.Set(m_sc.GetResolvedMask ());
159 }
160
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000161 if (!m_sc.target_sp && reg_context_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000162 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000163 m_sc.target_sp = reg_context_sp->CalculateTarget();
164 if (m_sc.target_sp)
165 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000166 }
167
Greg Claytone72dfb32012-02-24 01:59:29 +0000168 ModuleSP pc_module_sp (pc_addr.GetModule());
169 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000170 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000171 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000172 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000173 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000174 m_flags.Set (eSymbolContextModule);
175 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000176 else
177 {
178 m_sc.module_sp.reset();
179 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000180 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181}
182
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000183StackFrame::~StackFrame() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184
185StackID&
186StackFrame::GetStackID()
187{
Jason Molenda6a354702014-10-02 01:08:16 +0000188 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10 +0000189 // Make sure we have resolved the StackID object's symbol context scope if
190 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000192 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
193 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000194 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000195 {
Greg Clayton95897c62010-09-07 04:20:48 +0000196 // We already have a symbol context scope, we just don't have our
197 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000198 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
199 }
200 else
201 {
Greg Clayton95897c62010-09-07 04:20:48 +0000202 // Calculate the frame block and use this for the stack ID symbol
203 // context scope if we have one.
204 SymbolContextScope *scope = GetFrameBlock ();
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000205 if (scope == nullptr)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000206 {
Greg Clayton95897c62010-09-07 04:20:48 +0000207 // We don't have a block, so use the symbol
208 if (m_flags.IsClear (eSymbolContextSymbol))
209 GetSymbolContext (eSymbolContextSymbol);
210
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000211 // It is ok if m_sc.symbol is nullptr here
Greg Clayton95897c62010-09-07 04:20:48 +0000212 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000213 }
Greg Clayton95897c62010-09-07 04:20:48 +0000214 // Set the symbol context scope (the accessor will set the
215 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
216 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000217 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218 }
219 return m_id;
220}
221
Jim Ingham513c6bb2012-09-01 01:02:41 +0000222uint32_t
223StackFrame::GetFrameIndex () const
224{
225 ThreadSP thread_sp = GetThread();
226 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000227 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000228 else
229 return m_frame_index;
230}
231
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000232void
233StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
234{
Jason Molenda6a354702014-10-02 01:08:16 +0000235 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000236 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
237 m_id.SetSymbolContextScope (symbol_scope);
238}
239
Greg Clayton34132752011-07-06 04:07:21 +0000240const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000241StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000242{
Jason Molenda6a354702014-10-02 01:08:16 +0000243 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000244 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000246 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247
248 // Resolve the PC into a temporary address because if ResolveLoadAddress
249 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000250 ThreadSP thread_sp (GetThread());
251 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000253 TargetSP target_sp (thread_sp->CalculateTarget());
254 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000255 {
Tamas Berghammer25b9f7e2015-09-07 09:58:09 +0000256 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000257 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000258 ModuleSP module_sp (m_frame_code_addr.GetModule());
259 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000260 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000261 m_sc.module_sp = module_sp;
262 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000263 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 }
265 }
266 }
267 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000268 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269}
270
Jason Molenda99618472013-11-04 11:02:52 +0000271bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272StackFrame::ChangePC (addr_t pc)
273{
Jason Molenda6a354702014-10-02 01:08:16 +0000274 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000275 // We can't change the pc value of a history stack frame - it is immutable.
276 if (m_is_history_frame)
277 return false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000278 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47 +0000279 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59 +0000280 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26 +0000281 ThreadSP thread_sp (GetThread());
282 if (thread_sp)
283 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52 +0000284 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285}
286
287const char *
288StackFrame::Disassemble ()
289{
Jason Molenda6a354702014-10-02 01:08:16 +0000290 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291 if (m_disassembly.GetSize() == 0)
292 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000293 ExecutionContext exe_ctx (shared_from_this());
294 Target *target = exe_ctx.GetTargetPtr();
295 if (target)
296 {
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000297 const char *plugin_name = nullptr;
298 const char *flavor = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +0000299 Disassembler::Disassemble (target->GetDebugger(),
300 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000301 plugin_name,
302 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000303 exe_ctx,
304 0,
305 0,
306 0,
307 m_disassembly);
308 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309 if (m_disassembly.GetSize() == 0)
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000310 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311 }
312 return m_disassembly.GetData();
313}
314
Greg Clayton95897c62010-09-07 04:20:48 +0000315Block *
316StackFrame::GetFrameBlock ()
317{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000318 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock))
Greg Clayton95897c62010-09-07 04:20:48 +0000319 GetSymbolContext (eSymbolContextBlock);
320
321 if (m_sc.block)
322 {
323 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
324 if (inline_block)
325 {
326 // Use the block with the inlined function info
327 // as the frame block we want this frame to have only the variables
328 // for the inlined function and its non-inlined block child blocks.
329 return inline_block;
330 }
331 else
332 {
333 // This block is not contained withing any inlined function blocks
334 // with so we want to use the top most function block.
335 return &m_sc.function->GetBlock (false);
336 }
337 }
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000338 return nullptr;
Greg Clayton95897c62010-09-07 04:20:48 +0000339}
340
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341//----------------------------------------------------------------------
342// Get the symbol context if we already haven't done so by resolving the
343// PC address as much as possible. This way when we pass around a
344// StackFrame object, everyone will have as much information as
345// possible and no one will ever have to look things up manually.
346//----------------------------------------------------------------------
347const SymbolContext&
348StackFrame::GetSymbolContext (uint32_t resolve_scope)
349{
Jason Molenda6a354702014-10-02 01:08:16 +0000350 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000352 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353 {
Greg Clayton75a03332012-11-29 00:53:06 +0000354 uint32_t resolved = 0;
355
356 // If the target was requested add that:
357 if (!m_sc.target_sp)
358 {
359 m_sc.target_sp = CalculateTarget();
360 if (m_sc.target_sp)
361 resolved |= eSymbolContextTarget;
362 }
363
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000364 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365 // and if we don't have a module. The resolved address section will
366 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000367 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000368 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369
370 // If this is not frame zero, then we need to subtract 1 from the PC
371 // value when doing address lookups since the PC will be on the
372 // instruction following the function call instruction...
373
Greg Clayton9da7bd02010-08-24 21:05:24 +0000374 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000375 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 {
377 addr_t offset = lookup_addr.GetOffset();
378 if (offset > 0)
Jason Molendacf296752014-11-08 05:38:17 +0000379 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17 +0000381
382 }
383 else
384 {
385 // lookup_addr is the start of a section. We need
386 // do the math on the actual load address and re-compute
387 // the section. We're working with a 'noreturn' function
388 // at the end of a section.
389 ThreadSP thread_sp (GetThread());
390 if (thread_sp)
391 {
392 TargetSP target_sp (thread_sp->CalculateTarget());
393 if (target_sp)
394 {
395 addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1;
396 lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get());
397 }
398 else
399 {
400 lookup_addr.SetOffset(offset - 1);
401 }
402 }
403 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404 }
405
406 if (m_sc.module_sp)
407 {
408 // We have something in our stack frame symbol context, lets check
409 // if we haven't already tried to lookup one of those things. If we
410 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000411
412 uint32_t actual_resolve_scope = 0;
413
414 if (resolve_scope & eSymbolContextCompUnit)
415 {
416 if (m_flags.IsClear (eSymbolContextCompUnit))
417 {
418 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000419 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000420 else
421 actual_resolve_scope |= eSymbolContextCompUnit;
422 }
423 }
424
425 if (resolve_scope & eSymbolContextFunction)
426 {
427 if (m_flags.IsClear (eSymbolContextFunction))
428 {
429 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000430 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000431 else
432 actual_resolve_scope |= eSymbolContextFunction;
433 }
434 }
435
436 if (resolve_scope & eSymbolContextBlock)
437 {
438 if (m_flags.IsClear (eSymbolContextBlock))
439 {
440 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000441 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000442 else
443 actual_resolve_scope |= eSymbolContextBlock;
444 }
445 }
446
447 if (resolve_scope & eSymbolContextSymbol)
448 {
449 if (m_flags.IsClear (eSymbolContextSymbol))
450 {
451 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000452 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000453 else
454 actual_resolve_scope |= eSymbolContextSymbol;
455 }
456 }
457
458 if (resolve_scope & eSymbolContextLineEntry)
459 {
460 if (m_flags.IsClear (eSymbolContextLineEntry))
461 {
462 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000463 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000464 else
465 actual_resolve_scope |= eSymbolContextLineEntry;
466 }
467 }
468
469 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 {
471 // We might be resolving less information than what is already
472 // in our current symbol context so resolve into a temporary
473 // symbol context "sc" so we don't clear out data we have
474 // already found in "m_sc"
475 SymbolContext sc;
476 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000477 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000478 // Only replace what we didn't already have as we may have
479 // information for an inlined function scope that won't match
480 // what a standard lookup by address would match
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000481 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000482 m_sc.comp_unit = sc.comp_unit;
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000483 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000484 m_sc.function = sc.function;
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000485 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000486 m_sc.block = sc.block;
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000487 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000488 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000489 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
490 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000491 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000492 if (m_sc.target_sp)
493 {
494 // Be sure to apply and file remappings to our file and line
495 // entries when handing out a line entry
496 FileSpec new_file_spec;
497 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
498 m_sc.line_entry.file = new_file_spec;
499 }
500 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 }
502 }
503 else
504 {
505 // If we don't have a module, then we can't have the compile unit,
506 // function, block, line entry or symbol, so we can safely call
507 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000508 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000509 {
Greg Clayton75a03332012-11-29 00:53:06 +0000510 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000511 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000512 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513
514 // Update our internal flags so we remember what we have tried to locate so
515 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000516 // We might have dug up more information that was requested (for example
517 // if we were asked to only get the block, we will have gotten the
518 // compile unit, and function) so set any additional bits that we resolved
519 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 }
521
522 // Return the symbol context with everything that was possible to resolve
523 // resolved.
524 return m_sc;
525}
526
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000528StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529{
Jason Molenda6a354702014-10-02 01:08:16 +0000530 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 if (m_flags.IsClear(RESOLVED_VARIABLES))
532 {
533 m_flags.Set(RESOLVED_VARIABLES);
534
Greg Clayton95897c62010-09-07 04:20:48 +0000535 Block *frame_block = GetFrameBlock();
536
537 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 {
Greg Clayton95897c62010-09-07 04:20:48 +0000539 const bool get_child_variables = true;
540 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000541 const bool stop_if_child_block_is_inlined_function = true;
542 m_variable_list_sp.reset(new VariableList());
543 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 +0000544 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000545 }
546
547 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
548 get_file_globals)
549 {
550 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000551
Sean Callanan7c0962d2010-11-01 04:38:59 +0000552 if (m_flags.IsClear (eSymbolContextCompUnit))
553 GetSymbolContext (eSymbolContextCompUnit);
554
555 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000556 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000557 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
558 if (m_variable_list_sp)
559 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
560 else
561 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000562 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000564
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565 return m_variable_list_sp.get();
566}
567
Greg Claytond41f0322011-08-02 23:35:43 +0000568VariableListSP
569StackFrame::GetInScopeVariableList (bool get_file_globals)
570{
Jason Molenda6a354702014-10-02 01:08:16 +0000571 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +0000572 // We can't fetch variable information for a history stack frame.
573 if (m_is_history_frame)
574 return VariableListSP();
575
Greg Claytond41f0322011-08-02 23:35:43 +0000576 VariableListSP var_list_sp(new VariableList);
577 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
578
579 if (m_sc.block)
580 {
581 const bool can_create = true;
582 const bool get_parent_variables = true;
583 const bool stop_if_block_is_inlined_function = true;
584 m_sc.block->AppendVariables (can_create,
585 get_parent_variables,
586 stop_if_block_is_inlined_function,
587 var_list_sp.get());
588 }
589
Siva Chandrab90168f2016-02-02 23:49:41 +0000590 if (m_sc.comp_unit && get_file_globals)
Greg Claytond41f0322011-08-02 23:35:43 +0000591 {
592 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
593 if (global_variable_list_sp)
594 var_list_sp->AddVariables (global_variable_list_sp.get());
595 }
596
597 return var_list_sp;
598}
599
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000600ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000601StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000602 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000603 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000604 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000605 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000606{
Jason Molenda99618472013-11-04 11:02:52 +0000607 // We can't fetch variable information for a history stack frame.
608 if (m_is_history_frame)
609 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000610
611 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000612 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000613 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
614 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000615 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000616 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000617 error.Clear();
618 bool deref = false;
619 bool address_of = false;
620 ValueObjectSP valobj_sp;
621 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000622 // When looking up a variable for an expression, we need only consider the
623 // variables that are in scope.
624 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
625 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000626
627 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000628 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000629 // If first character is a '*', then show pointer contents
630 const char *var_expr = var_expr_cstr;
631 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000632 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000633 deref = true;
634 var_expr++; // Skip the '*'
635 }
636 else if (var_expr[0] == '&')
637 {
638 address_of = true;
639 var_expr++; // Skip the '&'
640 }
641
642 std::string var_path (var_expr);
643 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
644 StreamString var_expr_path_strm;
645
646 ConstString name_const_string;
647 if (separator_idx == std::string::npos)
648 name_const_string.SetCString (var_path.c_str());
649 else
650 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
651
Paul Herman10bc1a42015-08-18 22:46:57 +0000652 var_sp = variable_list->FindVariable(name_const_string, false);
Greg Clayton685c88c2012-07-14 00:53:55 +0000653
654 bool synthetically_added_instance_object = false;
655
656 if (var_sp)
657 {
658 var_path.erase (0, name_const_string.GetLength ());
659 }
Enrico Granata46252392015-11-19 22:28:58 +0000660
661 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess))
Greg Clayton685c88c2012-07-14 00:53:55 +0000662 {
663 // Check for direct ivars access which helps us with implicit
664 // access to ivars with the "this->" or "self->"
665 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
666 lldb::LanguageType method_language = eLanguageTypeUnknown;
667 bool is_instance_method = false;
668 ConstString method_object_name;
669 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
670 {
671 if (is_instance_method && method_object_name)
672 {
673 var_sp = variable_list->FindVariable(method_object_name);
674 if (var_sp)
675 {
676 separator_idx = 0;
677 var_path.insert(0, "->");
678 synthetically_added_instance_object = true;
679 }
680 }
681 }
682 }
Enrico Granata46252392015-11-19 22:28:58 +0000683
684 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions))
685 {
686 // Check if any anonymous unions are there which contain a variable with the name we need
687 for (size_t i = 0;
688 i < variable_list->GetSize();
689 i++)
690 {
691 if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i))
692 {
693 if (variable_sp->GetName().IsEmpty())
694 {
695 if (Type *var_type = variable_sp->GetType())
696 {
697 if (var_type->GetForwardCompilerType().IsAnonymousType())
698 {
699 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
700 if (!valobj_sp)
701 return valobj_sp;
702 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true);
703 if (valobj_sp)
704 break;
705 }
706 }
707 }
708 }
709 }
710 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000711
Enrico Granata46252392015-11-19 22:28:58 +0000712 if (var_sp && !valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000713 {
Jim Ingham2837b762011-05-04 03:43:18 +0000714 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000715 if (!valobj_sp)
716 return valobj_sp;
Enrico Granata46252392015-11-19 22:28:58 +0000717 }
718 if (valobj_sp)
719 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000720 // We are dumping at least one child
721 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000722 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000723 // Calculate the next separator index ahead of time
724 ValueObjectSP child_valobj_sp;
725 const char separator_type = var_path[0];
726 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000727 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000728 case '-':
729 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000730 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000731
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000732 if (no_fragile_ivar)
733 {
734 // Make sure we aren't trying to deref an objective
735 // C ivar if this is not allowed
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000736 const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo(nullptr);
Enrico Granata622be232014-10-21 20:52:14 +0000737 if ((pointer_type_flags & eTypeIsObjC) &&
738 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000739 {
740 // This was an objective C object pointer and
741 // it was requested we skip any fragile ivars
742 // so return nothing here
743 return ValueObjectSP();
744 }
745 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000746 var_path.erase (0, 1); // Remove the '-'
Jason Molenda62e06812016-02-16 04:14:33 +0000747 LLVM_FALLTHROUGH;
Greg Clayton54979cd2010-12-15 05:08:08 +0000748 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000749 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000750 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000751
Greg Clayton54979cd2010-12-15 05:08:08 +0000752 var_path.erase (0, 1); // Remove the '.' or '>'
753 separator_idx = var_path.find_first_of(".-[");
754 ConstString child_name;
755 if (separator_idx == std::string::npos)
756 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000757 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000758 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
759
760 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000761 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000762 // We either have a pointer type and need to verify
763 // valobj_sp is a pointer, or we have a member of a
764 // class/union/struct being accessed with the . syntax
765 // and need to verify we don't have a pointer.
766 const bool actual_is_ptr = valobj_sp->IsPointerType ();
767
768 if (actual_is_ptr != expr_is_ptr)
769 {
770 // Incorrect use of "." with a pointer, or "->" with
771 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000772 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000773 if (actual_is_ptr)
774 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
775 var_expr_path_strm.GetString().c_str(),
776 child_name.GetCString(),
777 var_expr_path_strm.GetString().c_str(),
778 var_path.c_str());
779 else
780 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
781 var_expr_path_strm.GetString().c_str(),
782 child_name.GetCString(),
783 var_expr_path_strm.GetString().c_str(),
784 var_path.c_str());
785 return ValueObjectSP();
786 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000787 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000788 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000789 if (!child_valobj_sp)
790 {
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000791 if (!no_synth_child)
Enrico Granata86cc9822012-03-19 22:58:49 +0000792 {
793 child_valobj_sp = valobj_sp->GetSyntheticValue();
794 if (child_valobj_sp)
795 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
796 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000797
798 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000799 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000800 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000801 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000802 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000803 // We added a "this->" or "self->" to the beginning of the expression
804 // and this is the first pointer ivar access, so just return the normal
805 // error
806 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
807 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000808 }
809 else
810 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000811 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
812 if (child_name)
813 {
814 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
815 child_name.GetCString(),
816 valobj_sp->GetTypeName().AsCString("<invalid type>"),
817 var_expr_path_strm.GetString().c_str());
818 }
819 else
820 {
821 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
822 var_expr_path_strm.GetString().c_str(),
823 var_expr_cstr);
824 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000825 }
826 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000827 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000828 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000829 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000830 // Remove the child name from the path
831 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000832 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000833 {
Jim Ingham2837b762011-05-04 03:43:18 +0000834 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000835 if (dynamic_value_sp)
836 child_valobj_sp = dynamic_value_sp;
837 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000838 }
839 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000840
Greg Clayton54979cd2010-12-15 05:08:08 +0000841 case '[':
842 // Array member access, or treating pointer as an array
843 if (var_path.size() > 2) // Need at least two brackets and a number
844 {
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000845 char *end = nullptr;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000846 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000847 if (end && *end == ']'
848 && *(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 +0000849 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000850 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000851 {
852 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
853 // and extract bit low out of it. reading array item low
854 // would be done by saying ptr[low], without a deref * sign
855 Error error;
856 ValueObjectSP temp(valobj_sp->Dereference(error));
857 if (error.Fail())
858 {
859 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
860 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
861 valobj_sp->GetTypeName().AsCString("<invalid type>"),
862 var_expr_path_strm.GetString().c_str());
863 return ValueObjectSP();
864 }
865 valobj_sp = temp;
866 deref = false;
867 }
Greg Clayton99558cc42015-08-24 23:46:31 +0000868 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000869 {
870 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
871 // (an operation that is equivalent to deref-ing arr)
872 // and extract bit low out of it. reading array item low
873 // would be done by saying arr[low], without a deref * sign
874 Error error;
875 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
876 if (error.Fail())
877 {
878 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
879 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
880 valobj_sp->GetTypeName().AsCString("<invalid type>"),
881 var_expr_path_strm.GetString().c_str());
882 return ValueObjectSP();
883 }
884 valobj_sp = temp;
885 deref = false;
886 }
887
Greg Clayton4ef877f2012-12-06 02:33:54 +0000888 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000889 if (valobj_sp->IsPointerType ())
890 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000891 bool is_objc_pointer = true;
892
Greg Clayton99558cc42015-08-24 23:46:31 +0000893 if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000894 is_objc_pointer = false;
Greg Clayton99558cc42015-08-24 23:46:31 +0000895 else if (!valobj_sp->GetCompilerType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000896 is_objc_pointer = false;
897
898 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000899 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000900 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
901 valobj_sp->GetTypeName().AsCString("<invalid type>"),
902 var_expr_path_strm.GetString().c_str());
903
904 return ValueObjectSP();
905 }
906 else if (is_objc_pointer)
907 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000908 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000909 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000910 if (!synthetic /* no synthetic */
Enrico Granata27b625e2011-08-09 01:04:56 +0000911 || synthetic == valobj_sp) /* synthetic is the same as the original object */
912 {
913 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
914 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
915 valobj_sp->GetTypeName().AsCString("<invalid type>"),
916 var_expr_path_strm.GetString().c_str());
917 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000918 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000919 {
920 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000921 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000922 child_index,
923 valobj_sp->GetTypeName().AsCString("<invalid type>"),
924 var_expr_path_strm.GetString().c_str());
925 }
926 else
927 {
928 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
929 if (!child_valobj_sp)
930 {
931 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000932 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000933 child_index,
934 valobj_sp->GetTypeName().AsCString("<invalid type>"),
935 var_expr_path_strm.GetString().c_str());
936 }
937 }
938 }
939 else
940 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000941 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +0000942 if (!child_valobj_sp)
943 {
944 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000945 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000946 child_index,
947 valobj_sp->GetTypeName().AsCString("<invalid type>"),
948 var_expr_path_strm.GetString().c_str());
949 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000950 }
951 }
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000952 else if (valobj_sp->GetCompilerType().IsArrayType(nullptr, nullptr, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000953 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000954 // Pass false to dynamic_value here so we can tell the difference between
955 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000956 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000957 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
Greg Clayton4ef877f2012-12-06 02:33:54 +0000958 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
959
Greg Clayton54979cd2010-12-15 05:08:08 +0000960 if (!child_valobj_sp)
961 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000962 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000963 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000964 child_index,
965 valobj_sp->GetTypeName().AsCString("<invalid type>"),
966 var_expr_path_strm.GetString().c_str());
967 }
968 }
Greg Clayton99558cc42015-08-24 23:46:31 +0000969 else if (valobj_sp->GetCompilerType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000970 {
971 // this is a bitfield asking to display just one bit
972 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
973 if (!child_valobj_sp)
974 {
975 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000976 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000977 child_index, child_index,
978 valobj_sp->GetTypeName().AsCString("<invalid type>"),
979 var_expr_path_strm.GetString().c_str());
980 }
981 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000982 else
983 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000984 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000985 if (no_synth_child /* synthetic is forbidden */ ||
Eugene Zelenkod70a6e72016-02-18 18:52:47 +0000986 !synthetic /* no synthetic */
Enrico Granata27b625e2011-08-09 01:04:56 +0000987 || synthetic == valobj_sp) /* synthetic is the same as the original object */
988 {
989 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
990 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
991 valobj_sp->GetTypeName().AsCString("<invalid type>"),
992 var_expr_path_strm.GetString().c_str());
993 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000994 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000995 {
996 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000997 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000998 child_index,
999 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1000 var_expr_path_strm.GetString().c_str());
1001 }
1002 else
1003 {
1004 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
1005 if (!child_valobj_sp)
1006 {
1007 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001008 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +00001009 child_index,
1010 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1011 var_expr_path_strm.GetString().c_str());
1012 }
1013 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001014 }
1015
1016 if (!child_valobj_sp)
1017 {
1018 // Invalid array index...
1019 return ValueObjectSP();
1020 }
1021
1022 // Erase the array member specification '[%i]' where
1023 // %i is the array index
1024 var_path.erase(0, (end - var_path.c_str()) + 1);
1025 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001026 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001027 {
Jim Ingham2837b762011-05-04 03:43:18 +00001028 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +00001029 if (dynamic_value_sp)
1030 child_valobj_sp = dynamic_value_sp;
1031 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001032 // Break out early from the switch since we were
1033 // able to find the child member
1034 break;
1035 }
Enrico Granata20edcdb2011-07-19 18:03:25 +00001036 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +00001037 {
1038 // this is most probably a BitField, let's take a look
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001039 char *real_end = nullptr;
Enrico Granata9fc19442011-07-06 02:13:41 +00001040 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001041 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +00001042 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +00001043 {
1044 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +00001045 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +00001046 {
1047 long temp = child_index;
1048 child_index = final_index;
1049 final_index = temp;
1050 }
1051
Greg Clayton99558cc42015-08-24 23:46:31 +00001052 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001053 {
1054 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1055 // and extract bits low thru high out of it. reading array items low thru high
1056 // would be done by saying ptr[low-high], without a deref * sign
1057 Error error;
1058 ValueObjectSP temp(valobj_sp->Dereference(error));
1059 if (error.Fail())
1060 {
1061 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1062 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1063 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1064 var_expr_path_strm.GetString().c_str());
1065 return ValueObjectSP();
1066 }
1067 valobj_sp = temp;
1068 deref = false;
1069 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001070 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001071 {
1072 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1073 // (an operation that is equivalent to deref-ing arr)
1074 // and extract bits low thru high out of it. reading array items low thru high
1075 // would be done by saying arr[low-high], without a deref * sign
1076 Error error;
1077 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1078 if (error.Fail())
1079 {
1080 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1081 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1082 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1083 var_expr_path_strm.GetString().c_str());
1084 return ValueObjectSP();
1085 }
1086 valobj_sp = temp;
1087 deref = false;
1088 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001089 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001090 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001091 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1092 expand_bitfield = false;
1093 if (!child_valobj_sp)
1094 {
1095 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1096 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1097 child_index, final_index,
1098 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1099 var_expr_path_strm.GetString().c_str());
1100 }
1101 }*/
1102
1103 if (expand_bitfield)
1104 {
1105 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1106 if (!child_valobj_sp)
1107 {
1108 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001109 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001110 child_index, final_index,
1111 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1112 var_expr_path_strm.GetString().c_str());
1113 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001114 }
1115 }
1116
1117 if (!child_valobj_sp)
1118 {
1119 // Invalid bitfield range...
1120 return ValueObjectSP();
1121 }
1122
1123 // Erase the bitfield member specification '[%i-%i]' where
1124 // %i is the index
1125 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1126 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001127 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001128 {
1129 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1130 if (dynamic_value_sp)
1131 child_valobj_sp = dynamic_value_sp;
1132 }
1133 // Break out early from the switch since we were
1134 // able to find the child member
1135 break;
1136
1137 }
1138 }
1139 else
1140 {
1141 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1142 var_expr_path_strm.GetString().c_str(),
1143 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001144 }
1145 return ValueObjectSP();
1146
1147 default:
1148 // Failure...
1149 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001150 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001151 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1152 separator_type,
1153 var_expr_path_strm.GetString().c_str(),
1154 var_path.c_str());
1155
1156 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001157 }
1158 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001159
Greg Clayton54979cd2010-12-15 05:08:08 +00001160 if (child_valobj_sp)
1161 valobj_sp = child_valobj_sp;
1162
1163 if (var_path.empty())
1164 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001165 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001166 if (valobj_sp)
1167 {
1168 if (deref)
1169 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001170 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001171 valobj_sp = deref_valobj_sp;
1172 }
1173 else if (address_of)
1174 {
1175 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1176 valobj_sp = address_of_valobj_sp;
1177 }
1178 }
1179 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001180 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001181 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001182 {
Jim Ingham2837b762011-05-04 03:43:18 +00001183 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1184 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001185 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001186 }
1187 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001188 else
1189 {
1190 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1191 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001192 return ValueObjectSP();
1193}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194
1195bool
1196StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1197{
Jason Molenda6a354702014-10-02 01:08:16 +00001198 Mutex::Locker locker(m_mutex);
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001199 if (!m_cfa_is_valid)
Jason Molenda99618472013-11-04 11:02:52 +00001200 {
1201 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1202 return false;
1203 }
1204
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205 if (m_flags.IsClear(GOT_FRAME_BASE))
1206 {
1207 if (m_sc.function)
1208 {
1209 m_frame_base.Clear();
1210 m_frame_base_error.Clear();
1211
1212 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001213 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001215 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1216 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001217 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001218
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001219 if (!m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, nullptr, nullptr, nullptr, loclist_base_addr,
1220 nullptr, expr_value, &m_frame_base_error))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001221 {
1222 // We should really have an error if evaluate returns, but in case
1223 // we don't, lets set the error to something at least.
1224 if (m_frame_base_error.Success())
1225 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1226 }
1227 else
1228 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001229 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 }
1231 }
1232 else
1233 {
1234 m_frame_base_error.SetErrorString ("No function in symbol context.");
1235 }
1236 }
1237
1238 if (m_frame_base_error.Success())
1239 frame_base = m_frame_base;
1240
1241 if (error_ptr)
1242 *error_ptr = m_frame_base_error;
1243 return m_frame_base_error.Success();
1244}
1245
Greg Clayton5ccbd292011-01-06 22:15:06 +00001246RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247StackFrame::GetRegisterContext ()
1248{
Jason Molenda6a354702014-10-02 01:08:16 +00001249 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001250 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001251 {
1252 ThreadSP thread_sp (GetThread());
1253 if (thread_sp)
1254 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1255 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001256 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257}
1258
1259bool
1260StackFrame::HasDebugInformation ()
1261{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001262 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263 return m_sc.line_entry.IsValid();
1264}
1265
Greg Clayton288bdf92010-09-02 02:59:18 +00001266ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001267StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268{
Jason Molenda6a354702014-10-02 01:08:16 +00001269 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:18 +00001270 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001271 if (m_is_history_frame)
1272 {
1273 return valobj_sp;
1274 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001275 VariableList *var_list = GetVariableList (true);
1276 if (var_list)
1277 {
1278 // Make sure the variable is a frame variable
1279 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1280 const uint32_t num_variables = var_list->GetSize();
1281 if (var_idx < num_variables)
1282 {
1283 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001284 if (!valobj_sp)
Greg Clayton288bdf92010-09-02 02:59:18 +00001285 {
1286 if (m_variable_list_value_objects.GetSize() < num_variables)
1287 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001288 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001289 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1290 }
1291 }
1292 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001293 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001294 {
Jim Ingham2837b762011-05-04 03:43:18 +00001295 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001296 if (dynamic_sp)
1297 return dynamic_sp;
1298 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001299 return valobj_sp;
1300}
1301
1302ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001303StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001304{
Jason Molenda6a354702014-10-02 01:08:16 +00001305 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52 +00001306 if (m_is_history_frame)
1307 return ValueObjectSP();
1308
Greg Clayton288bdf92010-09-02 02:59:18 +00001309 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001310 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001311 if (!valobj_sp)
1312 {
1313 // We aren't already tracking this global
1314 VariableList *var_list = GetVariableList (true);
1315 // If this frame has no variables, create a new list
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001316 if (var_list == nullptr)
Greg Clayton288bdf92010-09-02 02:59:18 +00001317 m_variable_list_sp.reset (new VariableList());
1318
1319 // Add the global/static variable to this frame
1320 m_variable_list_sp->AddVariable (variable_sp);
1321
1322 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001323 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001324 }
1325 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326}
1327
Jim Ingham6b8379c2010-08-26 20:44:45 +00001328bool
1329StackFrame::IsInlined ()
1330{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001331 if (m_sc.block == nullptr)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001332 GetSymbolContext (eSymbolContextBlock);
1333 if (m_sc.block)
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001334 return m_sc.block->GetContainingInlinedBlock() != nullptr;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001335 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001336}
1337
Dawn Perchik009d1102015-09-04 01:02:30 +00001338lldb::LanguageType
1339StackFrame::GetLanguage ()
1340{
1341 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1342 if (cu)
1343 return cu->GetLanguage();
1344 return lldb::eLanguageTypeUnknown;
1345}
1346
Greg Claytond9e416c2012-02-18 05:35:26 +00001347TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001348StackFrame::CalculateTarget ()
1349{
Greg Claytond9e416c2012-02-18 05:35:26 +00001350 TargetSP target_sp;
1351 ThreadSP thread_sp(GetThread());
1352 if (thread_sp)
1353 {
1354 ProcessSP process_sp (thread_sp->CalculateProcess());
1355 if (process_sp)
1356 target_sp = process_sp->CalculateTarget();
1357 }
1358 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001359}
1360
Greg Claytond9e416c2012-02-18 05:35:26 +00001361ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362StackFrame::CalculateProcess ()
1363{
Greg Claytond9e416c2012-02-18 05:35:26 +00001364 ProcessSP process_sp;
1365 ThreadSP thread_sp(GetThread());
1366 if (thread_sp)
1367 process_sp = thread_sp->CalculateProcess();
1368 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369}
1370
Greg Claytond9e416c2012-02-18 05:35:26 +00001371ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372StackFrame::CalculateThread ()
1373{
Greg Claytond9e416c2012-02-18 05:35:26 +00001374 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375}
1376
Jason Molendab57e4a12013-11-04 09:33:30 +00001377StackFrameSP
1378StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379{
Greg Claytond9e416c2012-02-18 05:35:26 +00001380 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381}
1382
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001383void
Greg Clayton0603aa92010-10-04 01:05:56 +00001384StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001385{
Greg Claytond9e416c2012-02-18 05:35:26 +00001386 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001387}
1388
1389void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001390StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001391{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001392 if (strm == nullptr)
Greg Clayton0603aa92010-10-04 01:05:56 +00001393 return;
1394
1395 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001396 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001397 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001398
1399 if (frame_marker)
1400 s.PutCString(frame_marker);
1401
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001402 const FormatEntity::Entry *frame_format = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26 +00001403 Target *target = exe_ctx.GetTargetPtr();
1404 if (target)
1405 frame_format = target->GetDebugger().GetFrameFormat();
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001406 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, nullptr, nullptr, false, false))
Greg Clayton0603aa92010-10-04 01:05:56 +00001407 {
1408 strm->Write(s.GetData(), s.GetSize());
1409 }
1410 else
1411 {
1412 Dump (strm, true, false);
1413 strm->EOL();
1414 }
1415}
1416
1417void
Greg Clayton6dadd502010-09-02 21:44:10 +00001418StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001420 if (strm == nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421 return;
1422
1423 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001424 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001425 ExecutionContext exe_ctx (shared_from_this());
1426 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001427 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001428 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1429 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001430 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001431 const bool show_module = true;
1432 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:36 +00001433 const bool show_function_arguments = true;
Jason Molendac980fa92015-02-13 23:24:21 +00001434 const bool show_function_name = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001435 m_sc.DumpStopContext (strm,
1436 exe_ctx.GetBestExecutionContextScope(),
1437 GetFrameCodeAddress(),
1438 show_fullpaths,
1439 show_module,
Jason Molendaaff1b352014-10-10 23:07:36 +00001440 show_inline,
Jason Molendac980fa92015-02-13 23:24:21 +00001441 show_function_arguments,
1442 show_function_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443}
1444
Greg Clayton5082c5f2010-08-27 18:24:16 +00001445void
Jason Molendab57e4a12013-11-04 09:33:30 +00001446StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001447{
Jason Molenda6a354702014-10-02 01:08:16 +00001448 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001449 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001450 m_variable_list_sp = prev_frame.m_variable_list_sp;
1451 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1452 if (!m_disassembly.GetString().empty())
1453 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001454}
Greg Clayton68275d52010-08-27 21:47:54 +00001455
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001456void
Jason Molendab57e4a12013-11-04 09:33:30 +00001457StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001458{
Jason Molenda6a354702014-10-02 01:08:16 +00001459 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:42 +00001460 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001461 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1462 assert (GetThread() == curr_frame.GetThread());
1463 m_frame_index = curr_frame.m_frame_index;
1464 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1465 m_reg_context_sp = curr_frame.m_reg_context_sp;
1466 m_frame_code_addr = curr_frame.m_frame_code_addr;
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001467 assert (!m_sc.target_sp || !curr_frame.m_sc.target_sp || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1468 assert (!m_sc.module_sp || !curr_frame.m_sc.module_sp || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1469 assert (m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1470 assert (m_sc.function == nullptr || curr_frame.m_sc.function == nullptr || m_sc.function == curr_frame.m_sc.function);
Jason Molendab57e4a12013-11-04 09:33:30 +00001471 m_sc = curr_frame.m_sc;
1472 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1473 m_flags.Set (m_sc.GetResolvedMask());
1474 m_frame_base.Clear();
1475 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001476}
1477
Greg Clayton2cad65a2010-09-03 17:10:42 +00001478bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001479StackFrame::HasCachedData () const
1480{
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001481 if (m_variable_list_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +00001482 return true;
1483 if (m_variable_list_value_objects.GetSize() > 0)
1484 return true;
1485 if (!m_disassembly.GetString().empty())
1486 return true;
1487 return false;
1488}
1489
1490bool
Greg Clayton7260f622011-04-18 08:33:37 +00001491StackFrame::GetStatus (Stream& strm,
1492 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001493 bool show_source,
1494 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001495{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001496
Greg Clayton7260f622011-04-18 08:33:37 +00001497 if (show_frame_info)
1498 {
1499 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001500 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001501 }
1502
1503 if (show_source)
1504 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001505 ExecutionContext exe_ctx (shared_from_this());
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001506 bool have_source = false, have_debuginfo = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001507 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001508 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001509 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001510 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001511 Debugger &debugger = target->GetDebugger();
1512 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1513 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1514 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001515
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001516 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1517 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001518 {
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001519 have_debuginfo = true;
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001520 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001521 {
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001522 size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001523 m_sc.line_entry.line,
1524 source_lines_before,
1525 source_lines_after,
1526 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001527 &strm);
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001528 if (num_lines != 0)
1529 have_source = true;
1530 // TODO: Give here a one time warning if source file is missing.
Greg Claytone372b982011-11-21 21:44:34 +00001531 }
1532 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001533 switch (disasm_display)
1534 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001535 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001536 break;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001537
1538 case Debugger::eStopDisassemblyTypeNoDebugInfo:
1539 if (have_debuginfo)
1540 break;
Jason Molenda62e06812016-02-16 04:14:33 +00001541 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001542
Greg Clayton67cc0632012-08-22 17:17:09 +00001543 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001544 if (have_source)
1545 break;
Jason Molenda62e06812016-02-16 04:14:33 +00001546 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:16 +00001547
Greg Clayton67cc0632012-08-22 17:17:09 +00001548 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001549 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001550 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001551 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1552 if (disasm_lines > 0)
1553 {
1554 const ArchSpec &target_arch = target->GetArchitecture();
1555 AddressRange pc_range;
1556 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1557 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Eugene Zelenkod70a6e72016-02-18 18:52:47 +00001558 const char *plugin_name = nullptr;
1559 const char *flavor = nullptr;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001560 Disassembler::Disassemble (target->GetDebugger(),
1561 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001562 plugin_name,
1563 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001564 exe_ctx,
1565 pc_range,
1566 disasm_lines,
1567 0,
1568 Disassembler::eOptionMarkPCAddress,
1569 strm);
1570 }
Greg Claytone372b982011-11-21 21:44:34 +00001571 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001572 break;
Greg Claytone372b982011-11-21 21:44:34 +00001573 }
Greg Clayton7260f622011-04-18 08:33:37 +00001574 }
1575 }
1576 return true;
1577}