blob: 803e49b6a96784ed7c60aa679d7b6404723357eb [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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 Clayton0603aa92010-10-04 01:05:5617#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2418#include "lldb/Core/Disassembler.h"
19#include "lldb/Core/Value.h"
Greg Clayton288bdf92010-09-02 02:59:1820#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton54979cd2010-12-15 05:08:0821#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Symbol/Function.h"
Greg Clayton288bdf92010-09-02 02:59:1823#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:2424#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 Clayton59e8fc1c2010-08-30 18:11:3536#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton6dadd502010-09-02 21:44:1037#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton59e8fc1c2010-08-30 18:11:3538#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
39#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan7c0962d2010-11-01 04:38:5940#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:2441
Greg Clayton1b72fcb2010-08-24 00:45:4142StackFrame::StackFrame
43(
44 lldb::user_id_t frame_idx,
Greg Clayton59e8fc1c2010-08-30 18:11:3545 lldb::user_id_t unwind_frame_index,
Greg Clayton1b72fcb2010-08-24 00:45:4146 Thread &thread,
47 lldb::addr_t cfa,
Greg Clayton1b72fcb2010-08-24 00:45:4148 lldb::addr_t pc,
49 const SymbolContext *sc_ptr
50) :
Greg Clayton1a65ae12011-01-25 23:55:3751 m_thread (thread),
Greg Clayton1b72fcb2010-08-24 00:45:4152 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:0653 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:4154 m_reg_context_sp (),
Greg Clayton6dadd502010-09-02 21:44:1055 m_id (pc, cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:4356 m_frame_code_addr (NULL, pc),
Greg Clayton1b72fcb2010-08-24 00:45:4157 m_sc (),
58 m_flags (),
59 m_frame_base (),
60 m_frame_base_error (),
Chris Lattner30fdc8d2010-06-08 16:52:2461 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:3762 m_variable_list_value_objects (),
63 m_disassembly ()
Chris Lattner30fdc8d2010-06-08 16:52:2464{
65 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:4166 {
Chris Lattner30fdc8d2010-06-08 16:52:2467 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:4168 m_flags.Set(m_sc.GetResolvedMask ());
69 }
Chris Lattner30fdc8d2010-06-08 16:52:2470}
71
Greg Clayton1b72fcb2010-08-24 00:45:4172StackFrame::StackFrame
73(
74 lldb::user_id_t frame_idx,
Greg Clayton59e8fc1c2010-08-30 18:11:3575 lldb::user_id_t unwind_frame_index,
Greg Clayton1b72fcb2010-08-24 00:45:4176 Thread &thread,
77 const RegisterContextSP &reg_context_sp,
78 lldb::addr_t cfa,
Greg Clayton1b72fcb2010-08-24 00:45:4179 lldb::addr_t pc,
80 const SymbolContext *sc_ptr
81) :
Greg Clayton1a65ae12011-01-25 23:55:3782 m_thread (thread),
Greg Clayton1b72fcb2010-08-24 00:45:4183 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:0684 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:4185 m_reg_context_sp (reg_context_sp),
Greg Clayton6dadd502010-09-02 21:44:1086 m_id (pc, cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:4387 m_frame_code_addr (NULL, pc),
Greg Clayton1b72fcb2010-08-24 00:45:4188 m_sc (),
89 m_flags (),
90 m_frame_base (),
91 m_frame_base_error (),
Chris Lattner30fdc8d2010-06-08 16:52:2492 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:3793 m_variable_list_value_objects (),
94 m_disassembly ()
Chris Lattner30fdc8d2010-06-08 16:52:2495{
96 if (sc_ptr != NULL)
Greg Clayton1b72fcb2010-08-24 00:45:4197 {
Chris Lattner30fdc8d2010-06-08 16:52:2498 m_sc = *sc_ptr;
Greg Clayton1b72fcb2010-08-24 00:45:4199 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 Clayton59e8fc1c2010-08-30 18:11:35112 lldb::user_id_t unwind_frame_index,
Greg Clayton1b72fcb2010-08-24 00:45:41113 Thread &thread,
114 const RegisterContextSP &reg_context_sp,
115 lldb::addr_t cfa,
Greg Clayton1b72fcb2010-08-24 00:45:41116 const Address& pc_addr,
117 const SymbolContext *sc_ptr
118) :
Greg Clayton1a65ae12011-01-25 23:55:37119 m_thread (thread),
Greg Clayton1b72fcb2010-08-24 00:45:41120 m_frame_index (frame_idx),
Greg Clayton5ccbd292011-01-06 22:15:06121 m_concrete_frame_index (unwind_frame_index),
Greg Clayton1b72fcb2010-08-24 00:45:41122 m_reg_context_sp (reg_context_sp),
Greg Claytonf5e56de2010-09-14 23:36:40123 m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL),
Greg Clayton12fc3e02010-08-26 22:05:43124 m_frame_code_addr (pc_addr),
Greg Clayton1b72fcb2010-08-24 00:45:41125 m_sc (),
126 m_flags (),
127 m_frame_base (),
128 m_frame_base_error (),
129 m_variable_list_sp (),
Greg Clayton1a65ae12011-01-25 23:55:37130 m_variable_list_value_objects (),
131 m_disassembly ()
Greg Clayton1b72fcb2010-08-24 00:45:41132{
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 Claytonffc1d662010-09-13 04:34:30145 Module *pc_module = pc_addr.GetModule();
146 if (m_sc.module_sp.get() == NULL || m_sc.module_sp.get() != pc_module)
Greg Clayton1b72fcb2010-08-24 00:45:41147 {
Greg Clayton1b72fcb2010-08-24 00:45:41148 if (pc_module)
149 {
150 m_sc.module_sp = pc_module->GetSP();
151 m_flags.Set (eSymbolContextModule);
152 }
Greg Claytonffc1d662010-09-13 04:34:30153 else
154 {
155 m_sc.module_sp.reset();
156 }
157
Greg Clayton1b72fcb2010-08-24 00:45:41158 }
Chris Lattner30fdc8d2010-06-08 16:52:24159}
160
161
162//----------------------------------------------------------------------
163// Destructor
164//----------------------------------------------------------------------
165StackFrame::~StackFrame()
166{
167}
168
169StackID&
170StackFrame::GetStackID()
171{
Greg Clayton6dadd502010-09-02 21:44:10172 // Make sure we have resolved the StackID object's symbol context scope if
173 // we already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24174
Greg Clayton59e8fc1c2010-08-30 18:11:35175 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
176 {
Greg Clayton2cad65a2010-09-03 17:10:42177 if (m_id.GetSymbolContextScope ())
Greg Clayton59e8fc1c2010-08-30 18:11:35178 {
Greg Clayton95897c62010-09-07 04:20:48179 // We already have a symbol context scope, we just don't have our
180 // flag bit set.
Greg Clayton59e8fc1c2010-08-30 18:11:35181 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
182 }
183 else
184 {
Greg Clayton95897c62010-09-07 04:20:48185 // 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 Clayton59e8fc1c2010-08-30 18:11:35189 {
Greg Clayton95897c62010-09-07 04:20:48190 // 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 Clayton59e8fc1c2010-08-30 18:11:35196 }
Greg Clayton95897c62010-09-07 04:20:48197 // Set the symbol context scope (the accessor will set the
198 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
199 SetSymbolContextScope (scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35200 }
Chris Lattner30fdc8d2010-06-08 16:52:24201 }
202 return m_id;
203}
204
Greg Clayton59e8fc1c2010-08-30 18:11:35205void
206StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
207{
208 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
209 m_id.SetSymbolContextScope (symbol_scope);
210}
211
Greg Clayton34132752011-07-06 04:07:21212const Address&
Greg Clayton9da7bd02010-08-24 21:05:24213StackFrame::GetFrameCodeAddress()
Chris Lattner30fdc8d2010-06-08 16:52:24214{
Greg Clayton59e8fc1c2010-08-30 18:11:35215 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24216 {
Greg Clayton59e8fc1c2010-08-30 18:11:35217 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24218
219 // Resolve the PC into a temporary address because if ResolveLoadAddress
220 // fails to resolve the address, it will clear the address object...
Greg Clayton34132752011-07-06 04:07:21221
222 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), &m_thread.GetProcess().GetTarget()))
Chris Lattner30fdc8d2010-06-08 16:52:24223 {
Greg Clayton12fc3e02010-08-26 22:05:43224 const Section *section = m_frame_code_addr.GetSection();
Chris Lattner30fdc8d2010-06-08 16:52:24225 if (section)
226 {
227 Module *module = section->GetModule();
228 if (module)
229 {
230 m_sc.module_sp = module->GetSP();
231 if (m_sc.module_sp)
232 m_flags.Set(eSymbolContextModule);
233 }
234 }
235 }
236 }
Greg Clayton12fc3e02010-08-26 22:05:43237 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24238}
239
240void
241StackFrame::ChangePC (addr_t pc)
242{
Greg Clayton12fc3e02010-08-26 22:05:43243 m_frame_code_addr.SetOffset(pc);
244 m_frame_code_addr.SetSection(NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24245 m_sc.Clear();
Greg Clayton73b472d2010-10-27 03:32:59246 m_flags.Reset(0);
Chris Lattner30fdc8d2010-06-08 16:52:24247 m_thread.ClearStackFrames ();
248}
249
250const char *
251StackFrame::Disassemble ()
252{
253 if (m_disassembly.GetSize() == 0)
254 {
255 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56256 CalculateExecutionContext(exe_ctx);
Greg Clayton66111032010-06-23 01:19:29257 Target &target = m_thread.GetProcess().GetTarget();
258 Disassembler::Disassemble (target.GetDebugger(),
259 target.GetArchitecture(),
Greg Clayton1080edbc2011-03-25 18:03:16260 NULL,
Chris Lattner30fdc8d2010-06-08 16:52:24261 exe_ctx,
262 0,
Jim Ingham37023b02011-03-22 01:48:42263 0,
Greg Clayton1da6f9d2011-06-22 01:39:49264 0,
Chris Lattner30fdc8d2010-06-08 16:52:24265 m_disassembly);
266 if (m_disassembly.GetSize() == 0)
267 return NULL;
268 }
269 return m_disassembly.GetData();
270}
271
Greg Clayton95897c62010-09-07 04:20:48272Block *
273StackFrame::GetFrameBlock ()
274{
275 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
276 GetSymbolContext (eSymbolContextBlock);
277
278 if (m_sc.block)
279 {
280 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
281 if (inline_block)
282 {
283 // Use the block with the inlined function info
284 // as the frame block we want this frame to have only the variables
285 // for the inlined function and its non-inlined block child blocks.
286 return inline_block;
287 }
288 else
289 {
290 // This block is not contained withing any inlined function blocks
291 // with so we want to use the top most function block.
292 return &m_sc.function->GetBlock (false);
293 }
294 }
295 return NULL;
296}
297
Chris Lattner30fdc8d2010-06-08 16:52:24298//----------------------------------------------------------------------
299// Get the symbol context if we already haven't done so by resolving the
300// PC address as much as possible. This way when we pass around a
301// StackFrame object, everyone will have as much information as
302// possible and no one will ever have to look things up manually.
303//----------------------------------------------------------------------
304const SymbolContext&
305StackFrame::GetSymbolContext (uint32_t resolve_scope)
306{
307 // Copy our internal symbol context into "sc".
Greg Clayton73b472d2010-10-27 03:32:59308 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24309 {
310 // Resolve our PC to section offset if we haven't alreday done so
311 // and if we don't have a module. The resolved address section will
312 // contain the module to which it belongs
Greg Clayton59e8fc1c2010-08-30 18:11:35313 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Clayton9da7bd02010-08-24 21:05:24314 GetFrameCodeAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24315
316 // If this is not frame zero, then we need to subtract 1 from the PC
317 // value when doing address lookups since the PC will be on the
318 // instruction following the function call instruction...
319
Greg Clayton9da7bd02010-08-24 21:05:24320 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton1b72fcb2010-08-24 00:45:41321 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24322 {
323 addr_t offset = lookup_addr.GetOffset();
324 if (offset > 0)
325 lookup_addr.SetOffset(offset - 1);
326 }
327
Greg Clayton9da7bd02010-08-24 21:05:24328
329 uint32_t resolved = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24330 if (m_sc.module_sp)
331 {
332 // We have something in our stack frame symbol context, lets check
333 // if we haven't already tried to lookup one of those things. If we
334 // haven't then we will do the query.
Greg Clayton1b72fcb2010-08-24 00:45:41335
336 uint32_t actual_resolve_scope = 0;
337
338 if (resolve_scope & eSymbolContextCompUnit)
339 {
340 if (m_flags.IsClear (eSymbolContextCompUnit))
341 {
342 if (m_sc.comp_unit)
Greg Clayton9da7bd02010-08-24 21:05:24343 resolved |= eSymbolContextCompUnit;
Greg Clayton1b72fcb2010-08-24 00:45:41344 else
345 actual_resolve_scope |= eSymbolContextCompUnit;
346 }
347 }
348
349 if (resolve_scope & eSymbolContextFunction)
350 {
351 if (m_flags.IsClear (eSymbolContextFunction))
352 {
353 if (m_sc.function)
Greg Clayton9da7bd02010-08-24 21:05:24354 resolved |= eSymbolContextFunction;
Greg Clayton1b72fcb2010-08-24 00:45:41355 else
356 actual_resolve_scope |= eSymbolContextFunction;
357 }
358 }
359
360 if (resolve_scope & eSymbolContextBlock)
361 {
362 if (m_flags.IsClear (eSymbolContextBlock))
363 {
364 if (m_sc.block)
Greg Clayton9da7bd02010-08-24 21:05:24365 resolved |= eSymbolContextBlock;
Greg Clayton1b72fcb2010-08-24 00:45:41366 else
367 actual_resolve_scope |= eSymbolContextBlock;
368 }
369 }
370
371 if (resolve_scope & eSymbolContextSymbol)
372 {
373 if (m_flags.IsClear (eSymbolContextSymbol))
374 {
375 if (m_sc.symbol)
Greg Clayton9da7bd02010-08-24 21:05:24376 resolved |= eSymbolContextSymbol;
Greg Clayton1b72fcb2010-08-24 00:45:41377 else
378 actual_resolve_scope |= eSymbolContextSymbol;
379 }
380 }
381
382 if (resolve_scope & eSymbolContextLineEntry)
383 {
384 if (m_flags.IsClear (eSymbolContextLineEntry))
385 {
386 if (m_sc.line_entry.IsValid())
Greg Clayton9da7bd02010-08-24 21:05:24387 resolved |= eSymbolContextLineEntry;
Greg Clayton1b72fcb2010-08-24 00:45:41388 else
389 actual_resolve_scope |= eSymbolContextLineEntry;
390 }
391 }
392
393 if (actual_resolve_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24394 {
395 // We might be resolving less information than what is already
396 // in our current symbol context so resolve into a temporary
397 // symbol context "sc" so we don't clear out data we have
398 // already found in "m_sc"
399 SymbolContext sc;
400 // Set flags that indicate what we have tried to resolve
Greg Clayton9da7bd02010-08-24 21:05:24401 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton1b72fcb2010-08-24 00:45:41402 // Only replace what we didn't already have as we may have
403 // information for an inlined function scope that won't match
404 // what a standard lookup by address would match
Greg Clayton9da7bd02010-08-24 21:05:24405 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
406 m_sc.comp_unit = sc.comp_unit;
407 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
408 m_sc.function = sc.function;
409 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
410 m_sc.block = sc.block;
411 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
412 m_sc.symbol = sc.symbol;
413 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
414 m_sc.line_entry = sc.line_entry;
415
Chris Lattner30fdc8d2010-06-08 16:52:24416 }
417 }
418 else
419 {
420 // If we don't have a module, then we can't have the compile unit,
421 // function, block, line entry or symbol, so we can safely call
422 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Clayton9da7bd02010-08-24 21:05:24423 resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Chris Lattner30fdc8d2010-06-08 16:52:24424 }
425
426 // If the target was requested add that:
427 if (m_sc.target_sp.get() == NULL)
Greg Clayton9da7bd02010-08-24 21:05:24428 {
Chris Lattner30fdc8d2010-06-08 16:52:24429 m_sc.target_sp = CalculateProcess()->GetTarget().GetSP();
Greg Clayton9da7bd02010-08-24 21:05:24430 if (m_sc.target_sp)
431 resolved |= eSymbolContextTarget;
432 }
Chris Lattner30fdc8d2010-06-08 16:52:24433
434 // Update our internal flags so we remember what we have tried to locate so
435 // we don't have to keep trying when more calls to this function are made.
Greg Clayton9da7bd02010-08-24 21:05:24436 // We might have dug up more information that was requested (for example
437 // if we were asked to only get the block, we will have gotten the
438 // compile unit, and function) so set any additional bits that we resolved
439 m_flags.Set (resolve_scope | resolved);
Chris Lattner30fdc8d2010-06-08 16:52:24440 }
441
442 // Return the symbol context with everything that was possible to resolve
443 // resolved.
444 return m_sc;
445}
446
447
448VariableList *
Greg Clayton288bdf92010-09-02 02:59:18449StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner30fdc8d2010-06-08 16:52:24450{
451 if (m_flags.IsClear(RESOLVED_VARIABLES))
452 {
453 m_flags.Set(RESOLVED_VARIABLES);
454
Greg Clayton95897c62010-09-07 04:20:48455 Block *frame_block = GetFrameBlock();
456
457 if (frame_block)
Chris Lattner30fdc8d2010-06-08 16:52:24458 {
Greg Clayton95897c62010-09-07 04:20:48459 const bool get_child_variables = true;
460 const bool can_create = true;
Greg Claytonc662ec82011-06-17 22:10:16461 const bool stop_if_child_block_is_inlined_function = true;
462 m_variable_list_sp.reset(new VariableList());
463 frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24464 }
Sean Callanan7c0962d2010-11-01 04:38:59465 }
466
467 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
468 get_file_globals)
469 {
470 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton288bdf92010-09-02 02:59:18471
Sean Callanan7c0962d2010-11-01 04:38:59472 if (m_flags.IsClear (eSymbolContextCompUnit))
473 GetSymbolContext (eSymbolContextCompUnit);
474
475 if (m_sc.comp_unit)
Greg Clayton288bdf92010-09-02 02:59:18476 {
Sean Callanan7c0962d2010-11-01 04:38:59477 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
478 if (m_variable_list_sp)
479 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
480 else
481 m_variable_list_sp = global_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:18482 }
Chris Lattner30fdc8d2010-06-08 16:52:24483 }
Sean Callanan7c0962d2010-11-01 04:38:59484
Chris Lattner30fdc8d2010-06-08 16:52:24485 return m_variable_list_sp.get();
486}
487
Greg Claytond41f0322011-08-02 23:35:43488VariableListSP
489StackFrame::GetInScopeVariableList (bool get_file_globals)
490{
491 VariableListSP var_list_sp(new VariableList);
492 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
493
494 if (m_sc.block)
495 {
496 const bool can_create = true;
497 const bool get_parent_variables = true;
498 const bool stop_if_block_is_inlined_function = true;
499 m_sc.block->AppendVariables (can_create,
500 get_parent_variables,
501 stop_if_block_is_inlined_function,
502 var_list_sp.get());
503 }
504
505 if (m_sc.comp_unit)
506 {
507 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
508 if (global_variable_list_sp)
509 var_list_sp->AddVariables (global_variable_list_sp.get());
510 }
511
512 return var_list_sp;
513}
514
515
Greg Clayton8b2fe6d2010-12-14 02:59:59516ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18517StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
518 lldb::DynamicValueType use_dynamic,
519 uint32_t options,
520 lldb::VariableSP &var_sp,
521 Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59522{
Greg Clayton54979cd2010-12-15 05:08:08523
524 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton8b2fe6d2010-12-14 02:59:59525 {
Greg Clayton6d5e68e2011-01-20 19:27:18526 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
527 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Greg Clayton54979cd2010-12-15 05:08:08528 error.Clear();
529 bool deref = false;
530 bool address_of = false;
531 ValueObjectSP valobj_sp;
532 const bool get_file_globals = true;
Greg Claytond41f0322011-08-02 23:35:43533 // When looking up a variable for an expression, we need only consider the
534 // variables that are in scope.
535 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
536 VariableList *variable_list = var_list_sp.get();
Greg Clayton54979cd2010-12-15 05:08:08537
538 if (variable_list)
Greg Clayton8b2fe6d2010-12-14 02:59:59539 {
Greg Clayton54979cd2010-12-15 05:08:08540 // If first character is a '*', then show pointer contents
541 const char *var_expr = var_expr_cstr;
542 if (var_expr[0] == '*')
Greg Clayton8b2fe6d2010-12-14 02:59:59543 {
Greg Clayton54979cd2010-12-15 05:08:08544 deref = true;
545 var_expr++; // Skip the '*'
546 }
547 else if (var_expr[0] == '&')
548 {
549 address_of = true;
550 var_expr++; // Skip the '&'
551 }
552
553 std::string var_path (var_expr);
554 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
555 StreamString var_expr_path_strm;
556
557 ConstString name_const_string;
558 if (separator_idx == std::string::npos)
559 name_const_string.SetCString (var_path.c_str());
560 else
561 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
562
Jim Ingham2837b762011-05-04 03:43:18563 var_sp = variable_list->FindVariable(name_const_string);
Greg Clayton54979cd2010-12-15 05:08:08564 if (var_sp)
565 {
Jim Ingham2837b762011-05-04 03:43:18566 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13567 if (!valobj_sp)
568 return valobj_sp;
569
Greg Clayton54979cd2010-12-15 05:08:08570 var_path.erase (0, name_const_string.GetLength ());
571 // We are dumping at least one child
572 while (separator_idx != std::string::npos)
Greg Clayton8b2fe6d2010-12-14 02:59:59573 {
Greg Clayton54979cd2010-12-15 05:08:08574 // Calculate the next separator index ahead of time
575 ValueObjectSP child_valobj_sp;
576 const char separator_type = var_path[0];
577 switch (separator_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59578 {
Greg Clayton54979cd2010-12-15 05:08:08579
580 case '-':
581 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton8b2fe6d2010-12-14 02:59:59582 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59583
Greg Clayton6d5e68e2011-01-20 19:27:18584 if (no_fragile_ivar)
585 {
586 // Make sure we aren't trying to deref an objective
587 // C ivar if this is not allowed
588 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
589 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
590 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
591 {
592 // This was an objective C object pointer and
593 // it was requested we skip any fragile ivars
594 // so return nothing here
595 return ValueObjectSP();
596 }
597 }
Greg Clayton54979cd2010-12-15 05:08:08598 var_path.erase (0, 1); // Remove the '-'
599 // Fall through
600 case '.':
Greg Clayton8b2fe6d2010-12-14 02:59:59601 {
Greg Clayton54979cd2010-12-15 05:08:08602 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton8b2fe6d2010-12-14 02:59:59603
Greg Clayton54979cd2010-12-15 05:08:08604 var_path.erase (0, 1); // Remove the '.' or '>'
605 separator_idx = var_path.find_first_of(".-[");
606 ConstString child_name;
607 if (separator_idx == std::string::npos)
608 child_name.SetCString (var_path.c_str());
Greg Clayton8b2fe6d2010-12-14 02:59:59609 else
Greg Clayton54979cd2010-12-15 05:08:08610 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
611
612 if (check_ptr_vs_member)
Greg Clayton8b2fe6d2010-12-14 02:59:59613 {
Greg Clayton54979cd2010-12-15 05:08:08614 // We either have a pointer type and need to verify
615 // valobj_sp is a pointer, or we have a member of a
616 // class/union/struct being accessed with the . syntax
617 // and need to verify we don't have a pointer.
618 const bool actual_is_ptr = valobj_sp->IsPointerType ();
619
620 if (actual_is_ptr != expr_is_ptr)
621 {
622 // Incorrect use of "." with a pointer, or "->" with
623 // a class/union/struct instance or reference.
Greg Clayton6beaaa62011-01-17 03:46:26624 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08625 if (actual_is_ptr)
626 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
627 var_expr_path_strm.GetString().c_str(),
628 child_name.GetCString(),
629 var_expr_path_strm.GetString().c_str(),
630 var_path.c_str());
631 else
632 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
633 var_expr_path_strm.GetString().c_str(),
634 child_name.GetCString(),
635 var_expr_path_strm.GetString().c_str(),
636 var_path.c_str());
637 return ValueObjectSP();
638 }
Greg Clayton8b2fe6d2010-12-14 02:59:59639 }
Greg Clayton54979cd2010-12-15 05:08:08640 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton8b2fe6d2010-12-14 02:59:59641 if (!child_valobj_sp)
642 {
Greg Clayton54979cd2010-12-15 05:08:08643 // No child member with name "child_name"
Greg Clayton6beaaa62011-01-17 03:46:26644 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08645 if (child_name)
646 {
647 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
648 child_name.GetCString(),
649 valobj_sp->GetTypeName().AsCString("<invalid type>"),
650 var_expr_path_strm.GetString().c_str());
651 }
652 else
653 {
654 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
655 var_expr_path_strm.GetString().c_str(),
656 var_expr_cstr);
657 }
658
Greg Clayton8b2fe6d2010-12-14 02:59:59659 return ValueObjectSP();
660 }
Greg Clayton54979cd2010-12-15 05:08:08661 // Remove the child name from the path
662 var_path.erase(0, child_name.GetLength());
Jim Ingham2837b762011-05-04 03:43:18663 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13664 {
Jim Ingham2837b762011-05-04 03:43:18665 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13666 if (dynamic_value_sp)
667 child_valobj_sp = dynamic_value_sp;
668 }
Greg Clayton54979cd2010-12-15 05:08:08669 }
670 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59671
Greg Clayton54979cd2010-12-15 05:08:08672 case '[':
673 // Array member access, or treating pointer as an array
674 if (var_path.size() > 2) // Need at least two brackets and a number
675 {
676 char *end = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37677 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9fc19442011-07-06 02:13:41678 if (end && *end == ']'
679 && *(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 Clayton54979cd2010-12-15 05:08:08680 {
Enrico Granata9fc19442011-07-06 02:13:41681 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
682 {
683 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
684 // and extract bit low out of it. reading array item low
685 // would be done by saying ptr[low], without a deref * sign
686 Error error;
687 ValueObjectSP temp(valobj_sp->Dereference(error));
688 if (error.Fail())
689 {
690 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
691 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
692 valobj_sp->GetTypeName().AsCString("<invalid type>"),
693 var_expr_path_strm.GetString().c_str());
694 return ValueObjectSP();
695 }
696 valobj_sp = temp;
697 deref = false;
698 }
699 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
700 {
701 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
702 // (an operation that is equivalent to deref-ing arr)
703 // and extract bit low out of it. reading array item low
704 // would be done by saying arr[low], without a deref * sign
705 Error error;
706 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
707 if (error.Fail())
708 {
709 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
710 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
711 valobj_sp->GetTypeName().AsCString("<invalid type>"),
712 var_expr_path_strm.GetString().c_str());
713 return ValueObjectSP();
714 }
715 valobj_sp = temp;
716 deref = false;
717 }
718
Greg Clayton54979cd2010-12-15 05:08:08719 if (valobj_sp->IsPointerType ())
720 {
721 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
722 if (!child_valobj_sp)
723 {
Greg Clayton6beaaa62011-01-17 03:46:26724 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08725 error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"",
726 child_index,
727 valobj_sp->GetTypeName().AsCString("<invalid type>"),
728 var_expr_path_strm.GetString().c_str());
729 }
730 }
731 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
732 {
Jim Ingham78a685a2011-04-16 00:01:13733 // Pass false to dynamic_value here so we can tell the difference between
734 // no dynamic value and no member of this type...
Greg Clayton54979cd2010-12-15 05:08:08735 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
736 if (!child_valobj_sp)
737 {
Greg Clayton6beaaa62011-01-17 03:46:26738 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08739 error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
740 child_index,
741 valobj_sp->GetTypeName().AsCString("<invalid type>"),
742 var_expr_path_strm.GetString().c_str());
743 }
744 }
Enrico Granata9fc19442011-07-06 02:13:41745 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
746 {
747 // this is a bitfield asking to display just one bit
748 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
749 if (!child_valobj_sp)
750 {
751 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
752 error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"",
753 child_index, child_index,
754 valobj_sp->GetTypeName().AsCString("<invalid type>"),
755 var_expr_path_strm.GetString().c_str());
756 }
757 }
Greg Clayton54979cd2010-12-15 05:08:08758 else
759 {
Greg Clayton6beaaa62011-01-17 03:46:26760 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08761 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
762 valobj_sp->GetTypeName().AsCString("<invalid type>"),
763 var_expr_path_strm.GetString().c_str());
764 }
765
766 if (!child_valobj_sp)
767 {
768 // Invalid array index...
769 return ValueObjectSP();
770 }
771
772 // Erase the array member specification '[%i]' where
773 // %i is the array index
774 var_path.erase(0, (end - var_path.c_str()) + 1);
775 separator_idx = var_path.find_first_of(".-[");
Jim Ingham2837b762011-05-04 03:43:18776 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13777 {
Jim Ingham2837b762011-05-04 03:43:18778 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Ingham78a685a2011-04-16 00:01:13779 if (dynamic_value_sp)
780 child_valobj_sp = dynamic_value_sp;
781 }
Greg Clayton54979cd2010-12-15 05:08:08782 // Break out early from the switch since we were
783 // able to find the child member
784 break;
785 }
Enrico Granata20edcdb2011-07-19 18:03:25786 else if (end && *end == '-')
Enrico Granata9fc19442011-07-06 02:13:41787 {
788 // this is most probably a BitField, let's take a look
789 char *real_end = NULL;
790 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granata20edcdb2011-07-19 18:03:25791 if (real_end && *real_end == ']')
Enrico Granata9fc19442011-07-06 02:13:41792 {
793 // if the format given is [high-low], swap range
Enrico Granata20edcdb2011-07-19 18:03:25794 if (child_index > final_index)
Enrico Granata9fc19442011-07-06 02:13:41795 {
796 long temp = child_index;
797 child_index = final_index;
798 final_index = temp;
799 }
800
801 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
802 {
803 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
804 // and extract bits low thru high out of it. reading array items low thru high
805 // would be done by saying ptr[low-high], without a deref * sign
806 Error error;
807 ValueObjectSP temp(valobj_sp->Dereference(error));
808 if (error.Fail())
809 {
810 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
811 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
812 valobj_sp->GetTypeName().AsCString("<invalid type>"),
813 var_expr_path_strm.GetString().c_str());
814 return ValueObjectSP();
815 }
816 valobj_sp = temp;
817 deref = false;
818 }
819 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
820 {
821 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
822 // (an operation that is equivalent to deref-ing arr)
823 // and extract bits low thru high out of it. reading array items low thru high
824 // would be done by saying arr[low-high], without a deref * sign
825 Error error;
826 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
827 if (error.Fail())
828 {
829 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
830 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
831 valobj_sp->GetTypeName().AsCString("<invalid type>"),
832 var_expr_path_strm.GetString().c_str());
833 return ValueObjectSP();
834 }
835 valobj_sp = temp;
836 deref = false;
837 }
838
839 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
840 if (!child_valobj_sp)
841 {
842 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
843 error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"",
844 child_index, final_index,
845 valobj_sp->GetTypeName().AsCString("<invalid type>"),
846 var_expr_path_strm.GetString().c_str());
847 }
848 }
849
850 if (!child_valobj_sp)
851 {
852 // Invalid bitfield range...
853 return ValueObjectSP();
854 }
855
856 // Erase the bitfield member specification '[%i-%i]' where
857 // %i is the index
858 var_path.erase(0, (real_end - var_path.c_str()) + 1);
859 separator_idx = var_path.find_first_of(".-[");
860 if (use_dynamic != lldb::eNoDynamicValues)
861 {
862 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
863 if (dynamic_value_sp)
864 child_valobj_sp = dynamic_value_sp;
865 }
866 // Break out early from the switch since we were
867 // able to find the child member
868 break;
869
870 }
871 }
872 else
873 {
874 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
875 var_expr_path_strm.GetString().c_str(),
876 var_path.c_str());
Greg Clayton54979cd2010-12-15 05:08:08877 }
878 return ValueObjectSP();
879
880 default:
881 // Failure...
882 {
Greg Clayton6beaaa62011-01-17 03:46:26883 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Clayton54979cd2010-12-15 05:08:08884 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
885 separator_type,
886 var_expr_path_strm.GetString().c_str(),
887 var_path.c_str());
888
889 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59890 }
891 }
Greg Clayton8b2fe6d2010-12-14 02:59:59892
Greg Clayton54979cd2010-12-15 05:08:08893 if (child_valobj_sp)
894 valobj_sp = child_valobj_sp;
895
896 if (var_path.empty())
897 break;
898
Greg Clayton8b2fe6d2010-12-14 02:59:59899 }
Greg Clayton54979cd2010-12-15 05:08:08900 if (valobj_sp)
901 {
902 if (deref)
903 {
Greg Claytonaf67cec2010-12-20 20:49:23904 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Clayton54979cd2010-12-15 05:08:08905 valobj_sp = deref_valobj_sp;
906 }
907 else if (address_of)
908 {
909 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
910 valobj_sp = address_of_valobj_sp;
911 }
912 }
913 return valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59914 }
Greg Clayton54979cd2010-12-15 05:08:08915 else
Greg Clayton8b2fe6d2010-12-14 02:59:59916 {
Jim Ingham2837b762011-05-04 03:43:18917 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
918 name_const_string.GetCString());
Greg Clayton8b2fe6d2010-12-14 02:59:59919 }
Greg Clayton8b2fe6d2010-12-14 02:59:59920 }
921 }
Greg Clayton54979cd2010-12-15 05:08:08922 else
923 {
924 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
925 }
Greg Clayton8b2fe6d2010-12-14 02:59:59926 return ValueObjectSP();
927}
Chris Lattner30fdc8d2010-06-08 16:52:24928
929bool
930StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
931{
932 if (m_flags.IsClear(GOT_FRAME_BASE))
933 {
934 if (m_sc.function)
935 {
936 m_frame_base.Clear();
937 m_frame_base_error.Clear();
938
939 m_flags.Set(GOT_FRAME_BASE);
940 ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this);
941 Value expr_value;
Greg Clayton016a95e2010-09-14 02:20:48942 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
943 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Claytonf5e56de2010-09-14 23:36:40944 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget());
Greg Clayton016a95e2010-09-14 02:20:48945
Greg Clayton1a65ae12011-01-25 23:55:37946 if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24947 {
948 // We should really have an error if evaluate returns, but in case
949 // we don't, lets set the error to something at least.
950 if (m_frame_base_error.Success())
951 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
952 }
953 else
954 {
955 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
956 }
957 }
958 else
959 {
960 m_frame_base_error.SetErrorString ("No function in symbol context.");
961 }
962 }
963
964 if (m_frame_base_error.Success())
965 frame_base = m_frame_base;
966
967 if (error_ptr)
968 *error_ptr = m_frame_base_error;
969 return m_frame_base_error.Success();
970}
971
Greg Clayton5ccbd292011-01-06 22:15:06972RegisterContextSP
Chris Lattner30fdc8d2010-06-08 16:52:24973StackFrame::GetRegisterContext ()
974{
Greg Clayton5ccbd292011-01-06 22:15:06975 if (!m_reg_context_sp)
976 m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this);
977 return m_reg_context_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24978}
979
980bool
981StackFrame::HasDebugInformation ()
982{
Greg Clayton9da7bd02010-08-24 21:05:24983 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner30fdc8d2010-06-08 16:52:24984 return m_sc.line_entry.IsValid();
985}
986
Greg Clayton288bdf92010-09-02 02:59:18987
988ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18989StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Chris Lattner30fdc8d2010-06-08 16:52:24990{
Greg Clayton288bdf92010-09-02 02:59:18991 ValueObjectSP valobj_sp;
992 VariableList *var_list = GetVariableList (true);
993 if (var_list)
994 {
995 // Make sure the variable is a frame variable
996 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
997 const uint32_t num_variables = var_list->GetSize();
998 if (var_idx < num_variables)
999 {
1000 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1001 if (valobj_sp.get() == NULL)
1002 {
1003 if (m_variable_list_value_objects.GetSize() < num_variables)
1004 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham58b59f92011-04-22 23:53:531005 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton288bdf92010-09-02 02:59:181006 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1007 }
1008 }
1009 }
Jim Ingham2837b762011-05-04 03:43:181010 if (use_dynamic != lldb::eNoDynamicValues && valobj_sp)
Jim Ingham78a685a2011-04-16 00:01:131011 {
Jim Ingham2837b762011-05-04 03:43:181012 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:131013 if (dynamic_sp)
1014 return dynamic_sp;
1015 }
Greg Clayton288bdf92010-09-02 02:59:181016 return valobj_sp;
1017}
1018
1019ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:181020StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Greg Clayton288bdf92010-09-02 02:59:181021{
1022 // Check to make sure we aren't already tracking this variable?
Jim Ingham78a685a2011-04-16 00:01:131023 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton288bdf92010-09-02 02:59:181024 if (!valobj_sp)
1025 {
1026 // We aren't already tracking this global
1027 VariableList *var_list = GetVariableList (true);
1028 // If this frame has no variables, create a new list
1029 if (var_list == NULL)
1030 m_variable_list_sp.reset (new VariableList());
1031
1032 // Add the global/static variable to this frame
1033 m_variable_list_sp->AddVariable (variable_sp);
1034
1035 // Now make a value object for it so we can track its changes
Jim Ingham78a685a2011-04-16 00:01:131036 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton288bdf92010-09-02 02:59:181037 }
1038 return valobj_sp;
Chris Lattner30fdc8d2010-06-08 16:52:241039}
1040
Jim Ingham6b8379c2010-08-26 20:44:451041bool
1042StackFrame::IsInlined ()
1043{
Greg Clayton59e8fc1c2010-08-30 18:11:351044 if (m_sc.block == NULL)
1045 GetSymbolContext (eSymbolContextBlock);
1046 if (m_sc.block)
1047 return m_sc.block->GetContainingInlinedBlock() != NULL;
1048 return false;
Jim Ingham6b8379c2010-08-26 20:44:451049}
1050
Chris Lattner30fdc8d2010-06-08 16:52:241051Target *
1052StackFrame::CalculateTarget ()
1053{
1054 return m_thread.CalculateTarget();
1055}
1056
1057Process *
1058StackFrame::CalculateProcess ()
1059{
1060 return m_thread.CalculateProcess();
1061}
1062
1063Thread *
1064StackFrame::CalculateThread ()
1065{
1066 return &m_thread;
1067}
1068
1069StackFrame *
1070StackFrame::CalculateStackFrame ()
1071{
1072 return this;
1073}
1074
1075
1076void
Greg Clayton0603aa92010-10-04 01:05:561077StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:241078{
Greg Clayton0603aa92010-10-04 01:05:561079 m_thread.CalculateExecutionContext (exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:241080 exe_ctx.frame = this;
1081}
1082
1083void
Greg Clayton0603aa92010-10-04 01:05:561084StackFrame::DumpUsingSettingsFormat (Stream *strm)
1085{
1086 if (strm == NULL)
1087 return;
1088
1089 GetSymbolContext(eSymbolContextEverything);
1090 ExecutionContext exe_ctx;
1091 CalculateExecutionContext(exe_ctx);
1092 const char *end = NULL;
1093 StreamString s;
1094 const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat();
1095 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1096 {
1097 strm->Write(s.GetData(), s.GetSize());
1098 }
1099 else
1100 {
1101 Dump (strm, true, false);
1102 strm->EOL();
1103 }
1104}
1105
1106void
Greg Clayton6dadd502010-09-02 21:44:101107StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner30fdc8d2010-06-08 16:52:241108{
1109 if (strm == NULL)
1110 return;
1111
1112 if (show_frame_index)
Greg Clayton1b72fcb2010-08-24 00:45:411113 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton514487e2011-02-15 21:59:321114 strm->Printf("0x%0*llx ", m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget()));
Greg Clayton9da7bd02010-08-24 21:05:241115 GetSymbolContext(eSymbolContextEverything);
Greg Clayton1b72fcb2010-08-24 00:45:411116 const bool show_module = true;
1117 const bool show_inline = true;
Greg Clayton6dadd502010-09-02 21:44:101118 m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline);
Chris Lattner30fdc8d2010-06-08 16:52:241119}
1120
Greg Clayton5082c5f2010-08-27 18:24:161121void
Greg Clayton59e8fc1c2010-08-30 18:11:351122StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton5082c5f2010-08-27 18:24:161123{
Greg Clayton59e8fc1c2010-08-30 18:11:351124 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
1125 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton288bdf92010-09-02 02:59:181126 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton68275d52010-08-27 21:47:541127 if (!m_disassembly.GetString().empty())
1128 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton5082c5f2010-08-27 18:24:161129}
Greg Clayton68275d52010-08-27 21:47:541130
1131
Greg Clayton59e8fc1c2010-08-30 18:11:351132void
1133StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1134{
Greg Clayton2cad65a2010-09-03 17:10:421135 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
1136 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton59e8fc1c2010-08-30 18:11:351137 assert (&m_thread == &curr_frame.m_thread);
1138 m_frame_index = curr_frame.m_frame_index;
Greg Clayton5ccbd292011-01-06 22:15:061139 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton59e8fc1c2010-08-30 18:11:351140 m_reg_context_sp = curr_frame.m_reg_context_sp;
1141 m_frame_code_addr = curr_frame.m_frame_code_addr;
1142 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());
1143 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());
1144 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1145 assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
Greg Clayton59e8fc1c2010-08-30 18:11:351146 m_sc = curr_frame.m_sc;
1147 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1148 m_flags.Set (m_sc.GetResolvedMask());
1149 m_frame_base.Clear();
1150 m_frame_base_error.Clear();
1151}
1152
1153
Greg Clayton2cad65a2010-09-03 17:10:421154bool
1155StackFrame::HasCachedData () const
1156{
1157 if (m_variable_list_sp.get())
1158 return true;
1159 if (m_variable_list_value_objects.GetSize() > 0)
1160 return true;
1161 if (!m_disassembly.GetString().empty())
1162 return true;
1163 return false;
Jim Inghame4284b72010-09-23 17:40:121164}
1165
1166lldb::StackFrameSP
1167StackFrame::GetSP ()
1168{
1169 return m_thread.GetStackFrameSPForStackFramePtr (this);
Greg Clayton1a65ae12011-01-25 23:55:371170}
Greg Clayton7260f622011-04-18 08:33:371171
1172
1173
1174bool
1175StackFrame::GetStatus (Stream& strm,
1176 bool show_frame_info,
1177 bool show_source,
1178 uint32_t source_lines_before,
1179 uint32_t source_lines_after)
1180{
1181 if (show_frame_info)
1182 {
1183 strm.Indent();
1184 DumpUsingSettingsFormat (&strm);
1185 }
1186
1187 if (show_source)
1188 {
1189 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1190
1191 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
1192 {
Greg Clayton7e14f912011-04-23 02:04:551193 Target &target = GetThread().GetProcess().GetTarget();
1194 target.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (
1195 &target,
Greg Clayton7260f622011-04-18 08:33:371196 m_sc.line_entry.file,
1197 m_sc.line_entry.line,
1198 3,
1199 3,
1200 "->",
1201 &strm);
1202
1203 }
1204 }
1205 return true;
1206}
1207