130fdc8d8SChris Lattner //===-- StackFrame.cpp ------------------------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
1093a64300SDaniel Malea #include "lldb/lldb-python.h"
1193a64300SDaniel Malea 
1230fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h"
1330fdc8d8SChris Lattner 
1430fdc8d8SChris Lattner // C Includes
1530fdc8d8SChris Lattner // C++ Includes
1630fdc8d8SChris Lattner // Other libraries and framework includes
1730fdc8d8SChris Lattner // Project includes
1830fdc8d8SChris Lattner #include "lldb/Core/Module.h"
190603aa9dSGreg Clayton #include "lldb/Core/Debugger.h"
2030fdc8d8SChris Lattner #include "lldb/Core/Disassembler.h"
2130fdc8d8SChris Lattner #include "lldb/Core/Value.h"
22288bdf9cSGreg Clayton #include "lldb/Core/ValueObjectVariable.h"
2354979cddSGreg Clayton #include "lldb/Core/ValueObjectConstResult.h"
241f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h"
2530fdc8d8SChris Lattner #include "lldb/Symbol/Function.h"
261f746071SGreg Clayton #include "lldb/Symbol/Symbol.h"
271f746071SGreg Clayton #include "lldb/Symbol/SymbolContextScope.h"
28288bdf9cSGreg Clayton #include "lldb/Symbol/VariableList.h"
2930fdc8d8SChris Lattner #include "lldb/Target/ExecutionContext.h"
3030fdc8d8SChris Lattner #include "lldb/Target/Process.h"
3130fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h"
3230fdc8d8SChris Lattner #include "lldb/Target/Target.h"
3330fdc8d8SChris Lattner #include "lldb/Target/Thread.h"
3430fdc8d8SChris Lattner 
3530fdc8d8SChris Lattner using namespace lldb;
3630fdc8d8SChris Lattner using namespace lldb_private;
3730fdc8d8SChris Lattner 
3830fdc8d8SChris Lattner // The first bits in the flags are reserved for the SymbolContext::Scope bits
3930fdc8d8SChris Lattner // so we know if we have tried to look up information in our internal symbol
4030fdc8d8SChris Lattner // context (m_sc) already.
4159e8fc1cSGreg Clayton #define RESOLVED_FRAME_CODE_ADDR        (uint32_t(eSymbolContextEverything + 1))
426dadd508SGreg Clayton #define RESOLVED_FRAME_ID_SYMBOL_SCOPE  (RESOLVED_FRAME_CODE_ADDR << 1)
4359e8fc1cSGreg Clayton #define GOT_FRAME_BASE                  (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
4459e8fc1cSGreg Clayton #define RESOLVED_VARIABLES              (GOT_FRAME_BASE << 1)
457c0962dcSSean Callanan #define RESOLVED_GLOBAL_VARIABLES       (RESOLVED_VARIABLES << 1)
4630fdc8d8SChris Lattner 
47d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp,
48d9e416c0SGreg Clayton                         user_id_t frame_idx,
494d122c40SGreg Clayton                         user_id_t unwind_frame_index,
504d122c40SGreg Clayton                         addr_t cfa,
514d122c40SGreg Clayton                         addr_t pc,
528f7180b1SGreg Clayton                         const SymbolContext *sc_ptr) :
53d9e416c0SGreg Clayton     m_thread_wp (thread_sp),
541b72fcb7SGreg Clayton     m_frame_index (frame_idx),
555ccbd294SGreg Clayton     m_concrete_frame_index (unwind_frame_index),
5630fdc8d8SChris Lattner     m_reg_context_sp (),
576dadd508SGreg Clayton     m_id (pc, cfa, NULL),
58e72dfb32SGreg Clayton     m_frame_code_addr (pc),
5930fdc8d8SChris Lattner     m_sc (),
6030fdc8d8SChris Lattner     m_flags (),
6130fdc8d8SChris Lattner     m_frame_base (),
6230fdc8d8SChris Lattner     m_frame_base_error (),
6330fdc8d8SChris Lattner     m_variable_list_sp (),
641a65ae11SGreg Clayton     m_variable_list_value_objects (),
651a65ae11SGreg Clayton     m_disassembly ()
6630fdc8d8SChris Lattner {
6730fdc8d8SChris Lattner     if (sc_ptr != NULL)
681b72fcb7SGreg Clayton     {
6930fdc8d8SChris Lattner         m_sc = *sc_ptr;
701b72fcb7SGreg Clayton         m_flags.Set(m_sc.GetResolvedMask ());
711b72fcb7SGreg Clayton     }
7230fdc8d8SChris Lattner }
7330fdc8d8SChris Lattner 
74d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp,
75d9e416c0SGreg Clayton                         user_id_t frame_idx,
764d122c40SGreg Clayton                         user_id_t unwind_frame_index,
771b72fcb7SGreg Clayton                         const RegisterContextSP &reg_context_sp,
784d122c40SGreg Clayton                         addr_t cfa,
794d122c40SGreg Clayton                         addr_t pc,
808f7180b1SGreg Clayton                         const SymbolContext *sc_ptr) :
81d9e416c0SGreg Clayton     m_thread_wp (thread_sp),
821b72fcb7SGreg Clayton     m_frame_index (frame_idx),
835ccbd294SGreg Clayton     m_concrete_frame_index (unwind_frame_index),
8430fdc8d8SChris Lattner     m_reg_context_sp (reg_context_sp),
856dadd508SGreg Clayton     m_id (pc, cfa, NULL),
86e72dfb32SGreg Clayton     m_frame_code_addr (pc),
8730fdc8d8SChris Lattner     m_sc (),
8830fdc8d8SChris Lattner     m_flags (),
8930fdc8d8SChris Lattner     m_frame_base (),
9030fdc8d8SChris Lattner     m_frame_base_error (),
9130fdc8d8SChris Lattner     m_variable_list_sp (),
921a65ae11SGreg Clayton     m_variable_list_value_objects (),
931a65ae11SGreg Clayton     m_disassembly ()
9430fdc8d8SChris Lattner {
9530fdc8d8SChris Lattner     if (sc_ptr != NULL)
961b72fcb7SGreg Clayton     {
9730fdc8d8SChris Lattner         m_sc = *sc_ptr;
981b72fcb7SGreg Clayton         m_flags.Set(m_sc.GetResolvedMask ());
991b72fcb7SGreg Clayton     }
1001b72fcb7SGreg Clayton 
1011b72fcb7SGreg Clayton     if (reg_context_sp && !m_sc.target_sp)
1021b72fcb7SGreg Clayton     {
103d9e416c0SGreg Clayton         m_sc.target_sp = reg_context_sp->CalculateTarget();
104d9e416c0SGreg Clayton         if (m_sc.target_sp)
1051b72fcb7SGreg Clayton             m_flags.Set (eSymbolContextTarget);
1061b72fcb7SGreg Clayton     }
1071b72fcb7SGreg Clayton }
1081b72fcb7SGreg Clayton 
109d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp,
110d9e416c0SGreg Clayton                         user_id_t frame_idx,
1114d122c40SGreg Clayton                         user_id_t unwind_frame_index,
1121b72fcb7SGreg Clayton                         const RegisterContextSP &reg_context_sp,
1134d122c40SGreg Clayton                         addr_t cfa,
1141b72fcb7SGreg Clayton                         const Address& pc_addr,
1158f7180b1SGreg Clayton                         const SymbolContext *sc_ptr) :
116d9e416c0SGreg Clayton     m_thread_wp (thread_sp),
1171b72fcb7SGreg Clayton     m_frame_index (frame_idx),
1185ccbd294SGreg Clayton     m_concrete_frame_index (unwind_frame_index),
1191b72fcb7SGreg Clayton     m_reg_context_sp (reg_context_sp),
1201ac04c30SGreg Clayton     m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL),
12112fc3e0fSGreg Clayton     m_frame_code_addr (pc_addr),
1221b72fcb7SGreg Clayton     m_sc (),
1231b72fcb7SGreg Clayton     m_flags (),
1241b72fcb7SGreg Clayton     m_frame_base (),
1251b72fcb7SGreg Clayton     m_frame_base_error (),
1261b72fcb7SGreg Clayton     m_variable_list_sp (),
1271a65ae11SGreg Clayton     m_variable_list_value_objects (),
1281a65ae11SGreg Clayton     m_disassembly ()
1291b72fcb7SGreg Clayton {
1301b72fcb7SGreg Clayton     if (sc_ptr != NULL)
1311b72fcb7SGreg Clayton     {
1321b72fcb7SGreg Clayton         m_sc = *sc_ptr;
1331b72fcb7SGreg Clayton         m_flags.Set(m_sc.GetResolvedMask ());
1341b72fcb7SGreg Clayton     }
1351b72fcb7SGreg Clayton 
1361b72fcb7SGreg Clayton     if (m_sc.target_sp.get() == NULL && reg_context_sp)
1371b72fcb7SGreg Clayton     {
138d9e416c0SGreg Clayton         m_sc.target_sp = reg_context_sp->CalculateTarget();
139d9e416c0SGreg Clayton         if (m_sc.target_sp)
1401b72fcb7SGreg Clayton             m_flags.Set (eSymbolContextTarget);
1411b72fcb7SGreg Clayton     }
1421b72fcb7SGreg Clayton 
143e72dfb32SGreg Clayton     ModuleSP pc_module_sp (pc_addr.GetModule());
144e72dfb32SGreg Clayton     if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp)
1451b72fcb7SGreg Clayton     {
146e72dfb32SGreg Clayton         if (pc_module_sp)
1471b72fcb7SGreg Clayton         {
148e72dfb32SGreg Clayton             m_sc.module_sp = pc_module_sp;
1491b72fcb7SGreg Clayton             m_flags.Set (eSymbolContextModule);
1501b72fcb7SGreg Clayton         }
151ffc1d667SGreg Clayton         else
152ffc1d667SGreg Clayton         {
153ffc1d667SGreg Clayton             m_sc.module_sp.reset();
154ffc1d667SGreg Clayton         }
1551b72fcb7SGreg Clayton     }
15630fdc8d8SChris Lattner }
15730fdc8d8SChris Lattner 
15830fdc8d8SChris Lattner 
15930fdc8d8SChris Lattner //----------------------------------------------------------------------
16030fdc8d8SChris Lattner // Destructor
16130fdc8d8SChris Lattner //----------------------------------------------------------------------
16230fdc8d8SChris Lattner StackFrame::~StackFrame()
16330fdc8d8SChris Lattner {
16430fdc8d8SChris Lattner }
16530fdc8d8SChris Lattner 
16630fdc8d8SChris Lattner StackID&
16730fdc8d8SChris Lattner StackFrame::GetStackID()
16830fdc8d8SChris Lattner {
1696dadd508SGreg Clayton     // Make sure we have resolved the StackID object's symbol context scope if
1706dadd508SGreg Clayton     // we already haven't looked it up.
17159e8fc1cSGreg Clayton 
17259e8fc1cSGreg Clayton     if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
17359e8fc1cSGreg Clayton     {
1742cad65a5SGreg Clayton         if (m_id.GetSymbolContextScope ())
17559e8fc1cSGreg Clayton         {
17695897c6aSGreg Clayton             // We already have a symbol context scope, we just don't have our
17795897c6aSGreg Clayton             // flag bit set.
17859e8fc1cSGreg Clayton             m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
17959e8fc1cSGreg Clayton         }
18059e8fc1cSGreg Clayton         else
18159e8fc1cSGreg Clayton         {
18295897c6aSGreg Clayton             // Calculate the frame block and use this for the stack ID symbol
18395897c6aSGreg Clayton             // context scope if we have one.
18495897c6aSGreg Clayton             SymbolContextScope *scope = GetFrameBlock ();
18595897c6aSGreg Clayton             if (scope == NULL)
18659e8fc1cSGreg Clayton             {
18795897c6aSGreg Clayton                 // We don't have a block, so use the symbol
18895897c6aSGreg Clayton                 if (m_flags.IsClear (eSymbolContextSymbol))
18959e8fc1cSGreg Clayton                     GetSymbolContext (eSymbolContextSymbol);
19095897c6aSGreg Clayton 
19195897c6aSGreg Clayton                 // It is ok if m_sc.symbol is NULL here
19295897c6aSGreg Clayton                 scope = m_sc.symbol;
19359e8fc1cSGreg Clayton             }
19495897c6aSGreg Clayton             // Set the symbol context scope (the accessor will set the
19595897c6aSGreg Clayton             // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
19695897c6aSGreg Clayton             SetSymbolContextScope (scope);
19759e8fc1cSGreg Clayton         }
19859e8fc1cSGreg Clayton     }
19930fdc8d8SChris Lattner     return m_id;
20030fdc8d8SChris Lattner }
20130fdc8d8SChris Lattner 
202513c6bb8SJim Ingham uint32_t
203513c6bb8SJim Ingham StackFrame::GetFrameIndex () const
204513c6bb8SJim Ingham {
205513c6bb8SJim Ingham     ThreadSP thread_sp = GetThread();
206513c6bb8SJim Ingham     if (thread_sp)
207513c6bb8SJim Ingham         return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index);
208513c6bb8SJim Ingham     else
209513c6bb8SJim Ingham         return m_frame_index;
210513c6bb8SJim Ingham }
211513c6bb8SJim Ingham 
21259e8fc1cSGreg Clayton void
21359e8fc1cSGreg Clayton StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope)
21459e8fc1cSGreg Clayton {
21559e8fc1cSGreg Clayton     m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
21659e8fc1cSGreg Clayton     m_id.SetSymbolContextScope (symbol_scope);
21759e8fc1cSGreg Clayton }
21859e8fc1cSGreg Clayton 
21934132754SGreg Clayton const Address&
2209da7bd07SGreg Clayton StackFrame::GetFrameCodeAddress()
22130fdc8d8SChris Lattner {
22259e8fc1cSGreg Clayton     if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset())
22330fdc8d8SChris Lattner     {
22459e8fc1cSGreg Clayton         m_flags.Set (RESOLVED_FRAME_CODE_ADDR);
22530fdc8d8SChris Lattner 
22630fdc8d8SChris Lattner         // Resolve the PC into a temporary address because if ResolveLoadAddress
22730fdc8d8SChris Lattner         // fails to resolve the address, it will clear the address object...
228d9e416c0SGreg Clayton         ThreadSP thread_sp (GetThread());
229d9e416c0SGreg Clayton         if (thread_sp)
230d9e416c0SGreg Clayton         {
231d9e416c0SGreg Clayton             TargetSP target_sp (thread_sp->CalculateTarget());
232d9e416c0SGreg Clayton             if (target_sp)
233d9e416c0SGreg Clayton             {
234d9e416c0SGreg Clayton                 if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get()))
23530fdc8d8SChris Lattner                 {
236e72dfb32SGreg Clayton                     ModuleSP module_sp (m_frame_code_addr.GetModule());
237e72dfb32SGreg Clayton                     if (module_sp)
23830fdc8d8SChris Lattner                     {
239e72dfb32SGreg Clayton                         m_sc.module_sp = module_sp;
24030fdc8d8SChris Lattner                         m_flags.Set(eSymbolContextModule);
24130fdc8d8SChris Lattner                     }
24230fdc8d8SChris Lattner                 }
24330fdc8d8SChris Lattner             }
24430fdc8d8SChris Lattner         }
245d9e416c0SGreg Clayton     }
24612fc3e0fSGreg Clayton     return m_frame_code_addr;
24730fdc8d8SChris Lattner }
24830fdc8d8SChris Lattner 
24930fdc8d8SChris Lattner void
25030fdc8d8SChris Lattner StackFrame::ChangePC (addr_t pc)
25130fdc8d8SChris Lattner {
252e72dfb32SGreg Clayton     m_frame_code_addr.SetRawAddress(pc);
25330fdc8d8SChris Lattner     m_sc.Clear();
25473b472d4SGreg Clayton     m_flags.Reset(0);
255d9e416c0SGreg Clayton     ThreadSP thread_sp (GetThread());
256d9e416c0SGreg Clayton     if (thread_sp)
257d9e416c0SGreg Clayton         thread_sp->ClearStackFrames ();
25830fdc8d8SChris Lattner }
25930fdc8d8SChris Lattner 
26030fdc8d8SChris Lattner const char *
26130fdc8d8SChris Lattner StackFrame::Disassemble ()
26230fdc8d8SChris Lattner {
26330fdc8d8SChris Lattner     if (m_disassembly.GetSize() == 0)
26430fdc8d8SChris Lattner     {
265d9e416c0SGreg Clayton         ExecutionContext exe_ctx (shared_from_this());
266d9e416c0SGreg Clayton         Target *target = exe_ctx.GetTargetPtr();
267d9e416c0SGreg Clayton         if (target)
268d9e416c0SGreg Clayton         {
269d9e416c0SGreg Clayton             Disassembler::Disassemble (target->GetDebugger(),
270d9e416c0SGreg Clayton                                        target->GetArchitecture(),
2711080edbcSGreg Clayton                                        NULL,
27230fdc8d8SChris Lattner                                        exe_ctx,
27330fdc8d8SChris Lattner                                        0,
27437023b06SJim Ingham                                        0,
2751da6f9d7SGreg Clayton                                        0,
27630fdc8d8SChris Lattner                                        m_disassembly);
277d9e416c0SGreg Clayton         }
27830fdc8d8SChris Lattner         if (m_disassembly.GetSize() == 0)
27930fdc8d8SChris Lattner             return NULL;
28030fdc8d8SChris Lattner     }
28130fdc8d8SChris Lattner     return m_disassembly.GetData();
28230fdc8d8SChris Lattner }
28330fdc8d8SChris Lattner 
28495897c6aSGreg Clayton Block *
28595897c6aSGreg Clayton StackFrame::GetFrameBlock ()
28695897c6aSGreg Clayton {
28795897c6aSGreg Clayton     if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock))
28895897c6aSGreg Clayton         GetSymbolContext (eSymbolContextBlock);
28995897c6aSGreg Clayton 
29095897c6aSGreg Clayton     if (m_sc.block)
29195897c6aSGreg Clayton     {
29295897c6aSGreg Clayton         Block *inline_block = m_sc.block->GetContainingInlinedBlock();
29395897c6aSGreg Clayton         if (inline_block)
29495897c6aSGreg Clayton         {
29595897c6aSGreg Clayton             // Use the block with the inlined function info
29695897c6aSGreg Clayton             // as the frame block we want this frame to have only the variables
29795897c6aSGreg Clayton             // for the inlined function and its non-inlined block child blocks.
29895897c6aSGreg Clayton             return inline_block;
29995897c6aSGreg Clayton         }
30095897c6aSGreg Clayton         else
30195897c6aSGreg Clayton         {
30295897c6aSGreg Clayton             // This block is not contained withing any inlined function blocks
30395897c6aSGreg Clayton             // with so we want to use the top most function block.
30495897c6aSGreg Clayton             return &m_sc.function->GetBlock (false);
30595897c6aSGreg Clayton         }
30695897c6aSGreg Clayton     }
30795897c6aSGreg Clayton     return NULL;
30895897c6aSGreg Clayton }
30995897c6aSGreg Clayton 
31030fdc8d8SChris Lattner //----------------------------------------------------------------------
31130fdc8d8SChris Lattner // Get the symbol context if we already haven't done so by resolving the
31230fdc8d8SChris Lattner // PC address as much as possible. This way when we pass around a
31330fdc8d8SChris Lattner // StackFrame object, everyone will have as much information as
31430fdc8d8SChris Lattner // possible and no one will ever have to look things up manually.
31530fdc8d8SChris Lattner //----------------------------------------------------------------------
31630fdc8d8SChris Lattner const SymbolContext&
31730fdc8d8SChris Lattner StackFrame::GetSymbolContext (uint32_t resolve_scope)
31830fdc8d8SChris Lattner {
31930fdc8d8SChris Lattner     // Copy our internal symbol context into "sc".
32073b472d4SGreg Clayton     if ((m_flags.Get() & resolve_scope) != resolve_scope)
32130fdc8d8SChris Lattner     {
32275a0333bSGreg Clayton         uint32_t resolved = 0;
32375a0333bSGreg Clayton 
32475a0333bSGreg Clayton         // If the target was requested add that:
32575a0333bSGreg Clayton         if (!m_sc.target_sp)
32675a0333bSGreg Clayton         {
32775a0333bSGreg Clayton             m_sc.target_sp = CalculateTarget();
32875a0333bSGreg Clayton             if (m_sc.target_sp)
32975a0333bSGreg Clayton                 resolved |= eSymbolContextTarget;
33075a0333bSGreg Clayton         }
33175a0333bSGreg Clayton 
33275a0333bSGreg Clayton 
33330fdc8d8SChris Lattner         // Resolve our PC to section offset if we haven't alreday done so
33430fdc8d8SChris Lattner         // and if we don't have a module. The resolved address section will
33530fdc8d8SChris Lattner         // contain the module to which it belongs
33659e8fc1cSGreg Clayton         if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
3379da7bd07SGreg Clayton             GetFrameCodeAddress();
33830fdc8d8SChris Lattner 
33930fdc8d8SChris Lattner         // If this is not frame zero, then we need to subtract 1 from the PC
34030fdc8d8SChris Lattner         // value when doing address lookups since the PC will be on the
34130fdc8d8SChris Lattner         // instruction following the function call instruction...
34230fdc8d8SChris Lattner 
3439da7bd07SGreg Clayton         Address lookup_addr(GetFrameCodeAddress());
3441b72fcb7SGreg Clayton         if (m_frame_index > 0 && lookup_addr.IsValid())
34530fdc8d8SChris Lattner         {
34630fdc8d8SChris Lattner             addr_t offset = lookup_addr.GetOffset();
34730fdc8d8SChris Lattner             if (offset > 0)
34830fdc8d8SChris Lattner                 lookup_addr.SetOffset(offset - 1);
34930fdc8d8SChris Lattner         }
35030fdc8d8SChris Lattner 
3519da7bd07SGreg Clayton 
35230fdc8d8SChris Lattner         if (m_sc.module_sp)
35330fdc8d8SChris Lattner         {
35430fdc8d8SChris Lattner             // We have something in our stack frame symbol context, lets check
35530fdc8d8SChris Lattner             // if we haven't already tried to lookup one of those things. If we
35630fdc8d8SChris Lattner             // haven't then we will do the query.
3571b72fcb7SGreg Clayton 
3581b72fcb7SGreg Clayton             uint32_t actual_resolve_scope = 0;
3591b72fcb7SGreg Clayton 
3601b72fcb7SGreg Clayton             if (resolve_scope & eSymbolContextCompUnit)
3611b72fcb7SGreg Clayton             {
3621b72fcb7SGreg Clayton                 if (m_flags.IsClear (eSymbolContextCompUnit))
3631b72fcb7SGreg Clayton                 {
3641b72fcb7SGreg Clayton                     if (m_sc.comp_unit)
3659da7bd07SGreg Clayton                         resolved |= eSymbolContextCompUnit;
3661b72fcb7SGreg Clayton                     else
3671b72fcb7SGreg Clayton                         actual_resolve_scope |= eSymbolContextCompUnit;
3681b72fcb7SGreg Clayton                 }
3691b72fcb7SGreg Clayton             }
3701b72fcb7SGreg Clayton 
3711b72fcb7SGreg Clayton             if (resolve_scope & eSymbolContextFunction)
3721b72fcb7SGreg Clayton             {
3731b72fcb7SGreg Clayton                 if (m_flags.IsClear (eSymbolContextFunction))
3741b72fcb7SGreg Clayton                 {
3751b72fcb7SGreg Clayton                     if (m_sc.function)
3769da7bd07SGreg Clayton                         resolved |= eSymbolContextFunction;
3771b72fcb7SGreg Clayton                     else
3781b72fcb7SGreg Clayton                         actual_resolve_scope |= eSymbolContextFunction;
3791b72fcb7SGreg Clayton                 }
3801b72fcb7SGreg Clayton             }
3811b72fcb7SGreg Clayton 
3821b72fcb7SGreg Clayton             if (resolve_scope & eSymbolContextBlock)
3831b72fcb7SGreg Clayton             {
3841b72fcb7SGreg Clayton                 if (m_flags.IsClear (eSymbolContextBlock))
3851b72fcb7SGreg Clayton                 {
3861b72fcb7SGreg Clayton                     if (m_sc.block)
3879da7bd07SGreg Clayton                         resolved |= eSymbolContextBlock;
3881b72fcb7SGreg Clayton                     else
3891b72fcb7SGreg Clayton                         actual_resolve_scope |= eSymbolContextBlock;
3901b72fcb7SGreg Clayton                 }
3911b72fcb7SGreg Clayton             }
3921b72fcb7SGreg Clayton 
3931b72fcb7SGreg Clayton             if (resolve_scope & eSymbolContextSymbol)
3941b72fcb7SGreg Clayton             {
3951b72fcb7SGreg Clayton                 if (m_flags.IsClear (eSymbolContextSymbol))
3961b72fcb7SGreg Clayton                 {
3971b72fcb7SGreg Clayton                     if (m_sc.symbol)
3989da7bd07SGreg Clayton                         resolved |= eSymbolContextSymbol;
3991b72fcb7SGreg Clayton                     else
4001b72fcb7SGreg Clayton                         actual_resolve_scope |= eSymbolContextSymbol;
4011b72fcb7SGreg Clayton                 }
4021b72fcb7SGreg Clayton             }
4031b72fcb7SGreg Clayton 
4041b72fcb7SGreg Clayton             if (resolve_scope & eSymbolContextLineEntry)
4051b72fcb7SGreg Clayton             {
4061b72fcb7SGreg Clayton                 if (m_flags.IsClear (eSymbolContextLineEntry))
4071b72fcb7SGreg Clayton                 {
4081b72fcb7SGreg Clayton                     if (m_sc.line_entry.IsValid())
4099da7bd07SGreg Clayton                         resolved |= eSymbolContextLineEntry;
4101b72fcb7SGreg Clayton                     else
4111b72fcb7SGreg Clayton                         actual_resolve_scope |= eSymbolContextLineEntry;
4121b72fcb7SGreg Clayton                 }
4131b72fcb7SGreg Clayton             }
4141b72fcb7SGreg Clayton 
4151b72fcb7SGreg Clayton             if (actual_resolve_scope)
41630fdc8d8SChris Lattner             {
41730fdc8d8SChris Lattner                 // We might be resolving less information than what is already
41830fdc8d8SChris Lattner                 // in our current symbol context so resolve into a temporary
41930fdc8d8SChris Lattner                 // symbol context "sc" so we don't clear out data we have
42030fdc8d8SChris Lattner                 // already found in "m_sc"
42130fdc8d8SChris Lattner                 SymbolContext sc;
42230fdc8d8SChris Lattner                 // Set flags that indicate what we have tried to resolve
4239da7bd07SGreg Clayton                 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc);
4241b72fcb7SGreg Clayton                 // Only replace what we didn't already have as we may have
4251b72fcb7SGreg Clayton                 // information for an inlined function scope that won't match
4261b72fcb7SGreg Clayton                 // what a standard lookup by address would match
4279da7bd07SGreg Clayton                 if ((resolved & eSymbolContextCompUnit)  && m_sc.comp_unit == NULL)
4289da7bd07SGreg Clayton                     m_sc.comp_unit = sc.comp_unit;
4299da7bd07SGreg Clayton                 if ((resolved & eSymbolContextFunction)  && m_sc.function == NULL)
4309da7bd07SGreg Clayton                     m_sc.function = sc.function;
4319da7bd07SGreg Clayton                 if ((resolved & eSymbolContextBlock)     && m_sc.block == NULL)
4329da7bd07SGreg Clayton                     m_sc.block = sc.block;
4339da7bd07SGreg Clayton                 if ((resolved & eSymbolContextSymbol)    && m_sc.symbol == NULL)
4349da7bd07SGreg Clayton                     m_sc.symbol = sc.symbol;
4359da7bd07SGreg Clayton                 if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid())
43675a0333bSGreg Clayton                 {
4379da7bd07SGreg Clayton                     m_sc.line_entry = sc.line_entry;
43875a0333bSGreg Clayton                     if (m_sc.target_sp)
43975a0333bSGreg Clayton                     {
44075a0333bSGreg Clayton                         // Be sure to apply and file remappings to our file and line
44175a0333bSGreg Clayton                         // entries when handing out a line entry
44275a0333bSGreg Clayton                         FileSpec new_file_spec;
44375a0333bSGreg Clayton                         if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec))
44475a0333bSGreg Clayton                             m_sc.line_entry.file = new_file_spec;
44575a0333bSGreg Clayton                     }
44675a0333bSGreg Clayton                 }
44730fdc8d8SChris Lattner             }
44830fdc8d8SChris Lattner         }
44930fdc8d8SChris Lattner         else
45030fdc8d8SChris Lattner         {
45130fdc8d8SChris Lattner             // If we don't have a module, then we can't have the compile unit,
45230fdc8d8SChris Lattner             // function, block, line entry or symbol, so we can safely call
45330fdc8d8SChris Lattner             // ResolveSymbolContextForAddress with our symbol context member m_sc.
4549da7bd07SGreg Clayton             if (m_sc.target_sp)
45575a0333bSGreg Clayton                 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc);
4569da7bd07SGreg Clayton         }
45730fdc8d8SChris Lattner 
45830fdc8d8SChris Lattner         // Update our internal flags so we remember what we have tried to locate so
45930fdc8d8SChris Lattner         // we don't have to keep trying when more calls to this function are made.
4609da7bd07SGreg Clayton         // We might have dug up more information that was requested (for example
4619da7bd07SGreg Clayton         // if we were asked to only get the block, we will have gotten the
4629da7bd07SGreg Clayton         // compile unit, and function) so set any additional bits that we resolved
4639da7bd07SGreg Clayton         m_flags.Set (resolve_scope | resolved);
46430fdc8d8SChris Lattner     }
46530fdc8d8SChris Lattner 
46630fdc8d8SChris Lattner     // Return the symbol context with everything that was possible to resolve
46730fdc8d8SChris Lattner     // resolved.
46830fdc8d8SChris Lattner     return m_sc;
46930fdc8d8SChris Lattner }
47030fdc8d8SChris Lattner 
47130fdc8d8SChris Lattner 
47230fdc8d8SChris Lattner VariableList *
473288bdf9cSGreg Clayton StackFrame::GetVariableList (bool get_file_globals)
47430fdc8d8SChris Lattner {
47530fdc8d8SChris Lattner     if (m_flags.IsClear(RESOLVED_VARIABLES))
47630fdc8d8SChris Lattner     {
47730fdc8d8SChris Lattner         m_flags.Set(RESOLVED_VARIABLES);
47830fdc8d8SChris Lattner 
47995897c6aSGreg Clayton         Block *frame_block = GetFrameBlock();
480288bdf9cSGreg Clayton 
48195897c6aSGreg Clayton         if (frame_block)
48230fdc8d8SChris Lattner         {
48395897c6aSGreg Clayton             const bool get_child_variables = true;
48495897c6aSGreg Clayton             const bool can_create = true;
485c662ec8bSGreg Clayton             const bool stop_if_child_block_is_inlined_function = true;
486c662ec8bSGreg Clayton             m_variable_list_sp.reset(new VariableList());
487c662ec8bSGreg Clayton             frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get());
48830fdc8d8SChris Lattner         }
4897c0962dcSSean Callanan     }
490288bdf9cSGreg Clayton 
4917c0962dcSSean Callanan     if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) &&
4927c0962dcSSean Callanan         get_file_globals)
49395897c6aSGreg Clayton     {
4947c0962dcSSean Callanan         m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
4957c0962dcSSean Callanan 
49695897c6aSGreg Clayton         if (m_flags.IsClear (eSymbolContextCompUnit))
49795897c6aSGreg Clayton             GetSymbolContext (eSymbolContextCompUnit);
49895897c6aSGreg Clayton 
49995897c6aSGreg Clayton         if (m_sc.comp_unit)
500288bdf9cSGreg Clayton         {
501288bdf9cSGreg Clayton             VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
502288bdf9cSGreg Clayton             if (m_variable_list_sp)
503288bdf9cSGreg Clayton                 m_variable_list_sp->AddVariables (global_variable_list_sp.get());
504288bdf9cSGreg Clayton             else
505288bdf9cSGreg Clayton                 m_variable_list_sp = global_variable_list_sp;
506288bdf9cSGreg Clayton         }
50730fdc8d8SChris Lattner     }
5087c0962dcSSean Callanan 
50930fdc8d8SChris Lattner     return m_variable_list_sp.get();
51030fdc8d8SChris Lattner }
51130fdc8d8SChris Lattner 
512d41f032aSGreg Clayton VariableListSP
513d41f032aSGreg Clayton StackFrame::GetInScopeVariableList (bool get_file_globals)
514d41f032aSGreg Clayton {
515d41f032aSGreg Clayton     VariableListSP var_list_sp(new VariableList);
516d41f032aSGreg Clayton     GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock);
517d41f032aSGreg Clayton 
518d41f032aSGreg Clayton     if (m_sc.block)
519d41f032aSGreg Clayton     {
520d41f032aSGreg Clayton         const bool can_create = true;
521d41f032aSGreg Clayton         const bool get_parent_variables = true;
522d41f032aSGreg Clayton         const bool stop_if_block_is_inlined_function = true;
523d41f032aSGreg Clayton         m_sc.block->AppendVariables (can_create,
524d41f032aSGreg Clayton                                      get_parent_variables,
525d41f032aSGreg Clayton                                      stop_if_block_is_inlined_function,
526d41f032aSGreg Clayton                                      var_list_sp.get());
527d41f032aSGreg Clayton     }
528d41f032aSGreg Clayton 
529d41f032aSGreg Clayton     if (m_sc.comp_unit)
530d41f032aSGreg Clayton     {
531d41f032aSGreg Clayton         VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true));
532d41f032aSGreg Clayton         if (global_variable_list_sp)
533d41f032aSGreg Clayton             var_list_sp->AddVariables (global_variable_list_sp.get());
534d41f032aSGreg Clayton     }
535d41f032aSGreg Clayton 
536d41f032aSGreg Clayton     return var_list_sp;
537d41f032aSGreg Clayton }
538d41f032aSGreg Clayton 
539d41f032aSGreg Clayton 
5408b2fe6dcSGreg Clayton ValueObjectSP
5412837b766SJim Ingham StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
5424d122c40SGreg Clayton                                                DynamicValueType use_dynamic,
5432837b766SJim Ingham                                                uint32_t options,
5444d122c40SGreg Clayton                                                VariableSP &var_sp,
5452837b766SJim Ingham                                                Error &error)
5468b2fe6dcSGreg Clayton {
54754979cddSGreg Clayton 
54854979cddSGreg Clayton     if (var_expr_cstr && var_expr_cstr[0])
54954979cddSGreg Clayton     {
5506d5e68eaSGreg Clayton         const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0;
5516d5e68eaSGreg Clayton         const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
55227b625e1SEnrico Granata         const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
55358ad3344SEnrico Granata         //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0;
55454979cddSGreg Clayton         error.Clear();
5558b2fe6dcSGreg Clayton         bool deref = false;
5568b2fe6dcSGreg Clayton         bool address_of = false;
5578b2fe6dcSGreg Clayton         ValueObjectSP valobj_sp;
5588b2fe6dcSGreg Clayton         const bool get_file_globals = true;
559d41f032aSGreg Clayton         // When looking up a variable for an expression, we need only consider the
560d41f032aSGreg Clayton         // variables that are in scope.
561d41f032aSGreg Clayton         VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals));
562d41f032aSGreg Clayton         VariableList *variable_list = var_list_sp.get();
5638b2fe6dcSGreg Clayton 
5648b2fe6dcSGreg Clayton         if (variable_list)
5658b2fe6dcSGreg Clayton         {
5668b2fe6dcSGreg Clayton             // If first character is a '*', then show pointer contents
56754979cddSGreg Clayton             const char *var_expr = var_expr_cstr;
5688b2fe6dcSGreg Clayton             if (var_expr[0] == '*')
5698b2fe6dcSGreg Clayton             {
5708b2fe6dcSGreg Clayton                 deref = true;
5718b2fe6dcSGreg Clayton                 var_expr++; // Skip the '*'
5728b2fe6dcSGreg Clayton             }
5738b2fe6dcSGreg Clayton             else if (var_expr[0] == '&')
5748b2fe6dcSGreg Clayton             {
5758b2fe6dcSGreg Clayton                 address_of = true;
5768b2fe6dcSGreg Clayton                 var_expr++; // Skip the '&'
5778b2fe6dcSGreg Clayton             }
5788b2fe6dcSGreg Clayton 
5798b2fe6dcSGreg Clayton             std::string var_path (var_expr);
58054979cddSGreg Clayton             size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}");
58154979cddSGreg Clayton             StreamString var_expr_path_strm;
5828b2fe6dcSGreg Clayton 
5838b2fe6dcSGreg Clayton             ConstString name_const_string;
5848b2fe6dcSGreg Clayton             if (separator_idx == std::string::npos)
5858b2fe6dcSGreg Clayton                 name_const_string.SetCString (var_path.c_str());
5868b2fe6dcSGreg Clayton             else
5878b2fe6dcSGreg Clayton                 name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx);
5888b2fe6dcSGreg Clayton 
5892837b766SJim Ingham             var_sp = variable_list->FindVariable(name_const_string);
590685c88c5SGreg Clayton 
591685c88c5SGreg Clayton             bool synthetically_added_instance_object = false;
592685c88c5SGreg Clayton 
593685c88c5SGreg Clayton             if (var_sp)
594685c88c5SGreg Clayton             {
595685c88c5SGreg Clayton                 var_path.erase (0, name_const_string.GetLength ());
596685c88c5SGreg Clayton             }
597685c88c5SGreg Clayton             else if (options & eExpressionPathOptionsAllowDirectIVarAccess)
598685c88c5SGreg Clayton             {
599685c88c5SGreg Clayton                 // Check for direct ivars access which helps us with implicit
600685c88c5SGreg Clayton                 // access to ivars with the "this->" or "self->"
601685c88c5SGreg Clayton                 GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock);
602685c88c5SGreg Clayton                 lldb::LanguageType method_language = eLanguageTypeUnknown;
603685c88c5SGreg Clayton                 bool is_instance_method = false;
604685c88c5SGreg Clayton                 ConstString method_object_name;
605685c88c5SGreg Clayton                 if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name))
606685c88c5SGreg Clayton                 {
607685c88c5SGreg Clayton                     if (is_instance_method && method_object_name)
608685c88c5SGreg Clayton                     {
609685c88c5SGreg Clayton                         var_sp = variable_list->FindVariable(method_object_name);
610685c88c5SGreg Clayton                         if (var_sp)
611685c88c5SGreg Clayton                         {
612685c88c5SGreg Clayton                             separator_idx = 0;
613685c88c5SGreg Clayton                             var_path.insert(0, "->");
614685c88c5SGreg Clayton                             synthetically_added_instance_object = true;
615685c88c5SGreg Clayton                         }
616685c88c5SGreg Clayton                     }
617685c88c5SGreg Clayton                 }
618685c88c5SGreg Clayton             }
619685c88c5SGreg Clayton 
6208b2fe6dcSGreg Clayton             if (var_sp)
6218b2fe6dcSGreg Clayton             {
6222837b766SJim Ingham                 valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic);
62378a685aaSJim Ingham                 if (!valobj_sp)
62478a685aaSJim Ingham                     return valobj_sp;
6258b2fe6dcSGreg Clayton 
6268b2fe6dcSGreg Clayton                 // We are dumping at least one child
6278b2fe6dcSGreg Clayton                 while (separator_idx != std::string::npos)
6288b2fe6dcSGreg Clayton                 {
6298b2fe6dcSGreg Clayton                     // Calculate the next separator index ahead of time
6308b2fe6dcSGreg Clayton                     ValueObjectSP child_valobj_sp;
6318b2fe6dcSGreg Clayton                     const char separator_type = var_path[0];
6328b2fe6dcSGreg Clayton                     switch (separator_type)
6338b2fe6dcSGreg Clayton                     {
6348b2fe6dcSGreg Clayton 
6358b2fe6dcSGreg Clayton                     case '-':
6368b2fe6dcSGreg Clayton                         if (var_path.size() >= 2 && var_path[1] != '>')
6378b2fe6dcSGreg Clayton                             return ValueObjectSP();
6388b2fe6dcSGreg Clayton 
6396d5e68eaSGreg Clayton                         if (no_fragile_ivar)
6406d5e68eaSGreg Clayton                         {
6416d5e68eaSGreg Clayton                             // Make sure we aren't trying to deref an objective
6426d5e68eaSGreg Clayton                             // C ivar if this is not allowed
6436d5e68eaSGreg Clayton                             const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL);
6446d5e68eaSGreg Clayton                             if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) &&
6456d5e68eaSGreg Clayton                                 (pointer_type_flags & ClangASTContext::eTypeIsPointer))
6466d5e68eaSGreg Clayton                             {
6476d5e68eaSGreg Clayton                                 // This was an objective C object pointer and
6486d5e68eaSGreg Clayton                                 // it was requested we skip any fragile ivars
6496d5e68eaSGreg Clayton                                 // so return nothing here
6506d5e68eaSGreg Clayton                                 return ValueObjectSP();
6516d5e68eaSGreg Clayton                             }
6526d5e68eaSGreg Clayton                         }
6538b2fe6dcSGreg Clayton                         var_path.erase (0, 1); // Remove the '-'
6548b2fe6dcSGreg Clayton                         // Fall through
6558b2fe6dcSGreg Clayton                     case '.':
6568b2fe6dcSGreg Clayton                         {
65754979cddSGreg Clayton                             const bool expr_is_ptr = var_path[0] == '>';
6588b2fe6dcSGreg Clayton 
6598b2fe6dcSGreg Clayton                             var_path.erase (0, 1); // Remove the '.' or '>'
6608b2fe6dcSGreg Clayton                             separator_idx = var_path.find_first_of(".-[");
6618b2fe6dcSGreg Clayton                             ConstString child_name;
6628b2fe6dcSGreg Clayton                             if (separator_idx == std::string::npos)
6638b2fe6dcSGreg Clayton                                 child_name.SetCString (var_path.c_str());
6648b2fe6dcSGreg Clayton                             else
6658b2fe6dcSGreg Clayton                                 child_name.SetCStringWithLength(var_path.c_str(), separator_idx);
6668b2fe6dcSGreg Clayton 
66754979cddSGreg Clayton                             if (check_ptr_vs_member)
66854979cddSGreg Clayton                             {
66954979cddSGreg Clayton                                 // We either have a pointer type and need to verify
67054979cddSGreg Clayton                                 // valobj_sp is a pointer, or we have a member of a
67154979cddSGreg Clayton                                 // class/union/struct being accessed with the . syntax
67254979cddSGreg Clayton                                 // and need to verify we don't have a pointer.
67354979cddSGreg Clayton                                 const bool actual_is_ptr = valobj_sp->IsPointerType ();
67454979cddSGreg Clayton 
67554979cddSGreg Clayton                                 if (actual_is_ptr != expr_is_ptr)
67654979cddSGreg Clayton                                 {
67754979cddSGreg Clayton                                     // Incorrect use of "." with a pointer, or "->" with
67854979cddSGreg Clayton                                     // a class/union/struct instance or reference.
6796beaaa68SGreg Clayton                                     valobj_sp->GetExpressionPath (var_expr_path_strm, false);
68054979cddSGreg Clayton                                     if (actual_is_ptr)
68154979cddSGreg Clayton                                         error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?",
68254979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str(),
68354979cddSGreg Clayton                                                                         child_name.GetCString(),
68454979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str(),
68554979cddSGreg Clayton                                                                         var_path.c_str());
68654979cddSGreg Clayton                                     else
68754979cddSGreg Clayton                                         error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?",
68854979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str(),
68954979cddSGreg Clayton                                                                         child_name.GetCString(),
69054979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str(),
69154979cddSGreg Clayton                                                                         var_path.c_str());
69254979cddSGreg Clayton                                     return ValueObjectSP();
69354979cddSGreg Clayton                                 }
69454979cddSGreg Clayton                             }
6958b2fe6dcSGreg Clayton                             child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true);
6968b2fe6dcSGreg Clayton                             if (!child_valobj_sp)
6978b2fe6dcSGreg Clayton                             {
6988c9d3560SEnrico Granata                                 if (no_synth_child == false)
69986cc9829SEnrico Granata                                 {
70086cc9829SEnrico Granata                                     child_valobj_sp = valobj_sp->GetSyntheticValue();
70186cc9829SEnrico Granata                                     if (child_valobj_sp)
70286cc9829SEnrico Granata                                         child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true);
70386cc9829SEnrico Granata                                 }
7048c9d3560SEnrico Granata 
7058c9d3560SEnrico Granata                                 if (no_synth_child || !child_valobj_sp)
7068c9d3560SEnrico Granata                                 {
7078b2fe6dcSGreg Clayton                                     // No child member with name "child_name"
708685c88c5SGreg Clayton                                     if (synthetically_added_instance_object)
709685c88c5SGreg Clayton                                     {
710685c88c5SGreg Clayton                                         // We added a "this->" or "self->" to the beginning of the expression
711685c88c5SGreg Clayton                                         // and this is the first pointer ivar access, so just return the normal
712685c88c5SGreg Clayton                                         // error
713685c88c5SGreg Clayton                                         error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame",
714685c88c5SGreg Clayton                                                                        name_const_string.GetCString());
715685c88c5SGreg Clayton                                     }
716685c88c5SGreg Clayton                                     else
717685c88c5SGreg Clayton                                     {
7186beaaa68SGreg Clayton                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
71954979cddSGreg Clayton                                         if (child_name)
72054979cddSGreg Clayton                                         {
72154979cddSGreg Clayton                                             error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"",
72254979cddSGreg Clayton                                                                             child_name.GetCString(),
72354979cddSGreg Clayton                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
72454979cddSGreg Clayton                                                                             var_expr_path_strm.GetString().c_str());
72554979cddSGreg Clayton                                         }
72654979cddSGreg Clayton                                         else
72754979cddSGreg Clayton                                         {
72854979cddSGreg Clayton                                             error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"",
72954979cddSGreg Clayton                                                                             var_expr_path_strm.GetString().c_str(),
73054979cddSGreg Clayton                                                                             var_expr_cstr);
73154979cddSGreg Clayton                                         }
732685c88c5SGreg Clayton                                     }
7338b2fe6dcSGreg Clayton                                     return ValueObjectSP();
7348b2fe6dcSGreg Clayton                                 }
7358c9d3560SEnrico Granata                             }
736685c88c5SGreg Clayton                             synthetically_added_instance_object = false;
7378b2fe6dcSGreg Clayton                             // Remove the child name from the path
7388b2fe6dcSGreg Clayton                             var_path.erase(0, child_name.GetLength());
7394d122c40SGreg Clayton                             if (use_dynamic != eNoDynamicValues)
74078a685aaSJim Ingham                             {
7412837b766SJim Ingham                                 ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
74278a685aaSJim Ingham                                 if (dynamic_value_sp)
74378a685aaSJim Ingham                                     child_valobj_sp = dynamic_value_sp;
74478a685aaSJim Ingham                             }
7458b2fe6dcSGreg Clayton                         }
7468b2fe6dcSGreg Clayton                         break;
7478b2fe6dcSGreg Clayton 
7488b2fe6dcSGreg Clayton                     case '[':
7498b2fe6dcSGreg Clayton                         // Array member access, or treating pointer as an array
7508b2fe6dcSGreg Clayton                         if (var_path.size() > 2) // Need at least two brackets and a number
7518b2fe6dcSGreg Clayton                         {
7528b2fe6dcSGreg Clayton                             char *end = NULL;
7531a65ae11SGreg Clayton                             long child_index = ::strtol (&var_path[1], &end, 0);
7549fc1944eSEnrico Granata                             if (end && *end == ']'
7559fc1944eSEnrico Granata                                 && *(end-1) != '[') // this code forces an error in the case of arr[]. as bitfield[] is not a good syntax we're good to go
7568b2fe6dcSGreg Clayton                             {
7579fc1944eSEnrico Granata                                 if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
7589fc1944eSEnrico Granata                                 {
7599fc1944eSEnrico Granata                                     // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr
7609fc1944eSEnrico Granata                                     // and extract bit low out of it. reading array item low
7619fc1944eSEnrico Granata                                     // would be done by saying ptr[low], without a deref * sign
7629fc1944eSEnrico Granata                                     Error error;
7639fc1944eSEnrico Granata                                     ValueObjectSP temp(valobj_sp->Dereference(error));
7649fc1944eSEnrico Granata                                     if (error.Fail())
7659fc1944eSEnrico Granata                                     {
7669fc1944eSEnrico Granata                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
7679fc1944eSEnrico Granata                                         error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
7689fc1944eSEnrico Granata                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
7699fc1944eSEnrico Granata                                                                         var_expr_path_strm.GetString().c_str());
7709fc1944eSEnrico Granata                                         return ValueObjectSP();
7719fc1944eSEnrico Granata                                     }
7729fc1944eSEnrico Granata                                     valobj_sp = temp;
7739fc1944eSEnrico Granata                                     deref = false;
7749fc1944eSEnrico Granata                                 }
7759fc1944eSEnrico Granata                                 else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
7769fc1944eSEnrico Granata                                 {
7779fc1944eSEnrico Granata                                     // what we have is *arr[low]. the most similar C++ syntax is to get arr[0]
7789fc1944eSEnrico Granata                                     // (an operation that is equivalent to deref-ing arr)
7799fc1944eSEnrico Granata                                     // and extract bit low out of it. reading array item low
7809fc1944eSEnrico Granata                                     // would be done by saying arr[low], without a deref * sign
7819fc1944eSEnrico Granata                                     Error error;
7829fc1944eSEnrico Granata                                     ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
7839fc1944eSEnrico Granata                                     if (error.Fail())
7849fc1944eSEnrico Granata                                     {
7859fc1944eSEnrico Granata                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
7869fc1944eSEnrico Granata                                         error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
7879fc1944eSEnrico Granata                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
7889fc1944eSEnrico Granata                                                                         var_expr_path_strm.GetString().c_str());
7899fc1944eSEnrico Granata                                         return ValueObjectSP();
7909fc1944eSEnrico Granata                                     }
7919fc1944eSEnrico Granata                                     valobj_sp = temp;
7929fc1944eSEnrico Granata                                     deref = false;
7939fc1944eSEnrico Granata                                 }
7948b2fe6dcSGreg Clayton 
795*4ef877f5SGreg Clayton                                 bool is_incomplete_array = false;
7968b2fe6dcSGreg Clayton                                 if (valobj_sp->IsPointerType ())
7978b2fe6dcSGreg Clayton                                 {
798226b70c1SSean Callanan                                     bool is_objc_pointer = true;
799226b70c1SSean Callanan 
800226b70c1SSean Callanan                                     if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC)
801226b70c1SSean Callanan                                         is_objc_pointer = false;
802226b70c1SSean Callanan                                     else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType()))
803226b70c1SSean Callanan                                         is_objc_pointer = false;
804226b70c1SSean Callanan 
805226b70c1SSean Callanan                                     if (no_synth_child && is_objc_pointer)
806226b70c1SSean Callanan                                     {
807226b70c1SSean Callanan                                         error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted",
808226b70c1SSean Callanan                                                                        valobj_sp->GetTypeName().AsCString("<invalid type>"),
809226b70c1SSean Callanan                                                                        var_expr_path_strm.GetString().c_str());
810226b70c1SSean Callanan 
811226b70c1SSean Callanan                                         return ValueObjectSP();
812226b70c1SSean Callanan                                     }
813226b70c1SSean Callanan                                     else if (is_objc_pointer)
81427b625e1SEnrico Granata                                     {
81527b625e1SEnrico Granata                                         // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children
81686cc9829SEnrico Granata                                         ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
81727b625e1SEnrico Granata                                         if (synthetic.get() == NULL /* no synthetic */
81827b625e1SEnrico Granata                                             || synthetic == valobj_sp) /* synthetic is the same as the original object */
81927b625e1SEnrico Granata                                         {
82027b625e1SEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
82127b625e1SEnrico Granata                                             error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
82227b625e1SEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
82327b625e1SEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
82427b625e1SEnrico Granata                                         }
82527b625e1SEnrico Granata                                         else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
82627b625e1SEnrico Granata                                         {
82727b625e1SEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
8287e589a60SJason Molenda                                             error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
82927b625e1SEnrico Granata                                                                             child_index,
83027b625e1SEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
83127b625e1SEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
83227b625e1SEnrico Granata                                         }
83327b625e1SEnrico Granata                                         else
83427b625e1SEnrico Granata                                         {
83527b625e1SEnrico Granata                                             child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
83627b625e1SEnrico Granata                                             if (!child_valobj_sp)
83727b625e1SEnrico Granata                                             {
83827b625e1SEnrico Granata                                                 valobj_sp->GetExpressionPath (var_expr_path_strm, false);
8397e589a60SJason Molenda                                                 error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
84027b625e1SEnrico Granata                                                                                 child_index,
84127b625e1SEnrico Granata                                                                                 valobj_sp->GetTypeName().AsCString("<invalid type>"),
84227b625e1SEnrico Granata                                                                                 var_expr_path_strm.GetString().c_str());
84327b625e1SEnrico Granata                                             }
84427b625e1SEnrico Granata                                         }
84527b625e1SEnrico Granata                                     }
84627b625e1SEnrico Granata                                     else
84727b625e1SEnrico Granata                                     {
8488b2fe6dcSGreg Clayton                                         child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true);
84954979cddSGreg Clayton                                         if (!child_valobj_sp)
85054979cddSGreg Clayton                                         {
8516beaaa68SGreg Clayton                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
8527e589a60SJason Molenda                                             error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
85354979cddSGreg Clayton                                                                             child_index,
85454979cddSGreg Clayton                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
85554979cddSGreg Clayton                                                                             var_expr_path_strm.GetString().c_str());
85654979cddSGreg Clayton                                         }
85754979cddSGreg Clayton                                     }
85827b625e1SEnrico Granata                                 }
859*4ef877f5SGreg Clayton                                 else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL, &is_incomplete_array))
86054979cddSGreg Clayton                                 {
86178a685aaSJim Ingham                                     // Pass false to dynamic_value here so we can tell the difference between
86278a685aaSJim Ingham                                     // no dynamic value and no member of this type...
86354979cddSGreg Clayton                                     child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true);
864*4ef877f5SGreg Clayton                                     if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false))
865*4ef877f5SGreg Clayton                                         child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true);
866*4ef877f5SGreg Clayton 
86754979cddSGreg Clayton                                     if (!child_valobj_sp)
86854979cddSGreg Clayton                                     {
8696beaaa68SGreg Clayton                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
8707e589a60SJason Molenda                                         error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
87154979cddSGreg Clayton                                                                         child_index,
87254979cddSGreg Clayton                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
87354979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str());
87454979cddSGreg Clayton                                     }
8758b2fe6dcSGreg Clayton                                 }
8769fc1944eSEnrico Granata                                 else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType()))
8779fc1944eSEnrico Granata                                 {
8789fc1944eSEnrico Granata                                     // this is a bitfield asking to display just one bit
8799fc1944eSEnrico Granata                                     child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true);
8809fc1944eSEnrico Granata                                     if (!child_valobj_sp)
8819fc1944eSEnrico Granata                                     {
8829fc1944eSEnrico Granata                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
8837e589a60SJason Molenda                                         error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
8849fc1944eSEnrico Granata                                                                         child_index, child_index,
8859fc1944eSEnrico Granata                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
8869fc1944eSEnrico Granata                                                                         var_expr_path_strm.GetString().c_str());
8879fc1944eSEnrico Granata                                     }
8889fc1944eSEnrico Granata                                 }
8898b2fe6dcSGreg Clayton                                 else
8908b2fe6dcSGreg Clayton                                 {
89186cc9829SEnrico Granata                                     ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
89227b625e1SEnrico Granata                                     if (no_synth_child /* synthetic is forbidden */ ||
89327b625e1SEnrico Granata                                         synthetic.get() == NULL /* no synthetic */
89427b625e1SEnrico Granata                                         || synthetic == valobj_sp) /* synthetic is the same as the original object */
89527b625e1SEnrico Granata                                     {
8966beaaa68SGreg Clayton                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
89754979cddSGreg Clayton                                         error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type",
89854979cddSGreg Clayton                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
89954979cddSGreg Clayton                                                                         var_expr_path_strm.GetString().c_str());
9008b2fe6dcSGreg Clayton                                     }
90127b625e1SEnrico Granata                                     else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
90227b625e1SEnrico Granata                                     {
90327b625e1SEnrico Granata                                         valobj_sp->GetExpressionPath (var_expr_path_strm, false);
9047e589a60SJason Molenda                                         error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
90527b625e1SEnrico Granata                                                                         child_index,
90627b625e1SEnrico Granata                                                                         valobj_sp->GetTypeName().AsCString("<invalid type>"),
90727b625e1SEnrico Granata                                                                         var_expr_path_strm.GetString().c_str());
90827b625e1SEnrico Granata                                     }
90927b625e1SEnrico Granata                                     else
91027b625e1SEnrico Granata                                     {
91127b625e1SEnrico Granata                                         child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
91227b625e1SEnrico Granata                                         if (!child_valobj_sp)
91327b625e1SEnrico Granata                                         {
91427b625e1SEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
9157e589a60SJason Molenda                                             error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
91627b625e1SEnrico Granata                                                                             child_index,
91727b625e1SEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
91827b625e1SEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
91927b625e1SEnrico Granata                                         }
92027b625e1SEnrico Granata                                     }
92127b625e1SEnrico Granata                                 }
9228b2fe6dcSGreg Clayton 
9238b2fe6dcSGreg Clayton                                 if (!child_valobj_sp)
9248b2fe6dcSGreg Clayton                                 {
9258b2fe6dcSGreg Clayton                                     // Invalid array index...
9268b2fe6dcSGreg Clayton                                     return ValueObjectSP();
9278b2fe6dcSGreg Clayton                                 }
9288b2fe6dcSGreg Clayton 
9298b2fe6dcSGreg Clayton                                 // Erase the array member specification '[%i]' where
9308b2fe6dcSGreg Clayton                                 // %i is the array index
9318b2fe6dcSGreg Clayton                                 var_path.erase(0, (end - var_path.c_str()) + 1);
9328b2fe6dcSGreg Clayton                                 separator_idx = var_path.find_first_of(".-[");
9334d122c40SGreg Clayton                                 if (use_dynamic != eNoDynamicValues)
93478a685aaSJim Ingham                                 {
9352837b766SJim Ingham                                     ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
93678a685aaSJim Ingham                                     if (dynamic_value_sp)
93778a685aaSJim Ingham                                         child_valobj_sp = dynamic_value_sp;
93878a685aaSJim Ingham                                 }
9398b2fe6dcSGreg Clayton                                 // Break out early from the switch since we were
9408b2fe6dcSGreg Clayton                                 // able to find the child member
9418b2fe6dcSGreg Clayton                                 break;
9428b2fe6dcSGreg Clayton                             }
9439fc1944eSEnrico Granata                             else if (end && *end == '-')
9449fc1944eSEnrico Granata                             {
9459fc1944eSEnrico Granata                                 // this is most probably a BitField, let's take a look
9469fc1944eSEnrico Granata                                 char *real_end = NULL;
9479fc1944eSEnrico Granata                                 long final_index = ::strtol (end+1, &real_end, 0);
948d64d0bc0SEnrico Granata                                 bool expand_bitfield = true;
9499fc1944eSEnrico Granata                                 if (real_end && *real_end == ']')
9509fc1944eSEnrico Granata                                 {
9519fc1944eSEnrico Granata                                     // if the format given is [high-low], swap range
9529fc1944eSEnrico Granata                                     if (child_index > final_index)
9539fc1944eSEnrico Granata                                     {
9549fc1944eSEnrico Granata                                         long temp = child_index;
9559fc1944eSEnrico Granata                                         child_index = final_index;
9569fc1944eSEnrico Granata                                         final_index = temp;
9579fc1944eSEnrico Granata                                     }
9589fc1944eSEnrico Granata 
9599fc1944eSEnrico Granata                                     if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref)
9609fc1944eSEnrico Granata                                     {
9619fc1944eSEnrico Granata                                         // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr
9629fc1944eSEnrico Granata                                         // and extract bits low thru high out of it. reading array items low thru high
9639fc1944eSEnrico Granata                                         // would be done by saying ptr[low-high], without a deref * sign
9649fc1944eSEnrico Granata                                         Error error;
9659fc1944eSEnrico Granata                                         ValueObjectSP temp(valobj_sp->Dereference(error));
9669fc1944eSEnrico Granata                                         if (error.Fail())
9679fc1944eSEnrico Granata                                         {
9689fc1944eSEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
9699fc1944eSEnrico Granata                                             error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"",
9709fc1944eSEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
9719fc1944eSEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
9729fc1944eSEnrico Granata                                             return ValueObjectSP();
9739fc1944eSEnrico Granata                                         }
9749fc1944eSEnrico Granata                                         valobj_sp = temp;
9759fc1944eSEnrico Granata                                         deref = false;
9769fc1944eSEnrico Granata                                     }
9779fc1944eSEnrico Granata                                     else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref)
9789fc1944eSEnrico Granata                                     {
9799fc1944eSEnrico Granata                                         // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0]
9809fc1944eSEnrico Granata                                         // (an operation that is equivalent to deref-ing arr)
9819fc1944eSEnrico Granata                                         // and extract bits low thru high out of it. reading array items low thru high
9829fc1944eSEnrico Granata                                         // would be done by saying arr[low-high], without a deref * sign
9839fc1944eSEnrico Granata                                         Error error;
9849fc1944eSEnrico Granata                                         ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true));
9859fc1944eSEnrico Granata                                         if (error.Fail())
9869fc1944eSEnrico Granata                                         {
9879fc1944eSEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
9889fc1944eSEnrico Granata                                             error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"",
9899fc1944eSEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
9909fc1944eSEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
9919fc1944eSEnrico Granata                                             return ValueObjectSP();
9929fc1944eSEnrico Granata                                         }
9939fc1944eSEnrico Granata                                         valobj_sp = temp;
9949fc1944eSEnrico Granata                                         deref = false;
9959fc1944eSEnrico Granata                                     }
996d64d0bc0SEnrico Granata                                     /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType())
997d64d0bc0SEnrico Granata                                     {
998d64d0bc0SEnrico Granata                                         child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true);
999d64d0bc0SEnrico Granata                                         expand_bitfield = false;
1000d64d0bc0SEnrico Granata                                         if (!child_valobj_sp)
1001d64d0bc0SEnrico Granata                                         {
1002d64d0bc0SEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
1003d64d0bc0SEnrico Granata                                             error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"",
1004d64d0bc0SEnrico Granata                                                                             child_index, final_index,
1005d64d0bc0SEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
1006d64d0bc0SEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
1007d64d0bc0SEnrico Granata                                         }
1008d64d0bc0SEnrico Granata                                     }*/
10099fc1944eSEnrico Granata 
1010d64d0bc0SEnrico Granata                                     if (expand_bitfield)
1011d64d0bc0SEnrico Granata                                     {
10129fc1944eSEnrico Granata                                         child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
10139fc1944eSEnrico Granata                                         if (!child_valobj_sp)
10149fc1944eSEnrico Granata                                         {
10159fc1944eSEnrico Granata                                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
10167e589a60SJason Molenda                                             error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
10179fc1944eSEnrico Granata                                                                             child_index, final_index,
10189fc1944eSEnrico Granata                                                                             valobj_sp->GetTypeName().AsCString("<invalid type>"),
10199fc1944eSEnrico Granata                                                                             var_expr_path_strm.GetString().c_str());
10209fc1944eSEnrico Granata                                         }
10219fc1944eSEnrico Granata                                     }
1022d64d0bc0SEnrico Granata                                 }
10239fc1944eSEnrico Granata 
10249fc1944eSEnrico Granata                                 if (!child_valobj_sp)
10259fc1944eSEnrico Granata                                 {
10269fc1944eSEnrico Granata                                     // Invalid bitfield range...
10279fc1944eSEnrico Granata                                     return ValueObjectSP();
10289fc1944eSEnrico Granata                                 }
10299fc1944eSEnrico Granata 
10309fc1944eSEnrico Granata                                 // Erase the bitfield member specification '[%i-%i]' where
10319fc1944eSEnrico Granata                                 // %i is the index
10329fc1944eSEnrico Granata                                 var_path.erase(0, (real_end - var_path.c_str()) + 1);
10339fc1944eSEnrico Granata                                 separator_idx = var_path.find_first_of(".-[");
10344d122c40SGreg Clayton                                 if (use_dynamic != eNoDynamicValues)
10359fc1944eSEnrico Granata                                 {
10369fc1944eSEnrico Granata                                     ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic));
10379fc1944eSEnrico Granata                                     if (dynamic_value_sp)
10389fc1944eSEnrico Granata                                         child_valobj_sp = dynamic_value_sp;
10399fc1944eSEnrico Granata                                 }
10409fc1944eSEnrico Granata                                 // Break out early from the switch since we were
10419fc1944eSEnrico Granata                                 // able to find the child member
10429fc1944eSEnrico Granata                                 break;
10439fc1944eSEnrico Granata 
10449fc1944eSEnrico Granata                             }
10459fc1944eSEnrico Granata                         }
10469fc1944eSEnrico Granata                         else
10479fc1944eSEnrico Granata                         {
10489fc1944eSEnrico Granata                             error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"",
10499fc1944eSEnrico Granata                                                            var_expr_path_strm.GetString().c_str(),
10509fc1944eSEnrico Granata                                                            var_path.c_str());
10518b2fe6dcSGreg Clayton                         }
10528b2fe6dcSGreg Clayton                         return ValueObjectSP();
10538b2fe6dcSGreg Clayton 
10548b2fe6dcSGreg Clayton                     default:
10558b2fe6dcSGreg Clayton                         // Failure...
105654979cddSGreg Clayton                         {
10576beaaa68SGreg Clayton                             valobj_sp->GetExpressionPath (var_expr_path_strm, false);
105854979cddSGreg Clayton                             error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"",
105954979cddSGreg Clayton                                                             separator_type,
106054979cddSGreg Clayton                                                             var_expr_path_strm.GetString().c_str(),
106154979cddSGreg Clayton                                                             var_path.c_str());
106254979cddSGreg Clayton 
10638b2fe6dcSGreg Clayton                             return ValueObjectSP();
10648b2fe6dcSGreg Clayton                         }
106554979cddSGreg Clayton                     }
10668b2fe6dcSGreg Clayton 
10678b2fe6dcSGreg Clayton                     if (child_valobj_sp)
10688b2fe6dcSGreg Clayton                         valobj_sp = child_valobj_sp;
10698b2fe6dcSGreg Clayton 
10708b2fe6dcSGreg Clayton                     if (var_path.empty())
10718b2fe6dcSGreg Clayton                         break;
10728b2fe6dcSGreg Clayton 
10738b2fe6dcSGreg Clayton                 }
10748b2fe6dcSGreg Clayton                 if (valobj_sp)
10758b2fe6dcSGreg Clayton                 {
10768b2fe6dcSGreg Clayton                     if (deref)
10778b2fe6dcSGreg Clayton                     {
1078af67cecdSGreg Clayton                         ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error));
10798b2fe6dcSGreg Clayton                         valobj_sp = deref_valobj_sp;
10808b2fe6dcSGreg Clayton                     }
10818b2fe6dcSGreg Clayton                     else if (address_of)
10828b2fe6dcSGreg Clayton                     {
108354979cddSGreg Clayton                         ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error));
10848b2fe6dcSGreg Clayton                         valobj_sp = address_of_valobj_sp;
10858b2fe6dcSGreg Clayton                     }
10868b2fe6dcSGreg Clayton                 }
10878b2fe6dcSGreg Clayton                 return valobj_sp;
10888b2fe6dcSGreg Clayton             }
108954979cddSGreg Clayton             else
109054979cddSGreg Clayton             {
10912837b766SJim Ingham                 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
10922837b766SJim Ingham                                                name_const_string.GetCString());
109354979cddSGreg Clayton             }
109454979cddSGreg Clayton         }
109554979cddSGreg Clayton     }
109654979cddSGreg Clayton     else
109754979cddSGreg Clayton     {
109854979cddSGreg Clayton         error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr);
10998b2fe6dcSGreg Clayton     }
11008b2fe6dcSGreg Clayton     return ValueObjectSP();
11018b2fe6dcSGreg Clayton }
110230fdc8d8SChris Lattner 
110330fdc8d8SChris Lattner bool
110430fdc8d8SChris Lattner StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr)
110530fdc8d8SChris Lattner {
110630fdc8d8SChris Lattner     if (m_flags.IsClear(GOT_FRAME_BASE))
110730fdc8d8SChris Lattner     {
110830fdc8d8SChris Lattner         if (m_sc.function)
110930fdc8d8SChris Lattner         {
111030fdc8d8SChris Lattner             m_frame_base.Clear();
111130fdc8d8SChris Lattner             m_frame_base_error.Clear();
111230fdc8d8SChris Lattner 
111330fdc8d8SChris Lattner             m_flags.Set(GOT_FRAME_BASE);
1114d9e416c0SGreg Clayton             ExecutionContext exe_ctx (shared_from_this());
111530fdc8d8SChris Lattner             Value expr_value;
1116016a95ebSGreg Clayton             addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1117016a95ebSGreg Clayton             if (m_sc.function->GetFrameBaseExpression().IsLocationList())
1118d9e416c0SGreg Clayton                 loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr());
1119016a95ebSGreg Clayton 
11201a65ae11SGreg Clayton             if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false)
112130fdc8d8SChris Lattner             {
112230fdc8d8SChris Lattner                 // We should really have an error if evaluate returns, but in case
112330fdc8d8SChris Lattner                 // we don't, lets set the error to something at least.
112430fdc8d8SChris Lattner                 if (m_frame_base_error.Success())
112530fdc8d8SChris Lattner                     m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed.");
112630fdc8d8SChris Lattner             }
112730fdc8d8SChris Lattner             else
112830fdc8d8SChris Lattner             {
112930fdc8d8SChris Lattner                 m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL);
113030fdc8d8SChris Lattner             }
113130fdc8d8SChris Lattner         }
113230fdc8d8SChris Lattner         else
113330fdc8d8SChris Lattner         {
113430fdc8d8SChris Lattner             m_frame_base_error.SetErrorString ("No function in symbol context.");
113530fdc8d8SChris Lattner         }
113630fdc8d8SChris Lattner     }
113730fdc8d8SChris Lattner 
113830fdc8d8SChris Lattner     if (m_frame_base_error.Success())
113930fdc8d8SChris Lattner         frame_base = m_frame_base;
114030fdc8d8SChris Lattner 
114130fdc8d8SChris Lattner     if (error_ptr)
114230fdc8d8SChris Lattner         *error_ptr = m_frame_base_error;
114330fdc8d8SChris Lattner     return m_frame_base_error.Success();
114430fdc8d8SChris Lattner }
114530fdc8d8SChris Lattner 
11465ccbd294SGreg Clayton RegisterContextSP
114730fdc8d8SChris Lattner StackFrame::GetRegisterContext ()
114830fdc8d8SChris Lattner {
11495ccbd294SGreg Clayton     if (!m_reg_context_sp)
1150d9e416c0SGreg Clayton     {
1151d9e416c0SGreg Clayton         ThreadSP thread_sp (GetThread());
1152d9e416c0SGreg Clayton         if (thread_sp)
1153d9e416c0SGreg Clayton             m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this);
1154d9e416c0SGreg Clayton     }
11555ccbd294SGreg Clayton     return m_reg_context_sp;
115630fdc8d8SChris Lattner }
115730fdc8d8SChris Lattner 
115830fdc8d8SChris Lattner bool
115930fdc8d8SChris Lattner StackFrame::HasDebugInformation ()
116030fdc8d8SChris Lattner {
116130fdc8d8SChris Lattner     GetSymbolContext (eSymbolContextLineEntry);
116230fdc8d8SChris Lattner     return m_sc.line_entry.IsValid();
116330fdc8d8SChris Lattner }
116430fdc8d8SChris Lattner 
1165288bdf9cSGreg Clayton 
1166288bdf9cSGreg Clayton ValueObjectSP
11674d122c40SGreg Clayton StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
116830fdc8d8SChris Lattner {
1169288bdf9cSGreg Clayton     ValueObjectSP valobj_sp;
1170288bdf9cSGreg Clayton     VariableList *var_list = GetVariableList (true);
1171288bdf9cSGreg Clayton     if (var_list)
1172288bdf9cSGreg Clayton     {
1173288bdf9cSGreg Clayton         // Make sure the variable is a frame variable
1174288bdf9cSGreg Clayton         const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get());
1175288bdf9cSGreg Clayton         const uint32_t num_variables = var_list->GetSize();
1176288bdf9cSGreg Clayton         if (var_idx < num_variables)
1177288bdf9cSGreg Clayton         {
1178288bdf9cSGreg Clayton             valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx);
1179288bdf9cSGreg Clayton             if (valobj_sp.get() == NULL)
1180288bdf9cSGreg Clayton             {
1181288bdf9cSGreg Clayton                 if (m_variable_list_value_objects.GetSize() < num_variables)
1182288bdf9cSGreg Clayton                     m_variable_list_value_objects.Resize(num_variables);
118358b59f95SJim Ingham                 valobj_sp = ValueObjectVariable::Create (this, variable_sp);
1184288bdf9cSGreg Clayton                 m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp);
1185288bdf9cSGreg Clayton             }
1186288bdf9cSGreg Clayton         }
1187288bdf9cSGreg Clayton     }
11884d122c40SGreg Clayton     if (use_dynamic != eNoDynamicValues && valobj_sp)
118978a685aaSJim Ingham     {
11902837b766SJim Ingham         ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic);
119178a685aaSJim Ingham         if (dynamic_sp)
119278a685aaSJim Ingham             return dynamic_sp;
119378a685aaSJim Ingham     }
1194288bdf9cSGreg Clayton     return valobj_sp;
1195288bdf9cSGreg Clayton }
1196288bdf9cSGreg Clayton 
1197288bdf9cSGreg Clayton ValueObjectSP
11984d122c40SGreg Clayton StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic)
1199288bdf9cSGreg Clayton {
1200288bdf9cSGreg Clayton     // Check to make sure we aren't already tracking this variable?
120178a685aaSJim Ingham     ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic));
1202288bdf9cSGreg Clayton     if (!valobj_sp)
1203288bdf9cSGreg Clayton     {
1204288bdf9cSGreg Clayton         // We aren't already tracking this global
1205288bdf9cSGreg Clayton         VariableList *var_list = GetVariableList (true);
1206288bdf9cSGreg Clayton         // If this frame has no variables, create a new list
1207288bdf9cSGreg Clayton         if (var_list == NULL)
1208288bdf9cSGreg Clayton             m_variable_list_sp.reset (new VariableList());
1209288bdf9cSGreg Clayton 
1210288bdf9cSGreg Clayton         // Add the global/static variable to this frame
1211288bdf9cSGreg Clayton         m_variable_list_sp->AddVariable (variable_sp);
1212288bdf9cSGreg Clayton 
1213288bdf9cSGreg Clayton         // Now make a value object for it so we can track its changes
121478a685aaSJim Ingham         valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic);
1215288bdf9cSGreg Clayton     }
1216288bdf9cSGreg Clayton     return valobj_sp;
121730fdc8d8SChris Lattner }
121830fdc8d8SChris Lattner 
12196b8379c4SJim Ingham bool
12206b8379c4SJim Ingham StackFrame::IsInlined ()
12216b8379c4SJim Ingham {
122259e8fc1cSGreg Clayton     if (m_sc.block == NULL)
122359e8fc1cSGreg Clayton         GetSymbolContext (eSymbolContextBlock);
122459e8fc1cSGreg Clayton     if (m_sc.block)
122559e8fc1cSGreg Clayton         return m_sc.block->GetContainingInlinedBlock() != NULL;
122659e8fc1cSGreg Clayton     return false;
12276b8379c4SJim Ingham }
12286b8379c4SJim Ingham 
1229d9e416c0SGreg Clayton TargetSP
123030fdc8d8SChris Lattner StackFrame::CalculateTarget ()
123130fdc8d8SChris Lattner {
1232d9e416c0SGreg Clayton     TargetSP target_sp;
1233d9e416c0SGreg Clayton     ThreadSP thread_sp(GetThread());
1234d9e416c0SGreg Clayton     if (thread_sp)
1235d9e416c0SGreg Clayton     {
1236d9e416c0SGreg Clayton         ProcessSP process_sp (thread_sp->CalculateProcess());
1237d9e416c0SGreg Clayton         if (process_sp)
1238d9e416c0SGreg Clayton             target_sp = process_sp->CalculateTarget();
1239d9e416c0SGreg Clayton     }
1240d9e416c0SGreg Clayton     return target_sp;
124130fdc8d8SChris Lattner }
124230fdc8d8SChris Lattner 
1243d9e416c0SGreg Clayton ProcessSP
124430fdc8d8SChris Lattner StackFrame::CalculateProcess ()
124530fdc8d8SChris Lattner {
1246d9e416c0SGreg Clayton     ProcessSP process_sp;
1247d9e416c0SGreg Clayton     ThreadSP thread_sp(GetThread());
1248d9e416c0SGreg Clayton     if (thread_sp)
1249d9e416c0SGreg Clayton         process_sp = thread_sp->CalculateProcess();
1250d9e416c0SGreg Clayton     return process_sp;
125130fdc8d8SChris Lattner }
125230fdc8d8SChris Lattner 
1253d9e416c0SGreg Clayton ThreadSP
125430fdc8d8SChris Lattner StackFrame::CalculateThread ()
125530fdc8d8SChris Lattner {
1256d9e416c0SGreg Clayton     return GetThread();
125730fdc8d8SChris Lattner }
125830fdc8d8SChris Lattner 
1259d9e416c0SGreg Clayton StackFrameSP
126030fdc8d8SChris Lattner StackFrame::CalculateStackFrame ()
126130fdc8d8SChris Lattner {
1262d9e416c0SGreg Clayton     return shared_from_this();
126330fdc8d8SChris Lattner }
126430fdc8d8SChris Lattner 
126530fdc8d8SChris Lattner 
126630fdc8d8SChris Lattner void
12670603aa9dSGreg Clayton StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
126830fdc8d8SChris Lattner {
1269d9e416c0SGreg Clayton     exe_ctx.SetContext (shared_from_this());
127030fdc8d8SChris Lattner }
127130fdc8d8SChris Lattner 
127230fdc8d8SChris Lattner void
12730603aa9dSGreg Clayton StackFrame::DumpUsingSettingsFormat (Stream *strm)
12740603aa9dSGreg Clayton {
12750603aa9dSGreg Clayton     if (strm == NULL)
12760603aa9dSGreg Clayton         return;
12770603aa9dSGreg Clayton 
12780603aa9dSGreg Clayton     GetSymbolContext(eSymbolContextEverything);
1279d9e416c0SGreg Clayton     ExecutionContext exe_ctx (shared_from_this());
12800603aa9dSGreg Clayton     const char *end = NULL;
12810603aa9dSGreg Clayton     StreamString s;
1282d9e416c0SGreg Clayton     const char *frame_format = NULL;
1283d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1284d9e416c0SGreg Clayton     if (target)
1285d9e416c0SGreg Clayton         frame_format = target->GetDebugger().GetFrameFormat();
12860603aa9dSGreg Clayton     if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
12870603aa9dSGreg Clayton     {
12880603aa9dSGreg Clayton         strm->Write(s.GetData(), s.GetSize());
12890603aa9dSGreg Clayton     }
12900603aa9dSGreg Clayton     else
12910603aa9dSGreg Clayton     {
12920603aa9dSGreg Clayton         Dump (strm, true, false);
12930603aa9dSGreg Clayton         strm->EOL();
12940603aa9dSGreg Clayton     }
12950603aa9dSGreg Clayton }
12960603aa9dSGreg Clayton 
12970603aa9dSGreg Clayton void
12986dadd508SGreg Clayton StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
129930fdc8d8SChris Lattner {
130030fdc8d8SChris Lattner     if (strm == NULL)
130130fdc8d8SChris Lattner         return;
130230fdc8d8SChris Lattner 
130330fdc8d8SChris Lattner     if (show_frame_index)
13041b72fcb7SGreg Clayton         strm->Printf("frame #%u: ", m_frame_index);
1305d9e416c0SGreg Clayton     ExecutionContext exe_ctx (shared_from_this());
1306d9e416c0SGreg Clayton     Target *target = exe_ctx.GetTargetPtr();
1307d01b2953SDaniel Malea     strm->Printf("0x%0*" PRIx64 " ",
1308d9e416c0SGreg Clayton                  target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16,
1309d9e416c0SGreg Clayton                  GetFrameCodeAddress().GetLoadAddress(target));
13109da7bd07SGreg Clayton     GetSymbolContext(eSymbolContextEverything);
13111b72fcb7SGreg Clayton     const bool show_module = true;
13121b72fcb7SGreg Clayton     const bool show_inline = true;
1313d9e416c0SGreg Clayton     m_sc.DumpStopContext (strm,
1314d9e416c0SGreg Clayton                           exe_ctx.GetBestExecutionContextScope(),
1315d9e416c0SGreg Clayton                           GetFrameCodeAddress(),
1316d9e416c0SGreg Clayton                           show_fullpaths,
1317d9e416c0SGreg Clayton                           show_module,
1318d9e416c0SGreg Clayton                           show_inline);
131930fdc8d8SChris Lattner }
132030fdc8d8SChris Lattner 
13215082c5fdSGreg Clayton void
132259e8fc1cSGreg Clayton StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame)
13235082c5fdSGreg Clayton {
132459e8fc1cSGreg Clayton     assert (GetStackID() == prev_frame.GetStackID());    // TODO: remove this after some testing
132559e8fc1cSGreg Clayton     m_variable_list_sp = prev_frame.m_variable_list_sp;
1326288bdf9cSGreg Clayton     m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects);
132768275d5eSGreg Clayton     if (!m_disassembly.GetString().empty())
132868275d5eSGreg Clayton         m_disassembly.GetString().swap (m_disassembly.GetString());
13295082c5fdSGreg Clayton }
133068275d5eSGreg Clayton 
133168275d5eSGreg Clayton 
133259e8fc1cSGreg Clayton void
133359e8fc1cSGreg Clayton StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame)
133459e8fc1cSGreg Clayton {
133559e8fc1cSGreg Clayton     assert (GetStackID() == curr_frame.GetStackID());        // TODO: remove this after some testing
13362cad65a5SGreg Clayton     m_id.SetPC (curr_frame.m_id.GetPC());       // Update the Stack ID PC value
1337d9e416c0SGreg Clayton     assert (GetThread() == curr_frame.GetThread());
133859e8fc1cSGreg Clayton     m_frame_index = curr_frame.m_frame_index;
13395ccbd294SGreg Clayton     m_concrete_frame_index = curr_frame.m_concrete_frame_index;
134059e8fc1cSGreg Clayton     m_reg_context_sp = curr_frame.m_reg_context_sp;
134159e8fc1cSGreg Clayton     m_frame_code_addr = curr_frame.m_frame_code_addr;
134259e8fc1cSGreg Clayton     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());
134359e8fc1cSGreg Clayton     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());
134459e8fc1cSGreg Clayton     assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit);
134559e8fc1cSGreg Clayton     assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function);
134659e8fc1cSGreg Clayton     m_sc = curr_frame.m_sc;
134759e8fc1cSGreg Clayton     m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
134859e8fc1cSGreg Clayton     m_flags.Set (m_sc.GetResolvedMask());
134959e8fc1cSGreg Clayton     m_frame_base.Clear();
135059e8fc1cSGreg Clayton     m_frame_base_error.Clear();
135159e8fc1cSGreg Clayton }
135259e8fc1cSGreg Clayton 
135359e8fc1cSGreg Clayton 
13542cad65a5SGreg Clayton bool
13552cad65a5SGreg Clayton StackFrame::HasCachedData () const
13562cad65a5SGreg Clayton {
13572cad65a5SGreg Clayton     if (m_variable_list_sp.get())
13582cad65a5SGreg Clayton         return true;
13592cad65a5SGreg Clayton     if (m_variable_list_value_objects.GetSize() > 0)
13602cad65a5SGreg Clayton         return true;
13612cad65a5SGreg Clayton     if (!m_disassembly.GetString().empty())
13622cad65a5SGreg Clayton         return true;
13632cad65a5SGreg Clayton     return false;
13642cad65a5SGreg Clayton }
1365e4284b71SJim Ingham 
13667260f620SGreg Clayton bool
13677260f620SGreg Clayton StackFrame::GetStatus (Stream& strm,
13687260f620SGreg Clayton                        bool show_frame_info,
136953eb7ad2SGreg Clayton                        bool show_source)
13707260f620SGreg Clayton {
137153eb7ad2SGreg Clayton 
13727260f620SGreg Clayton     if (show_frame_info)
13737260f620SGreg Clayton     {
13747260f620SGreg Clayton         strm.Indent();
13757260f620SGreg Clayton         DumpUsingSettingsFormat (&strm);
13767260f620SGreg Clayton     }
13777260f620SGreg Clayton 
13787260f620SGreg Clayton     if (show_source)
13797260f620SGreg Clayton     {
1380d9e416c0SGreg Clayton         ExecutionContext exe_ctx (shared_from_this());
1381e372b98dSGreg Clayton         bool have_source = false;
138267cc0636SGreg Clayton         Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever;
1383d9e416c0SGreg Clayton         Target *target = exe_ctx.GetTargetPtr();
138453eb7ad2SGreg Clayton         if (target)
138553eb7ad2SGreg Clayton         {
138653eb7ad2SGreg Clayton             Debugger &debugger = target->GetDebugger();
138753eb7ad2SGreg Clayton             const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true);
138853eb7ad2SGreg Clayton             const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false);
138953eb7ad2SGreg Clayton             disasm_display = debugger.GetStopDisassemblyDisplay ();
139053eb7ad2SGreg Clayton 
139153eb7ad2SGreg Clayton             if (source_lines_before > 0 || source_lines_after > 0)
1392e372b98dSGreg Clayton             {
13937260f620SGreg Clayton                 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
13947260f620SGreg Clayton 
13957260f620SGreg Clayton                 if (m_sc.comp_unit && m_sc.line_entry.IsValid())
13967260f620SGreg Clayton                 {
1397d9e416c0SGreg Clayton                     if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file,
13987260f620SGreg Clayton                                                                                       m_sc.line_entry.line,
1399d9e416c0SGreg Clayton                                                                                       source_lines_before,
1400d9e416c0SGreg Clayton                                                                                       source_lines_after,
14017260f620SGreg Clayton                                                                                       "->",
1402e372b98dSGreg Clayton                                                                                       &strm))
1403e372b98dSGreg Clayton                     {
1404e372b98dSGreg Clayton                         have_source = true;
1405e372b98dSGreg Clayton                     }
1406e372b98dSGreg Clayton                 }
1407e372b98dSGreg Clayton             }
1408e372b98dSGreg Clayton             switch (disasm_display)
1409e372b98dSGreg Clayton             {
141067cc0636SGreg Clayton             case Debugger::eStopDisassemblyTypeNever:
1411e372b98dSGreg Clayton                 break;
1412e372b98dSGreg Clayton 
141367cc0636SGreg Clayton             case Debugger::eStopDisassemblyTypeNoSource:
1414e372b98dSGreg Clayton                 if (have_source)
1415e372b98dSGreg Clayton                     break;
1416e372b98dSGreg Clayton                 // Fall through to next case
141767cc0636SGreg Clayton             case Debugger::eStopDisassemblyTypeAlways:
1418d9e416c0SGreg Clayton                 if (target)
1419e372b98dSGreg Clayton                 {
142053eb7ad2SGreg Clayton                     const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1421e372b98dSGreg Clayton                     if (disasm_lines > 0)
1422e372b98dSGreg Clayton                     {
1423d9e416c0SGreg Clayton                         const ArchSpec &target_arch = target->GetArchitecture();
1424e372b98dSGreg Clayton                         AddressRange pc_range;
1425e372b98dSGreg Clayton                         pc_range.GetBaseAddress() = GetFrameCodeAddress();
1426e372b98dSGreg Clayton                         pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize());
1427d9e416c0SGreg Clayton                         Disassembler::Disassemble (target->GetDebugger(),
1428e372b98dSGreg Clayton                                                    target_arch,
1429e372b98dSGreg Clayton                                                    NULL,
1430e372b98dSGreg Clayton                                                    exe_ctx,
1431e372b98dSGreg Clayton                                                    pc_range,
1432e372b98dSGreg Clayton                                                    disasm_lines,
1433e372b98dSGreg Clayton                                                    0,
1434e372b98dSGreg Clayton                                                    Disassembler::eOptionMarkPCAddress,
1435e372b98dSGreg Clayton                                                    strm);
1436e372b98dSGreg Clayton                     }
1437e372b98dSGreg Clayton                 }
1438e372b98dSGreg Clayton                 break;
14397260f620SGreg Clayton             }
14407260f620SGreg Clayton         }
144153eb7ad2SGreg Clayton     }
14427260f620SGreg Clayton     return true;
14437260f620SGreg Clayton }
14447260f620SGreg Clayton 
1445