blob: 43ca4b3f97ae62ac601b5ff0e038087588991d96 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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:2410// C Includes
11// C++ Includes
12// Other libraries and framework includes
13// Project includes
Eugene Zelenkod70a6e72016-02-18 18:52:4714#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:2415#include "lldb/Core/Module.h"
Greg Clayton0603aa92010-10-04 01:05:5616#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2417#include "lldb/Core/Disassembler.h"
Greg Clayton554f68d2015-02-04 22:00:5318#include "lldb/Core/FormatEntity.h"
Chris Lattner30fdc8d2010-06-08 16:52:2419#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:1820#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:0821#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:0622#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:2423#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:0624#include "lldb/Symbol/Symbol.h"
25#include "lldb/Symbol/SymbolContextScope.h"
Enrico Granata46252392015-11-19 22:28:5826#include "lldb/Symbol/Type.h"
Greg Clayton288bdf92010-09-02 02:59:1827#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:2428#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:3540#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:1041#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:3542#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
43#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:5944#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:2445
Greg Claytond9e416c2012-02-18 05:35:2646StackFrame::StackFrame (const ThreadSP &thread_sp,
47 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:2748 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:2749 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:5250 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:2751 addr_t pc,
Jason Molenda99618472013-11-04 11:02:5252 uint32_t stop_id,
53 bool stop_id_is_valid,
54 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:2755 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:2656 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:4157 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:0658 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:4159 m_reg_context_sp (),
Eugene Zelenkod70a6e72016-02-18 18:52:4760 m_id(pc, cfa, nullptr),
Greg Claytone72dfb32012-02-24 01:59:2961 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:4162 m_sc (),
63 m_flags (),
64 m_frame_base (),
65 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:5266 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:2470 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:3771 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:1672 m_disassembly (),
73 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:2474{
Jason Molenda99618472013-11-04 11:02:5275 // 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:4777 if (m_is_history_frame && !m_cfa_is_valid)
Jason Molenda99618472013-11-04 11:02:5278 {
79 m_id.SetCFA (m_frame_index);
80 }
81
Eugene Zelenkod70a6e72016-02-18 18:52:4782 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:4183 {
Chris Lattner30fdc8d2010-06-08 16:52:2484 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:4185 m_flags.Set(m_sc.GetResolvedMask ());
86 }
Chris Lattner30fdc8d2010-06-08 16:52:2487}
88
Greg Claytond9e416c2012-02-18 05:35:2689StackFrame::StackFrame (const ThreadSP &thread_sp,
90 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:2791 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:2792 const RegisterContextSP &reg_context_sp,
93 addr_t cfa,
94 addr_t pc,
95 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:2696 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:4197 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:0698 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:4199 m_reg_context_sp (reg_context_sp),
Eugene Zelenkod70a6e72016-02-18 18:52:47100 m_id(pc, cfa, nullptr),
Greg Claytone72dfb32012-02-24 01:59:29101 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41102 m_sc (),
103 m_flags (),
104 m_frame_base (),
105 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52106 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:24110 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37111 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16112 m_disassembly (),
113 m_mutex (Mutex::eMutexTypeRecursive)
Chris Lattner30fdc8d2010-06-08 16:52:24114{
Eugene Zelenkod70a6e72016-02-18 18:52:47115 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:41116 {
Chris Lattner30fdc8d2010-06-08 16:52:24117 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41118 m_flags.Set(m_sc.GetResolvedMask ());
119 }
120
121 if (reg_context_sp && !m_sc.target_sp)
122 {
Greg Claytond9e416c2012-02-18 05:35:26123 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:41126 }
127}
128
Greg Claytond9e416c2012-02-18 05:35:26129StackFrame::StackFrame (const ThreadSP &thread_sp,
130 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27131 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27132 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:26136 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41137 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06138 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41139 m_reg_context_sp (reg_context_sp),
Eugene Zelenkod70a6e72016-02-18 18:52:47140 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa, nullptr),
Greg Clayton12fc3e02010-08-26 22:05:43141 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41142 m_sc (),
143 m_flags (),
144 m_frame_base (),
145 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52146 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:41150 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37151 m_variable_list_value_objects (),
Jason Molenda6a354702014-10-02 01:08:16152 m_disassembly (),
153 m_mutex (Mutex::eMutexTypeRecursive)
Greg Clayton1b72fcb2010-08-24 00:45:41154{
Eugene Zelenkod70a6e72016-02-18 18:52:47155 if (sc_ptr != nullptr)
Greg Clayton1b72fcb2010-08-24 00:45:41156 {
157 m_sc = *sc_ptr;
158 m_flags.Set(m_sc.GetResolvedMask ());
159 }
160
Eugene Zelenkod70a6e72016-02-18 18:52:47161 if (!m_sc.target_sp && reg_context_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41162 {
Greg Claytond9e416c2012-02-18 05:35:26163 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:41166 }
167
Greg Claytone72dfb32012-02-24 01:59:29168 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:41170 {
Greg Claytone72dfb32012-02-24 01:59:29171 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41172 {
Greg Claytone72dfb32012-02-24 01:59:29173 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41174 m_flags.Set (eSymbolContextModule);
175 }
Greg Claytonffc1d662010-09-13 04:34:30176 else
177 {
178 m_sc.module_sp.reset();
179 }
Greg Clayton1b72fcb2010-08-24 00:45:41180 }
Chris Lattner30fdc8d2010-06-08 16:52:24181}
182
Eugene Zelenkod70a6e72016-02-18 18:52:47183StackFrame::~StackFrame() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24184
185StackID&
186StackFrame::GetStackID()
187{
Jason Molenda6a354702014-10-02 01:08:16188 Mutex::Locker locker(m_mutex);
Greg Clayton6dadd502010-09-02 21:44:10189 // 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:24191
Greg Clayton59e8fc1c2010-08-30 18:11:35192 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
193 {
Greg Clayton2cad65a2010-09-03 17:10:42194 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35195 {
Greg Clayton95897c62010-09-07 04:20:48196 // We already have a symbol context scope, we just don't have our
197 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35198 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
199 }
200 else
201 {
Greg Clayton95897c62010-09-07 04:20:48202 // 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:47205 if (scope == nullptr)
Greg Clayton59e8fc1c2010-08-30 18:11:35206 {
Greg Clayton95897c62010-09-07 04:20:48207 // 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:47211 // It is ok if m_sc.symbol is nullptr here
Greg Clayton95897c62010-09-07 04:20:48212 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35213 }
Greg Clayton95897c62010-09-07 04:20:48214 // 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:35217 }
Chris Lattner30fdc8d2010-06-08 16:52:24218 }
219 return m_id;
220}
221
Jim Ingham513c6bb2012-09-01 01:02:41222uint32_t
223StackFrame::GetFrameIndex () const
224{
225 ThreadSP thread_sp = GetThread();
226 if (thread_sp)
Jason Molendab57e4a1b2013-11-04 09:33:30227 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41228 else
229 return m_frame_index;
230}
231
Greg Clayton59e8fc1c2010-08-30 18:11:35232void
233StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
234{
Jason Molenda6a354702014-10-02 01:08:16235 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35236 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
237 m_id.SetSymbolContextScope (symbol_scope);
238}
239
Greg Clayton34132752011-07-06 04:07:21240const Address&
Greg Clayton9da7bd02010-08-24 21:05:24241StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24242{
Jason Molenda6a354702014-10-02 01:08:16243 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:35244 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24245 {
Greg Clayton59e8fc1c2010-08-30 18:11:35246 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24247
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:26250 ThreadSP thread_sp (GetThread());
251 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24252 {
Greg Claytond9e416c2012-02-18 05:35:26253 TargetSP target_sp (thread_sp->CalculateTarget());
254 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24255 {
Tamas Berghammer25b9f7e2015-09-07 09:58:09256 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode))
Chris Lattner30fdc8d2010-06-08 16:52:24257 {
Greg Claytone72dfb32012-02-24 01:59:29258 ModuleSP module_sp (m_frame_code_addr.GetModule());
259 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26260 {
Greg Claytone72dfb32012-02-24 01:59:29261 m_sc.module_sp = module_sp;
262 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26263 }
Chris Lattner30fdc8d2010-06-08 16:52:24264 }
265 }
266 }
267 }
Greg Clayton12fc3e02010-08-26 22:05:43268 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24269}
270
Jason Molenda99618472013-11-04 11:02:52271bool
Chris Lattner30fdc8d2010-06-08 16:52:24272StackFrame::ChangePC (addr_t pc)
273{
Jason Molenda6a354702014-10-02 01:08:16274 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52275 // 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:29278 m_frame_code_addr.SetRawAddress(pc);
Greg Clayton72310352013-02-23 04:12:47279 m_sc.Clear(false);
Greg Clayton73b472d2010-10-27 03:32:59280 m_flags.Reset(0);
Greg Claytond9e416c2012-02-18 05:35:26281 ThreadSP thread_sp (GetThread());
282 if (thread_sp)
283 thread_sp->ClearStackFrames ();
Jason Molenda99618472013-11-04 11:02:52284 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24285}
286
287const char *
288StackFrame::Disassemble ()
289{
Jason Molenda6a354702014-10-02 01:08:16290 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24291 if (m_disassembly.GetSize() == 0)
292 {
Greg Claytond9e416c2012-02-18 05:35:26293 ExecutionContext exe_ctx (shared_from_this());
294 Target *target = exe_ctx.GetTargetPtr();
295 if (target)
296 {
Eugene Zelenkod70a6e72016-02-18 18:52:47297 const char *plugin_name = nullptr;
298 const char *flavor = nullptr;
Greg Claytond9e416c2012-02-18 05:35:26299 Disassembler::Disassemble (target->GetDebugger(),
300 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47301 plugin_name,
302 flavor,
Greg Claytond9e416c2012-02-18 05:35:26303 exe_ctx,
304 0,
305 0,
306 0,
307 m_disassembly);
308 }
Chris Lattner30fdc8d2010-06-08 16:52:24309 if (m_disassembly.GetSize() == 0)
Eugene Zelenkod70a6e72016-02-18 18:52:47310 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24311 }
312 return m_disassembly.GetData();
313}
314
Greg Clayton95897c62010-09-07 04:20:48315Block *
316StackFrame::GetFrameBlock ()
317{
Eugene Zelenkod70a6e72016-02-18 18:52:47318 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock))
Greg Clayton95897c62010-09-07 04:20:48319 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:47338 return nullptr;
Greg Clayton95897c62010-09-07 04:20:48339}
340
Chris Lattner30fdc8d2010-06-08 16:52:24341//----------------------------------------------------------------------
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:16350 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24351 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59352 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24353 {
Greg Clayton75a03332012-11-29 00:53:06354 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:41364 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24365 // 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:35367 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24368 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24369
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:24374 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41375 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24376 {
377 addr_t offset = lookup_addr.GetOffset();
378 if (offset > 0)
Jason Molendacf296752014-11-08 05:38:17379 {
Chris Lattner30fdc8d2010-06-08 16:52:24380 lookup_addr.SetOffset(offset - 1);
Jason Molendacf296752014-11-08 05:38:17381
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:24404 }
405
Chris Lattner30fdc8d2010-06-08 16:52:24406 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:41411
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:24419 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41420 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:24430 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41431 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:24441 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41442 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:24452 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41453 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:24463 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41464 else
465 actual_resolve_scope |= eSymbolContextLineEntry;
466 }
467 }
468
469 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24470 {
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:24477 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41478 // 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:47481 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24482 m_sc.comp_unit = sc.comp_unit;
Eugene Zelenkod70a6e72016-02-18 18:52:47483 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24484 m_sc.function = sc.function;
Eugene Zelenkod70a6e72016-02-18 18:52:47485 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24486 m_sc.block = sc.block;
Eugene Zelenkod70a6e72016-02-18 18:52:47487 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr)
Greg Clayton9da7bd02010-08-24 21:05:24488 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06489 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
490 {
Greg Clayton9da7bd02010-08-24 21:05:24491 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06492 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:24501 }
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:24508 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33509 {
Greg Clayton75a03332012-11-29 00:53:06510 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33511 }
Greg Clayton9da7bd02010-08-24 21:05:24512 }
Chris Lattner30fdc8d2010-06-08 16:52:24513
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:24516 // 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:24520 }
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:24527VariableList *
Greg Clayton288bdf92010-09-02 02:59:18528StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24529{
Jason Molenda6a354702014-10-02 01:08:16530 Mutex::Locker locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24531 if (m_flags.IsClear(RESOLVED_VARIABLES))
532 {
533 m_flags.Set(RESOLVED_VARIABLES);
534
Greg Clayton95897c62010-09-07 04:20:48535 Block *frame_block = GetFrameBlock();
536
537 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24538 {
Greg Clayton95897c62010-09-07 04:20:48539 const bool get_child_variables = true;
540 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16541 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:24544 }
Sean Callanan7c0962d2010-11-01 04:38:59545 }
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:18551
Sean Callanan7c0962d2010-11-01 04:38:59552 if (m_flags.IsClear (eSymbolContextCompUnit))
553 GetSymbolContext (eSymbolContextCompUnit);
554
555 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18556 {
Sean Callanan7c0962d2010-11-01 04:38:59557 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:18562 }
Chris Lattner30fdc8d2010-06-08 16:52:24563 }
Sean Callanan7c0962d2010-11-01 04:38:59564
Chris Lattner30fdc8d2010-06-08 16:52:24565 return m_variable_list_sp.get();
566}
567
Greg Claytond41f0322011-08-02 23:35:43568VariableListSP
569StackFrame::GetInScopeVariableList (bool get_file_globals)
570{
Jason Molenda6a354702014-10-02 01:08:16571 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:52572 // 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:43576 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:41590 if (m_sc.comp_unit && get_file_globals)
Greg Claytond41f0322011-08-02 23:35:43591 {
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:59600ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55601StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22602 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18603 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22604 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18605 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59606{
Jason Molenda99618472013-11-04 11:02:52607 // 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:08610
611 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59612 {
Greg Clayton6d5e68e2011-01-20 19:27:18613 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
614 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56615 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10616 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08617 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:43622 // 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:08626
627 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59628 {
Greg Clayton54979cd2010-12-15 05:08:08629 // 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:59632 {
Greg Clayton54979cd2010-12-15 05:08:08633 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:57652 var_sp = variable_list->FindVariable(name_const_string, false);
Greg Clayton685c88c2012-07-14 00:53:55653
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:58660
661 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess))
Greg Clayton685c88c2012-07-14 00:53:55662 {
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:58683
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:55711
Enrico Granata46252392015-11-19 22:28:58712 if (var_sp && !valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08713 {
Jim Ingham2837b762011-05-04 03:43:18714 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13715 if (!valobj_sp)
716 return valobj_sp;
Enrico Granata46252392015-11-19 22:28:58717 }
718 if (valobj_sp)
719 {
Greg Clayton54979cd2010-12-15 05:08:08720 // We are dumping at least one child
721 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59722 {
Greg Clayton54979cd2010-12-15 05:08:08723 // 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:59727 {
Greg Clayton54979cd2010-12-15 05:08:08728 case '-':
729 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59730 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59731
Greg Clayton6d5e68e2011-01-20 19:27:18732 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:47736 const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo(nullptr);
Enrico Granata622be232014-10-21 20:52:14737 if ((pointer_type_flags & eTypeIsObjC) &&
738 (pointer_type_flags & eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18739 {
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:08746 var_path.erase (0, 1); // Remove the '-'
Jason Molenda62e06812016-02-16 04:14:33747 LLVM_FALLTHROUGH;
Greg Clayton54979cd2010-12-15 05:08:08748 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59749 {
Greg Clayton54979cd2010-12-15 05:08:08750 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59751
Greg Clayton54979cd2010-12-15 05:08:08752 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:59757 else
Greg Clayton54979cd2010-12-15 05:08:08758 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
759
760 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59761 {
Greg Clayton54979cd2010-12-15 05:08:08762 // 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:26772 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08773 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:59787 }
Greg Clayton54979cd2010-12-15 05:08:08788 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59789 if (!child_valobj_sp)
790 {
Eugene Zelenkod70a6e72016-02-18 18:52:47791 if (!no_synth_child)
Enrico Granata86cc9822012-03-19 22:58:49792 {
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:01797
798 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08799 {
Enrico Granata8c9d3562011-08-11 17:08:01800 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55801 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01802 {
Greg Clayton685c88c2012-07-14 00:53:55803 // 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:01808 }
809 else
810 {
Greg Clayton685c88c2012-07-14 00:53:55811 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:01825 }
826 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08827 }
Greg Clayton8b2fe6d2010-12-14 02:59:59828 }
Greg Clayton685c88c2012-07-14 00:53:55829 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08830 // Remove the child name from the path
831 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22832 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13833 {
Jim Ingham2837b762011-05-04 03:43:18834 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13835 if (dynamic_value_sp)
836 child_valobj_sp = dynamic_value_sp;
837 }
Greg Clayton54979cd2010-12-15 05:08:08838 }
839 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59840
Greg Clayton54979cd2010-12-15 05:08:08841 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:47845 char *end = nullptr;
Greg Clayton1a65ae12011-01-25 23:55:37846 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41847 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:08849 {
Greg Clayton99558cc42015-08-24 23:46:31850 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41851 {
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:31868 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41869 {
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:54888 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08889 if (valobj_sp->IsPointerType ())
890 {
Sean Callanan226b70c2012-03-08 02:39:03891 bool is_objc_pointer = true;
892
Greg Clayton99558cc42015-08-24 23:46:31893 if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03894 is_objc_pointer = false;
Greg Clayton99558cc42015-08-24 23:46:31895 else if (!valobj_sp->GetCompilerType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03896 is_objc_pointer = false;
897
898 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08899 {
Sean Callanan226b70c2012-03-08 02:39:03900 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:56908 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49909 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Eugene Zelenkod70a6e72016-02-18 18:52:47910 if (!synthetic /* no synthetic */
Enrico Granata27b625e2011-08-09 01:04:56911 || 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:35918 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56919 {
920 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08921 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56922 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:08932 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56933 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:39941 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
Enrico Granata27b625e2011-08-09 01:04:56942 if (!child_valobj_sp)
943 {
944 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08945 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56946 child_index,
947 valobj_sp->GetTypeName().AsCString("<invalid type>"),
948 var_expr_path_strm.GetString().c_str());
949 }
Greg Clayton54979cd2010-12-15 05:08:08950 }
951 }
Eugene Zelenkod70a6e72016-02-18 18:52:47952 else if (valobj_sp->GetCompilerType().IsArrayType(nullptr, nullptr, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08953 {
Jim Ingham78a685a2011-04-16 00:01:13954 // 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:08956 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Eugene Zelenkod70a6e72016-02-18 18:52:47957 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
Greg Clayton4ef877f2012-12-06 02:33:54958 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
959
Greg Clayton54979cd2010-12-15 05:08:08960 if (!child_valobj_sp)
961 {
Greg Clayton6beaaa62011-01-17 03:46:26962 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08963 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08964 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:31969 else if (valobj_sp->GetCompilerType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41970 {
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:08976 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41977 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:08982 else
983 {
Enrico Granata86cc9822012-03-19 22:58:49984 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56985 if (no_synth_child /* synthetic is forbidden */ ||
Eugene Zelenkod70a6e72016-02-18 18:52:47986 !synthetic /* no synthetic */
Enrico Granata27b625e2011-08-09 01:04:56987 || 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:35994 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56995 {
996 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08997 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56998 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:081008 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:561009 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:081014 }
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:221026 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:131027 {
Jim Ingham2837b762011-05-04 03:43:181028 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:131029 if (dynamic_value_sp)
1030 child_valobj_sp = dynamic_value_sp;
1031 }
Greg Clayton54979cd2010-12-15 05:08:081032 // 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:251036 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:411037 {
1038 // this is most probably a BitField, let's take a look
Eugene Zelenkod70a6e72016-02-18 18:52:471039 char *real_end = nullptr;
Enrico Granata9fc19442011-07-06 02:13:411040 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:461041 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:251042 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:411043 {
1044 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:251045 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:411046 {
1047 long temp = child_index;
1048 child_index = final_index;
1049 final_index = temp;
1050 }
1051
Greg Clayton99558cc42015-08-24 23:46:311052 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:411053 {
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:311070 else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:411071 {
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:461089 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:411090 {
Enrico Granatad64d0bc2011-08-19 21:13:461091 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:081109 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:461110 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:411114 }
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:221127 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:411128 {
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:081144 }
1145 return ValueObjectSP();
1146
1147 default:
1148 // Failure...
1149 {
Greg Clayton6beaaa62011-01-17 03:46:261150 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:081151 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:591157 }
1158 }
Greg Clayton8b2fe6d2010-12-14 02:59:591159
Greg Clayton54979cd2010-12-15 05:08:081160 if (child_valobj_sp)
1161 valobj_sp = child_valobj_sp;
1162
1163 if (var_path.empty())
1164 break;
Greg Clayton8b2fe6d2010-12-14 02:59:591165 }
Greg Clayton54979cd2010-12-15 05:08:081166 if (valobj_sp)
1167 {
1168 if (deref)
1169 {
Greg Claytonaf67cec2010-12-20 20:49:231170 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:081171 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:591180 }
Greg Clayton54979cd2010-12-15 05:08:081181 else
Greg Clayton8b2fe6d2010-12-14 02:59:591182 {
Jim Ingham2837b762011-05-04 03:43:181183 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1184 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:591185 }
Greg Clayton8b2fe6d2010-12-14 02:59:591186 }
1187 }
Greg Clayton54979cd2010-12-15 05:08:081188 else
1189 {
1190 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1191 }
Greg Clayton8b2fe6d2010-12-14 02:59:591192 return ValueObjectSP();
1193}
Chris Lattner30fdc8d2010-06-08 16:52:241194
1195bool
1196StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1197{
Jason Molenda6a354702014-10-02 01:08:161198 Mutex::Locker locker(m_mutex);
Eugene Zelenkod70a6e72016-02-18 18:52:471199 if (!m_cfa_is_valid)
Jason Molenda99618472013-11-04 11:02:521200 {
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:241205 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:261213 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:241214 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:481215 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1216 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:261217 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:481218
Eugene Zelenkod70a6e72016-02-18 18:52:471219 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:241221 {
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:581229 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:241230 }
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:061246RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:241247StackFrame::GetRegisterContext ()
1248{
Jason Molenda6a354702014-10-02 01:08:161249 Mutex::Locker locker(m_mutex);
Greg Clayton5ccbd292011-01-06 22:15:061250 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:261251 {
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:061256 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:241257}
1258
1259bool
1260StackFrame::HasDebugInformation ()
1261{
Greg Clayton9da7bd02010-08-24 21:05:241262 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:241263 return m_sc.line_entry.IsValid();
1264}
1265
Greg Clayton288bdf92010-09-02 02:59:181266ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:221267StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:241268{
Jason Molenda6a354702014-10-02 01:08:161269 Mutex::Locker locker(m_mutex);
Greg Clayton288bdf92010-09-02 02:59:181270 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:521271 if (m_is_history_frame)
1272 {
1273 return valobj_sp;
1274 }
Greg Clayton288bdf92010-09-02 02:59:181275 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:471284 if (!valobj_sp)
Greg Clayton288bdf92010-09-02 02:59:181285 {
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:531288 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:181289 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1290 }
1291 }
1292 }
Greg Clayton4d122c42011-09-17 08:33:221293 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:131294 {
Jim Ingham2837b762011-05-04 03:43:181295 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:131296 if (dynamic_sp)
1297 return dynamic_sp;
1298 }
Greg Clayton288bdf92010-09-02 02:59:181299 return valobj_sp;
1300}
1301
1302ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:221303StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:181304{
Jason Molenda6a354702014-10-02 01:08:161305 Mutex::Locker locker(m_mutex);
Jason Molenda99618472013-11-04 11:02:521306 if (m_is_history_frame)
1307 return ValueObjectSP();
1308
Greg Clayton288bdf92010-09-02 02:59:181309 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:131310 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:181311 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:471316 if (var_list == nullptr)
Greg Clayton288bdf92010-09-02 02:59:181317 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:131323 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:181324 }
1325 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:241326}
1327
Jim Ingham6b8379c2010-08-26 20:44:451328bool
1329StackFrame::IsInlined ()
1330{
Eugene Zelenkod70a6e72016-02-18 18:52:471331 if (m_sc.block == nullptr)
Greg Clayton59e8fc1c2010-08-30 18:11:351332 GetSymbolContext (eSymbolContextBlock);
1333 if (m_sc.block)
Eugene Zelenkod70a6e72016-02-18 18:52:471334 return m_sc.block->GetContainingInlinedBlock() != nullptr;
Greg Clayton59e8fc1c2010-08-30 18:11:351335 return false;
Jim Ingham6b8379c2010-08-26 20:44:451336}
1337
Dawn Perchik009d1102015-09-04 01:02:301338lldb::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:261347TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:241348StackFrame::CalculateTarget ()
1349{
Greg Claytond9e416c2012-02-18 05:35:261350 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:241359}
1360
Greg Claytond9e416c2012-02-18 05:35:261361ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:241362StackFrame::CalculateProcess ()
1363{
Greg Claytond9e416c2012-02-18 05:35:261364 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:241369}
1370
Greg Claytond9e416c2012-02-18 05:35:261371ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:241372StackFrame::CalculateThread ()
1373{
Greg Claytond9e416c2012-02-18 05:35:261374 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:241375}
1376
Jason Molendab57e4a1b2013-11-04 09:33:301377StackFrameSP
1378StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:241379{
Greg Claytond9e416c2012-02-18 05:35:261380 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:241381}
1382
Chris Lattner30fdc8d2010-06-08 16:52:241383void
Greg Clayton0603aa92010-10-04 01:05:561384StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:241385{
Greg Claytond9e416c2012-02-18 05:35:261386 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:241387}
1388
1389void
Jim Ingham8ec10ef2013-10-18 17:38:311390StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:561391{
Eugene Zelenkod70a6e72016-02-18 18:52:471392 if (strm == nullptr)
Greg Clayton0603aa92010-10-04 01:05:561393 return;
1394
1395 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:261396 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:561397 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:311398
1399 if (frame_marker)
1400 s.PutCString(frame_marker);
1401
Eugene Zelenkod70a6e72016-02-18 18:52:471402 const FormatEntity::Entry *frame_format = nullptr;
Greg Claytond9e416c2012-02-18 05:35:261403 Target *target = exe_ctx.GetTargetPtr();
1404 if (target)
1405 frame_format = target->GetDebugger().GetFrameFormat();
Eugene Zelenkod70a6e72016-02-18 18:52:471406 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, nullptr, nullptr, false, false))
Greg Clayton0603aa92010-10-04 01:05:561407 {
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:101418StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:241419{
Eugene Zelenkod70a6e72016-02-18 18:52:471420 if (strm == nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:241421 return;
1422
1423 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:411424 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:261425 ExecutionContext exe_ctx (shared_from_this());
1426 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:151427 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:261428 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1429 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:241430 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:411431 const bool show_module = true;
1432 const bool show_inline = true;
Jason Molendaaff1b352014-10-10 23:07:361433 const bool show_function_arguments = true;
Jason Molendac980fa92015-02-13 23:24:211434 const bool show_function_name = true;
Greg Claytond9e416c2012-02-18 05:35:261435 m_sc.DumpStopContext (strm,
1436 exe_ctx.GetBestExecutionContextScope(),
1437 GetFrameCodeAddress(),
1438 show_fullpaths,
1439 show_module,
Jason Molendaaff1b352014-10-10 23:07:361440 show_inline,
Jason Molendac980fa92015-02-13 23:24:211441 show_function_arguments,
1442 show_function_name);
Chris Lattner30fdc8d2010-06-08 16:52:241443}
1444
Greg Clayton5082c5f2010-08-27 18:24:161445void
Jason Molendab57e4a1b2013-11-04 09:33:301446StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:161447{
Jason Molenda6a354702014-10-02 01:08:161448 Mutex::Locker locker(m_mutex);
Greg Clayton59e8fc1c2010-08-30 18:11:351449 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a1b2013-11-04 09:33:301450 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:161454}
Greg Clayton68275d52010-08-27 21:47:541455
Greg Clayton59e8fc1c2010-08-30 18:11:351456void
Jason Molendab57e4a1b2013-11-04 09:33:301457StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:351458{
Jason Molenda6a354702014-10-02 01:08:161459 Mutex::Locker locker(m_mutex);
Greg Clayton2cad65a2010-09-03 17:10:421460 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a1b2013-11-04 09:33:301461 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:471467 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 Molendab57e4a1b2013-11-04 09:33:301471 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:351476}
1477
Greg Clayton2cad65a2010-09-03 17:10:421478bool
Jason Molendab57e4a1b2013-11-04 09:33:301479StackFrame::HasCachedData () const
1480{
Eugene Zelenkod70a6e72016-02-18 18:52:471481 if (m_variable_list_sp)
Jason Molendab57e4a1b2013-11-04 09:33:301482 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:371491StackFrame::GetStatus (Stream& strm,
1492 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:311493 bool show_source,
1494 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:371495{
Greg Clayton53eb7ad2012-07-11 20:33:481496
Greg Clayton7260f622011-04-18 08:33:371497 if (show_frame_info)
1498 {
1499 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:311500 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:371501 }
1502
1503 if (show_source)
1504 {
Greg Claytond9e416c2012-02-18 05:35:261505 ExecutionContext exe_ctx (shared_from_this());
Mohit K. Bhakkad8be74992015-12-03 04:56:161506 bool have_source = false, have_debuginfo = false;
Greg Clayton67cc0632012-08-22 17:17:091507 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:261508 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:481509 if (target)
Greg Clayton7260f622011-04-18 08:33:371510 {
Greg Clayton53eb7ad2012-07-11 20:33:481511 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:341515
Todd Fiala6d1fbc92014-07-07 20:47:241516 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1517 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:341518 {
Mohit K. Bhakkad8be74992015-12-03 04:56:161519 have_debuginfo = true;
Todd Fiala6d1fbc92014-07-07 20:47:241520 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:341521 {
Mohit K. Bhakkad8be74992015-12-03 04:56:161522 size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:481523 m_sc.line_entry.line,
1524 source_lines_before,
1525 source_lines_after,
1526 "->",
Jason Molenda7cd81c52013-04-29 09:59:311527 &strm);
Mohit K. Bhakkad8be74992015-12-03 04:56:161528 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:341531 }
1532 }
Greg Clayton53eb7ad2012-07-11 20:33:481533 switch (disasm_display)
1534 {
Greg Clayton67cc0632012-08-22 17:17:091535 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:341536 break;
Mohit K. Bhakkad8be74992015-12-03 04:56:161537
1538 case Debugger::eStopDisassemblyTypeNoDebugInfo:
1539 if (have_debuginfo)
1540 break;
Jason Molenda62e06812016-02-16 04:14:331541 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:161542
Greg Clayton67cc0632012-08-22 17:17:091543 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:481544 if (have_source)
1545 break;
Jason Molenda62e06812016-02-16 04:14:331546 LLVM_FALLTHROUGH;
Mohit K. Bhakkad8be74992015-12-03 04:56:161547
Greg Clayton67cc0632012-08-22 17:17:091548 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:481549 if (target)
Greg Claytone372b982011-11-21 21:44:341550 {
Greg Clayton53eb7ad2012-07-11 20:33:481551 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:471558 const char *plugin_name = nullptr;
1559 const char *flavor = nullptr;
Greg Clayton53eb7ad2012-07-11 20:33:481560 Disassembler::Disassemble (target->GetDebugger(),
1561 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:471562 plugin_name,
1563 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:481564 exe_ctx,
1565 pc_range,
1566 disasm_lines,
1567 0,
1568 Disassembler::eOptionMarkPCAddress,
1569 strm);
1570 }
Greg Claytone372b982011-11-21 21:44:341571 }
Greg Clayton53eb7ad2012-07-11 20:33:481572 break;
Greg Claytone372b982011-11-21 21:44:341573 }
Greg Clayton7260f622011-04-18 08:33:371574 }
1575 }
1576 return true;
1577}