blob: a70e664cef68dad5a2acb80acd1a408087a95b18 [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 Clayton33ed1702010-08-24 00:45:41 +000042StackFrame::StackFrame
43(
44 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +000045 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +000046 Thread &thread,
47 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +000048 lldb::addr_t pc,
49 const SymbolContext *sc_ptr
50) :
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000051 m_thread (thread),
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 Clayton65124ea2010-08-26 22:05:43 +000056 m_frame_code_addr (NULL, 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 Clayton33ed1702010-08-24 00:45:41 +000072StackFrame::StackFrame
73(
74 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +000075 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +000076 Thread &thread,
77 const RegisterContextSP &reg_context_sp,
78 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +000079 lldb::addr_t pc,
80 const SymbolContext *sc_ptr
81) :
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000082 m_thread (thread),
Greg Clayton33ed1702010-08-24 00:45:41 +000083 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000084 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000085 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +000086 m_id (pc, cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +000087 m_frame_code_addr (NULL, pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000088 m_sc (),
89 m_flags (),
90 m_frame_base (),
91 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000092 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000093 m_variable_list_value_objects (),
94 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000095{
96 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000097 {
Chris Lattner24943d22010-06-08 16:52:24 +000098 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000099 m_flags.Set(m_sc.GetResolvedMask ());
100 }
101
102 if (reg_context_sp && !m_sc.target_sp)
103 {
104 m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP();
105 m_flags.Set (eSymbolContextTarget);
106 }
107}
108
109StackFrame::StackFrame
110(
111 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +0000112 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +0000113 Thread &thread,
114 const RegisterContextSP &reg_context_sp,
115 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +0000116 const Address& pc_addr,
117 const SymbolContext *sc_ptr
118) :
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000119 m_thread (thread),
Greg Clayton33ed1702010-08-24 00:45:41 +0000120 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000121 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +0000122 m_reg_context_sp (reg_context_sp),
Greg Claytoneea26402010-09-14 23:36:40 +0000123 m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +0000124 m_frame_code_addr (pc_addr),
Greg Clayton33ed1702010-08-24 00:45:41 +0000125 m_sc (),
126 m_flags (),
127 m_frame_base (),
128 m_frame_base_error (),
129 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000130 m_variable_list_value_objects (),
131 m_disassembly ()
Greg Clayton33ed1702010-08-24 00:45:41 +0000132{
133 if (sc_ptr != NULL)
134 {
135 m_sc = *sc_ptr;
136 m_flags.Set(m_sc.GetResolvedMask ());
137 }
138
139 if (m_sc.target_sp.get() == NULL && reg_context_sp)
140 {
141 m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP();
142 m_flags.Set (eSymbolContextTarget);
143 }
144
Greg Claytone2c5e452010-09-13 04:34:30 +0000145 Module *pc_module = pc_addr.GetModule();
146 if (m_sc.module_sp.get() == NULL || m_sc.module_sp.get() != pc_module)
Greg Clayton33ed1702010-08-24 00:45:41 +0000147 {
Greg Clayton33ed1702010-08-24 00:45:41 +0000148 if (pc_module)
149 {
150 m_sc.module_sp = pc_module->GetSP();
151 m_flags.Set (eSymbolContextModule);
152 }
Greg Claytone2c5e452010-09-13 04:34:30 +0000153 else
154 {
155 m_sc.module_sp.reset();
156 }
157
Greg Clayton33ed1702010-08-24 00:45:41 +0000158 }
Chris Lattner24943d22010-06-08 16:52:24 +0000159}
160
161
162//----------------------------------------------------------------------
163// Destructor
164//----------------------------------------------------------------------
165StackFrame::~StackFrame()
166{
167}
168
169StackID&
170StackFrame::GetStackID()
171{
Greg Clayton72b71582010-09-02 21:44:10 +0000172 // Make sure we have resolved the StackID object's symbol context scope if
173 // we already haven't looked it up.
Chris Lattner24943d22010-06-08 16:52:24 +0000174
Greg Clayton4fb08152010-08-30 18:11:35 +0000175 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
176 {
Greg Clayton5205f0b2010-09-03 17:10:42 +0000177 if (m_id.GetSymbolContextScope ())
Greg Clayton4fb08152010-08-30 18:11:35 +0000178 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000179 // We already have a symbol context scope, we just don't have our
180 // flag bit set.
Greg Clayton4fb08152010-08-30 18:11:35 +0000181 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
182 }
183 else
184 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000185 // Calculate the frame block and use this for the stack ID symbol
186 // context scope if we have one.
187 SymbolContextScope *scope = GetFrameBlock ();
188 if (scope == NULL)
Greg Clayton4fb08152010-08-30 18:11:35 +0000189 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000190 // We don't have a block, so use the symbol
191 if (m_flags.IsClear (eSymbolContextSymbol))
192 GetSymbolContext (eSymbolContextSymbol);
193
194 // It is ok if m_sc.symbol is NULL here
195 scope = m_sc.symbol;
Greg Clayton4fb08152010-08-30 18:11:35 +0000196 }
Greg Clayton69aa5d92010-09-07 04:20:48 +0000197 // Set the symbol context scope (the accessor will set the
198 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
199 SetSymbolContextScope (scope);
Greg Clayton4fb08152010-08-30 18:11:35 +0000200 }
Chris Lattner24943d22010-06-08 16:52:24 +0000201 }
202 return m_id;
203}
204
Greg Clayton4fb08152010-08-30 18:11:35 +0000205void
206StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
207{
208 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
209 m_id.SetSymbolContextScope (symbol_scope);
210}
211
Chris Lattner24943d22010-06-08 16:52:24 +0000212Address&
Greg Claytonb04e7a82010-08-24 21:05:24 +0000213StackFrame::GetFrameCodeAddress()
Chris Lattner24943d22010-06-08 16:52:24 +0000214{
Greg Clayton4fb08152010-08-30 18:11:35 +0000215 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000216 {
Greg Clayton4fb08152010-08-30 18:11:35 +0000217 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner24943d22010-06-08 16:52:24 +0000218
219 // Resolve the PC into a temporary address because if ResolveLoadAddress
220 // fails to resolve the address, it will clear the address object...
221 Address resolved_pc;
Greg Claytoneea26402010-09-14 23:36:40 +0000222 if (m_thread.GetProcess().GetTarget().GetSectionLoadList().ResolveLoadAddress(m_frame_code_addr.GetOffset(), resolved_pc))
Chris Lattner24943d22010-06-08 16:52:24 +0000223 {
Greg Clayton65124ea2010-08-26 22:05:43 +0000224 m_frame_code_addr = resolved_pc;
225 const Section *section = m_frame_code_addr.GetSection();
Chris Lattner24943d22010-06-08 16:52:24 +0000226 if (section)
227 {
228 Module *module = section->GetModule();
229 if (module)
230 {
231 m_sc.module_sp = module->GetSP();
232 if (m_sc.module_sp)
233 m_flags.Set(eSymbolContextModule);
234 }
235 }
236 }
237 }
Greg Clayton65124ea2010-08-26 22:05:43 +0000238 return m_frame_code_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000239}
240
241void
242StackFrame::ChangePC (addr_t pc)
243{
Greg Clayton65124ea2010-08-26 22:05:43 +0000244 m_frame_code_addr.SetOffset(pc);
245 m_frame_code_addr.SetSection(NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000246 m_sc.Clear();
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000247 m_flags.Reset(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000248 m_thread.ClearStackFrames ();
249}
250
251const char *
252StackFrame::Disassemble ()
253{
254 if (m_disassembly.GetSize() == 0)
255 {
256 ExecutionContext exe_ctx;
Greg Claytona830adb2010-10-04 01:05:56 +0000257 CalculateExecutionContext(exe_ctx);
Greg Clayton63094e02010-06-23 01:19:29 +0000258 Target &target = m_thread.GetProcess().GetTarget();
259 Disassembler::Disassemble (target.GetDebugger(),
260 target.GetArchitecture(),
Greg Clayton149731c2011-03-25 18:03:16 +0000261 NULL,
Chris Lattner24943d22010-06-08 16:52:24 +0000262 exe_ctx,
263 0,
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000264 0,
Greg Clayton70436352010-06-30 23:03:03 +0000265 false,
Sean Callanana846cc32011-03-10 23:35:12 +0000266 false,
Chris Lattner24943d22010-06-08 16:52:24 +0000267 m_disassembly);
268 if (m_disassembly.GetSize() == 0)
269 return NULL;
270 }
271 return m_disassembly.GetData();
272}
273
Greg Clayton69aa5d92010-09-07 04:20:48 +0000274Block *
275StackFrame::GetFrameBlock ()
276{
277 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
278 GetSymbolContext (eSymbolContextBlock);
279
280 if (m_sc.block)
281 {
282 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
283 if (inline_block)
284 {
285 // Use the block with the inlined function info
286 // as the frame block we want this frame to have only the variables
287 // for the inlined function and its non-inlined block child blocks.
288 return inline_block;
289 }
290 else
291 {
292 // This block is not contained withing any inlined function blocks
293 // with so we want to use the top most function block.
294 return &m_sc.function->GetBlock (false);
295 }
296 }
297 return NULL;
298}
299
Chris Lattner24943d22010-06-08 16:52:24 +0000300//----------------------------------------------------------------------
301// Get the symbol context if we already haven't done so by resolving the
302// PC address as much as possible. This way when we pass around a
303// StackFrame object, everyone will have as much information as
304// possible and no one will ever have to look things up manually.
305//----------------------------------------------------------------------
306const SymbolContext&
307StackFrame::GetSymbolContext (uint32_t resolve_scope)
308{
309 // Copy our internal symbol context into "sc".
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000310 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000311 {
312 // Resolve our PC to section offset if we haven't alreday done so
313 // and if we don't have a module. The resolved address section will
314 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000315 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000316 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000317
318 // If this is not frame zero, then we need to subtract 1 from the PC
319 // value when doing address lookups since the PC will be on the
320 // instruction following the function call instruction...
321
Greg Claytonb04e7a82010-08-24 21:05:24 +0000322 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000323 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000324 {
325 addr_t offset = lookup_addr.GetOffset();
326 if (offset > 0)
327 lookup_addr.SetOffset(offset - 1);
328 }
329
Greg Claytonb04e7a82010-08-24 21:05:24 +0000330
331 uint32_t resolved = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000332 if (m_sc.module_sp)
333 {
334 // We have something in our stack frame symbol context, lets check
335 // if we haven't already tried to lookup one of those things. If we
336 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000337
338 uint32_t actual_resolve_scope = 0;
339
340 if (resolve_scope & eSymbolContextCompUnit)
341 {
342 if (m_flags.IsClear (eSymbolContextCompUnit))
343 {
344 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000345 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000346 else
347 actual_resolve_scope |= eSymbolContextCompUnit;
348 }
349 }
350
351 if (resolve_scope & eSymbolContextFunction)
352 {
353 if (m_flags.IsClear (eSymbolContextFunction))
354 {
355 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000356 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000357 else
358 actual_resolve_scope |= eSymbolContextFunction;
359 }
360 }
361
362 if (resolve_scope & eSymbolContextBlock)
363 {
364 if (m_flags.IsClear (eSymbolContextBlock))
365 {
366 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000367 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000368 else
369 actual_resolve_scope |= eSymbolContextBlock;
370 }
371 }
372
373 if (resolve_scope & eSymbolContextSymbol)
374 {
375 if (m_flags.IsClear (eSymbolContextSymbol))
376 {
377 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000378 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000379 else
380 actual_resolve_scope |= eSymbolContextSymbol;
381 }
382 }
383
384 if (resolve_scope & eSymbolContextLineEntry)
385 {
386 if (m_flags.IsClear (eSymbolContextLineEntry))
387 {
388 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000389 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000390 else
391 actual_resolve_scope |= eSymbolContextLineEntry;
392 }
393 }
394
395 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000396 {
397 // We might be resolving less information than what is already
398 // in our current symbol context so resolve into a temporary
399 // symbol context "sc" so we don't clear out data we have
400 // already found in "m_sc"
401 SymbolContext sc;
402 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000403 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000404 // Only replace what we didn't already have as we may have
405 // information for an inlined function scope that won't match
406 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000407 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
408 m_sc.comp_unit = sc.comp_unit;
409 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
410 m_sc.function = sc.function;
411 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
412 m_sc.block = sc.block;
413 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
414 m_sc.symbol = sc.symbol;
415 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
416 m_sc.line_entry = sc.line_entry;
417
Chris Lattner24943d22010-06-08 16:52:24 +0000418 }
419 }
420 else
421 {
422 // If we don't have a module, then we can't have the compile unit,
423 // function, block, line entry or symbol, so we can safely call
424 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000425 resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000426 }
427
428 // If the target was requested add that:
429 if (m_sc.target_sp.get() == NULL)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000430 {
Chris Lattner24943d22010-06-08 16:52:24 +0000431 m_sc.target_sp = CalculateProcess()->GetTarget().GetSP();
Greg Claytonb04e7a82010-08-24 21:05:24 +0000432 if (m_sc.target_sp)
433 resolved |= eSymbolContextTarget;
434 }
Chris Lattner24943d22010-06-08 16:52:24 +0000435
436 // Update our internal flags so we remember what we have tried to locate so
437 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000438 // We might have dug up more information that was requested (for example
439 // if we were asked to only get the block, we will have gotten the
440 // compile unit, and function) so set any additional bits that we resolved
441 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000442 }
443
444 // Return the symbol context with everything that was possible to resolve
445 // resolved.
446 return m_sc;
447}
448
449
450VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000451StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000452{
453 if (m_flags.IsClear(RESOLVED_VARIABLES))
454 {
455 m_flags.Set(RESOLVED_VARIABLES);
456
Greg Clayton69aa5d92010-09-07 04:20:48 +0000457 Block *frame_block = GetFrameBlock();
458
459 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000460 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000461 const bool get_child_variables = true;
462 const bool can_create = true;
Greg Clayton1bd2b2f2011-06-17 22:10:16 +0000463 const bool stop_if_child_block_is_inlined_function = true;
464 m_variable_list_sp.reset(new VariableList());
465 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 +0000466 }
Sean Callanan89363592010-11-01 04:38:59 +0000467 }
468
469 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
470 get_file_globals)
471 {
472 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton17dae082010-09-02 02:59:18 +0000473
Sean Callanan89363592010-11-01 04:38:59 +0000474 if (m_flags.IsClear (eSymbolContextCompUnit))
475 GetSymbolContext (eSymbolContextCompUnit);
476
477 if (m_sc.comp_unit)
Greg Clayton17dae082010-09-02 02:59:18 +0000478 {
Sean Callanan89363592010-11-01 04:38:59 +0000479 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
480 if (m_variable_list_sp)
481 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
482 else
483 m_variable_list_sp = global_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000484 }
Chris Lattner24943d22010-06-08 16:52:24 +0000485 }
Sean Callanan89363592010-11-01 04:38:59 +0000486
Chris Lattner24943d22010-06-08 16:52:24 +0000487 return m_variable_list_sp.get();
488}
489
Greg Clayton427f2902010-12-14 02:59:59 +0000490ValueObjectSP
Jim Ingham10de7d12011-05-04 03:43:18 +0000491StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
492 lldb::DynamicValueType use_dynamic,
493 uint32_t options,
494 lldb::VariableSP &var_sp,
495 Error &error)
Greg Clayton427f2902010-12-14 02:59:59 +0000496{
Greg Claytonc3b61d22010-12-15 05:08:08 +0000497
498 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton427f2902010-12-14 02:59:59 +0000499 {
Greg Claytonc67efa42011-01-20 19:27:18 +0000500 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
501 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000502 error.Clear();
503 bool deref = false;
504 bool address_of = false;
505 ValueObjectSP valobj_sp;
506 const bool get_file_globals = true;
507 VariableList *variable_list = GetVariableList (get_file_globals);
508
509 if (variable_list)
Greg Clayton427f2902010-12-14 02:59:59 +0000510 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000511 // If first character is a '*', then show pointer contents
512 const char *var_expr = var_expr_cstr;
513 if (var_expr[0] == '*')
Greg Clayton427f2902010-12-14 02:59:59 +0000514 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000515 deref = true;
516 var_expr++; // Skip the '*'
517 }
518 else if (var_expr[0] == '&')
519 {
520 address_of = true;
521 var_expr++; // Skip the '&'
522 }
523
524 std::string var_path (var_expr);
525 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
526 StreamString var_expr_path_strm;
527
528 ConstString name_const_string;
529 if (separator_idx == std::string::npos)
530 name_const_string.SetCString (var_path.c_str());
531 else
532 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
533
Jim Ingham10de7d12011-05-04 03:43:18 +0000534 var_sp = variable_list->FindVariable(name_const_string);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000535 if (var_sp)
536 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000537 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000538 if (!valobj_sp)
539 return valobj_sp;
540
Greg Claytonc3b61d22010-12-15 05:08:08 +0000541 var_path.erase (0, name_const_string.GetLength ());
542 // We are dumping at least one child
543 while (separator_idx != std::string::npos)
Greg Clayton427f2902010-12-14 02:59:59 +0000544 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000545 // Calculate the next separator index ahead of time
546 ValueObjectSP child_valobj_sp;
547 const char separator_type = var_path[0];
548 switch (separator_type)
Greg Clayton427f2902010-12-14 02:59:59 +0000549 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000550
551 case '-':
552 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton427f2902010-12-14 02:59:59 +0000553 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000554
Greg Claytonc67efa42011-01-20 19:27:18 +0000555 if (no_fragile_ivar)
556 {
557 // Make sure we aren't trying to deref an objective
558 // C ivar if this is not allowed
559 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
560 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
561 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
562 {
563 // This was an objective C object pointer and
564 // it was requested we skip any fragile ivars
565 // so return nothing here
566 return ValueObjectSP();
567 }
568 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000569 var_path.erase (0, 1); // Remove the '-'
570 // Fall through
571 case '.':
Greg Clayton427f2902010-12-14 02:59:59 +0000572 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000573 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton427f2902010-12-14 02:59:59 +0000574
Greg Claytonc3b61d22010-12-15 05:08:08 +0000575 var_path.erase (0, 1); // Remove the '.' or '>'
576 separator_idx = var_path.find_first_of(".-[");
577 ConstString child_name;
578 if (separator_idx == std::string::npos)
579 child_name.SetCString (var_path.c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000580 else
Greg Claytonc3b61d22010-12-15 05:08:08 +0000581 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
582
583 if (check_ptr_vs_member)
Greg Clayton427f2902010-12-14 02:59:59 +0000584 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000585 // We either have a pointer type and need to verify
586 // valobj_sp is a pointer, or we have a member of a
587 // class/union/struct being accessed with the . syntax
588 // and need to verify we don't have a pointer.
589 const bool actual_is_ptr = valobj_sp->IsPointerType ();
590
591 if (actual_is_ptr != expr_is_ptr)
592 {
593 // Incorrect use of "." with a pointer, or "->" with
594 // a class/union/struct instance or reference.
Greg Claytonb01000f2011-01-17 03:46:26 +0000595 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000596 if (actual_is_ptr)
597 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
598 var_expr_path_strm.GetString().c_str(),
599 child_name.GetCString(),
600 var_expr_path_strm.GetString().c_str(),
601 var_path.c_str());
602 else
603 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
604 var_expr_path_strm.GetString().c_str(),
605 child_name.GetCString(),
606 var_expr_path_strm.GetString().c_str(),
607 var_path.c_str());
608 return ValueObjectSP();
609 }
Greg Clayton427f2902010-12-14 02:59:59 +0000610 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000611 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton427f2902010-12-14 02:59:59 +0000612 if (!child_valobj_sp)
613 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000614 // No child member with name "child_name"
Greg Claytonb01000f2011-01-17 03:46:26 +0000615 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000616 if (child_name)
617 {
618 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
619 child_name.GetCString(),
620 valobj_sp->GetTypeName().AsCString("<invalid type>"),
621 var_expr_path_strm.GetString().c_str());
622 }
623 else
624 {
625 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
626 var_expr_path_strm.GetString().c_str(),
627 var_expr_cstr);
628 }
629
Greg Clayton427f2902010-12-14 02:59:59 +0000630 return ValueObjectSP();
631 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000632 // Remove the child name from the path
633 var_path.erase(0, child_name.GetLength());
Jim Ingham10de7d12011-05-04 03:43:18 +0000634 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000635 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000636 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000637 if (dynamic_value_sp)
638 child_valobj_sp = dynamic_value_sp;
639 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000640 }
641 break;
Greg Clayton427f2902010-12-14 02:59:59 +0000642
Greg Claytonc3b61d22010-12-15 05:08:08 +0000643 case '[':
644 // Array member access, or treating pointer as an array
645 if (var_path.size() > 2) // Need at least two brackets and a number
646 {
647 char *end = NULL;
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000648 long child_index = ::strtol (&var_path[1], &end, 0);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000649 if (end && *end == ']')
650 {
Greg Clayton427f2902010-12-14 02:59:59 +0000651
Greg Claytonc3b61d22010-12-15 05:08:08 +0000652 if (valobj_sp->IsPointerType ())
653 {
654 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
655 if (!child_valobj_sp)
656 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000657 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000658 error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"",
659 child_index,
660 valobj_sp->GetTypeName().AsCString("<invalid type>"),
661 var_expr_path_strm.GetString().c_str());
662 }
663 }
664 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
665 {
Jim Inghame41494a2011-04-16 00:01:13 +0000666 // Pass false to dynamic_value here so we can tell the difference between
667 // no dynamic value and no member of this type...
Greg Claytonc3b61d22010-12-15 05:08:08 +0000668 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
669 if (!child_valobj_sp)
670 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000671 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000672 error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
673 child_index,
674 valobj_sp->GetTypeName().AsCString("<invalid type>"),
675 var_expr_path_strm.GetString().c_str());
676 }
677 }
678 else
679 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000680 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000681 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
682 valobj_sp->GetTypeName().AsCString("<invalid type>"),
683 var_expr_path_strm.GetString().c_str());
684 }
685
686 if (!child_valobj_sp)
687 {
688 // Invalid array index...
689 return ValueObjectSP();
690 }
691
692 // Erase the array member specification '[%i]' where
693 // %i is the array index
694 var_path.erase(0, (end - var_path.c_str()) + 1);
695 separator_idx = var_path.find_first_of(".-[");
Jim Ingham10de7d12011-05-04 03:43:18 +0000696 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000697 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000698 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000699 if (dynamic_value_sp)
700 child_valobj_sp = dynamic_value_sp;
701 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000702 // Break out early from the switch since we were
703 // able to find the child member
704 break;
705 }
706 }
707 return ValueObjectSP();
708
709 default:
710 // Failure...
711 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000712 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000713 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
714 separator_type,
715 var_expr_path_strm.GetString().c_str(),
716 var_path.c_str());
717
718 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000719 }
720 }
Greg Clayton427f2902010-12-14 02:59:59 +0000721
Greg Claytonc3b61d22010-12-15 05:08:08 +0000722 if (child_valobj_sp)
723 valobj_sp = child_valobj_sp;
724
725 if (var_path.empty())
726 break;
727
Greg Clayton427f2902010-12-14 02:59:59 +0000728 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000729 if (valobj_sp)
730 {
731 if (deref)
732 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000733 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Claytonc3b61d22010-12-15 05:08:08 +0000734 valobj_sp = deref_valobj_sp;
735 }
736 else if (address_of)
737 {
738 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
739 valobj_sp = address_of_valobj_sp;
740 }
741 }
742 return valobj_sp;
Greg Clayton427f2902010-12-14 02:59:59 +0000743 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000744 else
Greg Clayton427f2902010-12-14 02:59:59 +0000745 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000746 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
747 name_const_string.GetCString());
Greg Clayton427f2902010-12-14 02:59:59 +0000748 }
Greg Clayton427f2902010-12-14 02:59:59 +0000749 }
750 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000751 else
752 {
753 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
754 }
Greg Clayton427f2902010-12-14 02:59:59 +0000755 return ValueObjectSP();
756}
Chris Lattner24943d22010-06-08 16:52:24 +0000757
758bool
759StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
760{
761 if (m_flags.IsClear(GOT_FRAME_BASE))
762 {
763 if (m_sc.function)
764 {
765 m_frame_base.Clear();
766 m_frame_base_error.Clear();
767
768 m_flags.Set(GOT_FRAME_BASE);
769 ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this);
770 Value expr_value;
Greg Clayton178710c2010-09-14 02:20:48 +0000771 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
772 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytoneea26402010-09-14 23:36:40 +0000773 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget());
Greg Clayton178710c2010-09-14 02:20:48 +0000774
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000775 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 +0000776 {
777 // We should really have an error if evaluate returns, but in case
778 // we don't, lets set the error to something at least.
779 if (m_frame_base_error.Success())
780 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
781 }
782 else
783 {
784 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
785 }
786 }
787 else
788 {
789 m_frame_base_error.SetErrorString ("No function in symbol context.");
790 }
791 }
792
793 if (m_frame_base_error.Success())
794 frame_base = m_frame_base;
795
796 if (error_ptr)
797 *error_ptr = m_frame_base_error;
798 return m_frame_base_error.Success();
799}
800
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000801RegisterContextSP
Chris Lattner24943d22010-06-08 16:52:24 +0000802StackFrame::GetRegisterContext ()
803{
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000804 if (!m_reg_context_sp)
805 m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this);
806 return m_reg_context_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000807}
808
809bool
810StackFrame::HasDebugInformation ()
811{
Greg Claytonb04e7a82010-08-24 21:05:24 +0000812 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +0000813 return m_sc.line_entry.IsValid();
814}
815
Greg Clayton17dae082010-09-02 02:59:18 +0000816
817ValueObjectSP
Jim Ingham10de7d12011-05-04 03:43:18 +0000818StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Chris Lattner24943d22010-06-08 16:52:24 +0000819{
Greg Clayton17dae082010-09-02 02:59:18 +0000820 ValueObjectSP valobj_sp;
821 VariableList *var_list = GetVariableList (true);
822 if (var_list)
823 {
824 // Make sure the variable is a frame variable
825 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
826 const uint32_t num_variables = var_list->GetSize();
827 if (var_idx < num_variables)
828 {
829 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
830 if (valobj_sp.get() == NULL)
831 {
832 if (m_variable_list_value_objects.GetSize() < num_variables)
833 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham47da8102011-04-22 23:53:53 +0000834 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton17dae082010-09-02 02:59:18 +0000835 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
836 }
837 }
838 }
Jim Ingham10de7d12011-05-04 03:43:18 +0000839 if (use_dynamic != lldb::eNoDynamicValues && valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000840 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000841 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000842 if (dynamic_sp)
843 return dynamic_sp;
844 }
Greg Clayton17dae082010-09-02 02:59:18 +0000845 return valobj_sp;
846}
847
848ValueObjectSP
Jim Ingham10de7d12011-05-04 03:43:18 +0000849StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Greg Clayton17dae082010-09-02 02:59:18 +0000850{
851 // Check to make sure we aren't already tracking this variable?
Jim Inghame41494a2011-04-16 00:01:13 +0000852 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton17dae082010-09-02 02:59:18 +0000853 if (!valobj_sp)
854 {
855 // We aren't already tracking this global
856 VariableList *var_list = GetVariableList (true);
857 // If this frame has no variables, create a new list
858 if (var_list == NULL)
859 m_variable_list_sp.reset (new VariableList());
860
861 // Add the global/static variable to this frame
862 m_variable_list_sp->AddVariable (variable_sp);
863
864 // Now make a value object for it so we can track its changes
Jim Inghame41494a2011-04-16 00:01:13 +0000865 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton17dae082010-09-02 02:59:18 +0000866 }
867 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000868}
869
Jim Ingham2154da42010-08-26 20:44:45 +0000870bool
871StackFrame::IsInlined ()
872{
Greg Clayton4fb08152010-08-30 18:11:35 +0000873 if (m_sc.block == NULL)
874 GetSymbolContext (eSymbolContextBlock);
875 if (m_sc.block)
876 return m_sc.block->GetContainingInlinedBlock() != NULL;
877 return false;
Jim Ingham2154da42010-08-26 20:44:45 +0000878}
879
Chris Lattner24943d22010-06-08 16:52:24 +0000880Target *
881StackFrame::CalculateTarget ()
882{
883 return m_thread.CalculateTarget();
884}
885
886Process *
887StackFrame::CalculateProcess ()
888{
889 return m_thread.CalculateProcess();
890}
891
892Thread *
893StackFrame::CalculateThread ()
894{
895 return &m_thread;
896}
897
898StackFrame *
899StackFrame::CalculateStackFrame ()
900{
901 return this;
902}
903
904
905void
Greg Claytona830adb2010-10-04 01:05:56 +0000906StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000907{
Greg Claytona830adb2010-10-04 01:05:56 +0000908 m_thread.CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000909 exe_ctx.frame = this;
910}
911
912void
Greg Claytona830adb2010-10-04 01:05:56 +0000913StackFrame::DumpUsingSettingsFormat (Stream *strm)
914{
915 if (strm == NULL)
916 return;
917
918 GetSymbolContext(eSymbolContextEverything);
919 ExecutionContext exe_ctx;
920 CalculateExecutionContext(exe_ctx);
921 const char *end = NULL;
922 StreamString s;
923 const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat();
924 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
925 {
926 strm->Write(s.GetData(), s.GetSize());
927 }
928 else
929 {
930 Dump (strm, true, false);
931 strm->EOL();
932 }
933}
934
935void
Greg Clayton72b71582010-09-02 21:44:10 +0000936StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +0000937{
938 if (strm == NULL)
939 return;
940
941 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +0000942 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton395fc332011-02-15 21:59:32 +0000943 strm->Printf("0x%0*llx ", m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget()));
Greg Claytonb04e7a82010-08-24 21:05:24 +0000944 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +0000945 const bool show_module = true;
946 const bool show_inline = true;
Greg Clayton72b71582010-09-02 21:44:10 +0000947 m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +0000948}
949
Greg Clayton1d66ef52010-08-27 18:24:16 +0000950void
Greg Clayton4fb08152010-08-30 18:11:35 +0000951StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +0000952{
Greg Clayton4fb08152010-08-30 18:11:35 +0000953 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
954 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000955 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +0000956 if (!m_disassembly.GetString().empty())
957 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +0000958}
Greg Clayton870a1cd2010-08-27 21:47:54 +0000959
960
Greg Clayton4fb08152010-08-30 18:11:35 +0000961void
962StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
963{
Greg Clayton5205f0b2010-09-03 17:10:42 +0000964 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
965 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton4fb08152010-08-30 18:11:35 +0000966 assert (&m_thread == &curr_frame.m_thread);
967 m_frame_index = curr_frame.m_frame_index;
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000968 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton4fb08152010-08-30 18:11:35 +0000969 m_reg_context_sp = curr_frame.m_reg_context_sp;
970 m_frame_code_addr = curr_frame.m_frame_code_addr;
971 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());
972 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());
973 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
974 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 +0000975 m_sc = curr_frame.m_sc;
976 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
977 m_flags.Set (m_sc.GetResolvedMask());
978 m_frame_base.Clear();
979 m_frame_base_error.Clear();
980}
981
982
Greg Clayton5205f0b2010-09-03 17:10:42 +0000983bool
984StackFrame::HasCachedData () const
985{
986 if (m_variable_list_sp.get())
987 return true;
988 if (m_variable_list_value_objects.GetSize() > 0)
989 return true;
990 if (!m_disassembly.GetString().empty())
991 return true;
992 return false;
Jim Inghamccd584d2010-09-23 17:40:12 +0000993}
994
995lldb::StackFrameSP
996StackFrame::GetSP ()
997{
998 return m_thread.GetStackFrameSPForStackFramePtr (this);
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000999}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001000
1001
1002
1003bool
1004StackFrame::GetStatus (Stream& strm,
1005 bool show_frame_info,
1006 bool show_source,
1007 uint32_t source_lines_before,
1008 uint32_t source_lines_after)
1009{
1010 if (show_frame_info)
1011 {
1012 strm.Indent();
1013 DumpUsingSettingsFormat (&strm);
1014 }
1015
1016 if (show_source)
1017 {
1018 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1019
1020 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
1021 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001022 Target &target = GetThread().GetProcess().GetTarget();
1023 target.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (
1024 &target,
Greg Claytonabe0fed2011-04-18 08:33:37 +00001025 m_sc.line_entry.file,
1026 m_sc.line_entry.line,
1027 3,
1028 3,
1029 "->",
1030 &strm);
1031
1032 }
1033 }
1034 return true;
1035}
1036