blob: 932d35bea263e554eca0cb5e328b9a566bb2d639 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- StackFrame.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/StackFrame.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Module.h"
Greg Claytona830adb2010-10-04 01:05:56 +000017#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Disassembler.h"
19#include "lldb/Core/Value.h"
Greg Clayton17dae082010-09-02 02:59:18 +000020#include "lldb/Core/ValueObjectVariable.h"
Greg Claytonc3b61d22010-12-15 05:08:08 +000021#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000022#include "lldb/Symbol/CompileUnit.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Symbol/Function.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Symbol/Symbol.h"
25#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton17dae082010-09-02 02:59:18 +000026#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ExecutionContext.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/RegisterContext.h"
30#include "lldb/Target/Target.h"
31#include "lldb/Target/Thread.h"
32
33using namespace lldb;
34using namespace lldb_private;
35
36// The first bits in the flags are reserved for the SymbolContext::Scope bits
37// so we know if we have tried to look up information in our internal symbol
38// context (m_sc) already.
Greg Clayton4fb08152010-08-30 18:11:35 +000039#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton72b71582010-09-02 21:44:10 +000040#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton4fb08152010-08-30 18:11:35 +000041#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
42#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan89363592010-11-01 04:38:59 +000043#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner24943d22010-06-08 16:52:24 +000044
Greg Clayton289afcb2012-02-18 05:35:26 +000045StackFrame::StackFrame (const ThreadSP &thread_sp,
46 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000047 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000048 addr_t cfa,
49 addr_t pc,
50 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000051 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000052 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000053 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000054 m_reg_context_sp (),
Greg Clayton72b71582010-09-02 21:44:10 +000055 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000056 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000057 m_sc (),
58 m_flags (),
59 m_frame_base (),
60 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000061 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000062 m_variable_list_value_objects (),
63 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000064{
65 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000066 {
Chris Lattner24943d22010-06-08 16:52:24 +000067 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000068 m_flags.Set(m_sc.GetResolvedMask ());
69 }
Chris Lattner24943d22010-06-08 16:52:24 +000070}
71
Greg Clayton289afcb2012-02-18 05:35:26 +000072StackFrame::StackFrame (const ThreadSP &thread_sp,
73 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000074 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000075 const RegisterContextSP &reg_context_sp,
76 addr_t cfa,
77 addr_t pc,
78 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000079 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000080 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000081 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000082 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +000083 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000084 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000085 m_sc (),
86 m_flags (),
87 m_frame_base (),
88 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000089 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000090 m_variable_list_value_objects (),
91 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000092{
93 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000094 {
Chris Lattner24943d22010-06-08 16:52:24 +000095 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000096 m_flags.Set(m_sc.GetResolvedMask ());
97 }
98
99 if (reg_context_sp && !m_sc.target_sp)
100 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000101 m_sc.target_sp = reg_context_sp->CalculateTarget();
102 if (m_sc.target_sp)
103 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000104 }
105}
106
Greg Clayton289afcb2012-02-18 05:35:26 +0000107StackFrame::StackFrame (const ThreadSP &thread_sp,
108 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000109 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000110 const RegisterContextSP &reg_context_sp,
111 addr_t cfa,
112 const Address& pc_addr,
113 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +0000114 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +0000115 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000116 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +0000117 m_reg_context_sp (reg_context_sp),
Greg Claytonf4124de2012-02-21 00:09:25 +0000118 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +0000119 m_frame_code_addr (pc_addr),
Greg Clayton33ed1702010-08-24 00:45:41 +0000120 m_sc (),
121 m_flags (),
122 m_frame_base (),
123 m_frame_base_error (),
124 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000125 m_variable_list_value_objects (),
126 m_disassembly ()
Greg Clayton33ed1702010-08-24 00:45:41 +0000127{
128 if (sc_ptr != NULL)
129 {
130 m_sc = *sc_ptr;
131 m_flags.Set(m_sc.GetResolvedMask ());
132 }
133
134 if (m_sc.target_sp.get() == NULL && reg_context_sp)
135 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000136 m_sc.target_sp = reg_context_sp->CalculateTarget();
137 if (m_sc.target_sp)
138 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000139 }
140
Greg Clayton3508c382012-02-24 01:59:29 +0000141 ModuleSP pc_module_sp (pc_addr.GetModule());
142 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000143 {
Greg Clayton3508c382012-02-24 01:59:29 +0000144 if (pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000145 {
Greg Clayton3508c382012-02-24 01:59:29 +0000146 m_sc.module_sp = pc_module_sp;
Greg Clayton33ed1702010-08-24 00:45:41 +0000147 m_flags.Set (eSymbolContextModule);
148 }
Greg Claytone2c5e452010-09-13 04:34:30 +0000149 else
150 {
151 m_sc.module_sp.reset();
152 }
Greg Clayton33ed1702010-08-24 00:45:41 +0000153 }
Chris Lattner24943d22010-06-08 16:52:24 +0000154}
155
156
157//----------------------------------------------------------------------
158// Destructor
159//----------------------------------------------------------------------
160StackFrame::~StackFrame()
161{
162}
163
164StackID&
165StackFrame::GetStackID()
166{
Greg Clayton72b71582010-09-02 21:44:10 +0000167 // Make sure we have resolved the StackID object's symbol context scope if
168 // we already haven't looked it up.
Chris Lattner24943d22010-06-08 16:52:24 +0000169
Greg Clayton4fb08152010-08-30 18:11:35 +0000170 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
171 {
Greg Clayton5205f0b2010-09-03 17:10:42 +0000172 if (m_id.GetSymbolContextScope ())
Greg Clayton4fb08152010-08-30 18:11:35 +0000173 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000174 // We already have a symbol context scope, we just don't have our
175 // flag bit set.
Greg Clayton4fb08152010-08-30 18:11:35 +0000176 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
177 }
178 else
179 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000180 // Calculate the frame block and use this for the stack ID symbol
181 // context scope if we have one.
182 SymbolContextScope *scope = GetFrameBlock ();
183 if (scope == NULL)
Greg Clayton4fb08152010-08-30 18:11:35 +0000184 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000185 // We don't have a block, so use the symbol
186 if (m_flags.IsClear (eSymbolContextSymbol))
187 GetSymbolContext (eSymbolContextSymbol);
188
189 // It is ok if m_sc.symbol is NULL here
190 scope = m_sc.symbol;
Greg Clayton4fb08152010-08-30 18:11:35 +0000191 }
Greg Clayton69aa5d92010-09-07 04:20:48 +0000192 // Set the symbol context scope (the accessor will set the
193 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
194 SetSymbolContextScope (scope);
Greg Clayton4fb08152010-08-30 18:11:35 +0000195 }
Chris Lattner24943d22010-06-08 16:52:24 +0000196 }
197 return m_id;
198}
199
Jim Ingham0c8fa2d2012-09-01 01:02:41 +0000200uint32_t
201StackFrame::GetFrameIndex () const
202{
203 ThreadSP thread_sp = GetThread();
204 if (thread_sp)
205 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
206 else
207 return m_frame_index;
208}
209
Greg Clayton4fb08152010-08-30 18:11:35 +0000210void
211StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
212{
213 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
214 m_id.SetSymbolContextScope (symbol_scope);
215}
216
Greg Clayton107e53d2011-07-06 04:07:21 +0000217const Address&
Greg Claytonb04e7a82010-08-24 21:05:24 +0000218StackFrame::GetFrameCodeAddress()
Chris Lattner24943d22010-06-08 16:52:24 +0000219{
Greg Clayton4fb08152010-08-30 18:11:35 +0000220 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000221 {
Greg Clayton4fb08152010-08-30 18:11:35 +0000222 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner24943d22010-06-08 16:52:24 +0000223
224 // Resolve the PC into a temporary address because if ResolveLoadAddress
225 // fails to resolve the address, it will clear the address object...
Greg Clayton289afcb2012-02-18 05:35:26 +0000226 ThreadSP thread_sp (GetThread());
227 if (thread_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000228 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000229 TargetSP target_sp (thread_sp->CalculateTarget());
230 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000231 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000232 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000233 {
Greg Clayton3508c382012-02-24 01:59:29 +0000234 ModuleSP module_sp (m_frame_code_addr.GetModule());
235 if (module_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +0000236 {
Greg Clayton3508c382012-02-24 01:59:29 +0000237 m_sc.module_sp = module_sp;
238 m_flags.Set(eSymbolContextModule);
Greg Clayton289afcb2012-02-18 05:35:26 +0000239 }
Chris Lattner24943d22010-06-08 16:52:24 +0000240 }
241 }
242 }
243 }
Greg Clayton65124ea2010-08-26 22:05:43 +0000244 return m_frame_code_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000245}
246
247void
248StackFrame::ChangePC (addr_t pc)
249{
Greg Clayton3508c382012-02-24 01:59:29 +0000250 m_frame_code_addr.SetRawAddress(pc);
Chris Lattner24943d22010-06-08 16:52:24 +0000251 m_sc.Clear();
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000252 m_flags.Reset(0);
Greg Clayton289afcb2012-02-18 05:35:26 +0000253 ThreadSP thread_sp (GetThread());
254 if (thread_sp)
255 thread_sp->ClearStackFrames ();
Chris Lattner24943d22010-06-08 16:52:24 +0000256}
257
258const char *
259StackFrame::Disassemble ()
260{
261 if (m_disassembly.GetSize() == 0)
262 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000263 ExecutionContext exe_ctx (shared_from_this());
264 Target *target = exe_ctx.GetTargetPtr();
265 if (target)
266 {
267 Disassembler::Disassemble (target->GetDebugger(),
268 target->GetArchitecture(),
269 NULL,
270 exe_ctx,
271 0,
272 0,
273 0,
274 m_disassembly);
275 }
Chris Lattner24943d22010-06-08 16:52:24 +0000276 if (m_disassembly.GetSize() == 0)
277 return NULL;
278 }
279 return m_disassembly.GetData();
280}
281
Greg Clayton69aa5d92010-09-07 04:20:48 +0000282Block *
283StackFrame::GetFrameBlock ()
284{
285 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
286 GetSymbolContext (eSymbolContextBlock);
287
288 if (m_sc.block)
289 {
290 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
291 if (inline_block)
292 {
293 // Use the block with the inlined function info
294 // as the frame block we want this frame to have only the variables
295 // for the inlined function and its non-inlined block child blocks.
296 return inline_block;
297 }
298 else
299 {
300 // This block is not contained withing any inlined function blocks
301 // with so we want to use the top most function block.
302 return &m_sc.function->GetBlock (false);
303 }
304 }
305 return NULL;
306}
307
Chris Lattner24943d22010-06-08 16:52:24 +0000308//----------------------------------------------------------------------
309// Get the symbol context if we already haven't done so by resolving the
310// PC address as much as possible. This way when we pass around a
311// StackFrame object, everyone will have as much information as
312// possible and no one will ever have to look things up manually.
313//----------------------------------------------------------------------
314const SymbolContext&
315StackFrame::GetSymbolContext (uint32_t resolve_scope)
316{
317 // Copy our internal symbol context into "sc".
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000318 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000319 {
320 // Resolve our PC to section offset if we haven't alreday done so
321 // and if we don't have a module. The resolved address section will
322 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000323 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000324 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000325
326 // If this is not frame zero, then we need to subtract 1 from the PC
327 // value when doing address lookups since the PC will be on the
328 // instruction following the function call instruction...
329
Greg Claytonb04e7a82010-08-24 21:05:24 +0000330 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000331 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000332 {
333 addr_t offset = lookup_addr.GetOffset();
334 if (offset > 0)
335 lookup_addr.SetOffset(offset - 1);
336 }
337
Greg Claytonb04e7a82010-08-24 21:05:24 +0000338
339 uint32_t resolved = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000340 if (m_sc.module_sp)
341 {
342 // We have something in our stack frame symbol context, lets check
343 // if we haven't already tried to lookup one of those things. If we
344 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000345
346 uint32_t actual_resolve_scope = 0;
347
348 if (resolve_scope & eSymbolContextCompUnit)
349 {
350 if (m_flags.IsClear (eSymbolContextCompUnit))
351 {
352 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000353 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000354 else
355 actual_resolve_scope |= eSymbolContextCompUnit;
356 }
357 }
358
359 if (resolve_scope & eSymbolContextFunction)
360 {
361 if (m_flags.IsClear (eSymbolContextFunction))
362 {
363 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000364 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000365 else
366 actual_resolve_scope |= eSymbolContextFunction;
367 }
368 }
369
370 if (resolve_scope & eSymbolContextBlock)
371 {
372 if (m_flags.IsClear (eSymbolContextBlock))
373 {
374 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000375 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000376 else
377 actual_resolve_scope |= eSymbolContextBlock;
378 }
379 }
380
381 if (resolve_scope & eSymbolContextSymbol)
382 {
383 if (m_flags.IsClear (eSymbolContextSymbol))
384 {
385 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000386 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000387 else
388 actual_resolve_scope |= eSymbolContextSymbol;
389 }
390 }
391
392 if (resolve_scope & eSymbolContextLineEntry)
393 {
394 if (m_flags.IsClear (eSymbolContextLineEntry))
395 {
396 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000397 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000398 else
399 actual_resolve_scope |= eSymbolContextLineEntry;
400 }
401 }
402
403 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000404 {
405 // We might be resolving less information than what is already
406 // in our current symbol context so resolve into a temporary
407 // symbol context "sc" so we don't clear out data we have
408 // already found in "m_sc"
409 SymbolContext sc;
410 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000411 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000412 // Only replace what we didn't already have as we may have
413 // information for an inlined function scope that won't match
414 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000415 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
416 m_sc.comp_unit = sc.comp_unit;
417 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
418 m_sc.function = sc.function;
419 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
420 m_sc.block = sc.block;
421 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
422 m_sc.symbol = sc.symbol;
423 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
424 m_sc.line_entry = sc.line_entry;
425
Chris Lattner24943d22010-06-08 16:52:24 +0000426 }
427 }
428 else
429 {
430 // If we don't have a module, then we can't have the compile unit,
431 // function, block, line entry or symbol, so we can safely call
432 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton289afcb2012-02-18 05:35:26 +0000433 TargetSP target_sp (CalculateTarget());
434 if (target_sp)
435 resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000436 }
437
438 // If the target was requested add that:
Greg Clayton289afcb2012-02-18 05:35:26 +0000439 if (!m_sc.target_sp)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000440 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000441 m_sc.target_sp = CalculateTarget();
Greg Claytonb04e7a82010-08-24 21:05:24 +0000442 if (m_sc.target_sp)
443 resolved |= eSymbolContextTarget;
444 }
Chris Lattner24943d22010-06-08 16:52:24 +0000445
446 // Update our internal flags so we remember what we have tried to locate so
447 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000448 // We might have dug up more information that was requested (for example
449 // if we were asked to only get the block, we will have gotten the
450 // compile unit, and function) so set any additional bits that we resolved
451 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000452 }
453
454 // Return the symbol context with everything that was possible to resolve
455 // resolved.
456 return m_sc;
457}
458
459
460VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000461StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000462{
463 if (m_flags.IsClear(RESOLVED_VARIABLES))
464 {
465 m_flags.Set(RESOLVED_VARIABLES);
466
Greg Clayton69aa5d92010-09-07 04:20:48 +0000467 Block *frame_block = GetFrameBlock();
468
469 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000470 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000471 const bool get_child_variables = true;
472 const bool can_create = true;
Greg Clayton1bd2b2f2011-06-17 22:10:16 +0000473 const bool stop_if_child_block_is_inlined_function = true;
474 m_variable_list_sp.reset(new VariableList());
475 frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000476 }
Sean Callanan89363592010-11-01 04:38:59 +0000477 }
478
479 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
480 get_file_globals)
481 {
482 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton17dae082010-09-02 02:59:18 +0000483
Sean Callanan89363592010-11-01 04:38:59 +0000484 if (m_flags.IsClear (eSymbolContextCompUnit))
485 GetSymbolContext (eSymbolContextCompUnit);
486
487 if (m_sc.comp_unit)
Greg Clayton17dae082010-09-02 02:59:18 +0000488 {
Sean Callanan89363592010-11-01 04:38:59 +0000489 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
490 if (m_variable_list_sp)
491 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
492 else
493 m_variable_list_sp = global_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000494 }
Chris Lattner24943d22010-06-08 16:52:24 +0000495 }
Sean Callanan89363592010-11-01 04:38:59 +0000496
Chris Lattner24943d22010-06-08 16:52:24 +0000497 return m_variable_list_sp.get();
498}
499
Greg Clayton6e2d2822011-08-02 23:35:43 +0000500VariableListSP
501StackFrame::GetInScopeVariableList (bool get_file_globals)
502{
503 VariableListSP var_list_sp(new VariableList);
504 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
505
506 if (m_sc.block)
507 {
508 const bool can_create = true;
509 const bool get_parent_variables = true;
510 const bool stop_if_block_is_inlined_function = true;
511 m_sc.block->AppendVariables (can_create,
512 get_parent_variables,
513 stop_if_block_is_inlined_function,
514 var_list_sp.get());
515 }
516
517 if (m_sc.comp_unit)
518 {
519 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
520 if (global_variable_list_sp)
521 var_list_sp->AddVariables (global_variable_list_sp.get());
522 }
523
524 return var_list_sp;
525}
526
527
Greg Clayton427f2902010-12-14 02:59:59 +0000528ValueObjectSP
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000529StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000530 DynamicValueType use_dynamic,
Jim Ingham10de7d12011-05-04 03:43:18 +0000531 uint32_t options,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000532 VariableSP &var_sp,
Jim Ingham10de7d12011-05-04 03:43:18 +0000533 Error &error)
Greg Clayton427f2902010-12-14 02:59:59 +0000534{
Greg Claytonc3b61d22010-12-15 05:08:08 +0000535
536 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton427f2902010-12-14 02:59:59 +0000537 {
Greg Claytonc67efa42011-01-20 19:27:18 +0000538 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
539 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granataf6698502011-08-09 01:04:56 +0000540 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata13a54a12011-08-19 21:56:10 +0000541 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000542 error.Clear();
543 bool deref = false;
544 bool address_of = false;
545 ValueObjectSP valobj_sp;
546 const bool get_file_globals = true;
Greg Clayton6e2d2822011-08-02 23:35:43 +0000547 // When looking up a variable for an expression, we need only consider the
548 // variables that are in scope.
549 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
550 VariableList *variable_list = var_list_sp.get();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000551
552 if (variable_list)
Greg Clayton427f2902010-12-14 02:59:59 +0000553 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000554 // If first character is a '*', then show pointer contents
555 const char *var_expr = var_expr_cstr;
556 if (var_expr[0] == '*')
Greg Clayton427f2902010-12-14 02:59:59 +0000557 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000558 deref = true;
559 var_expr++; // Skip the '*'
560 }
561 else if (var_expr[0] == '&')
562 {
563 address_of = true;
564 var_expr++; // Skip the '&'
565 }
566
567 std::string var_path (var_expr);
568 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
569 StreamString var_expr_path_strm;
570
571 ConstString name_const_string;
572 if (separator_idx == std::string::npos)
573 name_const_string.SetCString (var_path.c_str());
574 else
575 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
576
Jim Ingham10de7d12011-05-04 03:43:18 +0000577 var_sp = variable_list->FindVariable(name_const_string);
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000578
579 bool synthetically_added_instance_object = false;
580
581 if (var_sp)
582 {
583 var_path.erase (0, name_const_string.GetLength ());
584 }
585 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
586 {
587 // Check for direct ivars access which helps us with implicit
588 // access to ivars with the "this->" or "self->"
589 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
590 lldb::LanguageType method_language = eLanguageTypeUnknown;
591 bool is_instance_method = false;
592 ConstString method_object_name;
593 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
594 {
595 if (is_instance_method && method_object_name)
596 {
597 var_sp = variable_list->FindVariable(method_object_name);
598 if (var_sp)
599 {
600 separator_idx = 0;
601 var_path.insert(0, "->");
602 synthetically_added_instance_object = true;
603 }
604 }
605 }
606 }
607
Greg Claytonc3b61d22010-12-15 05:08:08 +0000608 if (var_sp)
609 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000610 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000611 if (!valobj_sp)
612 return valobj_sp;
613
Greg Claytonc3b61d22010-12-15 05:08:08 +0000614 // We are dumping at least one child
615 while (separator_idx != std::string::npos)
Greg Clayton427f2902010-12-14 02:59:59 +0000616 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000617 // Calculate the next separator index ahead of time
618 ValueObjectSP child_valobj_sp;
619 const char separator_type = var_path[0];
620 switch (separator_type)
Greg Clayton427f2902010-12-14 02:59:59 +0000621 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000622
623 case '-':
624 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton427f2902010-12-14 02:59:59 +0000625 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000626
Greg Claytonc67efa42011-01-20 19:27:18 +0000627 if (no_fragile_ivar)
628 {
629 // Make sure we aren't trying to deref an objective
630 // C ivar if this is not allowed
631 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
632 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
633 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
634 {
635 // This was an objective C object pointer and
636 // it was requested we skip any fragile ivars
637 // so return nothing here
638 return ValueObjectSP();
639 }
640 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000641 var_path.erase (0, 1); // Remove the '-'
642 // Fall through
643 case '.':
Greg Clayton427f2902010-12-14 02:59:59 +0000644 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000645 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton427f2902010-12-14 02:59:59 +0000646
Greg Claytonc3b61d22010-12-15 05:08:08 +0000647 var_path.erase (0, 1); // Remove the '.' or '>'
648 separator_idx = var_path.find_first_of(".-[");
649 ConstString child_name;
650 if (separator_idx == std::string::npos)
651 child_name.SetCString (var_path.c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000652 else
Greg Claytonc3b61d22010-12-15 05:08:08 +0000653 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
654
655 if (check_ptr_vs_member)
Greg Clayton427f2902010-12-14 02:59:59 +0000656 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000657 // We either have a pointer type and need to verify
658 // valobj_sp is a pointer, or we have a member of a
659 // class/union/struct being accessed with the . syntax
660 // and need to verify we don't have a pointer.
661 const bool actual_is_ptr = valobj_sp->IsPointerType ();
662
663 if (actual_is_ptr != expr_is_ptr)
664 {
665 // Incorrect use of "." with a pointer, or "->" with
666 // a class/union/struct instance or reference.
Greg Claytonb01000f2011-01-17 03:46:26 +0000667 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000668 if (actual_is_ptr)
669 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
670 var_expr_path_strm.GetString().c_str(),
671 child_name.GetCString(),
672 var_expr_path_strm.GetString().c_str(),
673 var_path.c_str());
674 else
675 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
676 var_expr_path_strm.GetString().c_str(),
677 child_name.GetCString(),
678 var_expr_path_strm.GetString().c_str(),
679 var_path.c_str());
680 return ValueObjectSP();
681 }
Greg Clayton427f2902010-12-14 02:59:59 +0000682 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000683 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton427f2902010-12-14 02:59:59 +0000684 if (!child_valobj_sp)
685 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000686 if (no_synth_child == false)
Enrico Granatacf09f882012-03-19 22:58:49 +0000687 {
688 child_valobj_sp = valobj_sp->GetSyntheticValue();
689 if (child_valobj_sp)
690 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
691 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000692
693 if (no_synth_child || !child_valobj_sp)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000694 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000695 // No child member with name "child_name"
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000696 if (synthetically_added_instance_object)
Enrico Granata9c57fc02011-08-11 17:08:01 +0000697 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000698 // We added a "this->" or "self->" to the beginning of the expression
699 // and this is the first pointer ivar access, so just return the normal
700 // error
701 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
702 name_const_string.GetCString());
Enrico Granata9c57fc02011-08-11 17:08:01 +0000703 }
704 else
705 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000706 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
707 if (child_name)
708 {
709 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
710 child_name.GetCString(),
711 valobj_sp->GetTypeName().AsCString("<invalid type>"),
712 var_expr_path_strm.GetString().c_str());
713 }
714 else
715 {
716 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
717 var_expr_path_strm.GetString().c_str(),
718 var_expr_cstr);
719 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000720 }
721 return ValueObjectSP();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000722 }
Greg Clayton427f2902010-12-14 02:59:59 +0000723 }
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000724 synthetically_added_instance_object = false;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000725 // Remove the child name from the path
726 var_path.erase(0, child_name.GetLength());
Greg Clayton987c7eb2011-09-17 08:33:22 +0000727 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000728 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000729 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000730 if (dynamic_value_sp)
731 child_valobj_sp = dynamic_value_sp;
732 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000733 }
734 break;
Greg Clayton427f2902010-12-14 02:59:59 +0000735
Greg Claytonc3b61d22010-12-15 05:08:08 +0000736 case '[':
737 // Array member access, or treating pointer as an array
738 if (var_path.size() > 2) // Need at least two brackets and a number
739 {
740 char *end = NULL;
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000741 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9762e102011-07-06 02:13:41 +0000742 if (end && *end == ']'
743 && *(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 Claytonc3b61d22010-12-15 05:08:08 +0000744 {
Enrico Granata9762e102011-07-06 02:13:41 +0000745 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
746 {
747 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
748 // and extract bit low out of it. reading array item low
749 // would be done by saying ptr[low], without a deref * sign
750 Error error;
751 ValueObjectSP temp(valobj_sp->Dereference(error));
752 if (error.Fail())
753 {
754 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
755 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
756 valobj_sp->GetTypeName().AsCString("<invalid type>"),
757 var_expr_path_strm.GetString().c_str());
758 return ValueObjectSP();
759 }
760 valobj_sp = temp;
761 deref = false;
762 }
763 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
764 {
765 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
766 // (an operation that is equivalent to deref-ing arr)
767 // and extract bit low out of it. reading array item low
768 // would be done by saying arr[low], without a deref * sign
769 Error error;
770 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
771 if (error.Fail())
772 {
773 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
774 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
775 valobj_sp->GetTypeName().AsCString("<invalid type>"),
776 var_expr_path_strm.GetString().c_str());
777 return ValueObjectSP();
778 }
779 valobj_sp = temp;
780 deref = false;
781 }
782
Greg Claytonc3b61d22010-12-15 05:08:08 +0000783 if (valobj_sp->IsPointerType ())
784 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000785 bool is_objc_pointer = true;
786
787 if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
788 is_objc_pointer = false;
789 else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
790 is_objc_pointer = false;
791
792 if (no_synth_child && is_objc_pointer)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000793 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000794 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
795 valobj_sp->GetTypeName().AsCString("<invalid type>"),
796 var_expr_path_strm.GetString().c_str());
797
798 return ValueObjectSP();
799 }
800 else if (is_objc_pointer)
801 {
Enrico Granataf6698502011-08-09 01:04:56 +0000802 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granatacf09f882012-03-19 22:58:49 +0000803 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000804 if (synthetic.get() == NULL /* no synthetic */
805 || synthetic == valobj_sp) /* synthetic is the same as the original object */
806 {
807 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
808 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
809 valobj_sp->GetTypeName().AsCString("<invalid type>"),
810 var_expr_path_strm.GetString().c_str());
811 }
812 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
813 {
814 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000815 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000816 child_index,
817 valobj_sp->GetTypeName().AsCString("<invalid type>"),
818 var_expr_path_strm.GetString().c_str());
819 }
820 else
821 {
822 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
823 if (!child_valobj_sp)
824 {
825 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000826 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000827 child_index,
828 valobj_sp->GetTypeName().AsCString("<invalid type>"),
829 var_expr_path_strm.GetString().c_str());
830 }
831 }
832 }
833 else
834 {
835 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
836 if (!child_valobj_sp)
837 {
838 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000839 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000840 child_index,
841 valobj_sp->GetTypeName().AsCString("<invalid type>"),
842 var_expr_path_strm.GetString().c_str());
843 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000844 }
845 }
846 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
847 {
Jim Inghame41494a2011-04-16 00:01:13 +0000848 // Pass false to dynamic_value here so we can tell the difference between
849 // no dynamic value and no member of this type...
Greg Claytonc3b61d22010-12-15 05:08:08 +0000850 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
851 if (!child_valobj_sp)
852 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000853 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000854 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Claytonc3b61d22010-12-15 05:08:08 +0000855 child_index,
856 valobj_sp->GetTypeName().AsCString("<invalid type>"),
857 var_expr_path_strm.GetString().c_str());
858 }
859 }
Enrico Granata9762e102011-07-06 02:13:41 +0000860 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
861 {
862 // this is a bitfield asking to display just one bit
863 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
864 if (!child_valobj_sp)
865 {
866 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000867 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9762e102011-07-06 02:13:41 +0000868 child_index, child_index,
869 valobj_sp->GetTypeName().AsCString("<invalid type>"),
870 var_expr_path_strm.GetString().c_str());
871 }
872 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000873 else
874 {
Enrico Granatacf09f882012-03-19 22:58:49 +0000875 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000876 if (no_synth_child /* synthetic is forbidden */ ||
877 synthetic.get() == NULL /* no synthetic */
878 || synthetic == valobj_sp) /* synthetic is the same as the original object */
879 {
880 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
881 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
882 valobj_sp->GetTypeName().AsCString("<invalid type>"),
883 var_expr_path_strm.GetString().c_str());
884 }
885 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
886 {
887 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000888 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000889 child_index,
890 valobj_sp->GetTypeName().AsCString("<invalid type>"),
891 var_expr_path_strm.GetString().c_str());
892 }
893 else
894 {
895 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
896 if (!child_valobj_sp)
897 {
898 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000899 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000900 child_index,
901 valobj_sp->GetTypeName().AsCString("<invalid type>"),
902 var_expr_path_strm.GetString().c_str());
903 }
904 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000905 }
906
907 if (!child_valobj_sp)
908 {
909 // Invalid array index...
910 return ValueObjectSP();
911 }
912
913 // Erase the array member specification '[%i]' where
914 // %i is the array index
915 var_path.erase(0, (end - var_path.c_str()) + 1);
916 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +0000917 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000918 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000919 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000920 if (dynamic_value_sp)
921 child_valobj_sp = dynamic_value_sp;
922 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000923 // Break out early from the switch since we were
924 // able to find the child member
925 break;
926 }
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000927 else if (end && *end == '-')
Enrico Granata9762e102011-07-06 02:13:41 +0000928 {
929 // this is most probably a BitField, let's take a look
930 char *real_end = NULL;
931 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granata6f302872011-08-19 21:13:46 +0000932 bool expand_bitfield = true;
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000933 if (real_end && *real_end == ']')
Enrico Granata9762e102011-07-06 02:13:41 +0000934 {
935 // if the format given is [high-low], swap range
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000936 if (child_index > final_index)
Enrico Granata9762e102011-07-06 02:13:41 +0000937 {
938 long temp = child_index;
939 child_index = final_index;
940 final_index = temp;
941 }
942
943 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
944 {
945 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
946 // and extract bits low thru high out of it. reading array items low thru high
947 // would be done by saying ptr[low-high], without a deref * sign
948 Error error;
949 ValueObjectSP temp(valobj_sp->Dereference(error));
950 if (error.Fail())
951 {
952 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
953 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
954 valobj_sp->GetTypeName().AsCString("<invalid type>"),
955 var_expr_path_strm.GetString().c_str());
956 return ValueObjectSP();
957 }
958 valobj_sp = temp;
959 deref = false;
960 }
961 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
962 {
963 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
964 // (an operation that is equivalent to deref-ing arr)
965 // and extract bits low thru high out of it. reading array items low thru high
966 // would be done by saying arr[low-high], without a deref * sign
967 Error error;
968 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
969 if (error.Fail())
970 {
971 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
972 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
973 valobj_sp->GetTypeName().AsCString("<invalid type>"),
974 var_expr_path_strm.GetString().c_str());
975 return ValueObjectSP();
976 }
977 valobj_sp = temp;
978 deref = false;
979 }
Enrico Granata6f302872011-08-19 21:13:46 +0000980 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9762e102011-07-06 02:13:41 +0000981 {
Enrico Granata6f302872011-08-19 21:13:46 +0000982 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
983 expand_bitfield = false;
984 if (!child_valobj_sp)
985 {
986 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
987 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
988 child_index, final_index,
989 valobj_sp->GetTypeName().AsCString("<invalid type>"),
990 var_expr_path_strm.GetString().c_str());
991 }
992 }*/
993
994 if (expand_bitfield)
995 {
996 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
997 if (!child_valobj_sp)
998 {
999 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +00001000 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata6f302872011-08-19 21:13:46 +00001001 child_index, final_index,
1002 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1003 var_expr_path_strm.GetString().c_str());
1004 }
Enrico Granata9762e102011-07-06 02:13:41 +00001005 }
1006 }
1007
1008 if (!child_valobj_sp)
1009 {
1010 // Invalid bitfield range...
1011 return ValueObjectSP();
1012 }
1013
1014 // Erase the bitfield member specification '[%i-%i]' where
1015 // %i is the index
1016 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1017 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +00001018 if (use_dynamic != eNoDynamicValues)
Enrico Granata9762e102011-07-06 02:13:41 +00001019 {
1020 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1021 if (dynamic_value_sp)
1022 child_valobj_sp = dynamic_value_sp;
1023 }
1024 // Break out early from the switch since we were
1025 // able to find the child member
1026 break;
1027
1028 }
1029 }
1030 else
1031 {
1032 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1033 var_expr_path_strm.GetString().c_str(),
1034 var_path.c_str());
Greg Claytonc3b61d22010-12-15 05:08:08 +00001035 }
1036 return ValueObjectSP();
1037
1038 default:
1039 // Failure...
1040 {
Greg Claytonb01000f2011-01-17 03:46:26 +00001041 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001042 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1043 separator_type,
1044 var_expr_path_strm.GetString().c_str(),
1045 var_path.c_str());
1046
1047 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +00001048 }
1049 }
Greg Clayton427f2902010-12-14 02:59:59 +00001050
Greg Claytonc3b61d22010-12-15 05:08:08 +00001051 if (child_valobj_sp)
1052 valobj_sp = child_valobj_sp;
1053
1054 if (var_path.empty())
1055 break;
1056
Greg Clayton427f2902010-12-14 02:59:59 +00001057 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001058 if (valobj_sp)
1059 {
1060 if (deref)
1061 {
Greg Claytonbdcda462010-12-20 20:49:23 +00001062 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Claytonc3b61d22010-12-15 05:08:08 +00001063 valobj_sp = deref_valobj_sp;
1064 }
1065 else if (address_of)
1066 {
1067 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1068 valobj_sp = address_of_valobj_sp;
1069 }
1070 }
1071 return valobj_sp;
Greg Clayton427f2902010-12-14 02:59:59 +00001072 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001073 else
Greg Clayton427f2902010-12-14 02:59:59 +00001074 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001075 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1076 name_const_string.GetCString());
Greg Clayton427f2902010-12-14 02:59:59 +00001077 }
Greg Clayton427f2902010-12-14 02:59:59 +00001078 }
1079 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001080 else
1081 {
1082 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1083 }
Greg Clayton427f2902010-12-14 02:59:59 +00001084 return ValueObjectSP();
1085}
Chris Lattner24943d22010-06-08 16:52:24 +00001086
1087bool
1088StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1089{
1090 if (m_flags.IsClear(GOT_FRAME_BASE))
1091 {
1092 if (m_sc.function)
1093 {
1094 m_frame_base.Clear();
1095 m_frame_base_error.Clear();
1096
1097 m_flags.Set(GOT_FRAME_BASE);
Greg Clayton289afcb2012-02-18 05:35:26 +00001098 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001099 Value expr_value;
Greg Clayton178710c2010-09-14 02:20:48 +00001100 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1101 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Clayton289afcb2012-02-18 05:35:26 +00001102 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton178710c2010-09-14 02:20:48 +00001103
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001104 if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
Chris Lattner24943d22010-06-08 16:52:24 +00001105 {
1106 // We should really have an error if evaluate returns, but in case
1107 // we don't, lets set the error to something at least.
1108 if (m_frame_base_error.Success())
1109 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1110 }
1111 else
1112 {
1113 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
1114 }
1115 }
1116 else
1117 {
1118 m_frame_base_error.SetErrorString ("No function in symbol context.");
1119 }
1120 }
1121
1122 if (m_frame_base_error.Success())
1123 frame_base = m_frame_base;
1124
1125 if (error_ptr)
1126 *error_ptr = m_frame_base_error;
1127 return m_frame_base_error.Success();
1128}
1129
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001130RegisterContextSP
Chris Lattner24943d22010-06-08 16:52:24 +00001131StackFrame::GetRegisterContext ()
1132{
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001133 if (!m_reg_context_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +00001134 {
1135 ThreadSP thread_sp (GetThread());
1136 if (thread_sp)
1137 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1138 }
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001139 return m_reg_context_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001140}
1141
1142bool
1143StackFrame::HasDebugInformation ()
1144{
Greg Claytonb04e7a82010-08-24 21:05:24 +00001145 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +00001146 return m_sc.line_entry.IsValid();
1147}
1148
Greg Clayton17dae082010-09-02 02:59:18 +00001149
1150ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001151StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner24943d22010-06-08 16:52:24 +00001152{
Greg Clayton17dae082010-09-02 02:59:18 +00001153 ValueObjectSP valobj_sp;
1154 VariableList *var_list = GetVariableList (true);
1155 if (var_list)
1156 {
1157 // Make sure the variable is a frame variable
1158 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1159 const uint32_t num_variables = var_list->GetSize();
1160 if (var_idx < num_variables)
1161 {
1162 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1163 if (valobj_sp.get() == NULL)
1164 {
1165 if (m_variable_list_value_objects.GetSize() < num_variables)
1166 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham47da8102011-04-22 23:53:53 +00001167 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton17dae082010-09-02 02:59:18 +00001168 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1169 }
1170 }
1171 }
Greg Clayton987c7eb2011-09-17 08:33:22 +00001172 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +00001173 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001174 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001175 if (dynamic_sp)
1176 return dynamic_sp;
1177 }
Greg Clayton17dae082010-09-02 02:59:18 +00001178 return valobj_sp;
1179}
1180
1181ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001182StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton17dae082010-09-02 02:59:18 +00001183{
1184 // Check to make sure we aren't already tracking this variable?
Jim Inghame41494a2011-04-16 00:01:13 +00001185 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton17dae082010-09-02 02:59:18 +00001186 if (!valobj_sp)
1187 {
1188 // We aren't already tracking this global
1189 VariableList *var_list = GetVariableList (true);
1190 // If this frame has no variables, create a new list
1191 if (var_list == NULL)
1192 m_variable_list_sp.reset (new VariableList());
1193
1194 // Add the global/static variable to this frame
1195 m_variable_list_sp->AddVariable (variable_sp);
1196
1197 // Now make a value object for it so we can track its changes
Jim Inghame41494a2011-04-16 00:01:13 +00001198 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton17dae082010-09-02 02:59:18 +00001199 }
1200 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001201}
1202
Jim Ingham2154da42010-08-26 20:44:45 +00001203bool
1204StackFrame::IsInlined ()
1205{
Greg Clayton4fb08152010-08-30 18:11:35 +00001206 if (m_sc.block == NULL)
1207 GetSymbolContext (eSymbolContextBlock);
1208 if (m_sc.block)
1209 return m_sc.block->GetContainingInlinedBlock() != NULL;
1210 return false;
Jim Ingham2154da42010-08-26 20:44:45 +00001211}
1212
Greg Clayton289afcb2012-02-18 05:35:26 +00001213TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001214StackFrame::CalculateTarget ()
1215{
Greg Clayton289afcb2012-02-18 05:35:26 +00001216 TargetSP target_sp;
1217 ThreadSP thread_sp(GetThread());
1218 if (thread_sp)
1219 {
1220 ProcessSP process_sp (thread_sp->CalculateProcess());
1221 if (process_sp)
1222 target_sp = process_sp->CalculateTarget();
1223 }
1224 return target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001225}
1226
Greg Clayton289afcb2012-02-18 05:35:26 +00001227ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001228StackFrame::CalculateProcess ()
1229{
Greg Clayton289afcb2012-02-18 05:35:26 +00001230 ProcessSP process_sp;
1231 ThreadSP thread_sp(GetThread());
1232 if (thread_sp)
1233 process_sp = thread_sp->CalculateProcess();
1234 return process_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001235}
1236
Greg Clayton289afcb2012-02-18 05:35:26 +00001237ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001238StackFrame::CalculateThread ()
1239{
Greg Clayton289afcb2012-02-18 05:35:26 +00001240 return GetThread();
Chris Lattner24943d22010-06-08 16:52:24 +00001241}
1242
Greg Clayton289afcb2012-02-18 05:35:26 +00001243StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001244StackFrame::CalculateStackFrame ()
1245{
Greg Clayton289afcb2012-02-18 05:35:26 +00001246 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001247}
1248
1249
1250void
Greg Claytona830adb2010-10-04 01:05:56 +00001251StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001252{
Greg Clayton289afcb2012-02-18 05:35:26 +00001253 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001254}
1255
1256void
Greg Claytona830adb2010-10-04 01:05:56 +00001257StackFrame::DumpUsingSettingsFormat (Stream *strm)
1258{
1259 if (strm == NULL)
1260 return;
1261
1262 GetSymbolContext(eSymbolContextEverything);
Greg Clayton289afcb2012-02-18 05:35:26 +00001263 ExecutionContext exe_ctx (shared_from_this());
Greg Claytona830adb2010-10-04 01:05:56 +00001264 const char *end = NULL;
1265 StreamString s;
Greg Clayton289afcb2012-02-18 05:35:26 +00001266 const char *frame_format = NULL;
1267 Target *target = exe_ctx.GetTargetPtr();
1268 if (target)
1269 frame_format = target->GetDebugger().GetFrameFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001270 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1271 {
1272 strm->Write(s.GetData(), s.GetSize());
1273 }
1274 else
1275 {
1276 Dump (strm, true, false);
1277 strm->EOL();
1278 }
1279}
1280
1281void
Greg Clayton72b71582010-09-02 21:44:10 +00001282StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +00001283{
1284 if (strm == NULL)
1285 return;
1286
1287 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +00001288 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton289afcb2012-02-18 05:35:26 +00001289 ExecutionContext exe_ctx (shared_from_this());
1290 Target *target = exe_ctx.GetTargetPtr();
1291 strm->Printf("0x%0*llx ",
1292 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1293 GetFrameCodeAddress().GetLoadAddress(target));
Greg Claytonb04e7a82010-08-24 21:05:24 +00001294 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +00001295 const bool show_module = true;
1296 const bool show_inline = true;
Greg Clayton289afcb2012-02-18 05:35:26 +00001297 m_sc.DumpStopContext (strm,
1298 exe_ctx.GetBestExecutionContextScope(),
1299 GetFrameCodeAddress(),
1300 show_fullpaths,
1301 show_module,
1302 show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +00001303}
1304
Greg Clayton1d66ef52010-08-27 18:24:16 +00001305void
Greg Clayton4fb08152010-08-30 18:11:35 +00001306StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +00001307{
Greg Clayton4fb08152010-08-30 18:11:35 +00001308 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
1309 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +00001310 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +00001311 if (!m_disassembly.GetString().empty())
1312 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +00001313}
Greg Clayton870a1cd2010-08-27 21:47:54 +00001314
1315
Greg Clayton4fb08152010-08-30 18:11:35 +00001316void
1317StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1318{
Greg Clayton5205f0b2010-09-03 17:10:42 +00001319 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
1320 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton289afcb2012-02-18 05:35:26 +00001321 assert (GetThread() == curr_frame.GetThread());
Greg Clayton4fb08152010-08-30 18:11:35 +00001322 m_frame_index = curr_frame.m_frame_index;
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001323 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton4fb08152010-08-30 18:11:35 +00001324 m_reg_context_sp = curr_frame.m_reg_context_sp;
1325 m_frame_code_addr = curr_frame.m_frame_code_addr;
1326 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());
1327 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());
1328 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1329 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
Greg Clayton4fb08152010-08-30 18:11:35 +00001330 m_sc = curr_frame.m_sc;
1331 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1332 m_flags.Set (m_sc.GetResolvedMask());
1333 m_frame_base.Clear();
1334 m_frame_base_error.Clear();
1335}
1336
1337
Greg Clayton5205f0b2010-09-03 17:10:42 +00001338bool
1339StackFrame::HasCachedData () const
1340{
1341 if (m_variable_list_sp.get())
1342 return true;
1343 if (m_variable_list_value_objects.GetSize() > 0)
1344 return true;
1345 if (!m_disassembly.GetString().empty())
1346 return true;
1347 return false;
Jim Inghamccd584d2010-09-23 17:40:12 +00001348}
1349
Greg Claytonabe0fed2011-04-18 08:33:37 +00001350bool
1351StackFrame::GetStatus (Stream& strm,
1352 bool show_frame_info,
Greg Claytona7d3dc72012-07-11 20:33:48 +00001353 bool show_source)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001354{
Greg Claytona7d3dc72012-07-11 20:33:48 +00001355
Greg Claytonabe0fed2011-04-18 08:33:37 +00001356 if (show_frame_info)
1357 {
1358 strm.Indent();
1359 DumpUsingSettingsFormat (&strm);
1360 }
1361
1362 if (show_source)
1363 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001364 ExecutionContext exe_ctx (shared_from_this());
Greg Claytonbe9875d2011-11-21 21:44:34 +00001365 bool have_source = false;
Greg Clayton73844aa2012-08-22 17:17:09 +00001366 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Clayton289afcb2012-02-18 05:35:26 +00001367 Target *target = exe_ctx.GetTargetPtr();
Greg Claytona7d3dc72012-07-11 20:33:48 +00001368 if (target)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001369 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001370 Debugger &debugger = target->GetDebugger();
1371 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1372 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1373 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytonbe9875d2011-11-21 21:44:34 +00001374
Greg Claytona7d3dc72012-07-11 20:33:48 +00001375 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001376 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001377 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1378
1379 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytonbe9875d2011-11-21 21:44:34 +00001380 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001381 if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
1382 m_sc.line_entry.line,
1383 source_lines_before,
1384 source_lines_after,
1385 "->",
1386 &strm))
1387 {
1388 have_source = true;
1389 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001390 }
1391 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001392 switch (disasm_display)
1393 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001394 case Debugger::eStopDisassemblyTypeNever:
Greg Claytonbe9875d2011-11-21 21:44:34 +00001395 break;
Greg Claytona7d3dc72012-07-11 20:33:48 +00001396
Greg Clayton73844aa2012-08-22 17:17:09 +00001397 case Debugger::eStopDisassemblyTypeNoSource:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001398 if (have_source)
1399 break;
1400 // Fall through to next case
Greg Clayton73844aa2012-08-22 17:17:09 +00001401 case Debugger::eStopDisassemblyTypeAlways:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001402 if (target)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001403 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001404 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1405 if (disasm_lines > 0)
1406 {
1407 const ArchSpec &target_arch = target->GetArchitecture();
1408 AddressRange pc_range;
1409 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1410 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1411 Disassembler::Disassemble (target->GetDebugger(),
1412 target_arch,
1413 NULL,
1414 exe_ctx,
1415 pc_range,
1416 disasm_lines,
1417 0,
1418 Disassembler::eOptionMarkPCAddress,
1419 strm);
1420 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001421 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001422 break;
Greg Claytonbe9875d2011-11-21 21:44:34 +00001423 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001424 }
1425 }
1426 return true;
1427}
1428