blob: e497b176ccfe2fc16abc5cacbd89de9354ede5ff [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- StackFrame.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Target/StackFrame.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/Module.h"
Greg Clayton0603aa92010-10-04 01:05:56 +000019#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/Disassembler.h"
21#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000022#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:08 +000023#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Symbol/Symbol.h"
27#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton288bdf92010-09-02 02:59:18 +000028#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Target/ExecutionContext.h"
30#include "lldb/Target/Process.h"
31#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38// The first bits in the flags are reserved for the SymbolContext::Scope bits
39// so we know if we have tried to look up information in our internal symbol
40// context (m_sc) already.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000041#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:10 +000042#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +000043#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
44#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:59 +000045#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046
Greg Claytond9e416c2012-02-18 05:35:26 +000047StackFrame::StackFrame (const ThreadSP &thread_sp,
48 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000049 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000050 addr_t cfa,
Jason Molenda99618472013-11-04 11:02:52 +000051 bool cfa_is_valid,
Greg Clayton8f7180b2011-09-26 07:11:27 +000052 addr_t pc,
Jason Molenda99618472013-11-04 11:02:52 +000053 uint32_t stop_id,
54 bool stop_id_is_valid,
55 bool is_history_frame,
Greg Clayton8f7180b2011-09-26 07:11:27 +000056 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000057 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000058 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000059 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000060 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:10 +000061 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +000062 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000063 m_sc (),
64 m_flags (),
65 m_frame_base (),
66 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +000067 m_cfa_is_valid (cfa_is_valid),
68 m_stop_id (stop_id),
69 m_stop_id_is_valid (stop_id_is_valid),
70 m_is_history_frame (is_history_frame),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +000072 m_variable_list_value_objects (),
73 m_disassembly ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074{
Jason Molenda99618472013-11-04 11:02:52 +000075 // If we don't have a CFA value, use the frame index for our StackID so that recursive
76 // functions properly aren't confused with one another on a history stack.
77 if (m_is_history_frame && m_cfa_is_valid == false)
78 {
79 m_id.SetCFA (m_frame_index);
80 }
81
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +000083 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +000085 m_flags.Set(m_sc.GetResolvedMask ());
86 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
Greg Claytond9e416c2012-02-18 05:35:26 +000089StackFrame::StackFrame (const ThreadSP &thread_sp,
90 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +000091 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +000092 const RegisterContextSP &reg_context_sp,
93 addr_t cfa,
94 addr_t pc,
95 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +000096 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000097 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +000098 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +000099 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:10 +0000100 m_id (pc, cfa, NULL),
Greg Claytone72dfb32012-02-24 01:59:29 +0000101 m_frame_code_addr (pc),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000102 m_sc (),
103 m_flags (),
104 m_frame_base (),
105 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000106 m_cfa_is_valid (true),
107 m_stop_id (0),
108 m_stop_id_is_valid (false),
109 m_is_history_frame (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000111 m_variable_list_value_objects (),
112 m_disassembly ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113{
114 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000115 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000117 m_flags.Set(m_sc.GetResolvedMask ());
118 }
119
120 if (reg_context_sp && !m_sc.target_sp)
121 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000122 m_sc.target_sp = reg_context_sp->CalculateTarget();
123 if (m_sc.target_sp)
124 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000125 }
126}
127
Greg Claytond9e416c2012-02-18 05:35:26 +0000128StackFrame::StackFrame (const ThreadSP &thread_sp,
129 user_id_t frame_idx,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000130 user_id_t unwind_frame_index,
Greg Clayton8f7180b2011-09-26 07:11:27 +0000131 const RegisterContextSP &reg_context_sp,
132 addr_t cfa,
133 const Address& pc_addr,
134 const SymbolContext *sc_ptr) :
Greg Claytond9e416c2012-02-18 05:35:26 +0000135 m_thread_wp (thread_sp),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000136 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06 +0000137 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000138 m_reg_context_sp (reg_context_sp),
Greg Clayton1ac04c32012-02-21 00:09:25 +0000139 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43 +0000140 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000141 m_sc (),
142 m_flags (),
143 m_frame_base (),
144 m_frame_base_error (),
Jason Molenda99618472013-11-04 11:02:52 +0000145 m_cfa_is_valid (true),
146 m_stop_id (0),
147 m_stop_id_is_valid (false),
148 m_is_history_frame (false),
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000149 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000150 m_variable_list_value_objects (),
151 m_disassembly ()
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000152{
153 if (sc_ptr != NULL)
154 {
155 m_sc = *sc_ptr;
156 m_flags.Set(m_sc.GetResolvedMask ());
157 }
158
159 if (m_sc.target_sp.get() == NULL && reg_context_sp)
160 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000161 m_sc.target_sp = reg_context_sp->CalculateTarget();
162 if (m_sc.target_sp)
163 m_flags.Set (eSymbolContextTarget);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000164 }
165
Greg Claytone72dfb32012-02-24 01:59:29 +0000166 ModuleSP pc_module_sp (pc_addr.GetModule());
167 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000168 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000169 if (pc_module_sp)
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000170 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000171 m_sc.module_sp = pc_module_sp;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000172 m_flags.Set (eSymbolContextModule);
173 }
Greg Claytonffc1d662010-09-13 04:34:30 +0000174 else
175 {
176 m_sc.module_sp.reset();
177 }
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000178 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179}
180
181
182//----------------------------------------------------------------------
183// Destructor
184//----------------------------------------------------------------------
185StackFrame::~StackFrame()
186{
187}
188
189StackID&
190StackFrame::GetStackID()
191{
Greg Clayton6dadd502010-09-02 21:44:10 +0000192 // Make sure we have resolved the StackID object's symbol context scope if
193 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000195 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
196 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000197 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000198 {
Greg Clayton95897c62010-09-07 04:20:48 +0000199 // We already have a symbol context scope, we just don't have our
200 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000201 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
202 }
203 else
204 {
Greg Clayton95897c62010-09-07 04:20:48 +0000205 // Calculate the frame block and use this for the stack ID symbol
206 // context scope if we have one.
207 SymbolContextScope *scope = GetFrameBlock ();
208 if (scope == NULL)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000209 {
Greg Clayton95897c62010-09-07 04:20:48 +0000210 // We don't have a block, so use the symbol
211 if (m_flags.IsClear (eSymbolContextSymbol))
212 GetSymbolContext (eSymbolContextSymbol);
213
214 // It is ok if m_sc.symbol is NULL here
215 scope = m_sc.symbol;
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000216 }
Greg Clayton95897c62010-09-07 04:20:48 +0000217 // Set the symbol context scope (the accessor will set the
218 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
219 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000220 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221 }
222 return m_id;
223}
224
Jim Ingham513c6bb2012-09-01 01:02:41 +0000225uint32_t
226StackFrame::GetFrameIndex () const
227{
228 ThreadSP thread_sp = GetThread();
229 if (thread_sp)
Jason Molendab57e4a12013-11-04 09:33:30 +0000230 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
Jim Ingham513c6bb2012-09-01 01:02:41 +0000231 else
232 return m_frame_index;
233}
234
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000235void
236StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
237{
238 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
239 m_id.SetSymbolContextScope (symbol_scope);
240}
241
Greg Clayton34132752011-07-06 04:07:21 +0000242const Address&
Greg Clayton9da7bd02010-08-24 21:05:24 +0000243StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000245 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246 {
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000247 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248
249 // Resolve the PC into a temporary address because if ResolveLoadAddress
250 // fails to resolve the address, it will clear the address object...
Greg Claytond9e416c2012-02-18 05:35:26 +0000251 ThreadSP thread_sp (GetThread());
252 if (thread_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000254 TargetSP target_sp (thread_sp->CalculateTarget());
255 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000257 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000259 ModuleSP module_sp (m_frame_code_addr.GetModule());
260 if (module_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +0000261 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000262 m_sc.module_sp = module_sp;
263 m_flags.Set(eSymbolContextModule);
Greg Claytond9e416c2012-02-18 05:35:26 +0000264 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 }
266 }
267 }
268 }
Greg Clayton12fc3e02010-08-26 22:05:43 +0000269 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
Jason Molenda99618472013-11-04 11:02:52 +0000272bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273StackFrame::ChangePC (addr_t pc)
274{
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{
290 if (m_disassembly.GetSize() == 0)
291 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000292 ExecutionContext exe_ctx (shared_from_this());
293 Target *target = exe_ctx.GetTargetPtr();
294 if (target)
295 {
Jim Ingham0f063ba2013-03-02 00:26:47 +0000296 const char *plugin_name = NULL;
297 const char *flavor = NULL;
Greg Claytond9e416c2012-02-18 05:35:26 +0000298 Disassembler::Disassemble (target->GetDebugger(),
299 target->GetArchitecture(),
Jim Ingham0f063ba2013-03-02 00:26:47 +0000300 plugin_name,
301 flavor,
Greg Claytond9e416c2012-02-18 05:35:26 +0000302 exe_ctx,
303 0,
304 0,
305 0,
306 m_disassembly);
307 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308 if (m_disassembly.GetSize() == 0)
309 return NULL;
310 }
311 return m_disassembly.GetData();
312}
313
Greg Clayton95897c62010-09-07 04:20:48 +0000314Block *
315StackFrame::GetFrameBlock ()
316{
317 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
318 GetSymbolContext (eSymbolContextBlock);
319
320 if (m_sc.block)
321 {
322 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
323 if (inline_block)
324 {
325 // Use the block with the inlined function info
326 // as the frame block we want this frame to have only the variables
327 // for the inlined function and its non-inlined block child blocks.
328 return inline_block;
329 }
330 else
331 {
332 // This block is not contained withing any inlined function blocks
333 // with so we want to use the top most function block.
334 return &m_sc.function->GetBlock (false);
335 }
336 }
337 return NULL;
338}
339
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340//----------------------------------------------------------------------
341// Get the symbol context if we already haven't done so by resolving the
342// PC address as much as possible. This way when we pass around a
343// StackFrame object, everyone will have as much information as
344// possible and no one will ever have to look things up manually.
345//----------------------------------------------------------------------
346const SymbolContext&
347StackFrame::GetSymbolContext (uint32_t resolve_scope)
348{
349 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59 +0000350 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 {
Greg Clayton75a03332012-11-29 00:53:06 +0000352 uint32_t resolved = 0;
353
354 // If the target was requested add that:
355 if (!m_sc.target_sp)
356 {
357 m_sc.target_sp = CalculateTarget();
358 if (m_sc.target_sp)
359 resolved |= eSymbolContextTarget;
360 }
361
362
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +0000363 // Resolve our PC to section offset if we haven't already done so
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364 // and if we don't have a module. The resolved address section will
365 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35 +0000366 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24 +0000367 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368
369 // If this is not frame zero, then we need to subtract 1 from the PC
370 // value when doing address lookups since the PC will be on the
371 // instruction following the function call instruction...
372
Greg Clayton9da7bd02010-08-24 21:05:24 +0000373 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000374 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 {
376 addr_t offset = lookup_addr.GetOffset();
377 if (offset > 0)
378 lookup_addr.SetOffset(offset - 1);
379 }
380
Greg Clayton9da7bd02010-08-24 21:05:24 +0000381
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382 if (m_sc.module_sp)
383 {
384 // We have something in our stack frame symbol context, lets check
385 // if we haven't already tried to lookup one of those things. If we
386 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000387
388 uint32_t actual_resolve_scope = 0;
389
390 if (resolve_scope & eSymbolContextCompUnit)
391 {
392 if (m_flags.IsClear (eSymbolContextCompUnit))
393 {
394 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000395 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000396 else
397 actual_resolve_scope |= eSymbolContextCompUnit;
398 }
399 }
400
401 if (resolve_scope & eSymbolContextFunction)
402 {
403 if (m_flags.IsClear (eSymbolContextFunction))
404 {
405 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000406 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000407 else
408 actual_resolve_scope |= eSymbolContextFunction;
409 }
410 }
411
412 if (resolve_scope & eSymbolContextBlock)
413 {
414 if (m_flags.IsClear (eSymbolContextBlock))
415 {
416 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000417 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000418 else
419 actual_resolve_scope |= eSymbolContextBlock;
420 }
421 }
422
423 if (resolve_scope & eSymbolContextSymbol)
424 {
425 if (m_flags.IsClear (eSymbolContextSymbol))
426 {
427 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24 +0000428 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000429 else
430 actual_resolve_scope |= eSymbolContextSymbol;
431 }
432 }
433
434 if (resolve_scope & eSymbolContextLineEntry)
435 {
436 if (m_flags.IsClear (eSymbolContextLineEntry))
437 {
438 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24 +0000439 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000440 else
441 actual_resolve_scope |= eSymbolContextLineEntry;
442 }
443 }
444
445 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 {
447 // We might be resolving less information than what is already
448 // in our current symbol context so resolve into a temporary
449 // symbol context "sc" so we don't clear out data we have
450 // already found in "m_sc"
451 SymbolContext sc;
452 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24 +0000453 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000454 // Only replace what we didn't already have as we may have
455 // information for an inlined function scope that won't match
456 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24 +0000457 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
458 m_sc.comp_unit = sc.comp_unit;
459 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
460 m_sc.function = sc.function;
461 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
462 m_sc.block = sc.block;
463 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
464 m_sc.symbol = sc.symbol;
Greg Clayton75a03332012-11-29 00:53:06 +0000465 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
466 {
Greg Clayton9da7bd02010-08-24 21:05:24 +0000467 m_sc.line_entry = sc.line_entry;
Greg Clayton75a03332012-11-29 00:53:06 +0000468 if (m_sc.target_sp)
469 {
470 // Be sure to apply and file remappings to our file and line
471 // entries when handing out a line entry
472 FileSpec new_file_spec;
473 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
474 m_sc.line_entry.file = new_file_spec;
475 }
476 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 }
478 }
479 else
480 {
481 // If we don't have a module, then we can't have the compile unit,
482 // function, block, line entry or symbol, so we can safely call
483 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000484 if (m_sc.target_sp)
Sean Callananf4be2272013-02-21 20:54:33 +0000485 {
Greg Clayton75a03332012-11-29 00:53:06 +0000486 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callananf4be2272013-02-21 20:54:33 +0000487 }
Greg Clayton9da7bd02010-08-24 21:05:24 +0000488 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489
490 // Update our internal flags so we remember what we have tried to locate so
491 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24 +0000492 // We might have dug up more information that was requested (for example
493 // if we were asked to only get the block, we will have gotten the
494 // compile unit, and function) so set any additional bits that we resolved
495 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496 }
497
498 // Return the symbol context with everything that was possible to resolve
499 // resolved.
500 return m_sc;
501}
502
503
504VariableList *
Greg Clayton288bdf92010-09-02 02:59:18 +0000505StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506{
507 if (m_flags.IsClear(RESOLVED_VARIABLES))
508 {
509 m_flags.Set(RESOLVED_VARIABLES);
510
Greg Clayton95897c62010-09-07 04:20:48 +0000511 Block *frame_block = GetFrameBlock();
512
513 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 {
Greg Clayton95897c62010-09-07 04:20:48 +0000515 const bool get_child_variables = true;
516 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16 +0000517 const bool stop_if_child_block_is_inlined_function = true;
518 m_variable_list_sp.reset(new VariableList());
519 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 +0000520 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000521 }
522
523 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
524 get_file_globals)
525 {
526 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18 +0000527
Sean Callanan7c0962d2010-11-01 04:38:59 +0000528 if (m_flags.IsClear (eSymbolContextCompUnit))
529 GetSymbolContext (eSymbolContextCompUnit);
530
531 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18 +0000532 {
Sean Callanan7c0962d2010-11-01 04:38:59 +0000533 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
534 if (m_variable_list_sp)
535 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
536 else
537 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18 +0000538 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539 }
Sean Callanan7c0962d2010-11-01 04:38:59 +0000540
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 return m_variable_list_sp.get();
542}
543
Greg Claytond41f0322011-08-02 23:35:43 +0000544VariableListSP
545StackFrame::GetInScopeVariableList (bool get_file_globals)
546{
Jason Molenda99618472013-11-04 11:02:52 +0000547 // We can't fetch variable information for a history stack frame.
548 if (m_is_history_frame)
549 return VariableListSP();
550
Greg Claytond41f0322011-08-02 23:35:43 +0000551 VariableListSP var_list_sp(new VariableList);
552 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
553
554 if (m_sc.block)
555 {
556 const bool can_create = true;
557 const bool get_parent_variables = true;
558 const bool stop_if_block_is_inlined_function = true;
559 m_sc.block->AppendVariables (can_create,
560 get_parent_variables,
561 stop_if_block_is_inlined_function,
562 var_list_sp.get());
563 }
564
565 if (m_sc.comp_unit)
566 {
567 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
568 if (global_variable_list_sp)
569 var_list_sp->AddVariables (global_variable_list_sp.get());
570 }
571
572 return var_list_sp;
573}
574
575
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000576ValueObjectSP
Greg Clayton685c88c2012-07-14 00:53:55 +0000577StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton4d122c42011-09-17 08:33:22 +0000578 DynamicValueType use_dynamic,
Jim Ingham2837b762011-05-04 03:43:18 +0000579 uint32_t options,
Greg Clayton4d122c42011-09-17 08:33:22 +0000580 VariableSP &var_sp,
Jim Ingham2837b762011-05-04 03:43:18 +0000581 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000582{
Jason Molenda99618472013-11-04 11:02:52 +0000583 // We can't fetch variable information for a history stack frame.
584 if (m_is_history_frame)
585 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000586
587 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000588 {
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000589 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
590 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granata27b625e2011-08-09 01:04:56 +0000591 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata58ad3342011-08-19 21:56:10 +0000592 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Clayton54979cd2010-12-15 05:08:08 +0000593 error.Clear();
594 bool deref = false;
595 bool address_of = false;
596 ValueObjectSP valobj_sp;
597 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43 +0000598 // When looking up a variable for an expression, we need only consider the
599 // variables that are in scope.
600 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
601 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08 +0000602
603 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000604 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000605 // If first character is a '*', then show pointer contents
606 const char *var_expr = var_expr_cstr;
607 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000608 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000609 deref = true;
610 var_expr++; // Skip the '*'
611 }
612 else if (var_expr[0] == '&')
613 {
614 address_of = true;
615 var_expr++; // Skip the '&'
616 }
617
618 std::string var_path (var_expr);
619 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
620 StreamString var_expr_path_strm;
621
622 ConstString name_const_string;
623 if (separator_idx == std::string::npos)
624 name_const_string.SetCString (var_path.c_str());
625 else
626 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
627
Jim Ingham2837b762011-05-04 03:43:18 +0000628 var_sp = variable_list->FindVariable(name_const_string);
Greg Clayton685c88c2012-07-14 00:53:55 +0000629
630 bool synthetically_added_instance_object = false;
631
632 if (var_sp)
633 {
634 var_path.erase (0, name_const_string.GetLength ());
635 }
636 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
637 {
638 // Check for direct ivars access which helps us with implicit
639 // access to ivars with the "this->" or "self->"
640 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
641 lldb::LanguageType method_language = eLanguageTypeUnknown;
642 bool is_instance_method = false;
643 ConstString method_object_name;
644 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
645 {
646 if (is_instance_method && method_object_name)
647 {
648 var_sp = variable_list->FindVariable(method_object_name);
649 if (var_sp)
650 {
651 separator_idx = 0;
652 var_path.insert(0, "->");
653 synthetically_added_instance_object = true;
654 }
655 }
656 }
657 }
658
Greg Clayton54979cd2010-12-15 05:08:08 +0000659 if (var_sp)
660 {
Jim Ingham2837b762011-05-04 03:43:18 +0000661 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000662 if (!valobj_sp)
663 return valobj_sp;
664
Greg Clayton54979cd2010-12-15 05:08:08 +0000665 // We are dumping at least one child
666 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000667 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000668 // Calculate the next separator index ahead of time
669 ValueObjectSP child_valobj_sp;
670 const char separator_type = var_path[0];
671 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000672 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000673
674 case '-':
675 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000676 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000677
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000678 if (no_fragile_ivar)
679 {
680 // Make sure we aren't trying to deref an objective
681 // C ivar if this is not allowed
Greg Clayton57ee3062013-07-11 22:46:58 +0000682 const uint32_t pointer_type_flags = valobj_sp->GetClangType().GetTypeInfo (NULL);
683 if ((pointer_type_flags & ClangASTType::eTypeIsObjC) &&
684 (pointer_type_flags & ClangASTType::eTypeIsPointer))
Greg Clayton6d5e68e2011-01-20 19:27:18 +0000685 {
686 // This was an objective C object pointer and
687 // it was requested we skip any fragile ivars
688 // so return nothing here
689 return ValueObjectSP();
690 }
691 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000692 var_path.erase (0, 1); // Remove the '-'
693 // Fall through
694 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000695 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000696 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000697
Greg Clayton54979cd2010-12-15 05:08:08 +0000698 var_path.erase (0, 1); // Remove the '.' or '>'
699 separator_idx = var_path.find_first_of(".-[");
700 ConstString child_name;
701 if (separator_idx == std::string::npos)
702 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000703 else
Greg Clayton54979cd2010-12-15 05:08:08 +0000704 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
705
706 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000707 {
Greg Clayton54979cd2010-12-15 05:08:08 +0000708 // We either have a pointer type and need to verify
709 // valobj_sp is a pointer, or we have a member of a
710 // class/union/struct being accessed with the . syntax
711 // and need to verify we don't have a pointer.
712 const bool actual_is_ptr = valobj_sp->IsPointerType ();
713
714 if (actual_is_ptr != expr_is_ptr)
715 {
716 // Incorrect use of "." with a pointer, or "->" with
717 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26 +0000718 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +0000719 if (actual_is_ptr)
720 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
721 var_expr_path_strm.GetString().c_str(),
722 child_name.GetCString(),
723 var_expr_path_strm.GetString().c_str(),
724 var_path.c_str());
725 else
726 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
727 var_expr_path_strm.GetString().c_str(),
728 child_name.GetCString(),
729 var_expr_path_strm.GetString().c_str(),
730 var_path.c_str());
731 return ValueObjectSP();
732 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000733 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000734 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000735 if (!child_valobj_sp)
736 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000737 if (no_synth_child == false)
Enrico Granata86cc9822012-03-19 22:58:49 +0000738 {
739 child_valobj_sp = valobj_sp->GetSyntheticValue();
740 if (child_valobj_sp)
741 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
742 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000743
744 if (no_synth_child || !child_valobj_sp)
Greg Clayton54979cd2010-12-15 05:08:08 +0000745 {
Enrico Granata8c9d3562011-08-11 17:08:01 +0000746 // No child member with name "child_name"
Greg Clayton685c88c2012-07-14 00:53:55 +0000747 if (synthetically_added_instance_object)
Enrico Granata8c9d3562011-08-11 17:08:01 +0000748 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000749 // We added a "this->" or "self->" to the beginning of the expression
750 // and this is the first pointer ivar access, so just return the normal
751 // error
752 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
753 name_const_string.GetCString());
Enrico Granata8c9d3562011-08-11 17:08:01 +0000754 }
755 else
756 {
Greg Clayton685c88c2012-07-14 00:53:55 +0000757 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
758 if (child_name)
759 {
760 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
761 child_name.GetCString(),
762 valobj_sp->GetTypeName().AsCString("<invalid type>"),
763 var_expr_path_strm.GetString().c_str());
764 }
765 else
766 {
767 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
768 var_expr_path_strm.GetString().c_str(),
769 var_expr_cstr);
770 }
Enrico Granata8c9d3562011-08-11 17:08:01 +0000771 }
772 return ValueObjectSP();
Greg Clayton54979cd2010-12-15 05:08:08 +0000773 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000774 }
Greg Clayton685c88c2012-07-14 00:53:55 +0000775 synthetically_added_instance_object = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000776 // Remove the child name from the path
777 var_path.erase(0, child_name.GetLength());
Greg Clayton4d122c42011-09-17 08:33:22 +0000778 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000779 {
Jim Ingham2837b762011-05-04 03:43:18 +0000780 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000781 if (dynamic_value_sp)
782 child_valobj_sp = dynamic_value_sp;
783 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000784 }
785 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000786
Greg Clayton54979cd2010-12-15 05:08:08 +0000787 case '[':
788 // Array member access, or treating pointer as an array
789 if (var_path.size() > 2) // Need at least two brackets and a number
790 {
791 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +0000792 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41 +0000793 if (end && *end == ']'
794 && *(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 +0000795 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000796 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000797 {
798 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
799 // and extract bit low out of it. reading array item low
800 // would be done by saying ptr[low], without a deref * sign
801 Error error;
802 ValueObjectSP temp(valobj_sp->Dereference(error));
803 if (error.Fail())
804 {
805 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
806 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
807 valobj_sp->GetTypeName().AsCString("<invalid type>"),
808 var_expr_path_strm.GetString().c_str());
809 return ValueObjectSP();
810 }
811 valobj_sp = temp;
812 deref = false;
813 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000814 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000815 {
816 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
817 // (an operation that is equivalent to deref-ing arr)
818 // and extract bit low out of it. reading array item low
819 // would be done by saying arr[low], without a deref * sign
820 Error error;
821 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
822 if (error.Fail())
823 {
824 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
825 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
826 valobj_sp->GetTypeName().AsCString("<invalid type>"),
827 var_expr_path_strm.GetString().c_str());
828 return ValueObjectSP();
829 }
830 valobj_sp = temp;
831 deref = false;
832 }
833
Greg Clayton4ef877f2012-12-06 02:33:54 +0000834 bool is_incomplete_array = false;
Greg Clayton54979cd2010-12-15 05:08:08 +0000835 if (valobj_sp->IsPointerType ())
836 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000837 bool is_objc_pointer = true;
838
Greg Clayton57ee3062013-07-11 22:46:58 +0000839 if (valobj_sp->GetClangType().GetMinimumLanguage() != eLanguageTypeObjC)
Sean Callanan226b70c2012-03-08 02:39:03 +0000840 is_objc_pointer = false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000841 else if (!valobj_sp->GetClangType().IsPointerType())
Sean Callanan226b70c2012-03-08 02:39:03 +0000842 is_objc_pointer = false;
843
844 if (no_synth_child && is_objc_pointer)
Greg Clayton54979cd2010-12-15 05:08:08 +0000845 {
Sean Callanan226b70c2012-03-08 02:39:03 +0000846 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
847 valobj_sp->GetTypeName().AsCString("<invalid type>"),
848 var_expr_path_strm.GetString().c_str());
849
850 return ValueObjectSP();
851 }
852 else if (is_objc_pointer)
853 {
Enrico Granata27b625e2011-08-09 01:04:56 +0000854 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granata86cc9822012-03-19 22:58:49 +0000855 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000856 if (synthetic.get() == NULL /* no synthetic */
857 || synthetic == valobj_sp) /* synthetic is the same as the original object */
858 {
859 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
860 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
861 valobj_sp->GetTypeName().AsCString("<invalid type>"),
862 var_expr_path_strm.GetString().c_str());
863 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000864 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000865 {
866 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000867 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000868 child_index,
869 valobj_sp->GetTypeName().AsCString("<invalid type>"),
870 var_expr_path_strm.GetString().c_str());
871 }
872 else
873 {
874 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
875 if (!child_valobj_sp)
876 {
877 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000878 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000879 child_index,
880 valobj_sp->GetTypeName().AsCString("<invalid type>"),
881 var_expr_path_strm.GetString().c_str());
882 }
883 }
884 }
885 else
886 {
887 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
888 if (!child_valobj_sp)
889 {
890 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000891 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000892 child_index,
893 valobj_sp->GetTypeName().AsCString("<invalid type>"),
894 var_expr_path_strm.GetString().c_str());
895 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000896 }
897 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000898 else if (valobj_sp->GetClangType().IsArrayType (NULL, NULL, &is_incomplete_array))
Greg Clayton54979cd2010-12-15 05:08:08 +0000899 {
Jim Ingham78a685a2011-04-16 00:01:13 +0000900 // Pass false to dynamic_value here so we can tell the difference between
901 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08 +0000902 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000903 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
904 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
905
Greg Clayton54979cd2010-12-15 05:08:08 +0000906 if (!child_valobj_sp)
907 {
Greg Clayton6beaaa62011-01-17 03:46:26 +0000908 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000909 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Clayton54979cd2010-12-15 05:08:08 +0000910 child_index,
911 valobj_sp->GetTypeName().AsCString("<invalid type>"),
912 var_expr_path_strm.GetString().c_str());
913 }
914 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000915 else if (valobj_sp->GetClangType().IsScalarType())
Enrico Granata9fc19442011-07-06 02:13:41 +0000916 {
917 // this is a bitfield asking to display just one bit
918 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
919 if (!child_valobj_sp)
920 {
921 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000922 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9fc19442011-07-06 02:13:41 +0000923 child_index, child_index,
924 valobj_sp->GetTypeName().AsCString("<invalid type>"),
925 var_expr_path_strm.GetString().c_str());
926 }
927 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000928 else
929 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000930 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granata27b625e2011-08-09 01:04:56 +0000931 if (no_synth_child /* synthetic is forbidden */ ||
932 synthetic.get() == NULL /* no synthetic */
933 || synthetic == valobj_sp) /* synthetic is the same as the original object */
934 {
935 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
936 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
937 valobj_sp->GetTypeName().AsCString("<invalid type>"),
938 var_expr_path_strm.GetString().c_str());
939 }
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000940 else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
Enrico Granata27b625e2011-08-09 01:04:56 +0000941 {
942 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000943 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000944 child_index,
945 valobj_sp->GetTypeName().AsCString("<invalid type>"),
946 var_expr_path_strm.GetString().c_str());
947 }
948 else
949 {
950 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
951 if (!child_valobj_sp)
952 {
953 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +0000954 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granata27b625e2011-08-09 01:04:56 +0000955 child_index,
956 valobj_sp->GetTypeName().AsCString("<invalid type>"),
957 var_expr_path_strm.GetString().c_str());
958 }
959 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000960 }
961
962 if (!child_valobj_sp)
963 {
964 // Invalid array index...
965 return ValueObjectSP();
966 }
967
968 // Erase the array member specification '[%i]' where
969 // %i is the array index
970 var_path.erase(0, (end - var_path.c_str()) + 1);
971 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +0000972 if (use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +0000973 {
Jim Ingham2837b762011-05-04 03:43:18 +0000974 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13 +0000975 if (dynamic_value_sp)
976 child_valobj_sp = dynamic_value_sp;
977 }
Greg Clayton54979cd2010-12-15 05:08:08 +0000978 // Break out early from the switch since we were
979 // able to find the child member
980 break;
981 }
Enrico Granata20edcdb2011-07-19 18:03:25 +0000982 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41 +0000983 {
984 // this is most probably a BitField, let's take a look
985 char *real_end = NULL;
986 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000987 bool expand_bitfield = true;
Enrico Granata20edcdb2011-07-19 18:03:25 +0000988 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41 +0000989 {
990 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25 +0000991 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41 +0000992 {
993 long temp = child_index;
994 child_index = final_index;
995 final_index = temp;
996 }
997
Greg Clayton57ee3062013-07-11 22:46:58 +0000998 if (valobj_sp->GetClangType().IsPointerToScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +0000999 {
1000 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
1001 // and extract bits low thru high out of it. reading array items low thru high
1002 // would be done by saying ptr[low-high], without a deref * sign
1003 Error error;
1004 ValueObjectSP temp(valobj_sp->Dereference(error));
1005 if (error.Fail())
1006 {
1007 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1008 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
1009 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1010 var_expr_path_strm.GetString().c_str());
1011 return ValueObjectSP();
1012 }
1013 valobj_sp = temp;
1014 deref = false;
1015 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001016 else if (valobj_sp->GetClangType().IsArrayOfScalarType() && deref)
Enrico Granata9fc19442011-07-06 02:13:41 +00001017 {
1018 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
1019 // (an operation that is equivalent to deref-ing arr)
1020 // and extract bits low thru high out of it. reading array items low thru high
1021 // would be done by saying arr[low-high], without a deref * sign
1022 Error error;
1023 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
1024 if (error.Fail())
1025 {
1026 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1027 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
1028 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1029 var_expr_path_strm.GetString().c_str());
1030 return ValueObjectSP();
1031 }
1032 valobj_sp = temp;
1033 deref = false;
1034 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001035 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9fc19442011-07-06 02:13:41 +00001036 {
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001037 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1038 expand_bitfield = false;
1039 if (!child_valobj_sp)
1040 {
1041 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1042 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1043 child_index, final_index,
1044 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1045 var_expr_path_strm.GetString().c_str());
1046 }
1047 }*/
1048
1049 if (expand_bitfield)
1050 {
1051 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1052 if (!child_valobj_sp)
1053 {
1054 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda7e589a62011-09-20 00:26:08 +00001055 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001056 child_index, final_index,
1057 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1058 var_expr_path_strm.GetString().c_str());
1059 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001060 }
1061 }
1062
1063 if (!child_valobj_sp)
1064 {
1065 // Invalid bitfield range...
1066 return ValueObjectSP();
1067 }
1068
1069 // Erase the bitfield member specification '[%i-%i]' where
1070 // %i is the index
1071 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1072 separator_idx = var_path.find_first_of(".-[");
Greg Clayton4d122c42011-09-17 08:33:22 +00001073 if (use_dynamic != eNoDynamicValues)
Enrico Granata9fc19442011-07-06 02:13:41 +00001074 {
1075 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1076 if (dynamic_value_sp)
1077 child_valobj_sp = dynamic_value_sp;
1078 }
1079 // Break out early from the switch since we were
1080 // able to find the child member
1081 break;
1082
1083 }
1084 }
1085 else
1086 {
1087 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1088 var_expr_path_strm.GetString().c_str(),
1089 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08 +00001090 }
1091 return ValueObjectSP();
1092
1093 default:
1094 // Failure...
1095 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001096 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08 +00001097 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1098 separator_type,
1099 var_expr_path_strm.GetString().c_str(),
1100 var_path.c_str());
1101
1102 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001103 }
1104 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001105
Greg Clayton54979cd2010-12-15 05:08:08 +00001106 if (child_valobj_sp)
1107 valobj_sp = child_valobj_sp;
1108
1109 if (var_path.empty())
1110 break;
1111
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001112 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001113 if (valobj_sp)
1114 {
1115 if (deref)
1116 {
Greg Claytonaf67cec2010-12-20 20:49:23 +00001117 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08 +00001118 valobj_sp = deref_valobj_sp;
1119 }
1120 else if (address_of)
1121 {
1122 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1123 valobj_sp = address_of_valobj_sp;
1124 }
1125 }
1126 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001127 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001128 else
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001129 {
Jim Ingham2837b762011-05-04 03:43:18 +00001130 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1131 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001132 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001133 }
1134 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001135 else
1136 {
1137 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1138 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001139 return ValueObjectSP();
1140}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001141
1142bool
1143StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1144{
Jason Molenda99618472013-11-04 11:02:52 +00001145 if (m_cfa_is_valid == false)
1146 {
1147 m_frame_base_error.SetErrorString("No frame base available for this historical stack frame.");
1148 return false;
1149 }
1150
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 if (m_flags.IsClear(GOT_FRAME_BASE))
1152 {
1153 if (m_sc.function)
1154 {
1155 m_frame_base.Clear();
1156 m_frame_base_error.Clear();
1157
1158 m_flags.Set(GOT_FRAME_BASE);
Greg Claytond9e416c2012-02-18 05:35:26 +00001159 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48 +00001161 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1162 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytond9e416c2012-02-18 05:35:26 +00001163 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton016a95e2010-09-14 02:20:48 +00001164
Greg Clayton57ee3062013-07-11 22:46:58 +00001165 if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166 {
1167 // We should really have an error if evaluate returns, but in case
1168 // we don't, lets set the error to something at least.
1169 if (m_frame_base_error.Success())
1170 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1171 }
1172 else
1173 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001174 m_frame_base = expr_value.ResolveValue(&exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 }
1176 }
1177 else
1178 {
1179 m_frame_base_error.SetErrorString ("No function in symbol context.");
1180 }
1181 }
1182
1183 if (m_frame_base_error.Success())
1184 frame_base = m_frame_base;
1185
1186 if (error_ptr)
1187 *error_ptr = m_frame_base_error;
1188 return m_frame_base_error.Success();
1189}
1190
Greg Clayton5ccbd292011-01-06 22:15:06 +00001191RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192StackFrame::GetRegisterContext ()
1193{
Greg Clayton5ccbd292011-01-06 22:15:06 +00001194 if (!m_reg_context_sp)
Greg Claytond9e416c2012-02-18 05:35:26 +00001195 {
1196 ThreadSP thread_sp (GetThread());
1197 if (thread_sp)
1198 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1199 }
Greg Clayton5ccbd292011-01-06 22:15:06 +00001200 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201}
1202
1203bool
1204StackFrame::HasDebugInformation ()
1205{
Greg Clayton9da7bd02010-08-24 21:05:24 +00001206 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207 return m_sc.line_entry.IsValid();
1208}
1209
Greg Clayton288bdf92010-09-02 02:59:18 +00001210
1211ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001212StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213{
Greg Clayton288bdf92010-09-02 02:59:18 +00001214 ValueObjectSP valobj_sp;
Jason Molenda99618472013-11-04 11:02:52 +00001215 if (m_is_history_frame)
1216 {
1217 return valobj_sp;
1218 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001219 VariableList *var_list = GetVariableList (true);
1220 if (var_list)
1221 {
1222 // Make sure the variable is a frame variable
1223 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1224 const uint32_t num_variables = var_list->GetSize();
1225 if (var_idx < num_variables)
1226 {
1227 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1228 if (valobj_sp.get() == NULL)
1229 {
1230 if (m_variable_list_value_objects.GetSize() < num_variables)
1231 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:53 +00001232 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:18 +00001233 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1234 }
1235 }
1236 }
Greg Clayton4d122c42011-09-17 08:33:22 +00001237 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +00001238 {
Jim Ingham2837b762011-05-04 03:43:18 +00001239 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001240 if (dynamic_sp)
1241 return dynamic_sp;
1242 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001243 return valobj_sp;
1244}
1245
1246ValueObjectSP
Greg Clayton4d122c42011-09-17 08:33:22 +00001247StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:18 +00001248{
Jason Molenda99618472013-11-04 11:02:52 +00001249 if (m_is_history_frame)
1250 return ValueObjectSP();
1251
Greg Clayton288bdf92010-09-02 02:59:18 +00001252 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:13 +00001253 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:18 +00001254 if (!valobj_sp)
1255 {
1256 // We aren't already tracking this global
1257 VariableList *var_list = GetVariableList (true);
1258 // If this frame has no variables, create a new list
1259 if (var_list == NULL)
1260 m_variable_list_sp.reset (new VariableList());
1261
1262 // Add the global/static variable to this frame
1263 m_variable_list_sp->AddVariable (variable_sp);
1264
1265 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:13 +00001266 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:18 +00001267 }
1268 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269}
1270
Jim Ingham6b8379c2010-08-26 20:44:45 +00001271bool
1272StackFrame::IsInlined ()
1273{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001274 if (m_sc.block == NULL)
1275 GetSymbolContext (eSymbolContextBlock);
1276 if (m_sc.block)
1277 return m_sc.block->GetContainingInlinedBlock() != NULL;
1278 return false;
Jim Ingham6b8379c2010-08-26 20:44:45 +00001279}
1280
Greg Claytond9e416c2012-02-18 05:35:26 +00001281TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282StackFrame::CalculateTarget ()
1283{
Greg Claytond9e416c2012-02-18 05:35:26 +00001284 TargetSP target_sp;
1285 ThreadSP thread_sp(GetThread());
1286 if (thread_sp)
1287 {
1288 ProcessSP process_sp (thread_sp->CalculateProcess());
1289 if (process_sp)
1290 target_sp = process_sp->CalculateTarget();
1291 }
1292 return target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001293}
1294
Greg Claytond9e416c2012-02-18 05:35:26 +00001295ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296StackFrame::CalculateProcess ()
1297{
Greg Claytond9e416c2012-02-18 05:35:26 +00001298 ProcessSP process_sp;
1299 ThreadSP thread_sp(GetThread());
1300 if (thread_sp)
1301 process_sp = thread_sp->CalculateProcess();
1302 return process_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303}
1304
Greg Claytond9e416c2012-02-18 05:35:26 +00001305ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001306StackFrame::CalculateThread ()
1307{
Greg Claytond9e416c2012-02-18 05:35:26 +00001308 return GetThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309}
1310
Jason Molendab57e4a12013-11-04 09:33:30 +00001311StackFrameSP
1312StackFrame::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313{
Greg Claytond9e416c2012-02-18 05:35:26 +00001314 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315}
1316
1317
1318void
Greg Clayton0603aa92010-10-04 01:05:56 +00001319StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320{
Greg Claytond9e416c2012-02-18 05:35:26 +00001321 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322}
1323
1324void
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001325StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker)
Greg Clayton0603aa92010-10-04 01:05:56 +00001326{
1327 if (strm == NULL)
1328 return;
1329
1330 GetSymbolContext(eSymbolContextEverything);
Greg Claytond9e416c2012-02-18 05:35:26 +00001331 ExecutionContext exe_ctx (shared_from_this());
Greg Clayton0603aa92010-10-04 01:05:56 +00001332 StreamString s;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001333
1334 if (frame_marker)
1335 s.PutCString(frame_marker);
1336
Greg Claytond9e416c2012-02-18 05:35:26 +00001337 const char *frame_format = NULL;
1338 Target *target = exe_ctx.GetTargetPtr();
1339 if (target)
1340 frame_format = target->GetDebugger().GetFrameFormat();
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001341 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s))
Greg Clayton0603aa92010-10-04 01:05:56 +00001342 {
1343 strm->Write(s.GetData(), s.GetSize());
1344 }
1345 else
1346 {
1347 Dump (strm, true, false);
1348 strm->EOL();
1349 }
1350}
1351
1352void
Greg Clayton6dadd502010-09-02 21:44:10 +00001353StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354{
1355 if (strm == NULL)
1356 return;
1357
1358 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001359 strm->Printf("frame #%u: ", m_frame_index);
Greg Claytond9e416c2012-02-18 05:35:26 +00001360 ExecutionContext exe_ctx (shared_from_this());
1361 Target *target = exe_ctx.GetTargetPtr();
Daniel Malead01b2952012-11-29 21:49:15 +00001362 strm->Printf("0x%0*" PRIx64 " ",
Greg Claytond9e416c2012-02-18 05:35:26 +00001363 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1364 GetFrameCodeAddress().GetLoadAddress(target));
Greg Clayton9da7bd02010-08-24 21:05:24 +00001365 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001366 const bool show_module = true;
1367 const bool show_inline = true;
Greg Claytond9e416c2012-02-18 05:35:26 +00001368 m_sc.DumpStopContext (strm,
1369 exe_ctx.GetBestExecutionContextScope(),
1370 GetFrameCodeAddress(),
1371 show_fullpaths,
1372 show_module,
1373 show_inline);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374}
1375
Greg Clayton5082c5f2010-08-27 18:24:16 +00001376void
Jason Molendab57e4a12013-11-04 09:33:30 +00001377StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:16 +00001378{
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001379 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001380 m_variable_list_sp = prev_frame.m_variable_list_sp;
1381 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1382 if (!m_disassembly.GetString().empty())
1383 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:16 +00001384}
Greg Clayton68275d52010-08-27 21:47:54 +00001385
1386
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001387void
Jason Molendab57e4a12013-11-04 09:33:30 +00001388StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001389{
Greg Clayton2cad65a2010-09-03 17:10:42 +00001390 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
Jason Molendab57e4a12013-11-04 09:33:30 +00001391 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1392 assert (GetThread() == curr_frame.GetThread());
1393 m_frame_index = curr_frame.m_frame_index;
1394 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1395 m_reg_context_sp = curr_frame.m_reg_context_sp;
1396 m_frame_code_addr = curr_frame.m_frame_code_addr;
1397 assert (m_sc.target_sp.get() == NULL || curr_frame.m_sc.target_sp.get() == NULL || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1398 assert (m_sc.module_sp.get() == NULL || curr_frame.m_sc.module_sp.get() == NULL || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1399 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1400 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1401 m_sc = curr_frame.m_sc;
1402 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1403 m_flags.Set (m_sc.GetResolvedMask());
1404 m_frame_base.Clear();
1405 m_frame_base_error.Clear();
Greg Clayton59e8fc1c2010-08-30 18:11:35 +00001406}
1407
1408
Greg Clayton2cad65a2010-09-03 17:10:42 +00001409bool
Jason Molendab57e4a12013-11-04 09:33:30 +00001410StackFrame::HasCachedData () const
1411{
1412 if (m_variable_list_sp.get())
1413 return true;
1414 if (m_variable_list_value_objects.GetSize() > 0)
1415 return true;
1416 if (!m_disassembly.GetString().empty())
1417 return true;
1418 return false;
1419}
1420
1421bool
Greg Clayton7260f622011-04-18 08:33:37 +00001422StackFrame::GetStatus (Stream& strm,
1423 bool show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001424 bool show_source,
1425 const char *frame_marker)
Greg Clayton7260f622011-04-18 08:33:37 +00001426{
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001427
Greg Clayton7260f622011-04-18 08:33:37 +00001428 if (show_frame_info)
1429 {
1430 strm.Indent();
Jim Ingham8ec10ef2013-10-18 17:38:31 +00001431 DumpUsingSettingsFormat (&strm, frame_marker);
Greg Clayton7260f622011-04-18 08:33:37 +00001432 }
1433
1434 if (show_source)
1435 {
Greg Claytond9e416c2012-02-18 05:35:26 +00001436 ExecutionContext exe_ctx (shared_from_this());
Greg Claytone372b982011-11-21 21:44:34 +00001437 bool have_source = false;
Greg Clayton67cc0632012-08-22 17:17:09 +00001438 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Claytond9e416c2012-02-18 05:35:26 +00001439 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001440 if (target)
Greg Clayton7260f622011-04-18 08:33:37 +00001441 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001442 Debugger &debugger = target->GetDebugger();
1443 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1444 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1445 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytone372b982011-11-21 21:44:34 +00001446
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001447 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1448 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytone372b982011-11-21 21:44:34 +00001449 {
Todd Fiala6d1fbc92014-07-07 20:47:24 +00001450 have_source = true;
1451 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytone372b982011-11-21 21:44:34 +00001452 {
Jason Molenda7cd81c52013-04-29 09:59:31 +00001453 target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001454 m_sc.line_entry.line,
1455 source_lines_before,
1456 source_lines_after,
1457 "->",
Jason Molenda7cd81c52013-04-29 09:59:31 +00001458 &strm);
Greg Claytone372b982011-11-21 21:44:34 +00001459 }
1460 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001461 switch (disasm_display)
1462 {
Greg Clayton67cc0632012-08-22 17:17:09 +00001463 case Debugger::eStopDisassemblyTypeNever:
Greg Claytone372b982011-11-21 21:44:34 +00001464 break;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001465
Greg Clayton67cc0632012-08-22 17:17:09 +00001466 case Debugger::eStopDisassemblyTypeNoSource:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001467 if (have_source)
1468 break;
1469 // Fall through to next case
Greg Clayton67cc0632012-08-22 17:17:09 +00001470 case Debugger::eStopDisassemblyTypeAlways:
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001471 if (target)
Greg Claytone372b982011-11-21 21:44:34 +00001472 {
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001473 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1474 if (disasm_lines > 0)
1475 {
1476 const ArchSpec &target_arch = target->GetArchitecture();
1477 AddressRange pc_range;
1478 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1479 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
Jim Ingham0f063ba2013-03-02 00:26:47 +00001480 const char *plugin_name = NULL;
1481 const char *flavor = NULL;
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001482 Disassembler::Disassemble (target->GetDebugger(),
1483 target_arch,
Jim Ingham0f063ba2013-03-02 00:26:47 +00001484 plugin_name,
1485 flavor,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001486 exe_ctx,
1487 pc_range,
1488 disasm_lines,
1489 0,
1490 Disassembler::eOptionMarkPCAddress,
1491 strm);
1492 }
Greg Claytone372b982011-11-21 21:44:34 +00001493 }
Greg Clayton53eb7ad2012-07-11 20:33:48 +00001494 break;
Greg Claytone372b982011-11-21 21:44:34 +00001495 }
Greg Clayton7260f622011-04-18 08:33:37 +00001496 }
1497 }
1498 return true;
1499}
1500