blob: 4fb4ea9c7fdfe41a7e265e09be90ccfaa6de2757 [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 {
Greg Clayton214d2a32012-11-29 00:53:06 +0000320 uint32_t resolved = 0;
321
322 // If the target was requested add that:
323 if (!m_sc.target_sp)
324 {
325 m_sc.target_sp = CalculateTarget();
326 if (m_sc.target_sp)
327 resolved |= eSymbolContextTarget;
328 }
329
330
Chris Lattner24943d22010-06-08 16:52:24 +0000331 // Resolve our PC to section offset if we haven't alreday done so
332 // and if we don't have a module. The resolved address section will
333 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000334 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000335 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000336
337 // If this is not frame zero, then we need to subtract 1 from the PC
338 // value when doing address lookups since the PC will be on the
339 // instruction following the function call instruction...
340
Greg Claytonb04e7a82010-08-24 21:05:24 +0000341 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000342 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000343 {
344 addr_t offset = lookup_addr.GetOffset();
345 if (offset > 0)
346 lookup_addr.SetOffset(offset - 1);
347 }
348
Greg Claytonb04e7a82010-08-24 21:05:24 +0000349
Chris Lattner24943d22010-06-08 16:52:24 +0000350 if (m_sc.module_sp)
351 {
352 // We have something in our stack frame symbol context, lets check
353 // if we haven't already tried to lookup one of those things. If we
354 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000355
356 uint32_t actual_resolve_scope = 0;
357
358 if (resolve_scope & eSymbolContextCompUnit)
359 {
360 if (m_flags.IsClear (eSymbolContextCompUnit))
361 {
362 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000363 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000364 else
365 actual_resolve_scope |= eSymbolContextCompUnit;
366 }
367 }
368
369 if (resolve_scope & eSymbolContextFunction)
370 {
371 if (m_flags.IsClear (eSymbolContextFunction))
372 {
373 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000374 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000375 else
376 actual_resolve_scope |= eSymbolContextFunction;
377 }
378 }
379
380 if (resolve_scope & eSymbolContextBlock)
381 {
382 if (m_flags.IsClear (eSymbolContextBlock))
383 {
384 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000385 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000386 else
387 actual_resolve_scope |= eSymbolContextBlock;
388 }
389 }
390
391 if (resolve_scope & eSymbolContextSymbol)
392 {
393 if (m_flags.IsClear (eSymbolContextSymbol))
394 {
395 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000396 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000397 else
398 actual_resolve_scope |= eSymbolContextSymbol;
399 }
400 }
401
402 if (resolve_scope & eSymbolContextLineEntry)
403 {
404 if (m_flags.IsClear (eSymbolContextLineEntry))
405 {
406 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000407 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000408 else
409 actual_resolve_scope |= eSymbolContextLineEntry;
410 }
411 }
412
413 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000414 {
415 // We might be resolving less information than what is already
416 // in our current symbol context so resolve into a temporary
417 // symbol context "sc" so we don't clear out data we have
418 // already found in "m_sc"
419 SymbolContext sc;
420 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000421 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000422 // Only replace what we didn't already have as we may have
423 // information for an inlined function scope that won't match
424 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000425 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
426 m_sc.comp_unit = sc.comp_unit;
427 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
428 m_sc.function = sc.function;
429 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
430 m_sc.block = sc.block;
431 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
432 m_sc.symbol = sc.symbol;
Greg Clayton214d2a32012-11-29 00:53:06 +0000433 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
434 {
Greg Claytonb04e7a82010-08-24 21:05:24 +0000435 m_sc.line_entry = sc.line_entry;
Greg Clayton214d2a32012-11-29 00:53:06 +0000436 if (m_sc.target_sp)
437 {
438 // Be sure to apply and file remappings to our file and line
439 // entries when handing out a line entry
440 FileSpec new_file_spec;
441 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
442 m_sc.line_entry.file = new_file_spec;
443 }
444 }
Chris Lattner24943d22010-06-08 16:52:24 +0000445 }
446 }
447 else
448 {
449 // If we don't have a module, then we can't have the compile unit,
450 // function, block, line entry or symbol, so we can safely call
451 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000452 if (m_sc.target_sp)
Greg Clayton214d2a32012-11-29 00:53:06 +0000453 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Greg Claytonb04e7a82010-08-24 21:05:24 +0000454 }
Chris Lattner24943d22010-06-08 16:52:24 +0000455
456 // Update our internal flags so we remember what we have tried to locate so
457 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000458 // We might have dug up more information that was requested (for example
459 // if we were asked to only get the block, we will have gotten the
460 // compile unit, and function) so set any additional bits that we resolved
461 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000462 }
463
464 // Return the symbol context with everything that was possible to resolve
465 // resolved.
466 return m_sc;
467}
468
469
470VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000471StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000472{
473 if (m_flags.IsClear(RESOLVED_VARIABLES))
474 {
475 m_flags.Set(RESOLVED_VARIABLES);
476
Greg Clayton69aa5d92010-09-07 04:20:48 +0000477 Block *frame_block = GetFrameBlock();
478
479 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000480 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000481 const bool get_child_variables = true;
482 const bool can_create = true;
Greg Clayton1bd2b2f2011-06-17 22:10:16 +0000483 const bool stop_if_child_block_is_inlined_function = true;
484 m_variable_list_sp.reset(new VariableList());
485 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 +0000486 }
Sean Callanan89363592010-11-01 04:38:59 +0000487 }
488
489 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
490 get_file_globals)
491 {
492 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton17dae082010-09-02 02:59:18 +0000493
Sean Callanan89363592010-11-01 04:38:59 +0000494 if (m_flags.IsClear (eSymbolContextCompUnit))
495 GetSymbolContext (eSymbolContextCompUnit);
496
497 if (m_sc.comp_unit)
Greg Clayton17dae082010-09-02 02:59:18 +0000498 {
Sean Callanan89363592010-11-01 04:38:59 +0000499 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
500 if (m_variable_list_sp)
501 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
502 else
503 m_variable_list_sp = global_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000504 }
Chris Lattner24943d22010-06-08 16:52:24 +0000505 }
Sean Callanan89363592010-11-01 04:38:59 +0000506
Chris Lattner24943d22010-06-08 16:52:24 +0000507 return m_variable_list_sp.get();
508}
509
Greg Clayton6e2d2822011-08-02 23:35:43 +0000510VariableListSP
511StackFrame::GetInScopeVariableList (bool get_file_globals)
512{
513 VariableListSP var_list_sp(new VariableList);
514 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
515
516 if (m_sc.block)
517 {
518 const bool can_create = true;
519 const bool get_parent_variables = true;
520 const bool stop_if_block_is_inlined_function = true;
521 m_sc.block->AppendVariables (can_create,
522 get_parent_variables,
523 stop_if_block_is_inlined_function,
524 var_list_sp.get());
525 }
526
527 if (m_sc.comp_unit)
528 {
529 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
530 if (global_variable_list_sp)
531 var_list_sp->AddVariables (global_variable_list_sp.get());
532 }
533
534 return var_list_sp;
535}
536
537
Greg Clayton427f2902010-12-14 02:59:59 +0000538ValueObjectSP
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000539StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000540 DynamicValueType use_dynamic,
Jim Ingham10de7d12011-05-04 03:43:18 +0000541 uint32_t options,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000542 VariableSP &var_sp,
Jim Ingham10de7d12011-05-04 03:43:18 +0000543 Error &error)
Greg Clayton427f2902010-12-14 02:59:59 +0000544{
Greg Claytonc3b61d22010-12-15 05:08:08 +0000545
546 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton427f2902010-12-14 02:59:59 +0000547 {
Greg Claytonc67efa42011-01-20 19:27:18 +0000548 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
549 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granataf6698502011-08-09 01:04:56 +0000550 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata13a54a12011-08-19 21:56:10 +0000551 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000552 error.Clear();
553 bool deref = false;
554 bool address_of = false;
555 ValueObjectSP valobj_sp;
556 const bool get_file_globals = true;
Greg Clayton6e2d2822011-08-02 23:35:43 +0000557 // When looking up a variable for an expression, we need only consider the
558 // variables that are in scope.
559 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
560 VariableList *variable_list = var_list_sp.get();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000561
562 if (variable_list)
Greg Clayton427f2902010-12-14 02:59:59 +0000563 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000564 // If first character is a '*', then show pointer contents
565 const char *var_expr = var_expr_cstr;
566 if (var_expr[0] == '*')
Greg Clayton427f2902010-12-14 02:59:59 +0000567 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000568 deref = true;
569 var_expr++; // Skip the '*'
570 }
571 else if (var_expr[0] == '&')
572 {
573 address_of = true;
574 var_expr++; // Skip the '&'
575 }
576
577 std::string var_path (var_expr);
578 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
579 StreamString var_expr_path_strm;
580
581 ConstString name_const_string;
582 if (separator_idx == std::string::npos)
583 name_const_string.SetCString (var_path.c_str());
584 else
585 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
586
Jim Ingham10de7d12011-05-04 03:43:18 +0000587 var_sp = variable_list->FindVariable(name_const_string);
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000588
589 bool synthetically_added_instance_object = false;
590
591 if (var_sp)
592 {
593 var_path.erase (0, name_const_string.GetLength ());
594 }
595 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
596 {
597 // Check for direct ivars access which helps us with implicit
598 // access to ivars with the "this->" or "self->"
599 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
600 lldb::LanguageType method_language = eLanguageTypeUnknown;
601 bool is_instance_method = false;
602 ConstString method_object_name;
603 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
604 {
605 if (is_instance_method && method_object_name)
606 {
607 var_sp = variable_list->FindVariable(method_object_name);
608 if (var_sp)
609 {
610 separator_idx = 0;
611 var_path.insert(0, "->");
612 synthetically_added_instance_object = true;
613 }
614 }
615 }
616 }
617
Greg Claytonc3b61d22010-12-15 05:08:08 +0000618 if (var_sp)
619 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000620 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000621 if (!valobj_sp)
622 return valobj_sp;
623
Greg Claytonc3b61d22010-12-15 05:08:08 +0000624 // We are dumping at least one child
625 while (separator_idx != std::string::npos)
Greg Clayton427f2902010-12-14 02:59:59 +0000626 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000627 // Calculate the next separator index ahead of time
628 ValueObjectSP child_valobj_sp;
629 const char separator_type = var_path[0];
630 switch (separator_type)
Greg Clayton427f2902010-12-14 02:59:59 +0000631 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000632
633 case '-':
634 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton427f2902010-12-14 02:59:59 +0000635 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000636
Greg Claytonc67efa42011-01-20 19:27:18 +0000637 if (no_fragile_ivar)
638 {
639 // Make sure we aren't trying to deref an objective
640 // C ivar if this is not allowed
641 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
642 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
643 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
644 {
645 // This was an objective C object pointer and
646 // it was requested we skip any fragile ivars
647 // so return nothing here
648 return ValueObjectSP();
649 }
650 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000651 var_path.erase (0, 1); // Remove the '-'
652 // Fall through
653 case '.':
Greg Clayton427f2902010-12-14 02:59:59 +0000654 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000655 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton427f2902010-12-14 02:59:59 +0000656
Greg Claytonc3b61d22010-12-15 05:08:08 +0000657 var_path.erase (0, 1); // Remove the '.' or '>'
658 separator_idx = var_path.find_first_of(".-[");
659 ConstString child_name;
660 if (separator_idx == std::string::npos)
661 child_name.SetCString (var_path.c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000662 else
Greg Claytonc3b61d22010-12-15 05:08:08 +0000663 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
664
665 if (check_ptr_vs_member)
Greg Clayton427f2902010-12-14 02:59:59 +0000666 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000667 // We either have a pointer type and need to verify
668 // valobj_sp is a pointer, or we have a member of a
669 // class/union/struct being accessed with the . syntax
670 // and need to verify we don't have a pointer.
671 const bool actual_is_ptr = valobj_sp->IsPointerType ();
672
673 if (actual_is_ptr != expr_is_ptr)
674 {
675 // Incorrect use of "." with a pointer, or "->" with
676 // a class/union/struct instance or reference.
Greg Claytonb01000f2011-01-17 03:46:26 +0000677 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000678 if (actual_is_ptr)
679 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
680 var_expr_path_strm.GetString().c_str(),
681 child_name.GetCString(),
682 var_expr_path_strm.GetString().c_str(),
683 var_path.c_str());
684 else
685 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
686 var_expr_path_strm.GetString().c_str(),
687 child_name.GetCString(),
688 var_expr_path_strm.GetString().c_str(),
689 var_path.c_str());
690 return ValueObjectSP();
691 }
Greg Clayton427f2902010-12-14 02:59:59 +0000692 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000693 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton427f2902010-12-14 02:59:59 +0000694 if (!child_valobj_sp)
695 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000696 if (no_synth_child == false)
Enrico Granatacf09f882012-03-19 22:58:49 +0000697 {
698 child_valobj_sp = valobj_sp->GetSyntheticValue();
699 if (child_valobj_sp)
700 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
701 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000702
703 if (no_synth_child || !child_valobj_sp)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000704 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000705 // No child member with name "child_name"
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000706 if (synthetically_added_instance_object)
Enrico Granata9c57fc02011-08-11 17:08:01 +0000707 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000708 // We added a "this->" or "self->" to the beginning of the expression
709 // and this is the first pointer ivar access, so just return the normal
710 // error
711 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
712 name_const_string.GetCString());
Enrico Granata9c57fc02011-08-11 17:08:01 +0000713 }
714 else
715 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000716 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
717 if (child_name)
718 {
719 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
720 child_name.GetCString(),
721 valobj_sp->GetTypeName().AsCString("<invalid type>"),
722 var_expr_path_strm.GetString().c_str());
723 }
724 else
725 {
726 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
727 var_expr_path_strm.GetString().c_str(),
728 var_expr_cstr);
729 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000730 }
731 return ValueObjectSP();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000732 }
Greg Clayton427f2902010-12-14 02:59:59 +0000733 }
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000734 synthetically_added_instance_object = false;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000735 // Remove the child name from the path
736 var_path.erase(0, child_name.GetLength());
Greg Clayton987c7eb2011-09-17 08:33:22 +0000737 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000738 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000739 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000740 if (dynamic_value_sp)
741 child_valobj_sp = dynamic_value_sp;
742 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000743 }
744 break;
Greg Clayton427f2902010-12-14 02:59:59 +0000745
Greg Claytonc3b61d22010-12-15 05:08:08 +0000746 case '[':
747 // Array member access, or treating pointer as an array
748 if (var_path.size() > 2) // Need at least two brackets and a number
749 {
750 char *end = NULL;
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000751 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9762e102011-07-06 02:13:41 +0000752 if (end && *end == ']'
753 && *(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 +0000754 {
Enrico Granata9762e102011-07-06 02:13:41 +0000755 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
756 {
757 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
758 // and extract bit low out of it. reading array item low
759 // would be done by saying ptr[low], without a deref * sign
760 Error error;
761 ValueObjectSP temp(valobj_sp->Dereference(error));
762 if (error.Fail())
763 {
764 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
765 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
766 valobj_sp->GetTypeName().AsCString("<invalid type>"),
767 var_expr_path_strm.GetString().c_str());
768 return ValueObjectSP();
769 }
770 valobj_sp = temp;
771 deref = false;
772 }
773 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
774 {
775 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
776 // (an operation that is equivalent to deref-ing arr)
777 // and extract bit low out of it. reading array item low
778 // would be done by saying arr[low], without a deref * sign
779 Error error;
780 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
781 if (error.Fail())
782 {
783 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
784 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
785 valobj_sp->GetTypeName().AsCString("<invalid type>"),
786 var_expr_path_strm.GetString().c_str());
787 return ValueObjectSP();
788 }
789 valobj_sp = temp;
790 deref = false;
791 }
792
Greg Claytonc3b61d22010-12-15 05:08:08 +0000793 if (valobj_sp->IsPointerType ())
794 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000795 bool is_objc_pointer = true;
796
797 if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
798 is_objc_pointer = false;
799 else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
800 is_objc_pointer = false;
801
802 if (no_synth_child && is_objc_pointer)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000803 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000804 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
805 valobj_sp->GetTypeName().AsCString("<invalid type>"),
806 var_expr_path_strm.GetString().c_str());
807
808 return ValueObjectSP();
809 }
810 else if (is_objc_pointer)
811 {
Enrico Granataf6698502011-08-09 01:04:56 +0000812 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granatacf09f882012-03-19 22:58:49 +0000813 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000814 if (synthetic.get() == NULL /* no synthetic */
815 || synthetic == valobj_sp) /* synthetic is the same as the original object */
816 {
817 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
818 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
819 valobj_sp->GetTypeName().AsCString("<invalid type>"),
820 var_expr_path_strm.GetString().c_str());
821 }
822 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
823 {
824 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000825 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000826 child_index,
827 valobj_sp->GetTypeName().AsCString("<invalid type>"),
828 var_expr_path_strm.GetString().c_str());
829 }
830 else
831 {
832 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
833 if (!child_valobj_sp)
834 {
835 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000836 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000837 child_index,
838 valobj_sp->GetTypeName().AsCString("<invalid type>"),
839 var_expr_path_strm.GetString().c_str());
840 }
841 }
842 }
843 else
844 {
845 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
846 if (!child_valobj_sp)
847 {
848 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000849 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000850 child_index,
851 valobj_sp->GetTypeName().AsCString("<invalid type>"),
852 var_expr_path_strm.GetString().c_str());
853 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000854 }
855 }
856 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
857 {
Jim Inghame41494a2011-04-16 00:01:13 +0000858 // Pass false to dynamic_value here so we can tell the difference between
859 // no dynamic value and no member of this type...
Greg Claytonc3b61d22010-12-15 05:08:08 +0000860 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
861 if (!child_valobj_sp)
862 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000863 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000864 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Claytonc3b61d22010-12-15 05:08:08 +0000865 child_index,
866 valobj_sp->GetTypeName().AsCString("<invalid type>"),
867 var_expr_path_strm.GetString().c_str());
868 }
869 }
Enrico Granata9762e102011-07-06 02:13:41 +0000870 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
871 {
872 // this is a bitfield asking to display just one bit
873 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
874 if (!child_valobj_sp)
875 {
876 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000877 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9762e102011-07-06 02:13:41 +0000878 child_index, child_index,
879 valobj_sp->GetTypeName().AsCString("<invalid type>"),
880 var_expr_path_strm.GetString().c_str());
881 }
882 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000883 else
884 {
Enrico Granatacf09f882012-03-19 22:58:49 +0000885 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000886 if (no_synth_child /* synthetic is forbidden */ ||
887 synthetic.get() == NULL /* no synthetic */
888 || synthetic == valobj_sp) /* synthetic is the same as the original object */
889 {
890 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
891 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
892 valobj_sp->GetTypeName().AsCString("<invalid type>"),
893 var_expr_path_strm.GetString().c_str());
894 }
895 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
896 {
897 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000898 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000899 child_index,
900 valobj_sp->GetTypeName().AsCString("<invalid type>"),
901 var_expr_path_strm.GetString().c_str());
902 }
903 else
904 {
905 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
906 if (!child_valobj_sp)
907 {
908 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000909 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000910 child_index,
911 valobj_sp->GetTypeName().AsCString("<invalid type>"),
912 var_expr_path_strm.GetString().c_str());
913 }
914 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000915 }
916
917 if (!child_valobj_sp)
918 {
919 // Invalid array index...
920 return ValueObjectSP();
921 }
922
923 // Erase the array member specification '[%i]' where
924 // %i is the array index
925 var_path.erase(0, (end - var_path.c_str()) + 1);
926 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +0000927 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000928 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000929 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000930 if (dynamic_value_sp)
931 child_valobj_sp = dynamic_value_sp;
932 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000933 // Break out early from the switch since we were
934 // able to find the child member
935 break;
936 }
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000937 else if (end && *end == '-')
Enrico Granata9762e102011-07-06 02:13:41 +0000938 {
939 // this is most probably a BitField, let's take a look
940 char *real_end = NULL;
941 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granata6f302872011-08-19 21:13:46 +0000942 bool expand_bitfield = true;
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000943 if (real_end && *real_end == ']')
Enrico Granata9762e102011-07-06 02:13:41 +0000944 {
945 // if the format given is [high-low], swap range
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000946 if (child_index > final_index)
Enrico Granata9762e102011-07-06 02:13:41 +0000947 {
948 long temp = child_index;
949 child_index = final_index;
950 final_index = temp;
951 }
952
953 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
954 {
955 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
956 // and extract bits low thru high out of it. reading array items low thru high
957 // would be done by saying ptr[low-high], without a deref * sign
958 Error error;
959 ValueObjectSP temp(valobj_sp->Dereference(error));
960 if (error.Fail())
961 {
962 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
963 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
964 valobj_sp->GetTypeName().AsCString("<invalid type>"),
965 var_expr_path_strm.GetString().c_str());
966 return ValueObjectSP();
967 }
968 valobj_sp = temp;
969 deref = false;
970 }
971 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
972 {
973 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
974 // (an operation that is equivalent to deref-ing arr)
975 // and extract bits low thru high out of it. reading array items low thru high
976 // would be done by saying arr[low-high], without a deref * sign
977 Error error;
978 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
979 if (error.Fail())
980 {
981 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
982 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
983 valobj_sp->GetTypeName().AsCString("<invalid type>"),
984 var_expr_path_strm.GetString().c_str());
985 return ValueObjectSP();
986 }
987 valobj_sp = temp;
988 deref = false;
989 }
Enrico Granata6f302872011-08-19 21:13:46 +0000990 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9762e102011-07-06 02:13:41 +0000991 {
Enrico Granata6f302872011-08-19 21:13:46 +0000992 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
993 expand_bitfield = false;
994 if (!child_valobj_sp)
995 {
996 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
997 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
998 child_index, final_index,
999 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1000 var_expr_path_strm.GetString().c_str());
1001 }
1002 }*/
1003
1004 if (expand_bitfield)
1005 {
1006 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1007 if (!child_valobj_sp)
1008 {
1009 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +00001010 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata6f302872011-08-19 21:13:46 +00001011 child_index, final_index,
1012 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1013 var_expr_path_strm.GetString().c_str());
1014 }
Enrico Granata9762e102011-07-06 02:13:41 +00001015 }
1016 }
1017
1018 if (!child_valobj_sp)
1019 {
1020 // Invalid bitfield range...
1021 return ValueObjectSP();
1022 }
1023
1024 // Erase the bitfield member specification '[%i-%i]' where
1025 // %i is the index
1026 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1027 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +00001028 if (use_dynamic != eNoDynamicValues)
Enrico Granata9762e102011-07-06 02:13:41 +00001029 {
1030 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1031 if (dynamic_value_sp)
1032 child_valobj_sp = dynamic_value_sp;
1033 }
1034 // Break out early from the switch since we were
1035 // able to find the child member
1036 break;
1037
1038 }
1039 }
1040 else
1041 {
1042 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1043 var_expr_path_strm.GetString().c_str(),
1044 var_path.c_str());
Greg Claytonc3b61d22010-12-15 05:08:08 +00001045 }
1046 return ValueObjectSP();
1047
1048 default:
1049 // Failure...
1050 {
Greg Claytonb01000f2011-01-17 03:46:26 +00001051 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001052 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1053 separator_type,
1054 var_expr_path_strm.GetString().c_str(),
1055 var_path.c_str());
1056
1057 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +00001058 }
1059 }
Greg Clayton427f2902010-12-14 02:59:59 +00001060
Greg Claytonc3b61d22010-12-15 05:08:08 +00001061 if (child_valobj_sp)
1062 valobj_sp = child_valobj_sp;
1063
1064 if (var_path.empty())
1065 break;
1066
Greg Clayton427f2902010-12-14 02:59:59 +00001067 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001068 if (valobj_sp)
1069 {
1070 if (deref)
1071 {
Greg Claytonbdcda462010-12-20 20:49:23 +00001072 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Claytonc3b61d22010-12-15 05:08:08 +00001073 valobj_sp = deref_valobj_sp;
1074 }
1075 else if (address_of)
1076 {
1077 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1078 valobj_sp = address_of_valobj_sp;
1079 }
1080 }
1081 return valobj_sp;
Greg Clayton427f2902010-12-14 02:59:59 +00001082 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001083 else
Greg Clayton427f2902010-12-14 02:59:59 +00001084 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001085 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1086 name_const_string.GetCString());
Greg Clayton427f2902010-12-14 02:59:59 +00001087 }
Greg Clayton427f2902010-12-14 02:59:59 +00001088 }
1089 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001090 else
1091 {
1092 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1093 }
Greg Clayton427f2902010-12-14 02:59:59 +00001094 return ValueObjectSP();
1095}
Chris Lattner24943d22010-06-08 16:52:24 +00001096
1097bool
1098StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1099{
1100 if (m_flags.IsClear(GOT_FRAME_BASE))
1101 {
1102 if (m_sc.function)
1103 {
1104 m_frame_base.Clear();
1105 m_frame_base_error.Clear();
1106
1107 m_flags.Set(GOT_FRAME_BASE);
Greg Clayton289afcb2012-02-18 05:35:26 +00001108 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001109 Value expr_value;
Greg Clayton178710c2010-09-14 02:20:48 +00001110 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1111 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Clayton289afcb2012-02-18 05:35:26 +00001112 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton178710c2010-09-14 02:20:48 +00001113
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001114 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 +00001115 {
1116 // We should really have an error if evaluate returns, but in case
1117 // we don't, lets set the error to something at least.
1118 if (m_frame_base_error.Success())
1119 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1120 }
1121 else
1122 {
1123 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
1124 }
1125 }
1126 else
1127 {
1128 m_frame_base_error.SetErrorString ("No function in symbol context.");
1129 }
1130 }
1131
1132 if (m_frame_base_error.Success())
1133 frame_base = m_frame_base;
1134
1135 if (error_ptr)
1136 *error_ptr = m_frame_base_error;
1137 return m_frame_base_error.Success();
1138}
1139
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001140RegisterContextSP
Chris Lattner24943d22010-06-08 16:52:24 +00001141StackFrame::GetRegisterContext ()
1142{
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001143 if (!m_reg_context_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +00001144 {
1145 ThreadSP thread_sp (GetThread());
1146 if (thread_sp)
1147 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1148 }
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001149 return m_reg_context_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001150}
1151
1152bool
1153StackFrame::HasDebugInformation ()
1154{
Greg Claytonb04e7a82010-08-24 21:05:24 +00001155 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +00001156 return m_sc.line_entry.IsValid();
1157}
1158
Greg Clayton17dae082010-09-02 02:59:18 +00001159
1160ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001161StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner24943d22010-06-08 16:52:24 +00001162{
Greg Clayton17dae082010-09-02 02:59:18 +00001163 ValueObjectSP valobj_sp;
1164 VariableList *var_list = GetVariableList (true);
1165 if (var_list)
1166 {
1167 // Make sure the variable is a frame variable
1168 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1169 const uint32_t num_variables = var_list->GetSize();
1170 if (var_idx < num_variables)
1171 {
1172 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1173 if (valobj_sp.get() == NULL)
1174 {
1175 if (m_variable_list_value_objects.GetSize() < num_variables)
1176 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham47da8102011-04-22 23:53:53 +00001177 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton17dae082010-09-02 02:59:18 +00001178 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1179 }
1180 }
1181 }
Greg Clayton987c7eb2011-09-17 08:33:22 +00001182 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +00001183 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001184 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001185 if (dynamic_sp)
1186 return dynamic_sp;
1187 }
Greg Clayton17dae082010-09-02 02:59:18 +00001188 return valobj_sp;
1189}
1190
1191ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001192StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton17dae082010-09-02 02:59:18 +00001193{
1194 // Check to make sure we aren't already tracking this variable?
Jim Inghame41494a2011-04-16 00:01:13 +00001195 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton17dae082010-09-02 02:59:18 +00001196 if (!valobj_sp)
1197 {
1198 // We aren't already tracking this global
1199 VariableList *var_list = GetVariableList (true);
1200 // If this frame has no variables, create a new list
1201 if (var_list == NULL)
1202 m_variable_list_sp.reset (new VariableList());
1203
1204 // Add the global/static variable to this frame
1205 m_variable_list_sp->AddVariable (variable_sp);
1206
1207 // Now make a value object for it so we can track its changes
Jim Inghame41494a2011-04-16 00:01:13 +00001208 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton17dae082010-09-02 02:59:18 +00001209 }
1210 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001211}
1212
Jim Ingham2154da42010-08-26 20:44:45 +00001213bool
1214StackFrame::IsInlined ()
1215{
Greg Clayton4fb08152010-08-30 18:11:35 +00001216 if (m_sc.block == NULL)
1217 GetSymbolContext (eSymbolContextBlock);
1218 if (m_sc.block)
1219 return m_sc.block->GetContainingInlinedBlock() != NULL;
1220 return false;
Jim Ingham2154da42010-08-26 20:44:45 +00001221}
1222
Greg Clayton289afcb2012-02-18 05:35:26 +00001223TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001224StackFrame::CalculateTarget ()
1225{
Greg Clayton289afcb2012-02-18 05:35:26 +00001226 TargetSP target_sp;
1227 ThreadSP thread_sp(GetThread());
1228 if (thread_sp)
1229 {
1230 ProcessSP process_sp (thread_sp->CalculateProcess());
1231 if (process_sp)
1232 target_sp = process_sp->CalculateTarget();
1233 }
1234 return target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001235}
1236
Greg Clayton289afcb2012-02-18 05:35:26 +00001237ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001238StackFrame::CalculateProcess ()
1239{
Greg Clayton289afcb2012-02-18 05:35:26 +00001240 ProcessSP process_sp;
1241 ThreadSP thread_sp(GetThread());
1242 if (thread_sp)
1243 process_sp = thread_sp->CalculateProcess();
1244 return process_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001245}
1246
Greg Clayton289afcb2012-02-18 05:35:26 +00001247ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001248StackFrame::CalculateThread ()
1249{
Greg Clayton289afcb2012-02-18 05:35:26 +00001250 return GetThread();
Chris Lattner24943d22010-06-08 16:52:24 +00001251}
1252
Greg Clayton289afcb2012-02-18 05:35:26 +00001253StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001254StackFrame::CalculateStackFrame ()
1255{
Greg Clayton289afcb2012-02-18 05:35:26 +00001256 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001257}
1258
1259
1260void
Greg Claytona830adb2010-10-04 01:05:56 +00001261StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001262{
Greg Clayton289afcb2012-02-18 05:35:26 +00001263 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001264}
1265
1266void
Greg Claytona830adb2010-10-04 01:05:56 +00001267StackFrame::DumpUsingSettingsFormat (Stream *strm)
1268{
1269 if (strm == NULL)
1270 return;
1271
1272 GetSymbolContext(eSymbolContextEverything);
Greg Clayton289afcb2012-02-18 05:35:26 +00001273 ExecutionContext exe_ctx (shared_from_this());
Greg Claytona830adb2010-10-04 01:05:56 +00001274 const char *end = NULL;
1275 StreamString s;
Greg Clayton289afcb2012-02-18 05:35:26 +00001276 const char *frame_format = NULL;
1277 Target *target = exe_ctx.GetTargetPtr();
1278 if (target)
1279 frame_format = target->GetDebugger().GetFrameFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001280 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1281 {
1282 strm->Write(s.GetData(), s.GetSize());
1283 }
1284 else
1285 {
1286 Dump (strm, true, false);
1287 strm->EOL();
1288 }
1289}
1290
1291void
Greg Clayton72b71582010-09-02 21:44:10 +00001292StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +00001293{
1294 if (strm == NULL)
1295 return;
1296
1297 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +00001298 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton289afcb2012-02-18 05:35:26 +00001299 ExecutionContext exe_ctx (shared_from_this());
1300 Target *target = exe_ctx.GetTargetPtr();
1301 strm->Printf("0x%0*llx ",
1302 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1303 GetFrameCodeAddress().GetLoadAddress(target));
Greg Claytonb04e7a82010-08-24 21:05:24 +00001304 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +00001305 const bool show_module = true;
1306 const bool show_inline = true;
Greg Clayton289afcb2012-02-18 05:35:26 +00001307 m_sc.DumpStopContext (strm,
1308 exe_ctx.GetBestExecutionContextScope(),
1309 GetFrameCodeAddress(),
1310 show_fullpaths,
1311 show_module,
1312 show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +00001313}
1314
Greg Clayton1d66ef52010-08-27 18:24:16 +00001315void
Greg Clayton4fb08152010-08-30 18:11:35 +00001316StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +00001317{
Greg Clayton4fb08152010-08-30 18:11:35 +00001318 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
1319 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +00001320 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +00001321 if (!m_disassembly.GetString().empty())
1322 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +00001323}
Greg Clayton870a1cd2010-08-27 21:47:54 +00001324
1325
Greg Clayton4fb08152010-08-30 18:11:35 +00001326void
1327StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1328{
Greg Clayton5205f0b2010-09-03 17:10:42 +00001329 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
1330 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton289afcb2012-02-18 05:35:26 +00001331 assert (GetThread() == curr_frame.GetThread());
Greg Clayton4fb08152010-08-30 18:11:35 +00001332 m_frame_index = curr_frame.m_frame_index;
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001333 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton4fb08152010-08-30 18:11:35 +00001334 m_reg_context_sp = curr_frame.m_reg_context_sp;
1335 m_frame_code_addr = curr_frame.m_frame_code_addr;
1336 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());
1337 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());
1338 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1339 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 +00001340 m_sc = curr_frame.m_sc;
1341 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1342 m_flags.Set (m_sc.GetResolvedMask());
1343 m_frame_base.Clear();
1344 m_frame_base_error.Clear();
1345}
1346
1347
Greg Clayton5205f0b2010-09-03 17:10:42 +00001348bool
1349StackFrame::HasCachedData () const
1350{
1351 if (m_variable_list_sp.get())
1352 return true;
1353 if (m_variable_list_value_objects.GetSize() > 0)
1354 return true;
1355 if (!m_disassembly.GetString().empty())
1356 return true;
1357 return false;
Jim Inghamccd584d2010-09-23 17:40:12 +00001358}
1359
Greg Claytonabe0fed2011-04-18 08:33:37 +00001360bool
1361StackFrame::GetStatus (Stream& strm,
1362 bool show_frame_info,
Greg Claytona7d3dc72012-07-11 20:33:48 +00001363 bool show_source)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001364{
Greg Claytona7d3dc72012-07-11 20:33:48 +00001365
Greg Claytonabe0fed2011-04-18 08:33:37 +00001366 if (show_frame_info)
1367 {
1368 strm.Indent();
1369 DumpUsingSettingsFormat (&strm);
1370 }
1371
1372 if (show_source)
1373 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001374 ExecutionContext exe_ctx (shared_from_this());
Greg Claytonbe9875d2011-11-21 21:44:34 +00001375 bool have_source = false;
Greg Clayton73844aa2012-08-22 17:17:09 +00001376 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Clayton289afcb2012-02-18 05:35:26 +00001377 Target *target = exe_ctx.GetTargetPtr();
Greg Claytona7d3dc72012-07-11 20:33:48 +00001378 if (target)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001379 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001380 Debugger &debugger = target->GetDebugger();
1381 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1382 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1383 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytonbe9875d2011-11-21 21:44:34 +00001384
Greg Claytona7d3dc72012-07-11 20:33:48 +00001385 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001386 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001387 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1388
1389 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytonbe9875d2011-11-21 21:44:34 +00001390 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001391 if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
1392 m_sc.line_entry.line,
1393 source_lines_before,
1394 source_lines_after,
1395 "->",
1396 &strm))
1397 {
1398 have_source = true;
1399 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001400 }
1401 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001402 switch (disasm_display)
1403 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001404 case Debugger::eStopDisassemblyTypeNever:
Greg Claytonbe9875d2011-11-21 21:44:34 +00001405 break;
Greg Claytona7d3dc72012-07-11 20:33:48 +00001406
Greg Clayton73844aa2012-08-22 17:17:09 +00001407 case Debugger::eStopDisassemblyTypeNoSource:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001408 if (have_source)
1409 break;
1410 // Fall through to next case
Greg Clayton73844aa2012-08-22 17:17:09 +00001411 case Debugger::eStopDisassemblyTypeAlways:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001412 if (target)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001413 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001414 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1415 if (disasm_lines > 0)
1416 {
1417 const ArchSpec &target_arch = target->GetArchitecture();
1418 AddressRange pc_range;
1419 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1420 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1421 Disassembler::Disassemble (target->GetDebugger(),
1422 target_arch,
1423 NULL,
1424 exe_ctx,
1425 pc_range,
1426 disasm_lines,
1427 0,
1428 Disassembler::eOptionMarkPCAddress,
1429 strm);
1430 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001431 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001432 break;
Greg Claytonbe9875d2011-11-21 21:44:34 +00001433 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001434 }
1435 }
1436 return true;
1437}
1438