blob: 6bfddf63e8f1a8823f6f4447ce26dbaf8d087860 [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"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Symbol/Function.h"
Greg Clayton17dae082010-09-02 02:59:18 +000023#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Target/ExecutionContext.h"
25#include "lldb/Target/Process.h"
26#include "lldb/Target/RegisterContext.h"
27#include "lldb/Target/Target.h"
28#include "lldb/Target/Thread.h"
29
30using namespace lldb;
31using namespace lldb_private;
32
33// The first bits in the flags are reserved for the SymbolContext::Scope bits
34// so we know if we have tried to look up information in our internal symbol
35// context (m_sc) already.
Greg Clayton4fb08152010-08-30 18:11:35 +000036#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton72b71582010-09-02 21:44:10 +000037#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton4fb08152010-08-30 18:11:35 +000038#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
39#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan89363592010-11-01 04:38:59 +000040#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner24943d22010-06-08 16:52:24 +000041
Greg Clayton289afcb2012-02-18 05:35:26 +000042StackFrame::StackFrame (const ThreadSP &thread_sp,
43 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000044 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000045 addr_t cfa,
46 addr_t pc,
47 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000048 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000049 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000050 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000051 m_reg_context_sp (),
Greg Clayton72b71582010-09-02 21:44:10 +000052 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000053 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000054 m_sc (),
55 m_flags (),
56 m_frame_base (),
57 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000058 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000059 m_variable_list_value_objects (),
60 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000061{
62 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000063 {
Chris Lattner24943d22010-06-08 16:52:24 +000064 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000065 m_flags.Set(m_sc.GetResolvedMask ());
66 }
Chris Lattner24943d22010-06-08 16:52:24 +000067}
68
Greg Clayton289afcb2012-02-18 05:35:26 +000069StackFrame::StackFrame (const ThreadSP &thread_sp,
70 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000071 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000072 const RegisterContextSP &reg_context_sp,
73 addr_t cfa,
74 addr_t pc,
75 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000076 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000077 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000078 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000079 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +000080 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000081 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000082 m_sc (),
83 m_flags (),
84 m_frame_base (),
85 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000086 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000087 m_variable_list_value_objects (),
88 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000089{
90 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000091 {
Chris Lattner24943d22010-06-08 16:52:24 +000092 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000093 m_flags.Set(m_sc.GetResolvedMask ());
94 }
95
96 if (reg_context_sp && !m_sc.target_sp)
97 {
Greg Clayton289afcb2012-02-18 05:35:26 +000098 m_sc.target_sp = reg_context_sp->CalculateTarget();
99 if (m_sc.target_sp)
100 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000101 }
102}
103
Greg Clayton289afcb2012-02-18 05:35:26 +0000104StackFrame::StackFrame (const ThreadSP &thread_sp,
105 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000106 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000107 const RegisterContextSP &reg_context_sp,
108 addr_t cfa,
109 const Address& pc_addr,
110 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +0000111 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +0000112 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000113 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +0000114 m_reg_context_sp (reg_context_sp),
Greg Claytonf4124de2012-02-21 00:09:25 +0000115 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +0000116 m_frame_code_addr (pc_addr),
Greg Clayton33ed1702010-08-24 00:45:41 +0000117 m_sc (),
118 m_flags (),
119 m_frame_base (),
120 m_frame_base_error (),
121 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000122 m_variable_list_value_objects (),
123 m_disassembly ()
Greg Clayton33ed1702010-08-24 00:45:41 +0000124{
125 if (sc_ptr != NULL)
126 {
127 m_sc = *sc_ptr;
128 m_flags.Set(m_sc.GetResolvedMask ());
129 }
130
131 if (m_sc.target_sp.get() == NULL && reg_context_sp)
132 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000133 m_sc.target_sp = reg_context_sp->CalculateTarget();
134 if (m_sc.target_sp)
135 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000136 }
137
Greg Clayton3508c382012-02-24 01:59:29 +0000138 ModuleSP pc_module_sp (pc_addr.GetModule());
139 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000140 {
Greg Clayton3508c382012-02-24 01:59:29 +0000141 if (pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000142 {
Greg Clayton3508c382012-02-24 01:59:29 +0000143 m_sc.module_sp = pc_module_sp;
Greg Clayton33ed1702010-08-24 00:45:41 +0000144 m_flags.Set (eSymbolContextModule);
145 }
Greg Claytone2c5e452010-09-13 04:34:30 +0000146 else
147 {
148 m_sc.module_sp.reset();
149 }
Greg Clayton33ed1702010-08-24 00:45:41 +0000150 }
Chris Lattner24943d22010-06-08 16:52:24 +0000151}
152
153
154//----------------------------------------------------------------------
155// Destructor
156//----------------------------------------------------------------------
157StackFrame::~StackFrame()
158{
159}
160
161StackID&
162StackFrame::GetStackID()
163{
Greg Clayton72b71582010-09-02 21:44:10 +0000164 // Make sure we have resolved the StackID object's symbol context scope if
165 // we already haven't looked it up.
Chris Lattner24943d22010-06-08 16:52:24 +0000166
Greg Clayton4fb08152010-08-30 18:11:35 +0000167 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
168 {
Greg Clayton5205f0b2010-09-03 17:10:42 +0000169 if (m_id.GetSymbolContextScope ())
Greg Clayton4fb08152010-08-30 18:11:35 +0000170 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000171 // We already have a symbol context scope, we just don't have our
172 // flag bit set.
Greg Clayton4fb08152010-08-30 18:11:35 +0000173 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
174 }
175 else
176 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000177 // Calculate the frame block and use this for the stack ID symbol
178 // context scope if we have one.
179 SymbolContextScope *scope = GetFrameBlock ();
180 if (scope == NULL)
Greg Clayton4fb08152010-08-30 18:11:35 +0000181 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000182 // We don't have a block, so use the symbol
183 if (m_flags.IsClear (eSymbolContextSymbol))
184 GetSymbolContext (eSymbolContextSymbol);
185
186 // It is ok if m_sc.symbol is NULL here
187 scope = m_sc.symbol;
Greg Clayton4fb08152010-08-30 18:11:35 +0000188 }
Greg Clayton69aa5d92010-09-07 04:20:48 +0000189 // Set the symbol context scope (the accessor will set the
190 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
191 SetSymbolContextScope (scope);
Greg Clayton4fb08152010-08-30 18:11:35 +0000192 }
Chris Lattner24943d22010-06-08 16:52:24 +0000193 }
194 return m_id;
195}
196
Greg Clayton4fb08152010-08-30 18:11:35 +0000197void
198StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
199{
200 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
201 m_id.SetSymbolContextScope (symbol_scope);
202}
203
Greg Clayton107e53d2011-07-06 04:07:21 +0000204const Address&
Greg Claytonb04e7a82010-08-24 21:05:24 +0000205StackFrame::GetFrameCodeAddress()
Chris Lattner24943d22010-06-08 16:52:24 +0000206{
Greg Clayton4fb08152010-08-30 18:11:35 +0000207 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000208 {
Greg Clayton4fb08152010-08-30 18:11:35 +0000209 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner24943d22010-06-08 16:52:24 +0000210
211 // Resolve the PC into a temporary address because if ResolveLoadAddress
212 // fails to resolve the address, it will clear the address object...
Greg Clayton289afcb2012-02-18 05:35:26 +0000213 ThreadSP thread_sp (GetThread());
214 if (thread_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000215 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000216 TargetSP target_sp (thread_sp->CalculateTarget());
217 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000218 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000219 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000220 {
Greg Clayton3508c382012-02-24 01:59:29 +0000221 ModuleSP module_sp (m_frame_code_addr.GetModule());
222 if (module_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +0000223 {
Greg Clayton3508c382012-02-24 01:59:29 +0000224 m_sc.module_sp = module_sp;
225 m_flags.Set(eSymbolContextModule);
Greg Clayton289afcb2012-02-18 05:35:26 +0000226 }
Chris Lattner24943d22010-06-08 16:52:24 +0000227 }
228 }
229 }
230 }
Greg Clayton65124ea2010-08-26 22:05:43 +0000231 return m_frame_code_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000232}
233
234void
235StackFrame::ChangePC (addr_t pc)
236{
Greg Clayton3508c382012-02-24 01:59:29 +0000237 m_frame_code_addr.SetRawAddress(pc);
Chris Lattner24943d22010-06-08 16:52:24 +0000238 m_sc.Clear();
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000239 m_flags.Reset(0);
Greg Clayton289afcb2012-02-18 05:35:26 +0000240 ThreadSP thread_sp (GetThread());
241 if (thread_sp)
242 thread_sp->ClearStackFrames ();
Chris Lattner24943d22010-06-08 16:52:24 +0000243}
244
245const char *
246StackFrame::Disassemble ()
247{
248 if (m_disassembly.GetSize() == 0)
249 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000250 ExecutionContext exe_ctx (shared_from_this());
251 Target *target = exe_ctx.GetTargetPtr();
252 if (target)
253 {
254 Disassembler::Disassemble (target->GetDebugger(),
255 target->GetArchitecture(),
256 NULL,
257 exe_ctx,
258 0,
259 0,
260 0,
261 m_disassembly);
262 }
Chris Lattner24943d22010-06-08 16:52:24 +0000263 if (m_disassembly.GetSize() == 0)
264 return NULL;
265 }
266 return m_disassembly.GetData();
267}
268
Greg Clayton69aa5d92010-09-07 04:20:48 +0000269Block *
270StackFrame::GetFrameBlock ()
271{
272 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
273 GetSymbolContext (eSymbolContextBlock);
274
275 if (m_sc.block)
276 {
277 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
278 if (inline_block)
279 {
280 // Use the block with the inlined function info
281 // as the frame block we want this frame to have only the variables
282 // for the inlined function and its non-inlined block child blocks.
283 return inline_block;
284 }
285 else
286 {
287 // This block is not contained withing any inlined function blocks
288 // with so we want to use the top most function block.
289 return &m_sc.function->GetBlock (false);
290 }
291 }
292 return NULL;
293}
294
Chris Lattner24943d22010-06-08 16:52:24 +0000295//----------------------------------------------------------------------
296// Get the symbol context if we already haven't done so by resolving the
297// PC address as much as possible. This way when we pass around a
298// StackFrame object, everyone will have as much information as
299// possible and no one will ever have to look things up manually.
300//----------------------------------------------------------------------
301const SymbolContext&
302StackFrame::GetSymbolContext (uint32_t resolve_scope)
303{
304 // Copy our internal symbol context into "sc".
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000305 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000306 {
307 // Resolve our PC to section offset if we haven't alreday done so
308 // and if we don't have a module. The resolved address section will
309 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000310 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000311 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000312
313 // If this is not frame zero, then we need to subtract 1 from the PC
314 // value when doing address lookups since the PC will be on the
315 // instruction following the function call instruction...
316
Greg Claytonb04e7a82010-08-24 21:05:24 +0000317 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000318 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000319 {
320 addr_t offset = lookup_addr.GetOffset();
321 if (offset > 0)
322 lookup_addr.SetOffset(offset - 1);
323 }
324
Greg Claytonb04e7a82010-08-24 21:05:24 +0000325
326 uint32_t resolved = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000327 if (m_sc.module_sp)
328 {
329 // We have something in our stack frame symbol context, lets check
330 // if we haven't already tried to lookup one of those things. If we
331 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000332
333 uint32_t actual_resolve_scope = 0;
334
335 if (resolve_scope & eSymbolContextCompUnit)
336 {
337 if (m_flags.IsClear (eSymbolContextCompUnit))
338 {
339 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000340 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000341 else
342 actual_resolve_scope |= eSymbolContextCompUnit;
343 }
344 }
345
346 if (resolve_scope & eSymbolContextFunction)
347 {
348 if (m_flags.IsClear (eSymbolContextFunction))
349 {
350 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000351 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000352 else
353 actual_resolve_scope |= eSymbolContextFunction;
354 }
355 }
356
357 if (resolve_scope & eSymbolContextBlock)
358 {
359 if (m_flags.IsClear (eSymbolContextBlock))
360 {
361 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000362 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000363 else
364 actual_resolve_scope |= eSymbolContextBlock;
365 }
366 }
367
368 if (resolve_scope & eSymbolContextSymbol)
369 {
370 if (m_flags.IsClear (eSymbolContextSymbol))
371 {
372 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000373 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000374 else
375 actual_resolve_scope |= eSymbolContextSymbol;
376 }
377 }
378
379 if (resolve_scope & eSymbolContextLineEntry)
380 {
381 if (m_flags.IsClear (eSymbolContextLineEntry))
382 {
383 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000384 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000385 else
386 actual_resolve_scope |= eSymbolContextLineEntry;
387 }
388 }
389
390 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000391 {
392 // We might be resolving less information than what is already
393 // in our current symbol context so resolve into a temporary
394 // symbol context "sc" so we don't clear out data we have
395 // already found in "m_sc"
396 SymbolContext sc;
397 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000398 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000399 // Only replace what we didn't already have as we may have
400 // information for an inlined function scope that won't match
401 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000402 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
403 m_sc.comp_unit = sc.comp_unit;
404 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
405 m_sc.function = sc.function;
406 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
407 m_sc.block = sc.block;
408 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
409 m_sc.symbol = sc.symbol;
410 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
411 m_sc.line_entry = sc.line_entry;
412
Chris Lattner24943d22010-06-08 16:52:24 +0000413 }
414 }
415 else
416 {
417 // If we don't have a module, then we can't have the compile unit,
418 // function, block, line entry or symbol, so we can safely call
419 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton289afcb2012-02-18 05:35:26 +0000420 TargetSP target_sp (CalculateTarget());
421 if (target_sp)
422 resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000423 }
424
425 // If the target was requested add that:
Greg Clayton289afcb2012-02-18 05:35:26 +0000426 if (!m_sc.target_sp)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000427 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000428 m_sc.target_sp = CalculateTarget();
Greg Claytonb04e7a82010-08-24 21:05:24 +0000429 if (m_sc.target_sp)
430 resolved |= eSymbolContextTarget;
431 }
Chris Lattner24943d22010-06-08 16:52:24 +0000432
433 // Update our internal flags so we remember what we have tried to locate so
434 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000435 // We might have dug up more information that was requested (for example
436 // if we were asked to only get the block, we will have gotten the
437 // compile unit, and function) so set any additional bits that we resolved
438 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000439 }
440
441 // Return the symbol context with everything that was possible to resolve
442 // resolved.
443 return m_sc;
444}
445
446
447VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000448StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000449{
450 if (m_flags.IsClear(RESOLVED_VARIABLES))
451 {
452 m_flags.Set(RESOLVED_VARIABLES);
453
Greg Clayton69aa5d92010-09-07 04:20:48 +0000454 Block *frame_block = GetFrameBlock();
455
456 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000457 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000458 const bool get_child_variables = true;
459 const bool can_create = true;
Greg Clayton1bd2b2f2011-06-17 22:10:16 +0000460 const bool stop_if_child_block_is_inlined_function = true;
461 m_variable_list_sp.reset(new VariableList());
462 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 +0000463 }
Sean Callanan89363592010-11-01 04:38:59 +0000464 }
465
466 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
467 get_file_globals)
468 {
469 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton17dae082010-09-02 02:59:18 +0000470
Sean Callanan89363592010-11-01 04:38:59 +0000471 if (m_flags.IsClear (eSymbolContextCompUnit))
472 GetSymbolContext (eSymbolContextCompUnit);
473
474 if (m_sc.comp_unit)
Greg Clayton17dae082010-09-02 02:59:18 +0000475 {
Sean Callanan89363592010-11-01 04:38:59 +0000476 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
477 if (m_variable_list_sp)
478 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
479 else
480 m_variable_list_sp = global_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000481 }
Chris Lattner24943d22010-06-08 16:52:24 +0000482 }
Sean Callanan89363592010-11-01 04:38:59 +0000483
Chris Lattner24943d22010-06-08 16:52:24 +0000484 return m_variable_list_sp.get();
485}
486
Greg Clayton6e2d2822011-08-02 23:35:43 +0000487VariableListSP
488StackFrame::GetInScopeVariableList (bool get_file_globals)
489{
490 VariableListSP var_list_sp(new VariableList);
491 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
492
493 if (m_sc.block)
494 {
495 const bool can_create = true;
496 const bool get_parent_variables = true;
497 const bool stop_if_block_is_inlined_function = true;
498 m_sc.block->AppendVariables (can_create,
499 get_parent_variables,
500 stop_if_block_is_inlined_function,
501 var_list_sp.get());
502 }
503
504 if (m_sc.comp_unit)
505 {
506 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
507 if (global_variable_list_sp)
508 var_list_sp->AddVariables (global_variable_list_sp.get());
509 }
510
511 return var_list_sp;
512}
513
514
Greg Clayton427f2902010-12-14 02:59:59 +0000515ValueObjectSP
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000516StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000517 DynamicValueType use_dynamic,
Jim Ingham10de7d12011-05-04 03:43:18 +0000518 uint32_t options,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000519 VariableSP &var_sp,
Jim Ingham10de7d12011-05-04 03:43:18 +0000520 Error &error)
Greg Clayton427f2902010-12-14 02:59:59 +0000521{
Greg Claytonc3b61d22010-12-15 05:08:08 +0000522
523 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton427f2902010-12-14 02:59:59 +0000524 {
Greg Claytonc67efa42011-01-20 19:27:18 +0000525 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
526 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granataf6698502011-08-09 01:04:56 +0000527 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata13a54a12011-08-19 21:56:10 +0000528 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000529 error.Clear();
530 bool deref = false;
531 bool address_of = false;
532 ValueObjectSP valobj_sp;
533 const bool get_file_globals = true;
Greg Clayton6e2d2822011-08-02 23:35:43 +0000534 // When looking up a variable for an expression, we need only consider the
535 // variables that are in scope.
536 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
537 VariableList *variable_list = var_list_sp.get();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000538
539 if (variable_list)
Greg Clayton427f2902010-12-14 02:59:59 +0000540 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000541 // If first character is a '*', then show pointer contents
542 const char *var_expr = var_expr_cstr;
543 if (var_expr[0] == '*')
Greg Clayton427f2902010-12-14 02:59:59 +0000544 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000545 deref = true;
546 var_expr++; // Skip the '*'
547 }
548 else if (var_expr[0] == '&')
549 {
550 address_of = true;
551 var_expr++; // Skip the '&'
552 }
553
554 std::string var_path (var_expr);
555 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
556 StreamString var_expr_path_strm;
557
558 ConstString name_const_string;
559 if (separator_idx == std::string::npos)
560 name_const_string.SetCString (var_path.c_str());
561 else
562 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
563
Jim Ingham10de7d12011-05-04 03:43:18 +0000564 var_sp = variable_list->FindVariable(name_const_string);
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000565
566 bool synthetically_added_instance_object = false;
567
568 if (var_sp)
569 {
570 var_path.erase (0, name_const_string.GetLength ());
571 }
572 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
573 {
574 // Check for direct ivars access which helps us with implicit
575 // access to ivars with the "this->" or "self->"
576 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
577 lldb::LanguageType method_language = eLanguageTypeUnknown;
578 bool is_instance_method = false;
579 ConstString method_object_name;
580 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
581 {
582 if (is_instance_method && method_object_name)
583 {
584 var_sp = variable_list->FindVariable(method_object_name);
585 if (var_sp)
586 {
587 separator_idx = 0;
588 var_path.insert(0, "->");
589 synthetically_added_instance_object = true;
590 }
591 }
592 }
593 }
594
Greg Claytonc3b61d22010-12-15 05:08:08 +0000595 if (var_sp)
596 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000597 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000598 if (!valobj_sp)
599 return valobj_sp;
600
Greg Claytonc3b61d22010-12-15 05:08:08 +0000601 // We are dumping at least one child
602 while (separator_idx != std::string::npos)
Greg Clayton427f2902010-12-14 02:59:59 +0000603 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000604 // Calculate the next separator index ahead of time
605 ValueObjectSP child_valobj_sp;
606 const char separator_type = var_path[0];
607 switch (separator_type)
Greg Clayton427f2902010-12-14 02:59:59 +0000608 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000609
610 case '-':
611 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton427f2902010-12-14 02:59:59 +0000612 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000613
Greg Claytonc67efa42011-01-20 19:27:18 +0000614 if (no_fragile_ivar)
615 {
616 // Make sure we aren't trying to deref an objective
617 // C ivar if this is not allowed
618 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
619 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
620 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
621 {
622 // This was an objective C object pointer and
623 // it was requested we skip any fragile ivars
624 // so return nothing here
625 return ValueObjectSP();
626 }
627 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000628 var_path.erase (0, 1); // Remove the '-'
629 // Fall through
630 case '.':
Greg Clayton427f2902010-12-14 02:59:59 +0000631 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000632 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton427f2902010-12-14 02:59:59 +0000633
Greg Claytonc3b61d22010-12-15 05:08:08 +0000634 var_path.erase (0, 1); // Remove the '.' or '>'
635 separator_idx = var_path.find_first_of(".-[");
636 ConstString child_name;
637 if (separator_idx == std::string::npos)
638 child_name.SetCString (var_path.c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000639 else
Greg Claytonc3b61d22010-12-15 05:08:08 +0000640 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
641
642 if (check_ptr_vs_member)
Greg Clayton427f2902010-12-14 02:59:59 +0000643 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000644 // We either have a pointer type and need to verify
645 // valobj_sp is a pointer, or we have a member of a
646 // class/union/struct being accessed with the . syntax
647 // and need to verify we don't have a pointer.
648 const bool actual_is_ptr = valobj_sp->IsPointerType ();
649
650 if (actual_is_ptr != expr_is_ptr)
651 {
652 // Incorrect use of "." with a pointer, or "->" with
653 // a class/union/struct instance or reference.
Greg Claytonb01000f2011-01-17 03:46:26 +0000654 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000655 if (actual_is_ptr)
656 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
657 var_expr_path_strm.GetString().c_str(),
658 child_name.GetCString(),
659 var_expr_path_strm.GetString().c_str(),
660 var_path.c_str());
661 else
662 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
663 var_expr_path_strm.GetString().c_str(),
664 child_name.GetCString(),
665 var_expr_path_strm.GetString().c_str(),
666 var_path.c_str());
667 return ValueObjectSP();
668 }
Greg Clayton427f2902010-12-14 02:59:59 +0000669 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000670 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton427f2902010-12-14 02:59:59 +0000671 if (!child_valobj_sp)
672 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000673 if (no_synth_child == false)
Enrico Granatacf09f882012-03-19 22:58:49 +0000674 {
675 child_valobj_sp = valobj_sp->GetSyntheticValue();
676 if (child_valobj_sp)
677 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
678 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000679
680 if (no_synth_child || !child_valobj_sp)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000681 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000682 // No child member with name "child_name"
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000683 if (synthetically_added_instance_object)
Enrico Granata9c57fc02011-08-11 17:08:01 +0000684 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000685 // We added a "this->" or "self->" to the beginning of the expression
686 // and this is the first pointer ivar access, so just return the normal
687 // error
688 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
689 name_const_string.GetCString());
Enrico Granata9c57fc02011-08-11 17:08:01 +0000690 }
691 else
692 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000693 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
694 if (child_name)
695 {
696 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
697 child_name.GetCString(),
698 valobj_sp->GetTypeName().AsCString("<invalid type>"),
699 var_expr_path_strm.GetString().c_str());
700 }
701 else
702 {
703 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
704 var_expr_path_strm.GetString().c_str(),
705 var_expr_cstr);
706 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000707 }
708 return ValueObjectSP();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000709 }
Greg Clayton427f2902010-12-14 02:59:59 +0000710 }
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000711 synthetically_added_instance_object = false;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000712 // Remove the child name from the path
713 var_path.erase(0, child_name.GetLength());
Greg Clayton987c7eb2011-09-17 08:33:22 +0000714 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000715 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000716 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000717 if (dynamic_value_sp)
718 child_valobj_sp = dynamic_value_sp;
719 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000720 }
721 break;
Greg Clayton427f2902010-12-14 02:59:59 +0000722
Greg Claytonc3b61d22010-12-15 05:08:08 +0000723 case '[':
724 // Array member access, or treating pointer as an array
725 if (var_path.size() > 2) // Need at least two brackets and a number
726 {
727 char *end = NULL;
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000728 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9762e102011-07-06 02:13:41 +0000729 if (end && *end == ']'
730 && *(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 +0000731 {
Enrico Granata9762e102011-07-06 02:13:41 +0000732 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
733 {
734 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
735 // and extract bit low out of it. reading array item low
736 // would be done by saying ptr[low], without a deref * sign
737 Error error;
738 ValueObjectSP temp(valobj_sp->Dereference(error));
739 if (error.Fail())
740 {
741 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
742 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
743 valobj_sp->GetTypeName().AsCString("<invalid type>"),
744 var_expr_path_strm.GetString().c_str());
745 return ValueObjectSP();
746 }
747 valobj_sp = temp;
748 deref = false;
749 }
750 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
751 {
752 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
753 // (an operation that is equivalent to deref-ing arr)
754 // and extract bit low out of it. reading array item low
755 // would be done by saying arr[low], without a deref * sign
756 Error error;
757 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
758 if (error.Fail())
759 {
760 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
761 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
762 valobj_sp->GetTypeName().AsCString("<invalid type>"),
763 var_expr_path_strm.GetString().c_str());
764 return ValueObjectSP();
765 }
766 valobj_sp = temp;
767 deref = false;
768 }
769
Greg Claytonc3b61d22010-12-15 05:08:08 +0000770 if (valobj_sp->IsPointerType ())
771 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000772 bool is_objc_pointer = true;
773
774 if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
775 is_objc_pointer = false;
776 else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
777 is_objc_pointer = false;
778
779 if (no_synth_child && is_objc_pointer)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000780 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000781 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
782 valobj_sp->GetTypeName().AsCString("<invalid type>"),
783 var_expr_path_strm.GetString().c_str());
784
785 return ValueObjectSP();
786 }
787 else if (is_objc_pointer)
788 {
Enrico Granataf6698502011-08-09 01:04:56 +0000789 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granatacf09f882012-03-19 22:58:49 +0000790 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000791 if (synthetic.get() == NULL /* no synthetic */
792 || synthetic == valobj_sp) /* synthetic is the same as the original object */
793 {
794 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
795 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
796 valobj_sp->GetTypeName().AsCString("<invalid type>"),
797 var_expr_path_strm.GetString().c_str());
798 }
799 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
800 {
801 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000802 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000803 child_index,
804 valobj_sp->GetTypeName().AsCString("<invalid type>"),
805 var_expr_path_strm.GetString().c_str());
806 }
807 else
808 {
809 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
810 if (!child_valobj_sp)
811 {
812 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000813 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000814 child_index,
815 valobj_sp->GetTypeName().AsCString("<invalid type>"),
816 var_expr_path_strm.GetString().c_str());
817 }
818 }
819 }
820 else
821 {
822 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (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 ("failed to use pointer as array for index %ld 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 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000831 }
832 }
833 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
834 {
Jim Inghame41494a2011-04-16 00:01:13 +0000835 // Pass false to dynamic_value here so we can tell the difference between
836 // no dynamic value and no member of this type...
Greg Claytonc3b61d22010-12-15 05:08:08 +0000837 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
838 if (!child_valobj_sp)
839 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000840 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000841 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Claytonc3b61d22010-12-15 05:08:08 +0000842 child_index,
843 valobj_sp->GetTypeName().AsCString("<invalid type>"),
844 var_expr_path_strm.GetString().c_str());
845 }
846 }
Enrico Granata9762e102011-07-06 02:13:41 +0000847 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
848 {
849 // this is a bitfield asking to display just one bit
850 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
851 if (!child_valobj_sp)
852 {
853 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000854 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9762e102011-07-06 02:13:41 +0000855 child_index, child_index,
856 valobj_sp->GetTypeName().AsCString("<invalid type>"),
857 var_expr_path_strm.GetString().c_str());
858 }
859 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000860 else
861 {
Enrico Granatacf09f882012-03-19 22:58:49 +0000862 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000863 if (no_synth_child /* synthetic is forbidden */ ||
864 synthetic.get() == NULL /* no synthetic */
865 || synthetic == valobj_sp) /* synthetic is the same as the original object */
866 {
867 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
868 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
869 valobj_sp->GetTypeName().AsCString("<invalid type>"),
870 var_expr_path_strm.GetString().c_str());
871 }
872 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
873 {
874 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000875 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000876 child_index,
877 valobj_sp->GetTypeName().AsCString("<invalid type>"),
878 var_expr_path_strm.GetString().c_str());
879 }
880 else
881 {
882 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
883 if (!child_valobj_sp)
884 {
885 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000886 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000887 child_index,
888 valobj_sp->GetTypeName().AsCString("<invalid type>"),
889 var_expr_path_strm.GetString().c_str());
890 }
891 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000892 }
893
894 if (!child_valobj_sp)
895 {
896 // Invalid array index...
897 return ValueObjectSP();
898 }
899
900 // Erase the array member specification '[%i]' where
901 // %i is the array index
902 var_path.erase(0, (end - var_path.c_str()) + 1);
903 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +0000904 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000905 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000906 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000907 if (dynamic_value_sp)
908 child_valobj_sp = dynamic_value_sp;
909 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000910 // Break out early from the switch since we were
911 // able to find the child member
912 break;
913 }
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000914 else if (end && *end == '-')
Enrico Granata9762e102011-07-06 02:13:41 +0000915 {
916 // this is most probably a BitField, let's take a look
917 char *real_end = NULL;
918 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granata6f302872011-08-19 21:13:46 +0000919 bool expand_bitfield = true;
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000920 if (real_end && *real_end == ']')
Enrico Granata9762e102011-07-06 02:13:41 +0000921 {
922 // if the format given is [high-low], swap range
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000923 if (child_index > final_index)
Enrico Granata9762e102011-07-06 02:13:41 +0000924 {
925 long temp = child_index;
926 child_index = final_index;
927 final_index = temp;
928 }
929
930 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
931 {
932 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
933 // and extract bits low thru high out of it. reading array items low thru high
934 // would be done by saying ptr[low-high], without a deref * sign
935 Error error;
936 ValueObjectSP temp(valobj_sp->Dereference(error));
937 if (error.Fail())
938 {
939 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
940 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
941 valobj_sp->GetTypeName().AsCString("<invalid type>"),
942 var_expr_path_strm.GetString().c_str());
943 return ValueObjectSP();
944 }
945 valobj_sp = temp;
946 deref = false;
947 }
948 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
949 {
950 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
951 // (an operation that is equivalent to deref-ing arr)
952 // and extract bits low thru high out of it. reading array items low thru high
953 // would be done by saying arr[low-high], without a deref * sign
954 Error error;
955 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
956 if (error.Fail())
957 {
958 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
959 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
960 valobj_sp->GetTypeName().AsCString("<invalid type>"),
961 var_expr_path_strm.GetString().c_str());
962 return ValueObjectSP();
963 }
964 valobj_sp = temp;
965 deref = false;
966 }
Enrico Granata6f302872011-08-19 21:13:46 +0000967 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9762e102011-07-06 02:13:41 +0000968 {
Enrico Granata6f302872011-08-19 21:13:46 +0000969 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
970 expand_bitfield = false;
971 if (!child_valobj_sp)
972 {
973 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
974 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
975 child_index, final_index,
976 valobj_sp->GetTypeName().AsCString("<invalid type>"),
977 var_expr_path_strm.GetString().c_str());
978 }
979 }*/
980
981 if (expand_bitfield)
982 {
983 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
984 if (!child_valobj_sp)
985 {
986 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000987 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata6f302872011-08-19 21:13:46 +0000988 child_index, final_index,
989 valobj_sp->GetTypeName().AsCString("<invalid type>"),
990 var_expr_path_strm.GetString().c_str());
991 }
Enrico Granata9762e102011-07-06 02:13:41 +0000992 }
993 }
994
995 if (!child_valobj_sp)
996 {
997 // Invalid bitfield range...
998 return ValueObjectSP();
999 }
1000
1001 // Erase the bitfield member specification '[%i-%i]' where
1002 // %i is the index
1003 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1004 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +00001005 if (use_dynamic != eNoDynamicValues)
Enrico Granata9762e102011-07-06 02:13:41 +00001006 {
1007 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1008 if (dynamic_value_sp)
1009 child_valobj_sp = dynamic_value_sp;
1010 }
1011 // Break out early from the switch since we were
1012 // able to find the child member
1013 break;
1014
1015 }
1016 }
1017 else
1018 {
1019 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1020 var_expr_path_strm.GetString().c_str(),
1021 var_path.c_str());
Greg Claytonc3b61d22010-12-15 05:08:08 +00001022 }
1023 return ValueObjectSP();
1024
1025 default:
1026 // Failure...
1027 {
Greg Claytonb01000f2011-01-17 03:46:26 +00001028 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001029 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1030 separator_type,
1031 var_expr_path_strm.GetString().c_str(),
1032 var_path.c_str());
1033
1034 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +00001035 }
1036 }
Greg Clayton427f2902010-12-14 02:59:59 +00001037
Greg Claytonc3b61d22010-12-15 05:08:08 +00001038 if (child_valobj_sp)
1039 valobj_sp = child_valobj_sp;
1040
1041 if (var_path.empty())
1042 break;
1043
Greg Clayton427f2902010-12-14 02:59:59 +00001044 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001045 if (valobj_sp)
1046 {
1047 if (deref)
1048 {
Greg Claytonbdcda462010-12-20 20:49:23 +00001049 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Claytonc3b61d22010-12-15 05:08:08 +00001050 valobj_sp = deref_valobj_sp;
1051 }
1052 else if (address_of)
1053 {
1054 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1055 valobj_sp = address_of_valobj_sp;
1056 }
1057 }
1058 return valobj_sp;
Greg Clayton427f2902010-12-14 02:59:59 +00001059 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001060 else
Greg Clayton427f2902010-12-14 02:59:59 +00001061 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001062 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1063 name_const_string.GetCString());
Greg Clayton427f2902010-12-14 02:59:59 +00001064 }
Greg Clayton427f2902010-12-14 02:59:59 +00001065 }
1066 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001067 else
1068 {
1069 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1070 }
Greg Clayton427f2902010-12-14 02:59:59 +00001071 return ValueObjectSP();
1072}
Chris Lattner24943d22010-06-08 16:52:24 +00001073
1074bool
1075StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1076{
1077 if (m_flags.IsClear(GOT_FRAME_BASE))
1078 {
1079 if (m_sc.function)
1080 {
1081 m_frame_base.Clear();
1082 m_frame_base_error.Clear();
1083
1084 m_flags.Set(GOT_FRAME_BASE);
Greg Clayton289afcb2012-02-18 05:35:26 +00001085 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001086 Value expr_value;
Greg Clayton178710c2010-09-14 02:20:48 +00001087 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1088 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Clayton289afcb2012-02-18 05:35:26 +00001089 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton178710c2010-09-14 02:20:48 +00001090
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001091 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 +00001092 {
1093 // We should really have an error if evaluate returns, but in case
1094 // we don't, lets set the error to something at least.
1095 if (m_frame_base_error.Success())
1096 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1097 }
1098 else
1099 {
1100 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
1101 }
1102 }
1103 else
1104 {
1105 m_frame_base_error.SetErrorString ("No function in symbol context.");
1106 }
1107 }
1108
1109 if (m_frame_base_error.Success())
1110 frame_base = m_frame_base;
1111
1112 if (error_ptr)
1113 *error_ptr = m_frame_base_error;
1114 return m_frame_base_error.Success();
1115}
1116
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001117RegisterContextSP
Chris Lattner24943d22010-06-08 16:52:24 +00001118StackFrame::GetRegisterContext ()
1119{
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001120 if (!m_reg_context_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +00001121 {
1122 ThreadSP thread_sp (GetThread());
1123 if (thread_sp)
1124 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1125 }
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001126 return m_reg_context_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001127}
1128
1129bool
1130StackFrame::HasDebugInformation ()
1131{
Greg Claytonb04e7a82010-08-24 21:05:24 +00001132 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +00001133 return m_sc.line_entry.IsValid();
1134}
1135
Greg Clayton17dae082010-09-02 02:59:18 +00001136
1137ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001138StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner24943d22010-06-08 16:52:24 +00001139{
Greg Clayton17dae082010-09-02 02:59:18 +00001140 ValueObjectSP valobj_sp;
1141 VariableList *var_list = GetVariableList (true);
1142 if (var_list)
1143 {
1144 // Make sure the variable is a frame variable
1145 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1146 const uint32_t num_variables = var_list->GetSize();
1147 if (var_idx < num_variables)
1148 {
1149 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1150 if (valobj_sp.get() == NULL)
1151 {
1152 if (m_variable_list_value_objects.GetSize() < num_variables)
1153 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham47da8102011-04-22 23:53:53 +00001154 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton17dae082010-09-02 02:59:18 +00001155 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1156 }
1157 }
1158 }
Greg Clayton987c7eb2011-09-17 08:33:22 +00001159 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +00001160 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001161 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001162 if (dynamic_sp)
1163 return dynamic_sp;
1164 }
Greg Clayton17dae082010-09-02 02:59:18 +00001165 return valobj_sp;
1166}
1167
1168ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001169StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton17dae082010-09-02 02:59:18 +00001170{
1171 // Check to make sure we aren't already tracking this variable?
Jim Inghame41494a2011-04-16 00:01:13 +00001172 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton17dae082010-09-02 02:59:18 +00001173 if (!valobj_sp)
1174 {
1175 // We aren't already tracking this global
1176 VariableList *var_list = GetVariableList (true);
1177 // If this frame has no variables, create a new list
1178 if (var_list == NULL)
1179 m_variable_list_sp.reset (new VariableList());
1180
1181 // Add the global/static variable to this frame
1182 m_variable_list_sp->AddVariable (variable_sp);
1183
1184 // Now make a value object for it so we can track its changes
Jim Inghame41494a2011-04-16 00:01:13 +00001185 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton17dae082010-09-02 02:59:18 +00001186 }
1187 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001188}
1189
Jim Ingham2154da42010-08-26 20:44:45 +00001190bool
1191StackFrame::IsInlined ()
1192{
Greg Clayton4fb08152010-08-30 18:11:35 +00001193 if (m_sc.block == NULL)
1194 GetSymbolContext (eSymbolContextBlock);
1195 if (m_sc.block)
1196 return m_sc.block->GetContainingInlinedBlock() != NULL;
1197 return false;
Jim Ingham2154da42010-08-26 20:44:45 +00001198}
1199
Greg Clayton289afcb2012-02-18 05:35:26 +00001200TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001201StackFrame::CalculateTarget ()
1202{
Greg Clayton289afcb2012-02-18 05:35:26 +00001203 TargetSP target_sp;
1204 ThreadSP thread_sp(GetThread());
1205 if (thread_sp)
1206 {
1207 ProcessSP process_sp (thread_sp->CalculateProcess());
1208 if (process_sp)
1209 target_sp = process_sp->CalculateTarget();
1210 }
1211 return target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001212}
1213
Greg Clayton289afcb2012-02-18 05:35:26 +00001214ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001215StackFrame::CalculateProcess ()
1216{
Greg Clayton289afcb2012-02-18 05:35:26 +00001217 ProcessSP process_sp;
1218 ThreadSP thread_sp(GetThread());
1219 if (thread_sp)
1220 process_sp = thread_sp->CalculateProcess();
1221 return process_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001222}
1223
Greg Clayton289afcb2012-02-18 05:35:26 +00001224ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001225StackFrame::CalculateThread ()
1226{
Greg Clayton289afcb2012-02-18 05:35:26 +00001227 return GetThread();
Chris Lattner24943d22010-06-08 16:52:24 +00001228}
1229
Greg Clayton289afcb2012-02-18 05:35:26 +00001230StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001231StackFrame::CalculateStackFrame ()
1232{
Greg Clayton289afcb2012-02-18 05:35:26 +00001233 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001234}
1235
1236
1237void
Greg Claytona830adb2010-10-04 01:05:56 +00001238StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001239{
Greg Clayton289afcb2012-02-18 05:35:26 +00001240 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001241}
1242
1243void
Greg Claytona830adb2010-10-04 01:05:56 +00001244StackFrame::DumpUsingSettingsFormat (Stream *strm)
1245{
1246 if (strm == NULL)
1247 return;
1248
1249 GetSymbolContext(eSymbolContextEverything);
Greg Clayton289afcb2012-02-18 05:35:26 +00001250 ExecutionContext exe_ctx (shared_from_this());
Greg Claytona830adb2010-10-04 01:05:56 +00001251 const char *end = NULL;
1252 StreamString s;
Greg Clayton289afcb2012-02-18 05:35:26 +00001253 const char *frame_format = NULL;
1254 Target *target = exe_ctx.GetTargetPtr();
1255 if (target)
1256 frame_format = target->GetDebugger().GetFrameFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001257 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1258 {
1259 strm->Write(s.GetData(), s.GetSize());
1260 }
1261 else
1262 {
1263 Dump (strm, true, false);
1264 strm->EOL();
1265 }
1266}
1267
1268void
Greg Clayton72b71582010-09-02 21:44:10 +00001269StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +00001270{
1271 if (strm == NULL)
1272 return;
1273
1274 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +00001275 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton289afcb2012-02-18 05:35:26 +00001276 ExecutionContext exe_ctx (shared_from_this());
1277 Target *target = exe_ctx.GetTargetPtr();
1278 strm->Printf("0x%0*llx ",
1279 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1280 GetFrameCodeAddress().GetLoadAddress(target));
Greg Claytonb04e7a82010-08-24 21:05:24 +00001281 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +00001282 const bool show_module = true;
1283 const bool show_inline = true;
Greg Clayton289afcb2012-02-18 05:35:26 +00001284 m_sc.DumpStopContext (strm,
1285 exe_ctx.GetBestExecutionContextScope(),
1286 GetFrameCodeAddress(),
1287 show_fullpaths,
1288 show_module,
1289 show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +00001290}
1291
Greg Clayton1d66ef52010-08-27 18:24:16 +00001292void
Greg Clayton4fb08152010-08-30 18:11:35 +00001293StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +00001294{
Greg Clayton4fb08152010-08-30 18:11:35 +00001295 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
1296 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +00001297 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +00001298 if (!m_disassembly.GetString().empty())
1299 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +00001300}
Greg Clayton870a1cd2010-08-27 21:47:54 +00001301
1302
Greg Clayton4fb08152010-08-30 18:11:35 +00001303void
1304StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1305{
Greg Clayton5205f0b2010-09-03 17:10:42 +00001306 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
1307 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton289afcb2012-02-18 05:35:26 +00001308 assert (GetThread() == curr_frame.GetThread());
Greg Clayton4fb08152010-08-30 18:11:35 +00001309 m_frame_index = curr_frame.m_frame_index;
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001310 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton4fb08152010-08-30 18:11:35 +00001311 m_reg_context_sp = curr_frame.m_reg_context_sp;
1312 m_frame_code_addr = curr_frame.m_frame_code_addr;
1313 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());
1314 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());
1315 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1316 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 +00001317 m_sc = curr_frame.m_sc;
1318 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1319 m_flags.Set (m_sc.GetResolvedMask());
1320 m_frame_base.Clear();
1321 m_frame_base_error.Clear();
1322}
1323
1324
Greg Clayton5205f0b2010-09-03 17:10:42 +00001325bool
1326StackFrame::HasCachedData () const
1327{
1328 if (m_variable_list_sp.get())
1329 return true;
1330 if (m_variable_list_value_objects.GetSize() > 0)
1331 return true;
1332 if (!m_disassembly.GetString().empty())
1333 return true;
1334 return false;
Jim Inghamccd584d2010-09-23 17:40:12 +00001335}
1336
Greg Claytonabe0fed2011-04-18 08:33:37 +00001337bool
1338StackFrame::GetStatus (Stream& strm,
1339 bool show_frame_info,
Greg Claytona7d3dc72012-07-11 20:33:48 +00001340 bool show_source)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001341{
Greg Claytona7d3dc72012-07-11 20:33:48 +00001342
Greg Claytonabe0fed2011-04-18 08:33:37 +00001343 if (show_frame_info)
1344 {
1345 strm.Indent();
1346 DumpUsingSettingsFormat (&strm);
1347 }
1348
1349 if (show_source)
1350 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001351 ExecutionContext exe_ctx (shared_from_this());
Greg Claytonbe9875d2011-11-21 21:44:34 +00001352 bool have_source = false;
Greg Clayton289afcb2012-02-18 05:35:26 +00001353 DebuggerInstanceSettings::StopDisassemblyType disasm_display = DebuggerInstanceSettings::eStopDisassemblyTypeNever;
1354 Target *target = exe_ctx.GetTargetPtr();
Greg Claytona7d3dc72012-07-11 20:33:48 +00001355 if (target)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001356 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001357 Debugger &debugger = target->GetDebugger();
1358 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1359 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1360 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytonbe9875d2011-11-21 21:44:34 +00001361
Greg Claytona7d3dc72012-07-11 20:33:48 +00001362 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001363 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001364 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1365
1366 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytonbe9875d2011-11-21 21:44:34 +00001367 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001368 if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
1369 m_sc.line_entry.line,
1370 source_lines_before,
1371 source_lines_after,
1372 "->",
1373 &strm))
1374 {
1375 have_source = true;
1376 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001377 }
1378 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001379 switch (disasm_display)
1380 {
1381 case DebuggerInstanceSettings::eStopDisassemblyTypeNever:
Greg Claytonbe9875d2011-11-21 21:44:34 +00001382 break;
Greg Claytona7d3dc72012-07-11 20:33:48 +00001383
1384 case DebuggerInstanceSettings::eStopDisassemblyTypeNoSource:
1385 if (have_source)
1386 break;
1387 // Fall through to next case
1388 case DebuggerInstanceSettings::eStopDisassemblyTypeAlways:
1389 if (target)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001390 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001391 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1392 if (disasm_lines > 0)
1393 {
1394 const ArchSpec &target_arch = target->GetArchitecture();
1395 AddressRange pc_range;
1396 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1397 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1398 Disassembler::Disassemble (target->GetDebugger(),
1399 target_arch,
1400 NULL,
1401 exe_ctx,
1402 pc_range,
1403 disasm_lines,
1404 0,
1405 Disassembler::eOptionMarkPCAddress,
1406 strm);
1407 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001408 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001409 break;
Greg Claytonbe9875d2011-11-21 21:44:34 +00001410 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001411 }
1412 }
1413 return true;
1414}
1415