blob: ad98c5fff992f6d75408b4c21ef05dd4901de6dd [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Target/StackFrame.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/Module.h"
Greg Claytona830adb2010-10-04 01:05:56 +000019#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Disassembler.h"
21#include "lldb/Core/Value.h"
Greg Clayton17dae082010-09-02 02:59:18 +000022#include "lldb/Core/ValueObjectVariable.h"
Greg Claytonc3b61d22010-12-15 05:08:08 +000023#include "lldb/Core/ValueObjectConstResult.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Symbol/CompileUnit.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Symbol/Function.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000026#include "lldb/Symbol/Symbol.h"
27#include "lldb/Symbol/SymbolContextScope.h"
Greg Clayton17dae082010-09-02 02:59:18 +000028#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/ExecutionContext.h"
30#include "lldb/Target/Process.h"
31#include "lldb/Target/RegisterContext.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38// The first bits in the flags are reserved for the SymbolContext::Scope bits
39// so we know if we have tried to look up information in our internal symbol
40// context (m_sc) already.
Greg Clayton4fb08152010-08-30 18:11:35 +000041#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
Greg Clayton72b71582010-09-02 21:44:10 +000042#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
Greg Clayton4fb08152010-08-30 18:11:35 +000043#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
44#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
Sean Callanan89363592010-11-01 04:38:59 +000045#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner24943d22010-06-08 16:52:24 +000046
Greg Clayton289afcb2012-02-18 05:35:26 +000047StackFrame::StackFrame (const ThreadSP &thread_sp,
48 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000049 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000050 addr_t cfa,
51 addr_t pc,
52 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000053 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000054 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000055 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000056 m_reg_context_sp (),
Greg Clayton72b71582010-09-02 21:44:10 +000057 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000058 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000059 m_sc (),
60 m_flags (),
61 m_frame_base (),
62 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000063 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000064 m_variable_list_value_objects (),
65 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000066{
67 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000068 {
Chris Lattner24943d22010-06-08 16:52:24 +000069 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000070 m_flags.Set(m_sc.GetResolvedMask ());
71 }
Chris Lattner24943d22010-06-08 16:52:24 +000072}
73
Greg Clayton289afcb2012-02-18 05:35:26 +000074StackFrame::StackFrame (const ThreadSP &thread_sp,
75 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +000076 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +000077 const RegisterContextSP &reg_context_sp,
78 addr_t cfa,
79 addr_t pc,
80 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +000081 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +000082 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +000083 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +000084 m_reg_context_sp (reg_context_sp),
Greg Clayton72b71582010-09-02 21:44:10 +000085 m_id (pc, cfa, NULL),
Greg Clayton3508c382012-02-24 01:59:29 +000086 m_frame_code_addr (pc),
Greg Clayton33ed1702010-08-24 00:45:41 +000087 m_sc (),
88 m_flags (),
89 m_frame_base (),
90 m_frame_base_error (),
Chris Lattner24943d22010-06-08 16:52:24 +000091 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +000092 m_variable_list_value_objects (),
93 m_disassembly ()
Chris Lattner24943d22010-06-08 16:52:24 +000094{
95 if (sc_ptr != NULL)
Greg Clayton33ed1702010-08-24 00:45:41 +000096 {
Chris Lattner24943d22010-06-08 16:52:24 +000097 m_sc = *sc_ptr;
Greg Clayton33ed1702010-08-24 00:45:41 +000098 m_flags.Set(m_sc.GetResolvedMask ());
99 }
100
101 if (reg_context_sp && !m_sc.target_sp)
102 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000103 m_sc.target_sp = reg_context_sp->CalculateTarget();
104 if (m_sc.target_sp)
105 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000106 }
107}
108
Greg Clayton289afcb2012-02-18 05:35:26 +0000109StackFrame::StackFrame (const ThreadSP &thread_sp,
110 user_id_t frame_idx,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000111 user_id_t unwind_frame_index,
Greg Clayton23b8abb2011-09-26 07:11:27 +0000112 const RegisterContextSP &reg_context_sp,
113 addr_t cfa,
114 const Address& pc_addr,
115 const SymbolContext *sc_ptr) :
Greg Clayton289afcb2012-02-18 05:35:26 +0000116 m_thread_wp (thread_sp),
Greg Clayton33ed1702010-08-24 00:45:41 +0000117 m_frame_index (frame_idx),
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000118 m_concrete_frame_index (unwind_frame_index),
Greg Clayton33ed1702010-08-24 00:45:41 +0000119 m_reg_context_sp (reg_context_sp),
Greg Claytonf4124de2012-02-21 00:09:25 +0000120 m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
Greg Clayton65124ea2010-08-26 22:05:43 +0000121 m_frame_code_addr (pc_addr),
Greg Clayton33ed1702010-08-24 00:45:41 +0000122 m_sc (),
123 m_flags (),
124 m_frame_base (),
125 m_frame_base_error (),
126 m_variable_list_sp (),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000127 m_variable_list_value_objects (),
128 m_disassembly ()
Greg Clayton33ed1702010-08-24 00:45:41 +0000129{
130 if (sc_ptr != NULL)
131 {
132 m_sc = *sc_ptr;
133 m_flags.Set(m_sc.GetResolvedMask ());
134 }
135
136 if (m_sc.target_sp.get() == NULL && reg_context_sp)
137 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000138 m_sc.target_sp = reg_context_sp->CalculateTarget();
139 if (m_sc.target_sp)
140 m_flags.Set (eSymbolContextTarget);
Greg Clayton33ed1702010-08-24 00:45:41 +0000141 }
142
Greg Clayton3508c382012-02-24 01:59:29 +0000143 ModuleSP pc_module_sp (pc_addr.GetModule());
144 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000145 {
Greg Clayton3508c382012-02-24 01:59:29 +0000146 if (pc_module_sp)
Greg Clayton33ed1702010-08-24 00:45:41 +0000147 {
Greg Clayton3508c382012-02-24 01:59:29 +0000148 m_sc.module_sp = pc_module_sp;
Greg Clayton33ed1702010-08-24 00:45:41 +0000149 m_flags.Set (eSymbolContextModule);
150 }
Greg Claytone2c5e452010-09-13 04:34:30 +0000151 else
152 {
153 m_sc.module_sp.reset();
154 }
Greg Clayton33ed1702010-08-24 00:45:41 +0000155 }
Chris Lattner24943d22010-06-08 16:52:24 +0000156}
157
158
159//----------------------------------------------------------------------
160// Destructor
161//----------------------------------------------------------------------
162StackFrame::~StackFrame()
163{
164}
165
166StackID&
167StackFrame::GetStackID()
168{
Greg Clayton72b71582010-09-02 21:44:10 +0000169 // Make sure we have resolved the StackID object's symbol context scope if
170 // we already haven't looked it up.
Chris Lattner24943d22010-06-08 16:52:24 +0000171
Greg Clayton4fb08152010-08-30 18:11:35 +0000172 if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
173 {
Greg Clayton5205f0b2010-09-03 17:10:42 +0000174 if (m_id.GetSymbolContextScope ())
Greg Clayton4fb08152010-08-30 18:11:35 +0000175 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000176 // We already have a symbol context scope, we just don't have our
177 // flag bit set.
Greg Clayton4fb08152010-08-30 18:11:35 +0000178 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
179 }
180 else
181 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000182 // Calculate the frame block and use this for the stack ID symbol
183 // context scope if we have one.
184 SymbolContextScope *scope = GetFrameBlock ();
185 if (scope == NULL)
Greg Clayton4fb08152010-08-30 18:11:35 +0000186 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000187 // We don't have a block, so use the symbol
188 if (m_flags.IsClear (eSymbolContextSymbol))
189 GetSymbolContext (eSymbolContextSymbol);
190
191 // It is ok if m_sc.symbol is NULL here
192 scope = m_sc.symbol;
Greg Clayton4fb08152010-08-30 18:11:35 +0000193 }
Greg Clayton69aa5d92010-09-07 04:20:48 +0000194 // Set the symbol context scope (the accessor will set the
195 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
196 SetSymbolContextScope (scope);
Greg Clayton4fb08152010-08-30 18:11:35 +0000197 }
Chris Lattner24943d22010-06-08 16:52:24 +0000198 }
199 return m_id;
200}
201
Jim Ingham0c8fa2d2012-09-01 01:02:41 +0000202uint32_t
203StackFrame::GetFrameIndex () const
204{
205 ThreadSP thread_sp = GetThread();
206 if (thread_sp)
207 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
208 else
209 return m_frame_index;
210}
211
Greg Clayton4fb08152010-08-30 18:11:35 +0000212void
213StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
214{
215 m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
216 m_id.SetSymbolContextScope (symbol_scope);
217}
218
Greg Clayton107e53d2011-07-06 04:07:21 +0000219const Address&
Greg Claytonb04e7a82010-08-24 21:05:24 +0000220StackFrame::GetFrameCodeAddress()
Chris Lattner24943d22010-06-08 16:52:24 +0000221{
Greg Clayton4fb08152010-08-30 18:11:35 +0000222 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000223 {
Greg Clayton4fb08152010-08-30 18:11:35 +0000224 m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
Chris Lattner24943d22010-06-08 16:52:24 +0000225
226 // Resolve the PC into a temporary address because if ResolveLoadAddress
227 // fails to resolve the address, it will clear the address object...
Greg Clayton289afcb2012-02-18 05:35:26 +0000228 ThreadSP thread_sp (GetThread());
229 if (thread_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000230 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000231 TargetSP target_sp (thread_sp->CalculateTarget());
232 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000233 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000234 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000235 {
Greg Clayton3508c382012-02-24 01:59:29 +0000236 ModuleSP module_sp (m_frame_code_addr.GetModule());
237 if (module_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +0000238 {
Greg Clayton3508c382012-02-24 01:59:29 +0000239 m_sc.module_sp = module_sp;
240 m_flags.Set(eSymbolContextModule);
Greg Clayton289afcb2012-02-18 05:35:26 +0000241 }
Chris Lattner24943d22010-06-08 16:52:24 +0000242 }
243 }
244 }
245 }
Greg Clayton65124ea2010-08-26 22:05:43 +0000246 return m_frame_code_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000247}
248
249void
250StackFrame::ChangePC (addr_t pc)
251{
Greg Clayton3508c382012-02-24 01:59:29 +0000252 m_frame_code_addr.SetRawAddress(pc);
Greg Claytona7e864c2013-02-23 04:12:47 +0000253 m_sc.Clear(false);
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000254 m_flags.Reset(0);
Greg Clayton289afcb2012-02-18 05:35:26 +0000255 ThreadSP thread_sp (GetThread());
256 if (thread_sp)
257 thread_sp->ClearStackFrames ();
Chris Lattner24943d22010-06-08 16:52:24 +0000258}
259
260const char *
261StackFrame::Disassemble ()
262{
263 if (m_disassembly.GetSize() == 0)
264 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000265 ExecutionContext exe_ctx (shared_from_this());
266 Target *target = exe_ctx.GetTargetPtr();
267 if (target)
268 {
269 Disassembler::Disassemble (target->GetDebugger(),
270 target->GetArchitecture(),
271 NULL,
272 exe_ctx,
273 0,
274 0,
275 0,
276 m_disassembly);
277 }
Chris Lattner24943d22010-06-08 16:52:24 +0000278 if (m_disassembly.GetSize() == 0)
279 return NULL;
280 }
281 return m_disassembly.GetData();
282}
283
Greg Clayton69aa5d92010-09-07 04:20:48 +0000284Block *
285StackFrame::GetFrameBlock ()
286{
287 if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
288 GetSymbolContext (eSymbolContextBlock);
289
290 if (m_sc.block)
291 {
292 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
293 if (inline_block)
294 {
295 // Use the block with the inlined function info
296 // as the frame block we want this frame to have only the variables
297 // for the inlined function and its non-inlined block child blocks.
298 return inline_block;
299 }
300 else
301 {
302 // This block is not contained withing any inlined function blocks
303 // with so we want to use the top most function block.
304 return &m_sc.function->GetBlock (false);
305 }
306 }
307 return NULL;
308}
309
Chris Lattner24943d22010-06-08 16:52:24 +0000310//----------------------------------------------------------------------
311// Get the symbol context if we already haven't done so by resolving the
312// PC address as much as possible. This way when we pass around a
313// StackFrame object, everyone will have as much information as
314// possible and no one will ever have to look things up manually.
315//----------------------------------------------------------------------
316const SymbolContext&
317StackFrame::GetSymbolContext (uint32_t resolve_scope)
318{
319 // Copy our internal symbol context into "sc".
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000320 if ((m_flags.Get() & resolve_scope) != resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000321 {
Greg Clayton214d2a32012-11-29 00:53:06 +0000322 uint32_t resolved = 0;
323
324 // If the target was requested add that:
325 if (!m_sc.target_sp)
326 {
327 m_sc.target_sp = CalculateTarget();
328 if (m_sc.target_sp)
329 resolved |= eSymbolContextTarget;
330 }
331
332
Chris Lattner24943d22010-06-08 16:52:24 +0000333 // Resolve our PC to section offset if we haven't alreday done so
334 // and if we don't have a module. The resolved address section will
335 // contain the module to which it belongs
Greg Clayton4fb08152010-08-30 18:11:35 +0000336 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
Greg Claytonb04e7a82010-08-24 21:05:24 +0000337 GetFrameCodeAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000338
339 // If this is not frame zero, then we need to subtract 1 from the PC
340 // value when doing address lookups since the PC will be on the
341 // instruction following the function call instruction...
342
Greg Claytonb04e7a82010-08-24 21:05:24 +0000343 Address lookup_addr(GetFrameCodeAddress());
Greg Clayton33ed1702010-08-24 00:45:41 +0000344 if (m_frame_index > 0 && lookup_addr.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000345 {
346 addr_t offset = lookup_addr.GetOffset();
347 if (offset > 0)
348 lookup_addr.SetOffset(offset - 1);
349 }
350
Greg Claytonb04e7a82010-08-24 21:05:24 +0000351
Chris Lattner24943d22010-06-08 16:52:24 +0000352 if (m_sc.module_sp)
353 {
354 // We have something in our stack frame symbol context, lets check
355 // if we haven't already tried to lookup one of those things. If we
356 // haven't then we will do the query.
Greg Clayton33ed1702010-08-24 00:45:41 +0000357
358 uint32_t actual_resolve_scope = 0;
359
360 if (resolve_scope & eSymbolContextCompUnit)
361 {
362 if (m_flags.IsClear (eSymbolContextCompUnit))
363 {
364 if (m_sc.comp_unit)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000365 resolved |= eSymbolContextCompUnit;
Greg Clayton33ed1702010-08-24 00:45:41 +0000366 else
367 actual_resolve_scope |= eSymbolContextCompUnit;
368 }
369 }
370
371 if (resolve_scope & eSymbolContextFunction)
372 {
373 if (m_flags.IsClear (eSymbolContextFunction))
374 {
375 if (m_sc.function)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000376 resolved |= eSymbolContextFunction;
Greg Clayton33ed1702010-08-24 00:45:41 +0000377 else
378 actual_resolve_scope |= eSymbolContextFunction;
379 }
380 }
381
382 if (resolve_scope & eSymbolContextBlock)
383 {
384 if (m_flags.IsClear (eSymbolContextBlock))
385 {
386 if (m_sc.block)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000387 resolved |= eSymbolContextBlock;
Greg Clayton33ed1702010-08-24 00:45:41 +0000388 else
389 actual_resolve_scope |= eSymbolContextBlock;
390 }
391 }
392
393 if (resolve_scope & eSymbolContextSymbol)
394 {
395 if (m_flags.IsClear (eSymbolContextSymbol))
396 {
397 if (m_sc.symbol)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000398 resolved |= eSymbolContextSymbol;
Greg Clayton33ed1702010-08-24 00:45:41 +0000399 else
400 actual_resolve_scope |= eSymbolContextSymbol;
401 }
402 }
403
404 if (resolve_scope & eSymbolContextLineEntry)
405 {
406 if (m_flags.IsClear (eSymbolContextLineEntry))
407 {
408 if (m_sc.line_entry.IsValid())
Greg Claytonb04e7a82010-08-24 21:05:24 +0000409 resolved |= eSymbolContextLineEntry;
Greg Clayton33ed1702010-08-24 00:45:41 +0000410 else
411 actual_resolve_scope |= eSymbolContextLineEntry;
412 }
413 }
414
415 if (actual_resolve_scope)
Chris Lattner24943d22010-06-08 16:52:24 +0000416 {
417 // We might be resolving less information than what is already
418 // in our current symbol context so resolve into a temporary
419 // symbol context "sc" so we don't clear out data we have
420 // already found in "m_sc"
421 SymbolContext sc;
422 // Set flags that indicate what we have tried to resolve
Greg Claytonb04e7a82010-08-24 21:05:24 +0000423 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
Greg Clayton33ed1702010-08-24 00:45:41 +0000424 // Only replace what we didn't already have as we may have
425 // information for an inlined function scope that won't match
426 // what a standard lookup by address would match
Greg Claytonb04e7a82010-08-24 21:05:24 +0000427 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL)
428 m_sc.comp_unit = sc.comp_unit;
429 if ((resolved & eSymbolContextFunction) && m_sc.function == NULL)
430 m_sc.function = sc.function;
431 if ((resolved & eSymbolContextBlock) && m_sc.block == NULL)
432 m_sc.block = sc.block;
433 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL)
434 m_sc.symbol = sc.symbol;
Greg Clayton214d2a32012-11-29 00:53:06 +0000435 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
436 {
Greg Claytonb04e7a82010-08-24 21:05:24 +0000437 m_sc.line_entry = sc.line_entry;
Greg Clayton214d2a32012-11-29 00:53:06 +0000438 if (m_sc.target_sp)
439 {
440 // Be sure to apply and file remappings to our file and line
441 // entries when handing out a line entry
442 FileSpec new_file_spec;
443 if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
444 m_sc.line_entry.file = new_file_spec;
445 }
446 }
Chris Lattner24943d22010-06-08 16:52:24 +0000447 }
448 }
449 else
450 {
451 // If we don't have a module, then we can't have the compile unit,
452 // function, block, line entry or symbol, so we can safely call
453 // ResolveSymbolContextForAddress with our symbol context member m_sc.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000454 if (m_sc.target_sp)
Sean Callanan8ea48782013-02-21 20:54:33 +0000455 {
Greg Clayton214d2a32012-11-29 00:53:06 +0000456 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
Sean Callanan8ea48782013-02-21 20:54:33 +0000457 }
Greg Claytonb04e7a82010-08-24 21:05:24 +0000458 }
Chris Lattner24943d22010-06-08 16:52:24 +0000459
460 // Update our internal flags so we remember what we have tried to locate so
461 // we don't have to keep trying when more calls to this function are made.
Greg Claytonb04e7a82010-08-24 21:05:24 +0000462 // We might have dug up more information that was requested (for example
463 // if we were asked to only get the block, we will have gotten the
464 // compile unit, and function) so set any additional bits that we resolved
465 m_flags.Set (resolve_scope | resolved);
Chris Lattner24943d22010-06-08 16:52:24 +0000466 }
467
468 // Return the symbol context with everything that was possible to resolve
469 // resolved.
470 return m_sc;
471}
472
473
474VariableList *
Greg Clayton17dae082010-09-02 02:59:18 +0000475StackFrame::GetVariableList (bool get_file_globals)
Chris Lattner24943d22010-06-08 16:52:24 +0000476{
477 if (m_flags.IsClear(RESOLVED_VARIABLES))
478 {
479 m_flags.Set(RESOLVED_VARIABLES);
480
Greg Clayton69aa5d92010-09-07 04:20:48 +0000481 Block *frame_block = GetFrameBlock();
482
483 if (frame_block)
Chris Lattner24943d22010-06-08 16:52:24 +0000484 {
Greg Clayton69aa5d92010-09-07 04:20:48 +0000485 const bool get_child_variables = true;
486 const bool can_create = true;
Greg Clayton1bd2b2f2011-06-17 22:10:16 +0000487 const bool stop_if_child_block_is_inlined_function = true;
488 m_variable_list_sp.reset(new VariableList());
489 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 +0000490 }
Sean Callanan89363592010-11-01 04:38:59 +0000491 }
492
493 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
494 get_file_globals)
495 {
496 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
Greg Clayton17dae082010-09-02 02:59:18 +0000497
Sean Callanan89363592010-11-01 04:38:59 +0000498 if (m_flags.IsClear (eSymbolContextCompUnit))
499 GetSymbolContext (eSymbolContextCompUnit);
500
501 if (m_sc.comp_unit)
Greg Clayton17dae082010-09-02 02:59:18 +0000502 {
Sean Callanan89363592010-11-01 04:38:59 +0000503 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
504 if (m_variable_list_sp)
505 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
506 else
507 m_variable_list_sp = global_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +0000508 }
Chris Lattner24943d22010-06-08 16:52:24 +0000509 }
Sean Callanan89363592010-11-01 04:38:59 +0000510
Chris Lattner24943d22010-06-08 16:52:24 +0000511 return m_variable_list_sp.get();
512}
513
Greg Clayton6e2d2822011-08-02 23:35:43 +0000514VariableListSP
515StackFrame::GetInScopeVariableList (bool get_file_globals)
516{
517 VariableListSP var_list_sp(new VariableList);
518 GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
519
520 if (m_sc.block)
521 {
522 const bool can_create = true;
523 const bool get_parent_variables = true;
524 const bool stop_if_block_is_inlined_function = true;
525 m_sc.block->AppendVariables (can_create,
526 get_parent_variables,
527 stop_if_block_is_inlined_function,
528 var_list_sp.get());
529 }
530
531 if (m_sc.comp_unit)
532 {
533 VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
534 if (global_variable_list_sp)
535 var_list_sp->AddVariables (global_variable_list_sp.get());
536 }
537
538 return var_list_sp;
539}
540
541
Greg Clayton427f2902010-12-14 02:59:59 +0000542ValueObjectSP
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000543StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000544 DynamicValueType use_dynamic,
Jim Ingham10de7d12011-05-04 03:43:18 +0000545 uint32_t options,
Greg Clayton987c7eb2011-09-17 08:33:22 +0000546 VariableSP &var_sp,
Jim Ingham10de7d12011-05-04 03:43:18 +0000547 Error &error)
Greg Clayton427f2902010-12-14 02:59:59 +0000548{
Greg Claytonc3b61d22010-12-15 05:08:08 +0000549
550 if (var_expr_cstr && var_expr_cstr[0])
Greg Clayton427f2902010-12-14 02:59:59 +0000551 {
Greg Claytonc67efa42011-01-20 19:27:18 +0000552 const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
553 const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
Enrico Granataf6698502011-08-09 01:04:56 +0000554 const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
Enrico Granata13a54a12011-08-19 21:56:10 +0000555 //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000556 error.Clear();
557 bool deref = false;
558 bool address_of = false;
559 ValueObjectSP valobj_sp;
560 const bool get_file_globals = true;
Greg Clayton6e2d2822011-08-02 23:35:43 +0000561 // When looking up a variable for an expression, we need only consider the
562 // variables that are in scope.
563 VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
564 VariableList *variable_list = var_list_sp.get();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000565
566 if (variable_list)
Greg Clayton427f2902010-12-14 02:59:59 +0000567 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000568 // If first character is a '*', then show pointer contents
569 const char *var_expr = var_expr_cstr;
570 if (var_expr[0] == '*')
Greg Clayton427f2902010-12-14 02:59:59 +0000571 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000572 deref = true;
573 var_expr++; // Skip the '*'
574 }
575 else if (var_expr[0] == '&')
576 {
577 address_of = true;
578 var_expr++; // Skip the '&'
579 }
580
581 std::string var_path (var_expr);
582 size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
583 StreamString var_expr_path_strm;
584
585 ConstString name_const_string;
586 if (separator_idx == std::string::npos)
587 name_const_string.SetCString (var_path.c_str());
588 else
589 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
590
Jim Ingham10de7d12011-05-04 03:43:18 +0000591 var_sp = variable_list->FindVariable(name_const_string);
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000592
593 bool synthetically_added_instance_object = false;
594
595 if (var_sp)
596 {
597 var_path.erase (0, name_const_string.GetLength ());
598 }
599 else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
600 {
601 // Check for direct ivars access which helps us with implicit
602 // access to ivars with the "this->" or "self->"
603 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
604 lldb::LanguageType method_language = eLanguageTypeUnknown;
605 bool is_instance_method = false;
606 ConstString method_object_name;
607 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
608 {
609 if (is_instance_method && method_object_name)
610 {
611 var_sp = variable_list->FindVariable(method_object_name);
612 if (var_sp)
613 {
614 separator_idx = 0;
615 var_path.insert(0, "->");
616 synthetically_added_instance_object = true;
617 }
618 }
619 }
620 }
621
Greg Claytonc3b61d22010-12-15 05:08:08 +0000622 if (var_sp)
623 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000624 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000625 if (!valobj_sp)
626 return valobj_sp;
627
Greg Claytonc3b61d22010-12-15 05:08:08 +0000628 // We are dumping at least one child
629 while (separator_idx != std::string::npos)
Greg Clayton427f2902010-12-14 02:59:59 +0000630 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000631 // Calculate the next separator index ahead of time
632 ValueObjectSP child_valobj_sp;
633 const char separator_type = var_path[0];
634 switch (separator_type)
Greg Clayton427f2902010-12-14 02:59:59 +0000635 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000636
637 case '-':
638 if (var_path.size() >= 2 && var_path[1] != '>')
Greg Clayton427f2902010-12-14 02:59:59 +0000639 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +0000640
Greg Claytonc67efa42011-01-20 19:27:18 +0000641 if (no_fragile_ivar)
642 {
643 // Make sure we aren't trying to deref an objective
644 // C ivar if this is not allowed
645 const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
646 if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
647 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
648 {
649 // This was an objective C object pointer and
650 // it was requested we skip any fragile ivars
651 // so return nothing here
652 return ValueObjectSP();
653 }
654 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000655 var_path.erase (0, 1); // Remove the '-'
656 // Fall through
657 case '.':
Greg Clayton427f2902010-12-14 02:59:59 +0000658 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000659 const bool expr_is_ptr = var_path[0] == '>';
Greg Clayton427f2902010-12-14 02:59:59 +0000660
Greg Claytonc3b61d22010-12-15 05:08:08 +0000661 var_path.erase (0, 1); // Remove the '.' or '>'
662 separator_idx = var_path.find_first_of(".-[");
663 ConstString child_name;
664 if (separator_idx == std::string::npos)
665 child_name.SetCString (var_path.c_str());
Greg Clayton427f2902010-12-14 02:59:59 +0000666 else
Greg Claytonc3b61d22010-12-15 05:08:08 +0000667 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
668
669 if (check_ptr_vs_member)
Greg Clayton427f2902010-12-14 02:59:59 +0000670 {
Greg Claytonc3b61d22010-12-15 05:08:08 +0000671 // We either have a pointer type and need to verify
672 // valobj_sp is a pointer, or we have a member of a
673 // class/union/struct being accessed with the . syntax
674 // and need to verify we don't have a pointer.
675 const bool actual_is_ptr = valobj_sp->IsPointerType ();
676
677 if (actual_is_ptr != expr_is_ptr)
678 {
679 // Incorrect use of "." with a pointer, or "->" with
680 // a class/union/struct instance or reference.
Greg Claytonb01000f2011-01-17 03:46:26 +0000681 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000682 if (actual_is_ptr)
683 error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
684 var_expr_path_strm.GetString().c_str(),
685 child_name.GetCString(),
686 var_expr_path_strm.GetString().c_str(),
687 var_path.c_str());
688 else
689 error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
690 var_expr_path_strm.GetString().c_str(),
691 child_name.GetCString(),
692 var_expr_path_strm.GetString().c_str(),
693 var_path.c_str());
694 return ValueObjectSP();
695 }
Greg Clayton427f2902010-12-14 02:59:59 +0000696 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000697 child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
Greg Clayton427f2902010-12-14 02:59:59 +0000698 if (!child_valobj_sp)
699 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000700 if (no_synth_child == false)
Enrico Granatacf09f882012-03-19 22:58:49 +0000701 {
702 child_valobj_sp = valobj_sp->GetSyntheticValue();
703 if (child_valobj_sp)
704 child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
705 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000706
707 if (no_synth_child || !child_valobj_sp)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000708 {
Enrico Granata9c57fc02011-08-11 17:08:01 +0000709 // No child member with name "child_name"
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000710 if (synthetically_added_instance_object)
Enrico Granata9c57fc02011-08-11 17:08:01 +0000711 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000712 // We added a "this->" or "self->" to the beginning of the expression
713 // and this is the first pointer ivar access, so just return the normal
714 // error
715 error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
716 name_const_string.GetCString());
Enrico Granata9c57fc02011-08-11 17:08:01 +0000717 }
718 else
719 {
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000720 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
721 if (child_name)
722 {
723 error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
724 child_name.GetCString(),
725 valobj_sp->GetTypeName().AsCString("<invalid type>"),
726 var_expr_path_strm.GetString().c_str());
727 }
728 else
729 {
730 error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
731 var_expr_path_strm.GetString().c_str(),
732 var_expr_cstr);
733 }
Enrico Granata9c57fc02011-08-11 17:08:01 +0000734 }
735 return ValueObjectSP();
Greg Claytonc3b61d22010-12-15 05:08:08 +0000736 }
Greg Clayton427f2902010-12-14 02:59:59 +0000737 }
Greg Claytonb3a1a2b2012-07-14 00:53:55 +0000738 synthetically_added_instance_object = false;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000739 // Remove the child name from the path
740 var_path.erase(0, child_name.GetLength());
Greg Clayton987c7eb2011-09-17 08:33:22 +0000741 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000742 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000743 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000744 if (dynamic_value_sp)
745 child_valobj_sp = dynamic_value_sp;
746 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000747 }
748 break;
Greg Clayton427f2902010-12-14 02:59:59 +0000749
Greg Claytonc3b61d22010-12-15 05:08:08 +0000750 case '[':
751 // Array member access, or treating pointer as an array
752 if (var_path.size() > 2) // Need at least two brackets and a number
753 {
754 char *end = NULL;
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000755 long child_index = ::strtol (&var_path[1], &end, 0);
Enrico Granata9762e102011-07-06 02:13:41 +0000756 if (end && *end == ']'
757 && *(end-1) != '[') // this code forces an error in the case of arr[]. as bitfield[] is not a good syntax we're good to go
Greg Claytonc3b61d22010-12-15 05:08:08 +0000758 {
Enrico Granata9762e102011-07-06 02:13:41 +0000759 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
760 {
761 // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
762 // and extract bit low out of it. reading array item low
763 // would be done by saying ptr[low], without a deref * sign
764 Error error;
765 ValueObjectSP temp(valobj_sp->Dereference(error));
766 if (error.Fail())
767 {
768 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
769 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
770 valobj_sp->GetTypeName().AsCString("<invalid type>"),
771 var_expr_path_strm.GetString().c_str());
772 return ValueObjectSP();
773 }
774 valobj_sp = temp;
775 deref = false;
776 }
777 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
778 {
779 // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
780 // (an operation that is equivalent to deref-ing arr)
781 // and extract bit low out of it. reading array item low
782 // would be done by saying arr[low], without a deref * sign
783 Error error;
784 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
785 if (error.Fail())
786 {
787 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
788 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
789 valobj_sp->GetTypeName().AsCString("<invalid type>"),
790 var_expr_path_strm.GetString().c_str());
791 return ValueObjectSP();
792 }
793 valobj_sp = temp;
794 deref = false;
795 }
796
Greg Claytonb9124572012-12-06 02:33:54 +0000797 bool is_incomplete_array = false;
Greg Claytonc3b61d22010-12-15 05:08:08 +0000798 if (valobj_sp->IsPointerType ())
799 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000800 bool is_objc_pointer = true;
801
802 if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
803 is_objc_pointer = false;
804 else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
805 is_objc_pointer = false;
806
807 if (no_synth_child && is_objc_pointer)
Greg Claytonc3b61d22010-12-15 05:08:08 +0000808 {
Sean Callanan6e12c7a2012-03-08 02:39:03 +0000809 error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
810 valobj_sp->GetTypeName().AsCString("<invalid type>"),
811 var_expr_path_strm.GetString().c_str());
812
813 return ValueObjectSP();
814 }
815 else if (is_objc_pointer)
816 {
Enrico Granataf6698502011-08-09 01:04:56 +0000817 // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
Enrico Granatacf09f882012-03-19 22:58:49 +0000818 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000819 if (synthetic.get() == NULL /* no synthetic */
820 || synthetic == valobj_sp) /* synthetic is the same as the original object */
821 {
822 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
823 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
824 valobj_sp->GetTypeName().AsCString("<invalid type>"),
825 var_expr_path_strm.GetString().c_str());
826 }
827 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
828 {
829 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000830 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000831 child_index,
832 valobj_sp->GetTypeName().AsCString("<invalid type>"),
833 var_expr_path_strm.GetString().c_str());
834 }
835 else
836 {
837 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
838 if (!child_valobj_sp)
839 {
840 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000841 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000842 child_index,
843 valobj_sp->GetTypeName().AsCString("<invalid type>"),
844 var_expr_path_strm.GetString().c_str());
845 }
846 }
847 }
848 else
849 {
850 child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
851 if (!child_valobj_sp)
852 {
853 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000854 error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000855 child_index,
856 valobj_sp->GetTypeName().AsCString("<invalid type>"),
857 var_expr_path_strm.GetString().c_str());
858 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000859 }
860 }
Greg Claytonb9124572012-12-06 02:33:54 +0000861 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL, &is_incomplete_array))
Greg Claytonc3b61d22010-12-15 05:08:08 +0000862 {
Jim Inghame41494a2011-04-16 00:01:13 +0000863 // Pass false to dynamic_value here so we can tell the difference between
864 // no dynamic value and no member of this type...
Greg Claytonc3b61d22010-12-15 05:08:08 +0000865 child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
Greg Claytonb9124572012-12-06 02:33:54 +0000866 if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
867 child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
868
Greg Claytonc3b61d22010-12-15 05:08:08 +0000869 if (!child_valobj_sp)
870 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000871 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000872 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Greg Claytonc3b61d22010-12-15 05:08:08 +0000873 child_index,
874 valobj_sp->GetTypeName().AsCString("<invalid type>"),
875 var_expr_path_strm.GetString().c_str());
876 }
877 }
Enrico Granata9762e102011-07-06 02:13:41 +0000878 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
879 {
880 // this is a bitfield asking to display just one bit
881 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
882 if (!child_valobj_sp)
883 {
884 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000885 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata9762e102011-07-06 02:13:41 +0000886 child_index, child_index,
887 valobj_sp->GetTypeName().AsCString("<invalid type>"),
888 var_expr_path_strm.GetString().c_str());
889 }
890 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000891 else
892 {
Enrico Granatacf09f882012-03-19 22:58:49 +0000893 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
Enrico Granataf6698502011-08-09 01:04:56 +0000894 if (no_synth_child /* synthetic is forbidden */ ||
895 synthetic.get() == NULL /* no synthetic */
896 || synthetic == valobj_sp) /* synthetic is the same as the original object */
897 {
898 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
899 error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
900 valobj_sp->GetTypeName().AsCString("<invalid type>"),
901 var_expr_path_strm.GetString().c_str());
902 }
903 else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
904 {
905 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000906 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000907 child_index,
908 valobj_sp->GetTypeName().AsCString("<invalid type>"),
909 var_expr_path_strm.GetString().c_str());
910 }
911 else
912 {
913 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
914 if (!child_valobj_sp)
915 {
916 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +0000917 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
Enrico Granataf6698502011-08-09 01:04:56 +0000918 child_index,
919 valobj_sp->GetTypeName().AsCString("<invalid type>"),
920 var_expr_path_strm.GetString().c_str());
921 }
922 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000923 }
924
925 if (!child_valobj_sp)
926 {
927 // Invalid array index...
928 return ValueObjectSP();
929 }
930
931 // Erase the array member specification '[%i]' where
932 // %i is the array index
933 var_path.erase(0, (end - var_path.c_str()) + 1);
934 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +0000935 if (use_dynamic != eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000936 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000937 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
Jim Inghame41494a2011-04-16 00:01:13 +0000938 if (dynamic_value_sp)
939 child_valobj_sp = dynamic_value_sp;
940 }
Greg Claytonc3b61d22010-12-15 05:08:08 +0000941 // Break out early from the switch since we were
942 // able to find the child member
943 break;
944 }
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000945 else if (end && *end == '-')
Enrico Granata9762e102011-07-06 02:13:41 +0000946 {
947 // this is most probably a BitField, let's take a look
948 char *real_end = NULL;
949 long final_index = ::strtol (end+1, &real_end, 0);
Enrico Granata6f302872011-08-19 21:13:46 +0000950 bool expand_bitfield = true;
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000951 if (real_end && *real_end == ']')
Enrico Granata9762e102011-07-06 02:13:41 +0000952 {
953 // if the format given is [high-low], swap range
Enrico Granata4c3fb4b2011-07-19 18:03:25 +0000954 if (child_index > final_index)
Enrico Granata9762e102011-07-06 02:13:41 +0000955 {
956 long temp = child_index;
957 child_index = final_index;
958 final_index = temp;
959 }
960
961 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
962 {
963 // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
964 // and extract bits low thru high out of it. reading array items low thru high
965 // would be done by saying ptr[low-high], without a deref * sign
966 Error error;
967 ValueObjectSP temp(valobj_sp->Dereference(error));
968 if (error.Fail())
969 {
970 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
971 error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
972 valobj_sp->GetTypeName().AsCString("<invalid type>"),
973 var_expr_path_strm.GetString().c_str());
974 return ValueObjectSP();
975 }
976 valobj_sp = temp;
977 deref = false;
978 }
979 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
980 {
981 // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
982 // (an operation that is equivalent to deref-ing arr)
983 // and extract bits low thru high out of it. reading array items low thru high
984 // would be done by saying arr[low-high], without a deref * sign
985 Error error;
986 ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
987 if (error.Fail())
988 {
989 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
990 error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
991 valobj_sp->GetTypeName().AsCString("<invalid type>"),
992 var_expr_path_strm.GetString().c_str());
993 return ValueObjectSP();
994 }
995 valobj_sp = temp;
996 deref = false;
997 }
Enrico Granata6f302872011-08-19 21:13:46 +0000998 /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
Enrico Granata9762e102011-07-06 02:13:41 +0000999 {
Enrico Granata6f302872011-08-19 21:13:46 +00001000 child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
1001 expand_bitfield = false;
1002 if (!child_valobj_sp)
1003 {
1004 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1005 error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1006 child_index, final_index,
1007 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1008 var_expr_path_strm.GetString().c_str());
1009 }
1010 }*/
1011
1012 if (expand_bitfield)
1013 {
1014 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1015 if (!child_valobj_sp)
1016 {
1017 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Jason Molenda95b7b432011-09-20 00:26:08 +00001018 error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
Enrico Granata6f302872011-08-19 21:13:46 +00001019 child_index, final_index,
1020 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1021 var_expr_path_strm.GetString().c_str());
1022 }
Enrico Granata9762e102011-07-06 02:13:41 +00001023 }
1024 }
1025
1026 if (!child_valobj_sp)
1027 {
1028 // Invalid bitfield range...
1029 return ValueObjectSP();
1030 }
1031
1032 // Erase the bitfield member specification '[%i-%i]' where
1033 // %i is the index
1034 var_path.erase(0, (real_end - var_path.c_str()) + 1);
1035 separator_idx = var_path.find_first_of(".-[");
Greg Clayton987c7eb2011-09-17 08:33:22 +00001036 if (use_dynamic != eNoDynamicValues)
Enrico Granata9762e102011-07-06 02:13:41 +00001037 {
1038 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
1039 if (dynamic_value_sp)
1040 child_valobj_sp = dynamic_value_sp;
1041 }
1042 // Break out early from the switch since we were
1043 // able to find the child member
1044 break;
1045
1046 }
1047 }
1048 else
1049 {
1050 error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
1051 var_expr_path_strm.GetString().c_str(),
1052 var_path.c_str());
Greg Claytonc3b61d22010-12-15 05:08:08 +00001053 }
1054 return ValueObjectSP();
1055
1056 default:
1057 // Failure...
1058 {
Greg Claytonb01000f2011-01-17 03:46:26 +00001059 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001060 error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
1061 separator_type,
1062 var_expr_path_strm.GetString().c_str(),
1063 var_path.c_str());
1064
1065 return ValueObjectSP();
Greg Clayton427f2902010-12-14 02:59:59 +00001066 }
1067 }
Greg Clayton427f2902010-12-14 02:59:59 +00001068
Greg Claytonc3b61d22010-12-15 05:08:08 +00001069 if (child_valobj_sp)
1070 valobj_sp = child_valobj_sp;
1071
1072 if (var_path.empty())
1073 break;
1074
Greg Clayton427f2902010-12-14 02:59:59 +00001075 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001076 if (valobj_sp)
1077 {
1078 if (deref)
1079 {
Greg Claytonbdcda462010-12-20 20:49:23 +00001080 ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
Greg Claytonc3b61d22010-12-15 05:08:08 +00001081 valobj_sp = deref_valobj_sp;
1082 }
1083 else if (address_of)
1084 {
1085 ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1086 valobj_sp = address_of_valobj_sp;
1087 }
1088 }
1089 return valobj_sp;
Greg Clayton427f2902010-12-14 02:59:59 +00001090 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001091 else
Greg Clayton427f2902010-12-14 02:59:59 +00001092 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001093 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1094 name_const_string.GetCString());
Greg Clayton427f2902010-12-14 02:59:59 +00001095 }
Greg Clayton427f2902010-12-14 02:59:59 +00001096 }
1097 }
Greg Claytonc3b61d22010-12-15 05:08:08 +00001098 else
1099 {
1100 error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1101 }
Greg Clayton427f2902010-12-14 02:59:59 +00001102 return ValueObjectSP();
1103}
Chris Lattner24943d22010-06-08 16:52:24 +00001104
1105bool
1106StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1107{
1108 if (m_flags.IsClear(GOT_FRAME_BASE))
1109 {
1110 if (m_sc.function)
1111 {
1112 m_frame_base.Clear();
1113 m_frame_base_error.Clear();
1114
1115 m_flags.Set(GOT_FRAME_BASE);
Greg Clayton289afcb2012-02-18 05:35:26 +00001116 ExecutionContext exe_ctx (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001117 Value expr_value;
Greg Clayton178710c2010-09-14 02:20:48 +00001118 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1119 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
Greg Clayton289afcb2012-02-18 05:35:26 +00001120 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
Greg Clayton178710c2010-09-14 02:20:48 +00001121
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001122 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 +00001123 {
1124 // We should really have an error if evaluate returns, but in case
1125 // we don't, lets set the error to something at least.
1126 if (m_frame_base_error.Success())
1127 m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1128 }
1129 else
1130 {
1131 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
1132 }
1133 }
1134 else
1135 {
1136 m_frame_base_error.SetErrorString ("No function in symbol context.");
1137 }
1138 }
1139
1140 if (m_frame_base_error.Success())
1141 frame_base = m_frame_base;
1142
1143 if (error_ptr)
1144 *error_ptr = m_frame_base_error;
1145 return m_frame_base_error.Success();
1146}
1147
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001148RegisterContextSP
Chris Lattner24943d22010-06-08 16:52:24 +00001149StackFrame::GetRegisterContext ()
1150{
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001151 if (!m_reg_context_sp)
Greg Clayton289afcb2012-02-18 05:35:26 +00001152 {
1153 ThreadSP thread_sp (GetThread());
1154 if (thread_sp)
1155 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1156 }
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001157 return m_reg_context_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001158}
1159
1160bool
1161StackFrame::HasDebugInformation ()
1162{
Greg Claytonb04e7a82010-08-24 21:05:24 +00001163 GetSymbolContext (eSymbolContextLineEntry);
Chris Lattner24943d22010-06-08 16:52:24 +00001164 return m_sc.line_entry.IsValid();
1165}
1166
Greg Clayton17dae082010-09-02 02:59:18 +00001167
1168ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001169StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Chris Lattner24943d22010-06-08 16:52:24 +00001170{
Greg Clayton17dae082010-09-02 02:59:18 +00001171 ValueObjectSP valobj_sp;
1172 VariableList *var_list = GetVariableList (true);
1173 if (var_list)
1174 {
1175 // Make sure the variable is a frame variable
1176 const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1177 const uint32_t num_variables = var_list->GetSize();
1178 if (var_idx < num_variables)
1179 {
1180 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1181 if (valobj_sp.get() == NULL)
1182 {
1183 if (m_variable_list_value_objects.GetSize() < num_variables)
1184 m_variable_list_value_objects.Resize(num_variables);
Jim Ingham47da8102011-04-22 23:53:53 +00001185 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
Greg Clayton17dae082010-09-02 02:59:18 +00001186 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1187 }
1188 }
1189 }
Greg Clayton987c7eb2011-09-17 08:33:22 +00001190 if (use_dynamic != eNoDynamicValues && valobj_sp)
Jim Inghame41494a2011-04-16 00:01:13 +00001191 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001192 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001193 if (dynamic_sp)
1194 return dynamic_sp;
1195 }
Greg Clayton17dae082010-09-02 02:59:18 +00001196 return valobj_sp;
1197}
1198
1199ValueObjectSP
Greg Clayton987c7eb2011-09-17 08:33:22 +00001200StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
Greg Clayton17dae082010-09-02 02:59:18 +00001201{
1202 // Check to make sure we aren't already tracking this variable?
Jim Inghame41494a2011-04-16 00:01:13 +00001203 ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
Greg Clayton17dae082010-09-02 02:59:18 +00001204 if (!valobj_sp)
1205 {
1206 // We aren't already tracking this global
1207 VariableList *var_list = GetVariableList (true);
1208 // If this frame has no variables, create a new list
1209 if (var_list == NULL)
1210 m_variable_list_sp.reset (new VariableList());
1211
1212 // Add the global/static variable to this frame
1213 m_variable_list_sp->AddVariable (variable_sp);
1214
1215 // Now make a value object for it so we can track its changes
Jim Inghame41494a2011-04-16 00:01:13 +00001216 valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
Greg Clayton17dae082010-09-02 02:59:18 +00001217 }
1218 return valobj_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001219}
1220
Jim Ingham2154da42010-08-26 20:44:45 +00001221bool
1222StackFrame::IsInlined ()
1223{
Greg Clayton4fb08152010-08-30 18:11:35 +00001224 if (m_sc.block == NULL)
1225 GetSymbolContext (eSymbolContextBlock);
1226 if (m_sc.block)
1227 return m_sc.block->GetContainingInlinedBlock() != NULL;
1228 return false;
Jim Ingham2154da42010-08-26 20:44:45 +00001229}
1230
Greg Clayton289afcb2012-02-18 05:35:26 +00001231TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001232StackFrame::CalculateTarget ()
1233{
Greg Clayton289afcb2012-02-18 05:35:26 +00001234 TargetSP target_sp;
1235 ThreadSP thread_sp(GetThread());
1236 if (thread_sp)
1237 {
1238 ProcessSP process_sp (thread_sp->CalculateProcess());
1239 if (process_sp)
1240 target_sp = process_sp->CalculateTarget();
1241 }
1242 return target_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001243}
1244
Greg Clayton289afcb2012-02-18 05:35:26 +00001245ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001246StackFrame::CalculateProcess ()
1247{
Greg Clayton289afcb2012-02-18 05:35:26 +00001248 ProcessSP process_sp;
1249 ThreadSP thread_sp(GetThread());
1250 if (thread_sp)
1251 process_sp = thread_sp->CalculateProcess();
1252 return process_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001253}
1254
Greg Clayton289afcb2012-02-18 05:35:26 +00001255ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001256StackFrame::CalculateThread ()
1257{
Greg Clayton289afcb2012-02-18 05:35:26 +00001258 return GetThread();
Chris Lattner24943d22010-06-08 16:52:24 +00001259}
1260
Greg Clayton289afcb2012-02-18 05:35:26 +00001261StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001262StackFrame::CalculateStackFrame ()
1263{
Greg Clayton289afcb2012-02-18 05:35:26 +00001264 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001265}
1266
1267
1268void
Greg Claytona830adb2010-10-04 01:05:56 +00001269StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001270{
Greg Clayton289afcb2012-02-18 05:35:26 +00001271 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001272}
1273
1274void
Greg Claytona830adb2010-10-04 01:05:56 +00001275StackFrame::DumpUsingSettingsFormat (Stream *strm)
1276{
1277 if (strm == NULL)
1278 return;
1279
1280 GetSymbolContext(eSymbolContextEverything);
Greg Clayton289afcb2012-02-18 05:35:26 +00001281 ExecutionContext exe_ctx (shared_from_this());
Greg Claytona830adb2010-10-04 01:05:56 +00001282 const char *end = NULL;
1283 StreamString s;
Greg Clayton289afcb2012-02-18 05:35:26 +00001284 const char *frame_format = NULL;
1285 Target *target = exe_ctx.GetTargetPtr();
1286 if (target)
1287 frame_format = target->GetDebugger().GetFrameFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001288 if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1289 {
1290 strm->Write(s.GetData(), s.GetSize());
1291 }
1292 else
1293 {
1294 Dump (strm, true, false);
1295 strm->EOL();
1296 }
1297}
1298
1299void
Greg Clayton72b71582010-09-02 21:44:10 +00001300StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
Chris Lattner24943d22010-06-08 16:52:24 +00001301{
1302 if (strm == NULL)
1303 return;
1304
1305 if (show_frame_index)
Greg Clayton33ed1702010-08-24 00:45:41 +00001306 strm->Printf("frame #%u: ", m_frame_index);
Greg Clayton289afcb2012-02-18 05:35:26 +00001307 ExecutionContext exe_ctx (shared_from_this());
1308 Target *target = exe_ctx.GetTargetPtr();
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001309 strm->Printf("0x%0*" PRIx64 " ",
Greg Clayton289afcb2012-02-18 05:35:26 +00001310 target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1311 GetFrameCodeAddress().GetLoadAddress(target));
Greg Claytonb04e7a82010-08-24 21:05:24 +00001312 GetSymbolContext(eSymbolContextEverything);
Greg Clayton33ed1702010-08-24 00:45:41 +00001313 const bool show_module = true;
1314 const bool show_inline = true;
Greg Clayton289afcb2012-02-18 05:35:26 +00001315 m_sc.DumpStopContext (strm,
1316 exe_ctx.GetBestExecutionContextScope(),
1317 GetFrameCodeAddress(),
1318 show_fullpaths,
1319 show_module,
1320 show_inline);
Chris Lattner24943d22010-06-08 16:52:24 +00001321}
1322
Greg Clayton1d66ef52010-08-27 18:24:16 +00001323void
Greg Clayton4fb08152010-08-30 18:11:35 +00001324StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
Greg Clayton1d66ef52010-08-27 18:24:16 +00001325{
Greg Clayton4fb08152010-08-30 18:11:35 +00001326 assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing
1327 m_variable_list_sp = prev_frame.m_variable_list_sp;
Greg Clayton17dae082010-09-02 02:59:18 +00001328 m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
Greg Clayton870a1cd2010-08-27 21:47:54 +00001329 if (!m_disassembly.GetString().empty())
1330 m_disassembly.GetString().swap (m_disassembly.GetString());
Greg Clayton1d66ef52010-08-27 18:24:16 +00001331}
Greg Clayton870a1cd2010-08-27 21:47:54 +00001332
1333
Greg Clayton4fb08152010-08-30 18:11:35 +00001334void
1335StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1336{
Greg Clayton5205f0b2010-09-03 17:10:42 +00001337 assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing
1338 m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value
Greg Clayton289afcb2012-02-18 05:35:26 +00001339 assert (GetThread() == curr_frame.GetThread());
Greg Clayton4fb08152010-08-30 18:11:35 +00001340 m_frame_index = curr_frame.m_frame_index;
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001341 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
Greg Clayton4fb08152010-08-30 18:11:35 +00001342 m_reg_context_sp = curr_frame.m_reg_context_sp;
1343 m_frame_code_addr = curr_frame.m_frame_code_addr;
1344 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());
1345 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());
1346 assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1347 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 +00001348 m_sc = curr_frame.m_sc;
1349 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1350 m_flags.Set (m_sc.GetResolvedMask());
1351 m_frame_base.Clear();
1352 m_frame_base_error.Clear();
1353}
1354
1355
Greg Clayton5205f0b2010-09-03 17:10:42 +00001356bool
1357StackFrame::HasCachedData () const
1358{
1359 if (m_variable_list_sp.get())
1360 return true;
1361 if (m_variable_list_value_objects.GetSize() > 0)
1362 return true;
1363 if (!m_disassembly.GetString().empty())
1364 return true;
1365 return false;
Jim Inghamccd584d2010-09-23 17:40:12 +00001366}
1367
Greg Claytonabe0fed2011-04-18 08:33:37 +00001368bool
1369StackFrame::GetStatus (Stream& strm,
1370 bool show_frame_info,
Greg Claytona7d3dc72012-07-11 20:33:48 +00001371 bool show_source)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001372{
Greg Claytona7d3dc72012-07-11 20:33:48 +00001373
Greg Claytonabe0fed2011-04-18 08:33:37 +00001374 if (show_frame_info)
1375 {
1376 strm.Indent();
1377 DumpUsingSettingsFormat (&strm);
1378 }
1379
1380 if (show_source)
1381 {
Greg Clayton289afcb2012-02-18 05:35:26 +00001382 ExecutionContext exe_ctx (shared_from_this());
Greg Claytonbe9875d2011-11-21 21:44:34 +00001383 bool have_source = false;
Greg Clayton73844aa2012-08-22 17:17:09 +00001384 Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
Greg Clayton289afcb2012-02-18 05:35:26 +00001385 Target *target = exe_ctx.GetTargetPtr();
Greg Claytona7d3dc72012-07-11 20:33:48 +00001386 if (target)
Greg Claytonabe0fed2011-04-18 08:33:37 +00001387 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001388 Debugger &debugger = target->GetDebugger();
1389 const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
1390 const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
1391 disasm_display = debugger.GetStopDisassemblyDisplay ();
Greg Claytonbe9875d2011-11-21 21:44:34 +00001392
Greg Claytona7d3dc72012-07-11 20:33:48 +00001393 if (source_lines_before > 0 || source_lines_after > 0)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001394 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001395 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1396
1397 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
Greg Claytonbe9875d2011-11-21 21:44:34 +00001398 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001399 if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
1400 m_sc.line_entry.line,
1401 source_lines_before,
1402 source_lines_after,
1403 "->",
1404 &strm))
1405 {
1406 have_source = true;
1407 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001408 }
1409 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001410 switch (disasm_display)
1411 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001412 case Debugger::eStopDisassemblyTypeNever:
Greg Claytonbe9875d2011-11-21 21:44:34 +00001413 break;
Greg Claytona7d3dc72012-07-11 20:33:48 +00001414
Greg Clayton73844aa2012-08-22 17:17:09 +00001415 case Debugger::eStopDisassemblyTypeNoSource:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001416 if (have_source)
1417 break;
1418 // Fall through to next case
Greg Clayton73844aa2012-08-22 17:17:09 +00001419 case Debugger::eStopDisassemblyTypeAlways:
Greg Claytona7d3dc72012-07-11 20:33:48 +00001420 if (target)
Greg Claytonbe9875d2011-11-21 21:44:34 +00001421 {
Greg Claytona7d3dc72012-07-11 20:33:48 +00001422 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1423 if (disasm_lines > 0)
1424 {
1425 const ArchSpec &target_arch = target->GetArchitecture();
1426 AddressRange pc_range;
1427 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1428 pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1429 Disassembler::Disassemble (target->GetDebugger(),
1430 target_arch,
1431 NULL,
1432 exe_ctx,
1433 pc_range,
1434 disasm_lines,
1435 0,
1436 Disassembler::eOptionMarkPCAddress,
1437 strm);
1438 }
Greg Claytonbe9875d2011-11-21 21:44:34 +00001439 }
Greg Claytona7d3dc72012-07-11 20:33:48 +00001440 break;
Greg Claytonbe9875d2011-11-21 21:44:34 +00001441 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001442 }
1443 }
1444 return true;
1445}
1446