blob: 6d2699d58b13ced27690d0e297fb8c7dca831359 [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"
17#include "lldb/Core/Disassembler.h"
18#include "lldb/Core/Value.h"
Greg Clayton17dae082010-09-02 02:59:18 +000019#include "lldb/Core/ValueObjectVariable.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Symbol/Function.h"
Greg Clayton17dae082010-09-02 02:59:18 +000021#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Target/ExecutionContext.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/RegisterContext.h"
25#include "lldb/Target/Target.h"
26#include "lldb/Target/Thread.h"
27
28using namespace lldb;
29using namespace lldb_private;
30
31// The first bits in the flags are reserved for the SymbolContext::Scope bits
32// so we know if we have tried to look up information in our internal symbol
33// context (m_sc) already.
Greg Clayton4fb08152010-08-30 18:11:35 +000034#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton72b71582010-09-02 21:44:10 +000035#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton4fb08152010-08-30 18:11:35 +000036#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
37#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Chris Lattner24943d22010-06-08 16:52:24 +000038
Greg Clayton33ed1702010-08-24 00:45:41 +000039StackFrame::StackFrame
40(
41 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +000042 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +000043 Thread &thread,
44 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +000045 lldb::addr_t pc,
46 const SymbolContext *sc_ptr
47) :
48 m_frame_index (frame_idx),
Greg Clayton4fb08152010-08-30 18:11:35 +000049 m_unwind_frame_index (unwind_frame_index),
Chris Lattner24943d22010-06-08 16:52:24 +000050 m_thread (thread),
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 Clayton65124ea2010-08-26 22:05:43 +000053 m_frame_code_addr (NULL, 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 Clayton17dae082010-09-02 02:59:18 +000059 m_variable_list_value_objects ()
Chris Lattner24943d22010-06-08 16:52:24 +000060{
61 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000062 {
Chris Lattner24943d22010-06-08 16:52:24 +000063 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000064 m_flags.Set(m_sc.GetResolvedMask ());
65 }
Chris Lattner24943d22010-06-08 16:52:24 +000066}
67
Greg Clayton33ed1702010-08-24 00:45:41 +000068StackFrame::StackFrame
69(
70 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +000071 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +000072 Thread &thread,
73 const RegisterContextSP &reg_context_sp,
74 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +000075 lldb::addr_t pc,
76 const SymbolContext *sc_ptr
77) :
78 m_frame_index (frame_idx),
Greg Clayton4fb08152010-08-30 18:11:35 +000079 m_unwind_frame_index (unwind_frame_index),
Chris Lattner24943d22010-06-08 16:52:24 +000080 m_thread (thread),
Greg Clayton33ed1702010-08-24 00:45:41 +000081 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +000082 m_id (pc, cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +000083 m_frame_code_addr (NULL, pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000084 m_sc (),
85 m_flags (),
86 m_frame_base (),
87 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000088 m_variable_list_sp (),
Greg Clayton17dae082010-09-02 02:59:18 +000089 m_variable_list_value_objects ()
Chris Lattner24943d22010-06-08 16:52:24 +000090{
91 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000092 {
Chris Lattner24943d22010-06-08 16:52:24 +000093 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000094 m_flags.Set(m_sc.GetResolvedMask ());
95 }
96
97 if (reg_context_sp && !m_sc.target_sp)
98 {
99 m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP();
100 m_flags.Set (eSymbolContextTarget);
101 }
102}
103
104StackFrame::StackFrame
105(
106 lldb::user_id_t frame_idx,
Greg Clayton4fb08152010-08-30 18:11:35 +0000107 lldb::user_id_t unwind_frame_index,
Greg Clayton33ed1702010-08-24 00:45:41 +0000108 Thread &thread,
109 const RegisterContextSP &reg_context_sp,
110 lldb::addr_t cfa,
Greg Clayton33ed1702010-08-24 00:45:41 +0000111 const Address& pc_addr,
112 const SymbolContext *sc_ptr
113) :
114 m_frame_index (frame_idx),
Greg Clayton4fb08152010-08-30 18:11:35 +0000115 m_unwind_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +0000116 m_thread (thread),
117 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +0000118 m_id (pc_addr.GetLoadAddress (&thread.GetProcess()), cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +0000119 m_frame_code_addr (pc_addr),
Greg Clayton33ed1702010-08-24 00:45:41 +0000120 m_sc (),
121 m_flags (),
122 m_frame_base (),
123 m_frame_base_error (),
124 m_variable_list_sp (),
Greg Clayton17dae082010-09-02 02:59:18 +0000125 m_variable_list_value_objects ()
Greg Clayton33ed1702010-08-24 00:45:41 +0000126{
127 if (sc_ptr != NULL)
128 {
129 m_sc = *sc_ptr;
130 m_flags.Set(m_sc.GetResolvedMask ());
131 }
132
133 if (m_sc.target_sp.get() == NULL && reg_context_sp)
134 {
135 m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP();
136 m_flags.Set (eSymbolContextTarget);
137 }
138
139 if (m_sc.module_sp.get() == NULL && pc_addr.GetSection())
140 {
141 Module *pc_module = pc_addr.GetSection()->GetModule();
142 if (pc_module)
143 {
144 m_sc.module_sp = pc_module->GetSP();
145 m_flags.Set (eSymbolContextModule);
146 }
147 }
Chris Lattner24943d22010-06-08 16:52:24 +0000148}
149
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154StackFrame::~StackFrame()
155{
156}
157
158StackID&
159StackFrame::GetStackID()
160{
Greg Clayton72b71582010-09-02 21:44:10 +0000161 // Make sure we have resolved the StackID object's symbol context scope if
162 // we already haven't looked it up.
Chris Lattner24943d22010-06-08 16:52:24 +0000163
Greg Clayton4fb08152010-08-30 18:11:35 +0000164 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
165 {
Greg Clayton5205f0b2010-09-03 17:10:42 +0000166 if (m_id.GetSymbolContextScope ())
Greg Clayton4fb08152010-08-30 18:11:35 +0000167 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000168 // We already have a symbol context scope, we just don't have our
169 // flag bit set.
Greg Clayton4fb08152010-08-30 18:11:35 +0000170 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
171 }
172 else
173 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000174 // Calculate the frame block and use this for the stack ID symbol
175 // context scope if we have one.
176 SymbolContextScope *scope = GetFrameBlock ();
177 if (scope == NULL)
Greg Clayton4fb08152010-08-30 18:11:35 +0000178 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000179 // We don't have a block, so use the symbol
180 if (m_flags.IsClear (eSymbolContextSymbol))
181 GetSymbolContext (eSymbolContextSymbol);
182
183 // It is ok if m_sc.symbol is NULL here
184 scope = m_sc.symbol;
Greg Clayton4fb08152010-08-30 18:11:35 +0000185 }
Greg Clayton69aa5d92010-09-07 04:20:48 +0000186 // Set the symbol context scope (the accessor will set the
187 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
188 SetSymbolContextScope (scope);
Greg Clayton4fb08152010-08-30 18:11:35 +0000189 }
Chris Lattner24943d22010-06-08 16:52:24 +0000190 }
191 return m_id;
192}
193
Greg Clayton4fb08152010-08-30 18:11:35 +0000194void
195StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
196{
197 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
198 m_id.SetSymbolContextScope (symbol_scope);
199}
200
Chris Lattner24943d22010-06-08 16:52:24 +0000201Address&
Greg Claytonb04e7a82010-08-24 21:05:24 +0000202StackFrame::GetFrameCodeAddress()
Chris Lattner24943d22010-06-08 16:52:24 +0000203{
Greg Clayton4fb08152010-08-30 18:11:35 +0000204 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000205 {
Greg Clayton4fb08152010-08-30 18:11:35 +0000206 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner24943d22010-06-08 16:52:24 +0000207
208 // Resolve the PC into a temporary address because if ResolveLoadAddress
209 // fails to resolve the address, it will clear the address object...
210 Address resolved_pc;
Greg Clayton65124ea2010-08-26 22:05:43 +0000211 if (m_thread.GetProcess().ResolveLoadAddress(m_frame_code_addr.GetOffset(), resolved_pc))
Chris Lattner24943d22010-06-08 16:52:24 +0000212 {
Greg Clayton65124ea2010-08-26 22:05:43 +0000213 m_frame_code_addr = resolved_pc;
214 const Section *section = m_frame_code_addr.GetSection();
Chris Lattner24943d22010-06-08 16:52:24 +0000215 if (section)
216 {
217 Module *module = section->GetModule();
218 if (module)
219 {
220 m_sc.module_sp = module->GetSP();
221 if (m_sc.module_sp)
222 m_flags.Set(eSymbolContextModule);
223 }
224 }
225 }
226 }
Greg Clayton65124ea2010-08-26 22:05:43 +0000227 return m_frame_code_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000228}
229
230void
231StackFrame::ChangePC (addr_t pc)
232{
Greg Clayton65124ea2010-08-26 22:05:43 +0000233 m_frame_code_addr.SetOffset(pc);
234 m_frame_code_addr.SetSection(NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000235 m_sc.Clear();
236 m_flags.SetAllFlagBits(0);
237 m_thread.ClearStackFrames ();
238}
239
240const char *
241StackFrame::Disassemble ()
242{
243 if (m_disassembly.GetSize() == 0)
244 {
245 ExecutionContext exe_ctx;
246 Calculate(exe_ctx);
Greg Clayton63094e02010-06-23 01:19:29 +0000247 Target &target = m_thread.GetProcess().GetTarget();
248 Disassembler::Disassemble (target.GetDebugger(),
249 target.GetArchitecture(),
Chris Lattner24943d22010-06-08 16:52:24 +0000250 exe_ctx,
251 0,
Greg Clayton70436352010-06-30 23:03:03 +0000252 false,
Chris Lattner24943d22010-06-08 16:52:24 +0000253 m_disassembly);
254 if (m_disassembly.GetSize() == 0)
255 return NULL;
256 }
257 return m_disassembly.GetData();
258}
259
Greg Clayton69aa5d92010-09-07 04:20:48 +0000260Block *
261StackFrame::GetFrameBlock ()
262{
263 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
264 GetSymbolContext (eSymbolContextBlock);
265
266 if (m_sc.block)
267 {
268 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
269 if (inline_block)
270 {
271 // Use the block with the inlined function info
272 // as the frame block we want this frame to have only the variables
273 // for the inlined function and its non-inlined block child blocks.
274 return inline_block;
275 }
276 else
277 {
278 // This block is not contained withing any inlined function blocks
279 // with so we want to use the top most function block.
280 return &m_sc.function->GetBlock (false);
281 }
282 }
283 return NULL;
284}
285
Chris Lattner24943d22010-06-08 16:52:24 +0000286//----------------------------------------------------------------------
287// Get the symbol context if we already haven't done so by resolving the
288// PC address as much as possible. This way when we pass around a
289// StackFrame object, everyone will have as much information as
290// possible and no one will ever have to look things up manually.
291//----------------------------------------------------------------------
292const SymbolContext&
293StackFrame::GetSymbolContext (uint32_t resolve_scope)
294{
295 // Copy our internal symbol context into "sc".
Chris Lattner24943d22010-06-08 16:52:24 +0000296 if ((m_flags.GetAllFlagBits() & resolve_scope) != resolve_scope)
297 {
298 // Resolve our PC to section offset if we haven't alreday done so
299 // and if we don't have a module. The resolved address section will
300 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000301 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000302 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000303
304 // If this is not frame zero, then we need to subtract 1 from the PC
305 // value when doing address lookups since the PC will be on the
306 // instruction following the function call instruction...
307
Greg Claytonb04e7a82010-08-24 21:05:24 +0000308 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000309 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000310 {
311 addr_t offset = lookup_addr.GetOffset();
312 if (offset > 0)
313 lookup_addr.SetOffset(offset - 1);
314 }
315
Greg Claytonb04e7a82010-08-24 21:05:24 +0000316
317 uint32_t resolved = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000318 if (m_sc.module_sp)
319 {
320 // We have something in our stack frame symbol context, lets check
321 // if we haven't already tried to lookup one of those things. If we
322 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000323
324 uint32_t actual_resolve_scope = 0;
325
326 if (resolve_scope & eSymbolContextCompUnit)
327 {
328 if (m_flags.IsClear (eSymbolContextCompUnit))
329 {
330 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000331 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000332 else
333 actual_resolve_scope |= eSymbolContextCompUnit;
334 }
335 }
336
337 if (resolve_scope & eSymbolContextFunction)
338 {
339 if (m_flags.IsClear (eSymbolContextFunction))
340 {
341 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000342 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000343 else
344 actual_resolve_scope |= eSymbolContextFunction;
345 }
346 }
347
348 if (resolve_scope & eSymbolContextBlock)
349 {
350 if (m_flags.IsClear (eSymbolContextBlock))
351 {
352 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000353 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000354 else
355 actual_resolve_scope |= eSymbolContextBlock;
356 }
357 }
358
359 if (resolve_scope & eSymbolContextSymbol)
360 {
361 if (m_flags.IsClear (eSymbolContextSymbol))
362 {
363 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000364 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000365 else
366 actual_resolve_scope |= eSymbolContextSymbol;
367 }
368 }
369
370 if (resolve_scope & eSymbolContextLineEntry)
371 {
372 if (m_flags.IsClear (eSymbolContextLineEntry))
373 {
374 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000375 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000376 else
377 actual_resolve_scope |= eSymbolContextLineEntry;
378 }
379 }
380
381 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000382 {
383 // We might be resolving less information than what is already
384 // in our current symbol context so resolve into a temporary
385 // symbol context "sc" so we don't clear out data we have
386 // already found in "m_sc"
387 SymbolContext sc;
388 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000389 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000390 // Only replace what we didn't already have as we may have
391 // information for an inlined function scope that won't match
392 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000393 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
394 m_sc.comp_unit = sc.comp_unit;
395 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
396 m_sc.function = sc.function;
397 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
398 m_sc.block = sc.block;
399 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
400 m_sc.symbol = sc.symbol;
401 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
402 m_sc.line_entry = sc.line_entry;
403
Chris Lattner24943d22010-06-08 16:52:24 +0000404 }
405 }
406 else
407 {
408 // If we don't have a module, then we can't have the compile unit,
409 // function, block, line entry or symbol, so we can safely call
410 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000411 resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000412 }
413
414 // If the target was requested add that:
415 if (m_sc.target_sp.get() == NULL)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000416 {
Chris Lattner24943d22010-06-08 16:52:24 +0000417 m_sc.target_sp = CalculateProcess()->GetTarget().GetSP();
Greg Claytonb04e7a82010-08-24 21:05:24 +0000418 if (m_sc.target_sp)
419 resolved |= eSymbolContextTarget;
420 }
Chris Lattner24943d22010-06-08 16:52:24 +0000421
422 // Update our internal flags so we remember what we have tried to locate so
423 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000424 // We might have dug up more information that was requested (for example
425 // if we were asked to only get the block, we will have gotten the
426 // compile unit, and function) so set any additional bits that we resolved
427 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000428 }
429
430 // Return the symbol context with everything that was possible to resolve
431 // resolved.
432 return m_sc;
433}
434
435
436VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000437StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000438{
439 if (m_flags.IsClear(RESOLVED_VARIABLES))
440 {
441 m_flags.Set(RESOLVED_VARIABLES);
442
Greg Clayton69aa5d92010-09-07 04:20:48 +0000443 Block *frame_block = GetFrameBlock();
444
445 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000446 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000447 const bool get_child_variables = true;
448 const bool can_create = true;
449 m_variable_list_sp = frame_block->GetVariableList (get_child_variables, can_create);
Chris Lattner24943d22010-06-08 16:52:24 +0000450 }
Greg Clayton17dae082010-09-02 02:59:18 +0000451
Greg Clayton69aa5d92010-09-07 04:20:48 +0000452 if (get_file_globals)
Greg Clayton17dae082010-09-02 02:59:18 +0000453 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000454 if (m_flags.IsClear (eSymbolContextCompUnit))
455 GetSymbolContext (eSymbolContextCompUnit);
456
457 if (m_sc.comp_unit)
458 {
459 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
460 if (m_variable_list_sp)
461 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
462 else
463 m_variable_list_sp = global_variable_list_sp;
464 }
Greg Clayton17dae082010-09-02 02:59:18 +0000465 }
Chris Lattner24943d22010-06-08 16:52:24 +0000466 }
467 return m_variable_list_sp.get();
468}
469
470
471bool
472StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
473{
474 if (m_flags.IsClear(GOT_FRAME_BASE))
475 {
476 if (m_sc.function)
477 {
478 m_frame_base.Clear();
479 m_frame_base_error.Clear();
480
481 m_flags.Set(GOT_FRAME_BASE);
482 ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this);
483 Value expr_value;
484 if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, expr_value, &m_frame_base_error) < 0)
485 {
486 // We should really have an error if evaluate returns, but in case
487 // we don't, lets set the error to something at least.
488 if (m_frame_base_error.Success())
489 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
490 }
491 else
492 {
493 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
494 }
495 }
496 else
497 {
498 m_frame_base_error.SetErrorString ("No function in symbol context.");
499 }
500 }
501
502 if (m_frame_base_error.Success())
503 frame_base = m_frame_base;
504
505 if (error_ptr)
506 *error_ptr = m_frame_base_error;
507 return m_frame_base_error.Success();
508}
509
510RegisterContext *
511StackFrame::GetRegisterContext ()
512{
513 if (m_reg_context_sp.get() == NULL)
514 m_reg_context_sp.reset (m_thread.CreateRegisterContextForFrame (this));
515 return m_reg_context_sp.get();
516}
517
518bool
519StackFrame::HasDebugInformation ()
520{
Greg Claytonb04e7a82010-08-24 21:05:24 +0000521 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +0000522 return m_sc.line_entry.IsValid();
523}
524
Greg Clayton17dae082010-09-02 02:59:18 +0000525
526ValueObjectSP
527StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000528{
Greg Clayton17dae082010-09-02 02:59:18 +0000529 ValueObjectSP valobj_sp;
530 VariableList *var_list = GetVariableList (true);
531 if (var_list)
532 {
533 // Make sure the variable is a frame variable
534 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
535 const uint32_t num_variables = var_list->GetSize();
536 if (var_idx < num_variables)
537 {
538 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
539 if (valobj_sp.get() == NULL)
540 {
541 if (m_variable_list_value_objects.GetSize() < num_variables)
542 m_variable_list_value_objects.Resize(num_variables);
543 valobj_sp.reset (new ValueObjectVariable (variable_sp));
544 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
545 }
546 }
547 }
548 return valobj_sp;
549}
550
551ValueObjectSP
552StackFrame::TrackGlobalVariable (const VariableSP &variable_sp)
553{
554 // Check to make sure we aren't already tracking this variable?
555 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp));
556 if (!valobj_sp)
557 {
558 // We aren't already tracking this global
559 VariableList *var_list = GetVariableList (true);
560 // If this frame has no variables, create a new list
561 if (var_list == NULL)
562 m_variable_list_sp.reset (new VariableList());
563
564 // Add the global/static variable to this frame
565 m_variable_list_sp->AddVariable (variable_sp);
566
567 // Now make a value object for it so we can track its changes
568 valobj_sp = GetValueObjectForFrameVariable (variable_sp);
569 }
570 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000571}
572
Jim Ingham2154da42010-08-26 20:44:45 +0000573bool
574StackFrame::IsInlined ()
575{
Greg Clayton4fb08152010-08-30 18:11:35 +0000576 if (m_sc.block == NULL)
577 GetSymbolContext (eSymbolContextBlock);
578 if (m_sc.block)
579 return m_sc.block->GetContainingInlinedBlock() != NULL;
580 return false;
Jim Ingham2154da42010-08-26 20:44:45 +0000581}
582
Chris Lattner24943d22010-06-08 16:52:24 +0000583Target *
584StackFrame::CalculateTarget ()
585{
586 return m_thread.CalculateTarget();
587}
588
589Process *
590StackFrame::CalculateProcess ()
591{
592 return m_thread.CalculateProcess();
593}
594
595Thread *
596StackFrame::CalculateThread ()
597{
598 return &m_thread;
599}
600
601StackFrame *
602StackFrame::CalculateStackFrame ()
603{
604 return this;
605}
606
607
608void
609StackFrame::Calculate (ExecutionContext &exe_ctx)
610{
611 m_thread.Calculate (exe_ctx);
612 exe_ctx.frame = this;
613}
614
615void
Greg Clayton72b71582010-09-02 21:44:10 +0000616StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +0000617{
618 if (strm == NULL)
619 return;
620
621 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +0000622 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton72b71582010-09-02 21:44:10 +0000623 strm->Printf("0x%0*llx ", m_thread.GetProcess().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()));
Greg Claytonb04e7a82010-08-24 21:05:24 +0000624 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +0000625 const bool show_module = true;
626 const bool show_inline = true;
Greg Clayton72b71582010-09-02 21:44:10 +0000627 m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +0000628}
629
Greg Clayton1d66ef52010-08-27 18:24:16 +0000630void
Greg Clayton4fb08152010-08-30 18:11:35 +0000631StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +0000632{
Greg Clayton4fb08152010-08-30 18:11:35 +0000633 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
634 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000635 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +0000636 if (!m_disassembly.GetString().empty())
637 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +0000638}
Greg Clayton870a1cd2010-08-27 21:47:54 +0000639
640
Greg Clayton4fb08152010-08-30 18:11:35 +0000641void
642StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
643{
Greg Clayton5205f0b2010-09-03 17:10:42 +0000644 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
645 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton4fb08152010-08-30 18:11:35 +0000646 assert (&m_thread == &curr_frame.m_thread);
647 m_frame_index = curr_frame.m_frame_index;
648 m_unwind_frame_index = curr_frame.m_unwind_frame_index;
649 m_reg_context_sp = curr_frame.m_reg_context_sp;
650 m_frame_code_addr = curr_frame.m_frame_code_addr;
651 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());
652 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());
653 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
654 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 +0000655 m_sc = curr_frame.m_sc;
656 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
657 m_flags.Set (m_sc.GetResolvedMask());
658 m_frame_base.Clear();
659 m_frame_base_error.Clear();
660}
661
662
Greg Clayton5205f0b2010-09-03 17:10:42 +0000663bool
664StackFrame::HasCachedData () const
665{
666 if (m_variable_list_sp.get())
667 return true;
668 if (m_variable_list_value_objects.GetSize() > 0)
669 return true;
670 if (!m_disassembly.GetString().empty())
671 return true;
672 return false;
673}