1 //===-- StackFrame.cpp ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Target/StackFrame.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/Debugger.h"
18 #include "lldb/Core/Disassembler.h"
19 #include "lldb/Core/Value.h"
20 #include "lldb/Core/ValueObjectVariable.h"
21 #include "lldb/Core/ValueObjectConstResult.h"
22 #include "lldb/Symbol/Function.h"
23 #include "lldb/Symbol/VariableList.h"
24 #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 
30 using namespace lldb;
31 using 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.
36 #define RESOLVED_FRAME_CODE_ADDR        (uint32_t(eSymbolContextEverything + 1))
37 #define RESOLVED_FRAME_ID_SYMBOL_SCOPE  (RESOLVED_FRAME_CODE_ADDR << 1)
38 #define GOT_FRAME_BASE                  (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
39 #define RESOLVED_VARIABLES              (GOT_FRAME_BASE << 1)
40 #define RESOLVED_GLOBAL_VARIABLES       (RESOLVED_VARIABLES << 1)
41 
42 StackFrame::StackFrame (const ThreadSP &thread_sp,
43                         user_id_t frame_idx,
44                         user_id_t unwind_frame_index,
45                         addr_t cfa,
46                         addr_t pc,
47                         const SymbolContext *sc_ptr) :
48     m_thread_wp (thread_sp),
49     m_frame_index (frame_idx),
50     m_concrete_frame_index (unwind_frame_index),
51     m_reg_context_sp (),
52     m_id (pc, cfa, NULL),
53     m_frame_code_addr (pc),
54     m_sc (),
55     m_flags (),
56     m_frame_base (),
57     m_frame_base_error (),
58     m_variable_list_sp (),
59     m_variable_list_value_objects (),
60     m_disassembly ()
61 {
62     if (sc_ptr != NULL)
63     {
64         m_sc = *sc_ptr;
65         m_flags.Set(m_sc.GetResolvedMask ());
66     }
67 }
68 
69 StackFrame::StackFrame (const ThreadSP &thread_sp,
70                         user_id_t frame_idx,
71                         user_id_t unwind_frame_index,
72                         const RegisterContextSP &reg_context_sp,
73                         addr_t cfa,
74                         addr_t pc,
75                         const SymbolContext *sc_ptr) :
76     m_thread_wp (thread_sp),
77     m_frame_index (frame_idx),
78     m_concrete_frame_index (unwind_frame_index),
79     m_reg_context_sp (reg_context_sp),
80     m_id (pc, cfa, NULL),
81     m_frame_code_addr (pc),
82     m_sc (),
83     m_flags (),
84     m_frame_base (),
85     m_frame_base_error (),
86     m_variable_list_sp (),
87     m_variable_list_value_objects (),
88     m_disassembly ()
89 {
90     if (sc_ptr != NULL)
91     {
92         m_sc = *sc_ptr;
93         m_flags.Set(m_sc.GetResolvedMask ());
94     }
95 
96     if (reg_context_sp && !m_sc.target_sp)
97     {
98         m_sc.target_sp = reg_context_sp->CalculateTarget();
99         if (m_sc.target_sp)
100             m_flags.Set (eSymbolContextTarget);
101     }
102 }
103 
104 StackFrame::StackFrame (const ThreadSP &thread_sp,
105                         user_id_t frame_idx,
106                         user_id_t unwind_frame_index,
107                         const RegisterContextSP &reg_context_sp,
108                         addr_t cfa,
109                         const Address& pc_addr,
110                         const SymbolContext *sc_ptr) :
111     m_thread_wp (thread_sp),
112     m_frame_index (frame_idx),
113     m_concrete_frame_index (unwind_frame_index),
114     m_reg_context_sp (reg_context_sp),
115     m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
116     m_frame_code_addr (pc_addr),
117     m_sc (),
118     m_flags (),
119     m_frame_base (),
120     m_frame_base_error (),
121     m_variable_list_sp (),
122     m_variable_list_value_objects (),
123     m_disassembly ()
124 {
125     if (sc_ptr != NULL)
126     {
127         m_sc = *sc_ptr;
128         m_flags.Set(m_sc.GetResolvedMask ());
129     }
130 
131     if (m_sc.target_sp.get() == NULL && reg_context_sp)
132     {
133         m_sc.target_sp = reg_context_sp->CalculateTarget();
134         if (m_sc.target_sp)
135             m_flags.Set (eSymbolContextTarget);
136     }
137 
138     ModuleSP pc_module_sp (pc_addr.GetModule());
139     if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
140     {
141         if (pc_module_sp)
142         {
143             m_sc.module_sp = pc_module_sp;
144             m_flags.Set (eSymbolContextModule);
145         }
146         else
147         {
148             m_sc.module_sp.reset();
149         }
150     }
151 }
152 
153 
154 //----------------------------------------------------------------------
155 // Destructor
156 //----------------------------------------------------------------------
157 StackFrame::~StackFrame()
158 {
159 }
160 
161 StackID&
162 StackFrame::GetStackID()
163 {
164     // Make sure we have resolved the StackID object's symbol context scope if
165     // we already haven't looked it up.
166 
167     if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
168     {
169         if (m_id.GetSymbolContextScope ())
170         {
171             // We already have a symbol context scope, we just don't have our
172             // flag bit set.
173             m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
174         }
175         else
176         {
177             // Calculate the frame block and use this for the stack ID symbol
178             // context scope if we have one.
179             SymbolContextScope *scope = GetFrameBlock ();
180             if (scope == NULL)
181             {
182                 // We don't have a block, so use the symbol
183                 if (m_flags.IsClear (eSymbolContextSymbol))
184                     GetSymbolContext (eSymbolContextSymbol);
185 
186                 // It is ok if m_sc.symbol is NULL here
187                 scope = m_sc.symbol;
188             }
189             // Set the symbol context scope (the accessor will set the
190             // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
191             SetSymbolContextScope (scope);
192         }
193     }
194     return m_id;
195 }
196 
197 void
198 StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
199 {
200     m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
201     m_id.SetSymbolContextScope (symbol_scope);
202 }
203 
204 const Address&
205 StackFrame::GetFrameCodeAddress()
206 {
207     if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
208     {
209         m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
210 
211         // Resolve the PC into a temporary address because if ResolveLoadAddress
212         // fails to resolve the address, it will clear the address object...
213         ThreadSP thread_sp (GetThread());
214         if (thread_sp)
215         {
216             TargetSP target_sp (thread_sp->CalculateTarget());
217             if (target_sp)
218             {
219                 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
220                 {
221                     ModuleSP module_sp (m_frame_code_addr.GetModule());
222                     if (module_sp)
223                     {
224                         m_sc.module_sp = module_sp;
225                         m_flags.Set(eSymbolContextModule);
226                     }
227                 }
228             }
229         }
230     }
231     return m_frame_code_addr;
232 }
233 
234 void
235 StackFrame::ChangePC (addr_t pc)
236 {
237     m_frame_code_addr.SetRawAddress(pc);
238     m_sc.Clear();
239     m_flags.Reset(0);
240     ThreadSP thread_sp (GetThread());
241     if (thread_sp)
242         thread_sp->ClearStackFrames ();
243 }
244 
245 const char *
246 StackFrame::Disassemble ()
247 {
248     if (m_disassembly.GetSize() == 0)
249     {
250         ExecutionContext exe_ctx (shared_from_this());
251         Target *target = exe_ctx.GetTargetPtr();
252         if (target)
253         {
254             Disassembler::Disassemble (target->GetDebugger(),
255                                        target->GetArchitecture(),
256                                        NULL,
257                                        exe_ctx,
258                                        0,
259                                        0,
260                                        0,
261                                        m_disassembly);
262         }
263         if (m_disassembly.GetSize() == 0)
264             return NULL;
265     }
266     return m_disassembly.GetData();
267 }
268 
269 Block *
270 StackFrame::GetFrameBlock ()
271 {
272     if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
273         GetSymbolContext (eSymbolContextBlock);
274 
275     if (m_sc.block)
276     {
277         Block *inline_block = m_sc.block->GetContainingInlinedBlock();
278         if (inline_block)
279         {
280             // Use the block with the inlined function info
281             // as the frame block we want this frame to have only the variables
282             // for the inlined function and its non-inlined block child blocks.
283             return inline_block;
284         }
285         else
286         {
287             // This block is not contained withing any inlined function blocks
288             // with so we want to use the top most function block.
289             return &m_sc.function->GetBlock (false);
290         }
291     }
292     return NULL;
293 }
294 
295 //----------------------------------------------------------------------
296 // Get the symbol context if we already haven't done so by resolving the
297 // PC address as much as possible. This way when we pass around a
298 // StackFrame object, everyone will have as much information as
299 // possible and no one will ever have to look things up manually.
300 //----------------------------------------------------------------------
301 const SymbolContext&
302 StackFrame::GetSymbolContext (uint32_t resolve_scope)
303 {
304     // Copy our internal symbol context into "sc".
305     if ((m_flags.Get() & resolve_scope) != resolve_scope)
306     {
307         // Resolve our PC to section offset if we haven't alreday done so
308         // and if we don't have a module. The resolved address section will
309         // contain the module to which it belongs
310         if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
311             GetFrameCodeAddress();
312 
313         // If this is not frame zero, then we need to subtract 1 from the PC
314         // value when doing address lookups since the PC will be on the
315         // instruction following the function call instruction...
316 
317         Address lookup_addr(GetFrameCodeAddress());
318         if (m_frame_index > 0 && lookup_addr.IsValid())
319         {
320             addr_t offset = lookup_addr.GetOffset();
321             if (offset > 0)
322                 lookup_addr.SetOffset(offset - 1);
323         }
324 
325 
326         uint32_t resolved = 0;
327         if (m_sc.module_sp)
328         {
329             // We have something in our stack frame symbol context, lets check
330             // if we haven't already tried to lookup one of those things. If we
331             // haven't then we will do the query.
332 
333             uint32_t actual_resolve_scope = 0;
334 
335             if (resolve_scope & eSymbolContextCompUnit)
336             {
337                 if (m_flags.IsClear (eSymbolContextCompUnit))
338                 {
339                     if (m_sc.comp_unit)
340                         resolved |= eSymbolContextCompUnit;
341                     else
342                         actual_resolve_scope |= eSymbolContextCompUnit;
343                 }
344             }
345 
346             if (resolve_scope & eSymbolContextFunction)
347             {
348                 if (m_flags.IsClear (eSymbolContextFunction))
349                 {
350                     if (m_sc.function)
351                         resolved |= eSymbolContextFunction;
352                     else
353                         actual_resolve_scope |= eSymbolContextFunction;
354                 }
355             }
356 
357             if (resolve_scope & eSymbolContextBlock)
358             {
359                 if (m_flags.IsClear (eSymbolContextBlock))
360                 {
361                     if (m_sc.block)
362                         resolved |= eSymbolContextBlock;
363                     else
364                         actual_resolve_scope |= eSymbolContextBlock;
365                 }
366             }
367 
368             if (resolve_scope & eSymbolContextSymbol)
369             {
370                 if (m_flags.IsClear (eSymbolContextSymbol))
371                 {
372                     if (m_sc.symbol)
373                         resolved |= eSymbolContextSymbol;
374                     else
375                         actual_resolve_scope |= eSymbolContextSymbol;
376                 }
377             }
378 
379             if (resolve_scope & eSymbolContextLineEntry)
380             {
381                 if (m_flags.IsClear (eSymbolContextLineEntry))
382                 {
383                     if (m_sc.line_entry.IsValid())
384                         resolved |= eSymbolContextLineEntry;
385                     else
386                         actual_resolve_scope |= eSymbolContextLineEntry;
387                 }
388             }
389 
390             if (actual_resolve_scope)
391             {
392                 // We might be resolving less information than what is already
393                 // in our current symbol context so resolve into a temporary
394                 // symbol context "sc" so we don't clear out data we have
395                 // already found in "m_sc"
396                 SymbolContext sc;
397                 // Set flags that indicate what we have tried to resolve
398                 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
399                 // Only replace what we didn't already have as we may have
400                 // information for an inlined function scope that won't match
401                 // what a standard lookup by address would match
402                 if ((resolved & eSymbolContextCompUnit)  && m_sc.comp_unit == NULL)
403                     m_sc.comp_unit = sc.comp_unit;
404                 if ((resolved & eSymbolContextFunction)  && m_sc.function == NULL)
405                     m_sc.function = sc.function;
406                 if ((resolved & eSymbolContextBlock)     && m_sc.block == NULL)
407                     m_sc.block = sc.block;
408                 if ((resolved & eSymbolContextSymbol)    && m_sc.symbol == NULL)
409                     m_sc.symbol = sc.symbol;
410                 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
411                     m_sc.line_entry = sc.line_entry;
412 
413             }
414         }
415         else
416         {
417             // If we don't have a module, then we can't have the compile unit,
418             // function, block, line entry or symbol, so we can safely call
419             // ResolveSymbolContextForAddress with our symbol context member m_sc.
420             TargetSP target_sp (CalculateTarget());
421             if (target_sp)
422                 resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
423         }
424 
425         // If the target was requested add that:
426         if (!m_sc.target_sp)
427         {
428             m_sc.target_sp = CalculateTarget();
429             if (m_sc.target_sp)
430                 resolved |= eSymbolContextTarget;
431         }
432 
433         // Update our internal flags so we remember what we have tried to locate so
434         // we don't have to keep trying when more calls to this function are made.
435         // We might have dug up more information that was requested (for example
436         // if we were asked to only get the block, we will have gotten the
437         // compile unit, and function) so set any additional bits that we resolved
438         m_flags.Set (resolve_scope | resolved);
439     }
440 
441     // Return the symbol context with everything that was possible to resolve
442     // resolved.
443     return m_sc;
444 }
445 
446 
447 VariableList *
448 StackFrame::GetVariableList (bool get_file_globals)
449 {
450     if (m_flags.IsClear(RESOLVED_VARIABLES))
451     {
452         m_flags.Set(RESOLVED_VARIABLES);
453 
454         Block *frame_block = GetFrameBlock();
455 
456         if (frame_block)
457         {
458             const bool get_child_variables = true;
459             const bool can_create = true;
460             const bool stop_if_child_block_is_inlined_function = true;
461             m_variable_list_sp.reset(new VariableList());
462             frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
463         }
464     }
465 
466     if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
467         get_file_globals)
468     {
469         m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
470 
471         if (m_flags.IsClear (eSymbolContextCompUnit))
472             GetSymbolContext (eSymbolContextCompUnit);
473 
474         if (m_sc.comp_unit)
475         {
476             VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
477             if (m_variable_list_sp)
478                 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
479             else
480                 m_variable_list_sp = global_variable_list_sp;
481         }
482     }
483 
484     return m_variable_list_sp.get();
485 }
486 
487 VariableListSP
488 StackFrame::GetInScopeVariableList (bool get_file_globals)
489 {
490     VariableListSP var_list_sp(new VariableList);
491     GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
492 
493     if (m_sc.block)
494     {
495         const bool can_create = true;
496         const bool get_parent_variables = true;
497         const bool stop_if_block_is_inlined_function = true;
498         m_sc.block->AppendVariables (can_create,
499                                      get_parent_variables,
500                                      stop_if_block_is_inlined_function,
501                                      var_list_sp.get());
502     }
503 
504     if (m_sc.comp_unit)
505     {
506         VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
507         if (global_variable_list_sp)
508             var_list_sp->AddVariables (global_variable_list_sp.get());
509     }
510 
511     return var_list_sp;
512 }
513 
514 
515 ValueObjectSP
516 StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
517                                                DynamicValueType use_dynamic,
518                                                uint32_t options,
519                                                VariableSP &var_sp,
520                                                Error &error)
521 {
522 
523     if (var_expr_cstr && var_expr_cstr[0])
524     {
525         const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
526         const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
527         const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
528         //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
529         error.Clear();
530         bool deref = false;
531         bool address_of = false;
532         ValueObjectSP valobj_sp;
533         const bool get_file_globals = true;
534         // When looking up a variable for an expression, we need only consider the
535         // variables that are in scope.
536         VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
537         VariableList *variable_list = var_list_sp.get();
538 
539         if (variable_list)
540         {
541             // If first character is a '*', then show pointer contents
542             const char *var_expr = var_expr_cstr;
543             if (var_expr[0] == '*')
544             {
545                 deref = true;
546                 var_expr++; // Skip the '*'
547             }
548             else if (var_expr[0] == '&')
549             {
550                 address_of = true;
551                 var_expr++; // Skip the '&'
552             }
553 
554             std::string var_path (var_expr);
555             size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
556             StreamString var_expr_path_strm;
557 
558             ConstString name_const_string;
559             if (separator_idx == std::string::npos)
560                 name_const_string.SetCString (var_path.c_str());
561             else
562                 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
563 
564             var_sp = variable_list->FindVariable(name_const_string);
565             if (var_sp)
566             {
567                 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
568                 if (!valobj_sp)
569                     return valobj_sp;
570 
571                 var_path.erase (0, name_const_string.GetLength ());
572                 // We are dumping at least one child
573                 while (separator_idx != std::string::npos)
574                 {
575                     // Calculate the next separator index ahead of time
576                     ValueObjectSP child_valobj_sp;
577                     const char separator_type = var_path[0];
578                     switch (separator_type)
579                     {
580 
581                     case '-':
582                         if (var_path.size() >= 2 && var_path[1] != '>')
583                             return ValueObjectSP();
584 
585                         if (no_fragile_ivar)
586                         {
587                             // Make sure we aren't trying to deref an objective
588                             // C ivar if this is not allowed
589                             const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
590                             if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
591                                 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
592                             {
593                                 // This was an objective C object pointer and
594                                 // it was requested we skip any fragile ivars
595                                 // so return nothing here
596                                 return ValueObjectSP();
597                             }
598                         }
599                         var_path.erase (0, 1); // Remove the '-'
600                         // Fall through
601                     case '.':
602                         {
603                             const bool expr_is_ptr = var_path[0] == '>';
604 
605                             var_path.erase (0, 1); // Remove the '.' or '>'
606                             separator_idx = var_path.find_first_of(".-[");
607                             ConstString child_name;
608                             if (separator_idx == std::string::npos)
609                                 child_name.SetCString (var_path.c_str());
610                             else
611                                 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
612 
613                             if (check_ptr_vs_member)
614                             {
615                                 // We either have a pointer type and need to verify
616                                 // valobj_sp is a pointer, or we have a member of a
617                                 // class/union/struct being accessed with the . syntax
618                                 // and need to verify we don't have a pointer.
619                                 const bool actual_is_ptr = valobj_sp->IsPointerType ();
620 
621                                 if (actual_is_ptr != expr_is_ptr)
622                                 {
623                                     // Incorrect use of "." with a pointer, or "->" with
624                                     // a class/union/struct instance or reference.
625                                     valobj_sp->GetExpressionPath (var_expr_path_strm, false);
626                                     if (actual_is_ptr)
627                                         error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
628                                                                         var_expr_path_strm.GetString().c_str(),
629                                                                         child_name.GetCString(),
630                                                                         var_expr_path_strm.GetString().c_str(),
631                                                                         var_path.c_str());
632                                     else
633                                         error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
634                                                                         var_expr_path_strm.GetString().c_str(),
635                                                                         child_name.GetCString(),
636                                                                         var_expr_path_strm.GetString().c_str(),
637                                                                         var_path.c_str());
638                                     return ValueObjectSP();
639                                 }
640                             }
641                             child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
642                             if (!child_valobj_sp)
643                             {
644                                 if (no_synth_child == false)
645                                 {
646                                     child_valobj_sp = valobj_sp->GetSyntheticValue();
647                                     if (child_valobj_sp)
648                                         child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
649                                 }
650 
651                                 if (no_synth_child || !child_valobj_sp)
652                                 {
653                                     // No child member with name "child_name"
654                                     valobj_sp->GetExpressionPath (var_expr_path_strm, false);
655                                     if (child_name)
656                                     {
657                                         error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
658                                                                         child_name.GetCString(),
659                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
660                                                                         var_expr_path_strm.GetString().c_str());
661                                     }
662                                     else
663                                     {
664                                         error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
665                                                                         var_expr_path_strm.GetString().c_str(),
666                                                                         var_expr_cstr);
667                                     }
668                                     return ValueObjectSP();
669                                 }
670                             }
671                             // Remove the child name from the path
672                             var_path.erase(0, child_name.GetLength());
673                             if (use_dynamic != eNoDynamicValues)
674                             {
675                                 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
676                                 if (dynamic_value_sp)
677                                     child_valobj_sp = dynamic_value_sp;
678                             }
679                         }
680                         break;
681 
682                     case '[':
683                         // Array member access, or treating pointer as an array
684                         if (var_path.size() > 2) // Need at least two brackets and a number
685                         {
686                             char *end = NULL;
687                             long child_index = ::strtol (&var_path[1], &end, 0);
688                             if (end && *end == ']'
689                                 && *(end-1) != '[') // this code forces an error in the case of arr[]. as bitfield[] is not a good syntax we're good to go
690                             {
691                                 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
692                                 {
693                                     // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
694                                     // and extract bit low out of it. reading array item low
695                                     // would be done by saying ptr[low], without a deref * sign
696                                     Error error;
697                                     ValueObjectSP temp(valobj_sp->Dereference(error));
698                                     if (error.Fail())
699                                     {
700                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
701                                         error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
702                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
703                                                                         var_expr_path_strm.GetString().c_str());
704                                         return ValueObjectSP();
705                                     }
706                                     valobj_sp = temp;
707                                     deref = false;
708                                 }
709                                 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
710                                 {
711                                     // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
712                                     // (an operation that is equivalent to deref-ing arr)
713                                     // and extract bit low out of it. reading array item low
714                                     // would be done by saying arr[low], without a deref * sign
715                                     Error error;
716                                     ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
717                                     if (error.Fail())
718                                     {
719                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
720                                         error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
721                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
722                                                                         var_expr_path_strm.GetString().c_str());
723                                         return ValueObjectSP();
724                                     }
725                                     valobj_sp = temp;
726                                     deref = false;
727                                 }
728 
729                                 if (valobj_sp->IsPointerType ())
730                                 {
731                                     bool is_objc_pointer = true;
732 
733                                     if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
734                                         is_objc_pointer = false;
735                                     else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
736                                         is_objc_pointer = false;
737 
738                                     if (no_synth_child && is_objc_pointer)
739                                     {
740                                         error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
741                                                                        valobj_sp->GetTypeName().AsCString("<invalid type>"),
742                                                                        var_expr_path_strm.GetString().c_str());
743 
744                                         return ValueObjectSP();
745                                     }
746                                     else if (is_objc_pointer)
747                                     {
748                                         // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
749                                         ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
750                                         if (synthetic.get() == NULL /* no synthetic */
751                                             || synthetic == valobj_sp) /* synthetic is the same as the original object */
752                                         {
753                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
754                                             error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
755                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
756                                                                             var_expr_path_strm.GetString().c_str());
757                                         }
758                                         else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
759                                         {
760                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
761                                             error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
762                                                                             child_index,
763                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
764                                                                             var_expr_path_strm.GetString().c_str());
765                                         }
766                                         else
767                                         {
768                                             child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
769                                             if (!child_valobj_sp)
770                                             {
771                                                 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
772                                                 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
773                                                                                 child_index,
774                                                                                 valobj_sp->GetTypeName().AsCString("<invalid type>"),
775                                                                                 var_expr_path_strm.GetString().c_str());
776                                             }
777                                         }
778                                     }
779                                     else
780                                     {
781                                         child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
782                                         if (!child_valobj_sp)
783                                         {
784                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
785                                             error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
786                                                                             child_index,
787                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
788                                                                             var_expr_path_strm.GetString().c_str());
789                                         }
790                                     }
791                                 }
792                                 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL))
793                                 {
794                                     // Pass false to dynamic_value here so we can tell the difference between
795                                     // no dynamic value and no member of this type...
796                                     child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
797                                     if (!child_valobj_sp)
798                                     {
799                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
800                                         error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
801                                                                         child_index,
802                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
803                                                                         var_expr_path_strm.GetString().c_str());
804                                     }
805                                 }
806                                 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
807                                 {
808                                     // this is a bitfield asking to display just one bit
809                                     child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
810                                     if (!child_valobj_sp)
811                                     {
812                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
813                                         error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
814                                                                         child_index, child_index,
815                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
816                                                                         var_expr_path_strm.GetString().c_str());
817                                     }
818                                 }
819                                 else
820                                 {
821                                     ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
822                                     if (no_synth_child /* synthetic is forbidden */ ||
823                                         synthetic.get() == NULL /* no synthetic */
824                                         || synthetic == valobj_sp) /* synthetic is the same as the original object */
825                                     {
826                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
827                                         error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
828                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
829                                                                         var_expr_path_strm.GetString().c_str());
830                                     }
831                                     else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
832                                     {
833                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
834                                         error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
835                                                                         child_index,
836                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
837                                                                         var_expr_path_strm.GetString().c_str());
838                                     }
839                                     else
840                                     {
841                                         child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
842                                         if (!child_valobj_sp)
843                                         {
844                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
845                                             error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
846                                                                             child_index,
847                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
848                                                                             var_expr_path_strm.GetString().c_str());
849                                         }
850                                     }
851                                 }
852 
853                                 if (!child_valobj_sp)
854                                 {
855                                     // Invalid array index...
856                                     return ValueObjectSP();
857                                 }
858 
859                                 // Erase the array member specification '[%i]' where
860                                 // %i is the array index
861                                 var_path.erase(0, (end - var_path.c_str()) + 1);
862                                 separator_idx = var_path.find_first_of(".-[");
863                                 if (use_dynamic != eNoDynamicValues)
864                                 {
865                                     ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
866                                     if (dynamic_value_sp)
867                                         child_valobj_sp = dynamic_value_sp;
868                                 }
869                                 // Break out early from the switch since we were
870                                 // able to find the child member
871                                 break;
872                             }
873                             else if (end && *end == '-')
874                             {
875                                 // this is most probably a BitField, let's take a look
876                                 char *real_end = NULL;
877                                 long final_index = ::strtol (end+1, &real_end, 0);
878                                 bool expand_bitfield = true;
879                                 if (real_end && *real_end == ']')
880                                 {
881                                     // if the format given is [high-low], swap range
882                                     if (child_index > final_index)
883                                     {
884                                         long temp = child_index;
885                                         child_index = final_index;
886                                         final_index = temp;
887                                     }
888 
889                                     if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
890                                     {
891                                         // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
892                                         // and extract bits low thru high out of it. reading array items low thru high
893                                         // would be done by saying ptr[low-high], without a deref * sign
894                                         Error error;
895                                         ValueObjectSP temp(valobj_sp->Dereference(error));
896                                         if (error.Fail())
897                                         {
898                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
899                                             error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
900                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
901                                                                             var_expr_path_strm.GetString().c_str());
902                                             return ValueObjectSP();
903                                         }
904                                         valobj_sp = temp;
905                                         deref = false;
906                                     }
907                                     else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
908                                     {
909                                         // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
910                                         // (an operation that is equivalent to deref-ing arr)
911                                         // and extract bits low thru high out of it. reading array items low thru high
912                                         // would be done by saying arr[low-high], without a deref * sign
913                                         Error error;
914                                         ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
915                                         if (error.Fail())
916                                         {
917                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
918                                             error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
919                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
920                                                                             var_expr_path_strm.GetString().c_str());
921                                             return ValueObjectSP();
922                                         }
923                                         valobj_sp = temp;
924                                         deref = false;
925                                     }
926                                     /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
927                                     {
928                                         child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
929                                         expand_bitfield = false;
930                                         if (!child_valobj_sp)
931                                         {
932                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
933                                             error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
934                                                                             child_index, final_index,
935                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
936                                                                             var_expr_path_strm.GetString().c_str());
937                                         }
938                                     }*/
939 
940                                     if (expand_bitfield)
941                                     {
942                                         child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
943                                         if (!child_valobj_sp)
944                                         {
945                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
946                                             error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
947                                                                             child_index, final_index,
948                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
949                                                                             var_expr_path_strm.GetString().c_str());
950                                         }
951                                     }
952                                 }
953 
954                                 if (!child_valobj_sp)
955                                 {
956                                     // Invalid bitfield range...
957                                     return ValueObjectSP();
958                                 }
959 
960                                 // Erase the bitfield member specification '[%i-%i]' where
961                                 // %i is the index
962                                 var_path.erase(0, (real_end - var_path.c_str()) + 1);
963                                 separator_idx = var_path.find_first_of(".-[");
964                                 if (use_dynamic != eNoDynamicValues)
965                                 {
966                                     ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
967                                     if (dynamic_value_sp)
968                                         child_valobj_sp = dynamic_value_sp;
969                                 }
970                                 // Break out early from the switch since we were
971                                 // able to find the child member
972                                 break;
973 
974                             }
975                         }
976                         else
977                         {
978                             error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
979                                                            var_expr_path_strm.GetString().c_str(),
980                                                            var_path.c_str());
981                         }
982                         return ValueObjectSP();
983 
984                     default:
985                         // Failure...
986                         {
987                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
988                             error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
989                                                             separator_type,
990                                                             var_expr_path_strm.GetString().c_str(),
991                                                             var_path.c_str());
992 
993                             return ValueObjectSP();
994                         }
995                     }
996 
997                     if (child_valobj_sp)
998                         valobj_sp = child_valobj_sp;
999 
1000                     if (var_path.empty())
1001                         break;
1002 
1003                 }
1004                 if (valobj_sp)
1005                 {
1006                     if (deref)
1007                     {
1008                         ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
1009                         valobj_sp = deref_valobj_sp;
1010                     }
1011                     else if (address_of)
1012                     {
1013                         ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
1014                         valobj_sp = address_of_valobj_sp;
1015                     }
1016                 }
1017                 return valobj_sp;
1018             }
1019             else
1020             {
1021                 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
1022                                                name_const_string.GetCString());
1023             }
1024         }
1025     }
1026     else
1027     {
1028         error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
1029     }
1030     return ValueObjectSP();
1031 }
1032 
1033 bool
1034 StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
1035 {
1036     if (m_flags.IsClear(GOT_FRAME_BASE))
1037     {
1038         if (m_sc.function)
1039         {
1040             m_frame_base.Clear();
1041             m_frame_base_error.Clear();
1042 
1043             m_flags.Set(GOT_FRAME_BASE);
1044             ExecutionContext exe_ctx (shared_from_this());
1045             Value expr_value;
1046             addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1047             if (m_sc.function->GetFrameBaseExpression().IsLocationList())
1048                 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
1049 
1050             if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
1051             {
1052                 // We should really have an error if evaluate returns, but in case
1053                 // we don't, lets set the error to something at least.
1054                 if (m_frame_base_error.Success())
1055                     m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
1056             }
1057             else
1058             {
1059                 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
1060             }
1061         }
1062         else
1063         {
1064             m_frame_base_error.SetErrorString ("No function in symbol context.");
1065         }
1066     }
1067 
1068     if (m_frame_base_error.Success())
1069         frame_base = m_frame_base;
1070 
1071     if (error_ptr)
1072         *error_ptr = m_frame_base_error;
1073     return m_frame_base_error.Success();
1074 }
1075 
1076 RegisterContextSP
1077 StackFrame::GetRegisterContext ()
1078 {
1079     if (!m_reg_context_sp)
1080     {
1081         ThreadSP thread_sp (GetThread());
1082         if (thread_sp)
1083             m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1084     }
1085     return m_reg_context_sp;
1086 }
1087 
1088 bool
1089 StackFrame::HasDebugInformation ()
1090 {
1091     GetSymbolContext (eSymbolContextLineEntry);
1092     return m_sc.line_entry.IsValid();
1093 }
1094 
1095 
1096 ValueObjectSP
1097 StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
1098 {
1099     ValueObjectSP valobj_sp;
1100     VariableList *var_list = GetVariableList (true);
1101     if (var_list)
1102     {
1103         // Make sure the variable is a frame variable
1104         const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1105         const uint32_t num_variables = var_list->GetSize();
1106         if (var_idx < num_variables)
1107         {
1108             valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1109             if (valobj_sp.get() == NULL)
1110             {
1111                 if (m_variable_list_value_objects.GetSize() < num_variables)
1112                     m_variable_list_value_objects.Resize(num_variables);
1113                 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
1114                 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1115             }
1116         }
1117     }
1118     if (use_dynamic != eNoDynamicValues && valobj_sp)
1119     {
1120         ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
1121         if (dynamic_sp)
1122             return dynamic_sp;
1123     }
1124     return valobj_sp;
1125 }
1126 
1127 ValueObjectSP
1128 StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
1129 {
1130     // Check to make sure we aren't already tracking this variable?
1131     ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
1132     if (!valobj_sp)
1133     {
1134         // We aren't already tracking this global
1135         VariableList *var_list = GetVariableList (true);
1136         // If this frame has no variables, create a new list
1137         if (var_list == NULL)
1138             m_variable_list_sp.reset (new VariableList());
1139 
1140         // Add the global/static variable to this frame
1141         m_variable_list_sp->AddVariable (variable_sp);
1142 
1143         // Now make a value object for it so we can track its changes
1144         valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
1145     }
1146     return valobj_sp;
1147 }
1148 
1149 bool
1150 StackFrame::IsInlined ()
1151 {
1152     if (m_sc.block == NULL)
1153         GetSymbolContext (eSymbolContextBlock);
1154     if (m_sc.block)
1155         return m_sc.block->GetContainingInlinedBlock() != NULL;
1156     return false;
1157 }
1158 
1159 TargetSP
1160 StackFrame::CalculateTarget ()
1161 {
1162     TargetSP target_sp;
1163     ThreadSP thread_sp(GetThread());
1164     if (thread_sp)
1165     {
1166         ProcessSP process_sp (thread_sp->CalculateProcess());
1167         if (process_sp)
1168             target_sp = process_sp->CalculateTarget();
1169     }
1170     return target_sp;
1171 }
1172 
1173 ProcessSP
1174 StackFrame::CalculateProcess ()
1175 {
1176     ProcessSP process_sp;
1177     ThreadSP thread_sp(GetThread());
1178     if (thread_sp)
1179         process_sp = thread_sp->CalculateProcess();
1180     return process_sp;
1181 }
1182 
1183 ThreadSP
1184 StackFrame::CalculateThread ()
1185 {
1186     return GetThread();
1187 }
1188 
1189 StackFrameSP
1190 StackFrame::CalculateStackFrame ()
1191 {
1192     return shared_from_this();
1193 }
1194 
1195 
1196 void
1197 StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
1198 {
1199     exe_ctx.SetContext (shared_from_this());
1200 }
1201 
1202 void
1203 StackFrame::DumpUsingSettingsFormat (Stream *strm)
1204 {
1205     if (strm == NULL)
1206         return;
1207 
1208     GetSymbolContext(eSymbolContextEverything);
1209     ExecutionContext exe_ctx (shared_from_this());
1210     const char *end = NULL;
1211     StreamString s;
1212     const char *frame_format = NULL;
1213     Target *target = exe_ctx.GetTargetPtr();
1214     if (target)
1215         frame_format = target->GetDebugger().GetFrameFormat();
1216     if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
1217     {
1218         strm->Write(s.GetData(), s.GetSize());
1219     }
1220     else
1221     {
1222         Dump (strm, true, false);
1223         strm->EOL();
1224     }
1225 }
1226 
1227 void
1228 StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
1229 {
1230     if (strm == NULL)
1231         return;
1232 
1233     if (show_frame_index)
1234         strm->Printf("frame #%u: ", m_frame_index);
1235     ExecutionContext exe_ctx (shared_from_this());
1236     Target *target = exe_ctx.GetTargetPtr();
1237     strm->Printf("0x%0*llx ",
1238                  target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1239                  GetFrameCodeAddress().GetLoadAddress(target));
1240     GetSymbolContext(eSymbolContextEverything);
1241     const bool show_module = true;
1242     const bool show_inline = true;
1243     m_sc.DumpStopContext (strm,
1244                           exe_ctx.GetBestExecutionContextScope(),
1245                           GetFrameCodeAddress(),
1246                           show_fullpaths,
1247                           show_module,
1248                           show_inline);
1249 }
1250 
1251 void
1252 StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
1253 {
1254     assert (GetStackID() == prev_frame.GetStackID());    // TODO: remove this after some testing
1255     m_variable_list_sp = prev_frame.m_variable_list_sp;
1256     m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
1257     if (!m_disassembly.GetString().empty())
1258         m_disassembly.GetString().swap (m_disassembly.GetString());
1259 }
1260 
1261 
1262 void
1263 StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
1264 {
1265     assert (GetStackID() == curr_frame.GetStackID());        // TODO: remove this after some testing
1266     m_id.SetPC (curr_frame.m_id.GetPC());       // Update the Stack ID PC value
1267     assert (GetThread() == curr_frame.GetThread());
1268     m_frame_index = curr_frame.m_frame_index;
1269     m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1270     m_reg_context_sp = curr_frame.m_reg_context_sp;
1271     m_frame_code_addr = curr_frame.m_frame_code_addr;
1272     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());
1273     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());
1274     assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1275     assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
1276     m_sc = curr_frame.m_sc;
1277     m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1278     m_flags.Set (m_sc.GetResolvedMask());
1279     m_frame_base.Clear();
1280     m_frame_base_error.Clear();
1281 }
1282 
1283 
1284 bool
1285 StackFrame::HasCachedData () const
1286 {
1287     if (m_variable_list_sp.get())
1288         return true;
1289     if (m_variable_list_value_objects.GetSize() > 0)
1290         return true;
1291     if (!m_disassembly.GetString().empty())
1292         return true;
1293     return false;
1294 }
1295 
1296 bool
1297 StackFrame::GetStatus (Stream& strm,
1298                        bool show_frame_info,
1299                        bool show_source,
1300                        uint32_t source_lines_before,
1301                        uint32_t source_lines_after)
1302 {
1303     if (show_frame_info)
1304     {
1305         strm.Indent();
1306         DumpUsingSettingsFormat (&strm);
1307     }
1308 
1309     if (show_source)
1310     {
1311         ExecutionContext exe_ctx (shared_from_this());
1312         bool have_source = false;
1313         DebuggerInstanceSettings::StopDisassemblyType disasm_display = DebuggerInstanceSettings::eStopDisassemblyTypeNever;
1314         Target *target = exe_ctx.GetTargetPtr();
1315         if (target && (source_lines_before || source_lines_after))
1316         {
1317             GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1318 
1319             if (m_sc.comp_unit && m_sc.line_entry.IsValid())
1320             {
1321                 if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
1322                                                                                   m_sc.line_entry.line,
1323                                                                                   source_lines_before,
1324                                                                                   source_lines_after,
1325                                                                                   "->",
1326                                                                                   &strm))
1327                 {
1328                     have_source = true;
1329                 }
1330             }
1331             disasm_display = target->GetDebugger().GetStopDisassemblyDisplay ();
1332         }
1333 
1334         switch (disasm_display)
1335         {
1336         case DebuggerInstanceSettings::eStopDisassemblyTypeNever:
1337             break;
1338 
1339         case DebuggerInstanceSettings::eStopDisassemblyTypeNoSource:
1340             if (have_source)
1341                 break;
1342             // Fall through to next case
1343         case DebuggerInstanceSettings::eStopDisassemblyTypeAlways:
1344             if (target)
1345             {
1346                 const uint32_t disasm_lines = target->GetDebugger().GetDisassemblyLineCount();
1347                 if (disasm_lines > 0)
1348                 {
1349                     const ArchSpec &target_arch = target->GetArchitecture();
1350                     AddressRange pc_range;
1351                     pc_range.GetBaseAddress() = GetFrameCodeAddress();
1352                     pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1353                     Disassembler::Disassemble (target->GetDebugger(),
1354                                                target_arch,
1355                                                NULL,
1356                                                exe_ctx,
1357                                                pc_range,
1358                                                disasm_lines,
1359                                                0,
1360                                                Disassembler::eOptionMarkPCAddress,
1361                                                strm);
1362                 }
1363             }
1364             break;
1365         }
1366     }
1367     return true;
1368 }
1369 
1370