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