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 1030fdc8d8SChris Lattner #include "lldb/Target/StackFrame.h" 1130fdc8d8SChris Lattner 1230fdc8d8SChris Lattner // C Includes 1330fdc8d8SChris Lattner // C++ Includes 1430fdc8d8SChris Lattner // Other libraries and framework includes 1530fdc8d8SChris Lattner // Project includes 1630fdc8d8SChris Lattner #include "lldb/Core/Module.h" 170603aa9dSGreg Clayton #include "lldb/Core/Debugger.h" 1830fdc8d8SChris Lattner #include "lldb/Core/Disassembler.h" 1930fdc8d8SChris Lattner #include "lldb/Core/Value.h" 20288bdf9cSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 2154979cddSGreg Clayton #include "lldb/Core/ValueObjectConstResult.h" 22*1f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h" 2330fdc8d8SChris Lattner #include "lldb/Symbol/Function.h" 24*1f746071SGreg Clayton #include "lldb/Symbol/Symbol.h" 25*1f746071SGreg Clayton #include "lldb/Symbol/SymbolContextScope.h" 26288bdf9cSGreg Clayton #include "lldb/Symbol/VariableList.h" 2730fdc8d8SChris Lattner #include "lldb/Target/ExecutionContext.h" 2830fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2930fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h" 3030fdc8d8SChris Lattner #include "lldb/Target/Target.h" 3130fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner using namespace lldb; 3430fdc8d8SChris Lattner using namespace lldb_private; 3530fdc8d8SChris Lattner 3630fdc8d8SChris Lattner // The first bits in the flags are reserved for the SymbolContext::Scope bits 3730fdc8d8SChris Lattner // so we know if we have tried to look up information in our internal symbol 3830fdc8d8SChris Lattner // context (m_sc) already. 3959e8fc1cSGreg Clayton #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) 406dadd508SGreg Clayton #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) 4159e8fc1cSGreg Clayton #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) 4259e8fc1cSGreg Clayton #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) 437c0962dcSSean Callanan #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) 4430fdc8d8SChris Lattner 45d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 46d9e416c0SGreg Clayton user_id_t frame_idx, 474d122c40SGreg Clayton user_id_t unwind_frame_index, 484d122c40SGreg Clayton addr_t cfa, 494d122c40SGreg Clayton addr_t pc, 508f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 51d9e416c0SGreg Clayton m_thread_wp (thread_sp), 521b72fcb7SGreg Clayton m_frame_index (frame_idx), 535ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 5430fdc8d8SChris Lattner m_reg_context_sp (), 556dadd508SGreg Clayton m_id (pc, cfa, NULL), 56e72dfb32SGreg Clayton m_frame_code_addr (pc), 5730fdc8d8SChris Lattner m_sc (), 5830fdc8d8SChris Lattner m_flags (), 5930fdc8d8SChris Lattner m_frame_base (), 6030fdc8d8SChris Lattner m_frame_base_error (), 6130fdc8d8SChris Lattner m_variable_list_sp (), 621a65ae11SGreg Clayton m_variable_list_value_objects (), 631a65ae11SGreg Clayton m_disassembly () 6430fdc8d8SChris Lattner { 6530fdc8d8SChris Lattner if (sc_ptr != NULL) 661b72fcb7SGreg Clayton { 6730fdc8d8SChris Lattner m_sc = *sc_ptr; 681b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 691b72fcb7SGreg Clayton } 7030fdc8d8SChris Lattner } 7130fdc8d8SChris Lattner 72d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 73d9e416c0SGreg Clayton user_id_t frame_idx, 744d122c40SGreg Clayton user_id_t unwind_frame_index, 751b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 764d122c40SGreg Clayton addr_t cfa, 774d122c40SGreg Clayton addr_t pc, 788f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 79d9e416c0SGreg Clayton m_thread_wp (thread_sp), 801b72fcb7SGreg Clayton m_frame_index (frame_idx), 815ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 8230fdc8d8SChris Lattner m_reg_context_sp (reg_context_sp), 836dadd508SGreg Clayton m_id (pc, cfa, NULL), 84e72dfb32SGreg Clayton m_frame_code_addr (pc), 8530fdc8d8SChris Lattner m_sc (), 8630fdc8d8SChris Lattner m_flags (), 8730fdc8d8SChris Lattner m_frame_base (), 8830fdc8d8SChris Lattner m_frame_base_error (), 8930fdc8d8SChris Lattner m_variable_list_sp (), 901a65ae11SGreg Clayton m_variable_list_value_objects (), 911a65ae11SGreg Clayton m_disassembly () 9230fdc8d8SChris Lattner { 9330fdc8d8SChris Lattner if (sc_ptr != NULL) 941b72fcb7SGreg Clayton { 9530fdc8d8SChris Lattner m_sc = *sc_ptr; 961b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 971b72fcb7SGreg Clayton } 981b72fcb7SGreg Clayton 991b72fcb7SGreg Clayton if (reg_context_sp && !m_sc.target_sp) 1001b72fcb7SGreg Clayton { 101d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 102d9e416c0SGreg Clayton if (m_sc.target_sp) 1031b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1041b72fcb7SGreg Clayton } 1051b72fcb7SGreg Clayton } 1061b72fcb7SGreg Clayton 107d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 108d9e416c0SGreg Clayton user_id_t frame_idx, 1094d122c40SGreg Clayton user_id_t unwind_frame_index, 1101b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 1114d122c40SGreg Clayton addr_t cfa, 1121b72fcb7SGreg Clayton const Address& pc_addr, 1138f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 114d9e416c0SGreg Clayton m_thread_wp (thread_sp), 1151b72fcb7SGreg Clayton m_frame_index (frame_idx), 1165ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 1171b72fcb7SGreg Clayton m_reg_context_sp (reg_context_sp), 1181ac04c30SGreg Clayton m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL), 11912fc3e0fSGreg Clayton m_frame_code_addr (pc_addr), 1201b72fcb7SGreg Clayton m_sc (), 1211b72fcb7SGreg Clayton m_flags (), 1221b72fcb7SGreg Clayton m_frame_base (), 1231b72fcb7SGreg Clayton m_frame_base_error (), 1241b72fcb7SGreg Clayton m_variable_list_sp (), 1251a65ae11SGreg Clayton m_variable_list_value_objects (), 1261a65ae11SGreg Clayton m_disassembly () 1271b72fcb7SGreg Clayton { 1281b72fcb7SGreg Clayton if (sc_ptr != NULL) 1291b72fcb7SGreg Clayton { 1301b72fcb7SGreg Clayton m_sc = *sc_ptr; 1311b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1321b72fcb7SGreg Clayton } 1331b72fcb7SGreg Clayton 1341b72fcb7SGreg Clayton if (m_sc.target_sp.get() == NULL && reg_context_sp) 1351b72fcb7SGreg Clayton { 136d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 137d9e416c0SGreg Clayton if (m_sc.target_sp) 1381b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1391b72fcb7SGreg Clayton } 1401b72fcb7SGreg Clayton 141e72dfb32SGreg Clayton ModuleSP pc_module_sp (pc_addr.GetModule()); 142e72dfb32SGreg Clayton if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) 1431b72fcb7SGreg Clayton { 144e72dfb32SGreg Clayton if (pc_module_sp) 1451b72fcb7SGreg Clayton { 146e72dfb32SGreg Clayton m_sc.module_sp = pc_module_sp; 1471b72fcb7SGreg Clayton m_flags.Set (eSymbolContextModule); 1481b72fcb7SGreg Clayton } 149ffc1d667SGreg Clayton else 150ffc1d667SGreg Clayton { 151ffc1d667SGreg Clayton m_sc.module_sp.reset(); 152ffc1d667SGreg Clayton } 1531b72fcb7SGreg Clayton } 15430fdc8d8SChris Lattner } 15530fdc8d8SChris Lattner 15630fdc8d8SChris Lattner 15730fdc8d8SChris Lattner //---------------------------------------------------------------------- 15830fdc8d8SChris Lattner // Destructor 15930fdc8d8SChris Lattner //---------------------------------------------------------------------- 16030fdc8d8SChris Lattner StackFrame::~StackFrame() 16130fdc8d8SChris Lattner { 16230fdc8d8SChris Lattner } 16330fdc8d8SChris Lattner 16430fdc8d8SChris Lattner StackID& 16530fdc8d8SChris Lattner StackFrame::GetStackID() 16630fdc8d8SChris Lattner { 1676dadd508SGreg Clayton // Make sure we have resolved the StackID object's symbol context scope if 1686dadd508SGreg Clayton // we already haven't looked it up. 16959e8fc1cSGreg Clayton 17059e8fc1cSGreg Clayton if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) 17159e8fc1cSGreg Clayton { 1722cad65a5SGreg Clayton if (m_id.GetSymbolContextScope ()) 17359e8fc1cSGreg Clayton { 17495897c6aSGreg Clayton // We already have a symbol context scope, we just don't have our 17595897c6aSGreg Clayton // flag bit set. 17659e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 17759e8fc1cSGreg Clayton } 17859e8fc1cSGreg Clayton else 17959e8fc1cSGreg Clayton { 18095897c6aSGreg Clayton // Calculate the frame block and use this for the stack ID symbol 18195897c6aSGreg Clayton // context scope if we have one. 18295897c6aSGreg Clayton SymbolContextScope *scope = GetFrameBlock (); 18395897c6aSGreg Clayton if (scope == NULL) 18459e8fc1cSGreg Clayton { 18595897c6aSGreg Clayton // We don't have a block, so use the symbol 18695897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 18759e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextSymbol); 18895897c6aSGreg Clayton 18995897c6aSGreg Clayton // It is ok if m_sc.symbol is NULL here 19095897c6aSGreg Clayton scope = m_sc.symbol; 19159e8fc1cSGreg Clayton } 19295897c6aSGreg Clayton // Set the symbol context scope (the accessor will set the 19395897c6aSGreg Clayton // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). 19495897c6aSGreg Clayton SetSymbolContextScope (scope); 19559e8fc1cSGreg Clayton } 19659e8fc1cSGreg Clayton } 19730fdc8d8SChris Lattner return m_id; 19830fdc8d8SChris Lattner } 19930fdc8d8SChris Lattner 20059e8fc1cSGreg Clayton void 20159e8fc1cSGreg Clayton StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) 20259e8fc1cSGreg Clayton { 20359e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 20459e8fc1cSGreg Clayton m_id.SetSymbolContextScope (symbol_scope); 20559e8fc1cSGreg Clayton } 20659e8fc1cSGreg Clayton 20734132754SGreg Clayton const Address& 2089da7bd07SGreg Clayton StackFrame::GetFrameCodeAddress() 20930fdc8d8SChris Lattner { 21059e8fc1cSGreg Clayton if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) 21130fdc8d8SChris Lattner { 21259e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_CODE_ADDR); 21330fdc8d8SChris Lattner 21430fdc8d8SChris Lattner // Resolve the PC into a temporary address because if ResolveLoadAddress 21530fdc8d8SChris Lattner // fails to resolve the address, it will clear the address object... 216d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 217d9e416c0SGreg Clayton if (thread_sp) 218d9e416c0SGreg Clayton { 219d9e416c0SGreg Clayton TargetSP target_sp (thread_sp->CalculateTarget()); 220d9e416c0SGreg Clayton if (target_sp) 221d9e416c0SGreg Clayton { 222d9e416c0SGreg Clayton if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get())) 22330fdc8d8SChris Lattner { 224e72dfb32SGreg Clayton ModuleSP module_sp (m_frame_code_addr.GetModule()); 225e72dfb32SGreg Clayton if (module_sp) 22630fdc8d8SChris Lattner { 227e72dfb32SGreg Clayton m_sc.module_sp = module_sp; 22830fdc8d8SChris Lattner m_flags.Set(eSymbolContextModule); 22930fdc8d8SChris Lattner } 23030fdc8d8SChris Lattner } 23130fdc8d8SChris Lattner } 23230fdc8d8SChris Lattner } 233d9e416c0SGreg Clayton } 23412fc3e0fSGreg Clayton return m_frame_code_addr; 23530fdc8d8SChris Lattner } 23630fdc8d8SChris Lattner 23730fdc8d8SChris Lattner void 23830fdc8d8SChris Lattner StackFrame::ChangePC (addr_t pc) 23930fdc8d8SChris Lattner { 240e72dfb32SGreg Clayton m_frame_code_addr.SetRawAddress(pc); 24130fdc8d8SChris Lattner m_sc.Clear(); 24273b472d4SGreg Clayton m_flags.Reset(0); 243d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 244d9e416c0SGreg Clayton if (thread_sp) 245d9e416c0SGreg Clayton thread_sp->ClearStackFrames (); 24630fdc8d8SChris Lattner } 24730fdc8d8SChris Lattner 24830fdc8d8SChris Lattner const char * 24930fdc8d8SChris Lattner StackFrame::Disassemble () 25030fdc8d8SChris Lattner { 25130fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 25230fdc8d8SChris Lattner { 253d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 254d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 255d9e416c0SGreg Clayton if (target) 256d9e416c0SGreg Clayton { 257d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 258d9e416c0SGreg Clayton target->GetArchitecture(), 2591080edbcSGreg Clayton NULL, 26030fdc8d8SChris Lattner exe_ctx, 26130fdc8d8SChris Lattner 0, 26237023b06SJim Ingham 0, 2631da6f9d7SGreg Clayton 0, 26430fdc8d8SChris Lattner m_disassembly); 265d9e416c0SGreg Clayton } 26630fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 26730fdc8d8SChris Lattner return NULL; 26830fdc8d8SChris Lattner } 26930fdc8d8SChris Lattner return m_disassembly.GetData(); 27030fdc8d8SChris Lattner } 27130fdc8d8SChris Lattner 27295897c6aSGreg Clayton Block * 27395897c6aSGreg Clayton StackFrame::GetFrameBlock () 27495897c6aSGreg Clayton { 27595897c6aSGreg Clayton if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock)) 27695897c6aSGreg Clayton GetSymbolContext (eSymbolContextBlock); 27795897c6aSGreg Clayton 27895897c6aSGreg Clayton if (m_sc.block) 27995897c6aSGreg Clayton { 28095897c6aSGreg Clayton Block *inline_block = m_sc.block->GetContainingInlinedBlock(); 28195897c6aSGreg Clayton if (inline_block) 28295897c6aSGreg Clayton { 28395897c6aSGreg Clayton // Use the block with the inlined function info 28495897c6aSGreg Clayton // as the frame block we want this frame to have only the variables 28595897c6aSGreg Clayton // for the inlined function and its non-inlined block child blocks. 28695897c6aSGreg Clayton return inline_block; 28795897c6aSGreg Clayton } 28895897c6aSGreg Clayton else 28995897c6aSGreg Clayton { 29095897c6aSGreg Clayton // This block is not contained withing any inlined function blocks 29195897c6aSGreg Clayton // with so we want to use the top most function block. 29295897c6aSGreg Clayton return &m_sc.function->GetBlock (false); 29395897c6aSGreg Clayton } 29495897c6aSGreg Clayton } 29595897c6aSGreg Clayton return NULL; 29695897c6aSGreg Clayton } 29795897c6aSGreg Clayton 29830fdc8d8SChris Lattner //---------------------------------------------------------------------- 29930fdc8d8SChris Lattner // Get the symbol context if we already haven't done so by resolving the 30030fdc8d8SChris Lattner // PC address as much as possible. This way when we pass around a 30130fdc8d8SChris Lattner // StackFrame object, everyone will have as much information as 30230fdc8d8SChris Lattner // possible and no one will ever have to look things up manually. 30330fdc8d8SChris Lattner //---------------------------------------------------------------------- 30430fdc8d8SChris Lattner const SymbolContext& 30530fdc8d8SChris Lattner StackFrame::GetSymbolContext (uint32_t resolve_scope) 30630fdc8d8SChris Lattner { 30730fdc8d8SChris Lattner // Copy our internal symbol context into "sc". 30873b472d4SGreg Clayton if ((m_flags.Get() & resolve_scope) != resolve_scope) 30930fdc8d8SChris Lattner { 31030fdc8d8SChris Lattner // Resolve our PC to section offset if we haven't alreday done so 31130fdc8d8SChris Lattner // and if we don't have a module. The resolved address section will 31230fdc8d8SChris Lattner // contain the module to which it belongs 31359e8fc1cSGreg Clayton if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) 3149da7bd07SGreg Clayton GetFrameCodeAddress(); 31530fdc8d8SChris Lattner 31630fdc8d8SChris Lattner // If this is not frame zero, then we need to subtract 1 from the PC 31730fdc8d8SChris Lattner // value when doing address lookups since the PC will be on the 31830fdc8d8SChris Lattner // instruction following the function call instruction... 31930fdc8d8SChris Lattner 3209da7bd07SGreg Clayton Address lookup_addr(GetFrameCodeAddress()); 3211b72fcb7SGreg Clayton if (m_frame_index > 0 && lookup_addr.IsValid()) 32230fdc8d8SChris Lattner { 32330fdc8d8SChris Lattner addr_t offset = lookup_addr.GetOffset(); 32430fdc8d8SChris Lattner if (offset > 0) 32530fdc8d8SChris Lattner lookup_addr.SetOffset(offset - 1); 32630fdc8d8SChris Lattner } 32730fdc8d8SChris Lattner 3289da7bd07SGreg Clayton 3299da7bd07SGreg Clayton uint32_t resolved = 0; 33030fdc8d8SChris Lattner if (m_sc.module_sp) 33130fdc8d8SChris Lattner { 33230fdc8d8SChris Lattner // We have something in our stack frame symbol context, lets check 33330fdc8d8SChris Lattner // if we haven't already tried to lookup one of those things. If we 33430fdc8d8SChris Lattner // haven't then we will do the query. 3351b72fcb7SGreg Clayton 3361b72fcb7SGreg Clayton uint32_t actual_resolve_scope = 0; 3371b72fcb7SGreg Clayton 3381b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextCompUnit) 3391b72fcb7SGreg Clayton { 3401b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 3411b72fcb7SGreg Clayton { 3421b72fcb7SGreg Clayton if (m_sc.comp_unit) 3439da7bd07SGreg Clayton resolved |= eSymbolContextCompUnit; 3441b72fcb7SGreg Clayton else 3451b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextCompUnit; 3461b72fcb7SGreg Clayton } 3471b72fcb7SGreg Clayton } 3481b72fcb7SGreg Clayton 3491b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextFunction) 3501b72fcb7SGreg Clayton { 3511b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextFunction)) 3521b72fcb7SGreg Clayton { 3531b72fcb7SGreg Clayton if (m_sc.function) 3549da7bd07SGreg Clayton resolved |= eSymbolContextFunction; 3551b72fcb7SGreg Clayton else 3561b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextFunction; 3571b72fcb7SGreg Clayton } 3581b72fcb7SGreg Clayton } 3591b72fcb7SGreg Clayton 3601b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextBlock) 3611b72fcb7SGreg Clayton { 3621b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextBlock)) 3631b72fcb7SGreg Clayton { 3641b72fcb7SGreg Clayton if (m_sc.block) 3659da7bd07SGreg Clayton resolved |= eSymbolContextBlock; 3661b72fcb7SGreg Clayton else 3671b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextBlock; 3681b72fcb7SGreg Clayton } 3691b72fcb7SGreg Clayton } 3701b72fcb7SGreg Clayton 3711b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextSymbol) 3721b72fcb7SGreg Clayton { 3731b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 3741b72fcb7SGreg Clayton { 3751b72fcb7SGreg Clayton if (m_sc.symbol) 3769da7bd07SGreg Clayton resolved |= eSymbolContextSymbol; 3771b72fcb7SGreg Clayton else 3781b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextSymbol; 3791b72fcb7SGreg Clayton } 3801b72fcb7SGreg Clayton } 3811b72fcb7SGreg Clayton 3821b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextLineEntry) 3831b72fcb7SGreg Clayton { 3841b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextLineEntry)) 3851b72fcb7SGreg Clayton { 3861b72fcb7SGreg Clayton if (m_sc.line_entry.IsValid()) 3879da7bd07SGreg Clayton resolved |= eSymbolContextLineEntry; 3881b72fcb7SGreg Clayton else 3891b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextLineEntry; 3901b72fcb7SGreg Clayton } 3911b72fcb7SGreg Clayton } 3921b72fcb7SGreg Clayton 3931b72fcb7SGreg Clayton if (actual_resolve_scope) 39430fdc8d8SChris Lattner { 39530fdc8d8SChris Lattner // We might be resolving less information than what is already 39630fdc8d8SChris Lattner // in our current symbol context so resolve into a temporary 39730fdc8d8SChris Lattner // symbol context "sc" so we don't clear out data we have 39830fdc8d8SChris Lattner // already found in "m_sc" 39930fdc8d8SChris Lattner SymbolContext sc; 40030fdc8d8SChris Lattner // Set flags that indicate what we have tried to resolve 4019da7bd07SGreg Clayton resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); 4021b72fcb7SGreg Clayton // Only replace what we didn't already have as we may have 4031b72fcb7SGreg Clayton // information for an inlined function scope that won't match 4041b72fcb7SGreg Clayton // what a standard lookup by address would match 4059da7bd07SGreg Clayton if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL) 4069da7bd07SGreg Clayton m_sc.comp_unit = sc.comp_unit; 4079da7bd07SGreg Clayton if ((resolved & eSymbolContextFunction) && m_sc.function == NULL) 4089da7bd07SGreg Clayton m_sc.function = sc.function; 4099da7bd07SGreg Clayton if ((resolved & eSymbolContextBlock) && m_sc.block == NULL) 4109da7bd07SGreg Clayton m_sc.block = sc.block; 4119da7bd07SGreg Clayton if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL) 4129da7bd07SGreg Clayton m_sc.symbol = sc.symbol; 4139da7bd07SGreg Clayton if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) 4149da7bd07SGreg Clayton m_sc.line_entry = sc.line_entry; 4159da7bd07SGreg Clayton 41630fdc8d8SChris Lattner } 41730fdc8d8SChris Lattner } 41830fdc8d8SChris Lattner else 41930fdc8d8SChris Lattner { 42030fdc8d8SChris Lattner // If we don't have a module, then we can't have the compile unit, 42130fdc8d8SChris Lattner // function, block, line entry or symbol, so we can safely call 42230fdc8d8SChris Lattner // ResolveSymbolContextForAddress with our symbol context member m_sc. 423d9e416c0SGreg Clayton TargetSP target_sp (CalculateTarget()); 424d9e416c0SGreg Clayton if (target_sp) 425d9e416c0SGreg Clayton resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); 42630fdc8d8SChris Lattner } 42730fdc8d8SChris Lattner 42830fdc8d8SChris Lattner // If the target was requested add that: 429d9e416c0SGreg Clayton if (!m_sc.target_sp) 4309da7bd07SGreg Clayton { 431d9e416c0SGreg Clayton m_sc.target_sp = CalculateTarget(); 4329da7bd07SGreg Clayton if (m_sc.target_sp) 4339da7bd07SGreg Clayton resolved |= eSymbolContextTarget; 4349da7bd07SGreg Clayton } 43530fdc8d8SChris Lattner 43630fdc8d8SChris Lattner // Update our internal flags so we remember what we have tried to locate so 43730fdc8d8SChris Lattner // we don't have to keep trying when more calls to this function are made. 4389da7bd07SGreg Clayton // We might have dug up more information that was requested (for example 4399da7bd07SGreg Clayton // if we were asked to only get the block, we will have gotten the 4409da7bd07SGreg Clayton // compile unit, and function) so set any additional bits that we resolved 4419da7bd07SGreg Clayton m_flags.Set (resolve_scope | resolved); 44230fdc8d8SChris Lattner } 44330fdc8d8SChris Lattner 44430fdc8d8SChris Lattner // Return the symbol context with everything that was possible to resolve 44530fdc8d8SChris Lattner // resolved. 44630fdc8d8SChris Lattner return m_sc; 44730fdc8d8SChris Lattner } 44830fdc8d8SChris Lattner 44930fdc8d8SChris Lattner 45030fdc8d8SChris Lattner VariableList * 451288bdf9cSGreg Clayton StackFrame::GetVariableList (bool get_file_globals) 45230fdc8d8SChris Lattner { 45330fdc8d8SChris Lattner if (m_flags.IsClear(RESOLVED_VARIABLES)) 45430fdc8d8SChris Lattner { 45530fdc8d8SChris Lattner m_flags.Set(RESOLVED_VARIABLES); 45630fdc8d8SChris Lattner 45795897c6aSGreg Clayton Block *frame_block = GetFrameBlock(); 458288bdf9cSGreg Clayton 45995897c6aSGreg Clayton if (frame_block) 46030fdc8d8SChris Lattner { 46195897c6aSGreg Clayton const bool get_child_variables = true; 46295897c6aSGreg Clayton const bool can_create = true; 463c662ec8bSGreg Clayton const bool stop_if_child_block_is_inlined_function = true; 464c662ec8bSGreg Clayton m_variable_list_sp.reset(new VariableList()); 465c662ec8bSGreg Clayton frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); 46630fdc8d8SChris Lattner } 4677c0962dcSSean Callanan } 468288bdf9cSGreg Clayton 4697c0962dcSSean Callanan if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && 4707c0962dcSSean Callanan get_file_globals) 47195897c6aSGreg Clayton { 4727c0962dcSSean Callanan m_flags.Set(RESOLVED_GLOBAL_VARIABLES); 4737c0962dcSSean Callanan 47495897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 47595897c6aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit); 47695897c6aSGreg Clayton 47795897c6aSGreg Clayton if (m_sc.comp_unit) 478288bdf9cSGreg Clayton { 479288bdf9cSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 480288bdf9cSGreg Clayton if (m_variable_list_sp) 481288bdf9cSGreg Clayton m_variable_list_sp->AddVariables (global_variable_list_sp.get()); 482288bdf9cSGreg Clayton else 483288bdf9cSGreg Clayton m_variable_list_sp = global_variable_list_sp; 484288bdf9cSGreg Clayton } 48530fdc8d8SChris Lattner } 4867c0962dcSSean Callanan 48730fdc8d8SChris Lattner return m_variable_list_sp.get(); 48830fdc8d8SChris Lattner } 48930fdc8d8SChris Lattner 490d41f032aSGreg Clayton VariableListSP 491d41f032aSGreg Clayton StackFrame::GetInScopeVariableList (bool get_file_globals) 492d41f032aSGreg Clayton { 493d41f032aSGreg Clayton VariableListSP var_list_sp(new VariableList); 494d41f032aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); 495d41f032aSGreg Clayton 496d41f032aSGreg Clayton if (m_sc.block) 497d41f032aSGreg Clayton { 498d41f032aSGreg Clayton const bool can_create = true; 499d41f032aSGreg Clayton const bool get_parent_variables = true; 500d41f032aSGreg Clayton const bool stop_if_block_is_inlined_function = true; 501d41f032aSGreg Clayton m_sc.block->AppendVariables (can_create, 502d41f032aSGreg Clayton get_parent_variables, 503d41f032aSGreg Clayton stop_if_block_is_inlined_function, 504d41f032aSGreg Clayton var_list_sp.get()); 505d41f032aSGreg Clayton } 506d41f032aSGreg Clayton 507d41f032aSGreg Clayton if (m_sc.comp_unit) 508d41f032aSGreg Clayton { 509d41f032aSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 510d41f032aSGreg Clayton if (global_variable_list_sp) 511d41f032aSGreg Clayton var_list_sp->AddVariables (global_variable_list_sp.get()); 512d41f032aSGreg Clayton } 513d41f032aSGreg Clayton 514d41f032aSGreg Clayton return var_list_sp; 515d41f032aSGreg Clayton } 516d41f032aSGreg Clayton 517d41f032aSGreg Clayton 5188b2fe6dcSGreg Clayton ValueObjectSP 5192837b766SJim Ingham StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, 5204d122c40SGreg Clayton DynamicValueType use_dynamic, 5212837b766SJim Ingham uint32_t options, 5224d122c40SGreg Clayton VariableSP &var_sp, 5232837b766SJim Ingham Error &error) 5248b2fe6dcSGreg Clayton { 52554979cddSGreg Clayton 52654979cddSGreg Clayton if (var_expr_cstr && var_expr_cstr[0]) 52754979cddSGreg Clayton { 5286d5e68eaSGreg Clayton const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; 5296d5e68eaSGreg Clayton const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; 53027b625e1SEnrico Granata const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0; 53158ad3344SEnrico Granata //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0; 53254979cddSGreg Clayton error.Clear(); 5338b2fe6dcSGreg Clayton bool deref = false; 5348b2fe6dcSGreg Clayton bool address_of = false; 5358b2fe6dcSGreg Clayton ValueObjectSP valobj_sp; 5368b2fe6dcSGreg Clayton const bool get_file_globals = true; 537d41f032aSGreg Clayton // When looking up a variable for an expression, we need only consider the 538d41f032aSGreg Clayton // variables that are in scope. 539d41f032aSGreg Clayton VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); 540d41f032aSGreg Clayton VariableList *variable_list = var_list_sp.get(); 5418b2fe6dcSGreg Clayton 5428b2fe6dcSGreg Clayton if (variable_list) 5438b2fe6dcSGreg Clayton { 5448b2fe6dcSGreg Clayton // If first character is a '*', then show pointer contents 54554979cddSGreg Clayton const char *var_expr = var_expr_cstr; 5468b2fe6dcSGreg Clayton if (var_expr[0] == '*') 5478b2fe6dcSGreg Clayton { 5488b2fe6dcSGreg Clayton deref = true; 5498b2fe6dcSGreg Clayton var_expr++; // Skip the '*' 5508b2fe6dcSGreg Clayton } 5518b2fe6dcSGreg Clayton else if (var_expr[0] == '&') 5528b2fe6dcSGreg Clayton { 5538b2fe6dcSGreg Clayton address_of = true; 5548b2fe6dcSGreg Clayton var_expr++; // Skip the '&' 5558b2fe6dcSGreg Clayton } 5568b2fe6dcSGreg Clayton 5578b2fe6dcSGreg Clayton std::string var_path (var_expr); 55854979cddSGreg Clayton size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); 55954979cddSGreg Clayton StreamString var_expr_path_strm; 5608b2fe6dcSGreg Clayton 5618b2fe6dcSGreg Clayton ConstString name_const_string; 5628b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 5638b2fe6dcSGreg Clayton name_const_string.SetCString (var_path.c_str()); 5648b2fe6dcSGreg Clayton else 5658b2fe6dcSGreg Clayton name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); 5668b2fe6dcSGreg Clayton 5672837b766SJim Ingham var_sp = variable_list->FindVariable(name_const_string); 568685c88c5SGreg Clayton 569685c88c5SGreg Clayton bool synthetically_added_instance_object = false; 570685c88c5SGreg Clayton 571685c88c5SGreg Clayton if (var_sp) 572685c88c5SGreg Clayton { 573685c88c5SGreg Clayton var_path.erase (0, name_const_string.GetLength ()); 574685c88c5SGreg Clayton } 575685c88c5SGreg Clayton else if (options & eExpressionPathOptionsAllowDirectIVarAccess) 576685c88c5SGreg Clayton { 577685c88c5SGreg Clayton // Check for direct ivars access which helps us with implicit 578685c88c5SGreg Clayton // access to ivars with the "this->" or "self->" 579685c88c5SGreg Clayton GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock); 580685c88c5SGreg Clayton lldb::LanguageType method_language = eLanguageTypeUnknown; 581685c88c5SGreg Clayton bool is_instance_method = false; 582685c88c5SGreg Clayton ConstString method_object_name; 583685c88c5SGreg Clayton if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name)) 584685c88c5SGreg Clayton { 585685c88c5SGreg Clayton if (is_instance_method && method_object_name) 586685c88c5SGreg Clayton { 587685c88c5SGreg Clayton var_sp = variable_list->FindVariable(method_object_name); 588685c88c5SGreg Clayton if (var_sp) 589685c88c5SGreg Clayton { 590685c88c5SGreg Clayton separator_idx = 0; 591685c88c5SGreg Clayton var_path.insert(0, "->"); 592685c88c5SGreg Clayton synthetically_added_instance_object = true; 593685c88c5SGreg Clayton } 594685c88c5SGreg Clayton } 595685c88c5SGreg Clayton } 596685c88c5SGreg Clayton } 597685c88c5SGreg Clayton 5988b2fe6dcSGreg Clayton if (var_sp) 5998b2fe6dcSGreg Clayton { 6002837b766SJim Ingham valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); 60178a685aaSJim Ingham if (!valobj_sp) 60278a685aaSJim Ingham return valobj_sp; 6038b2fe6dcSGreg Clayton 6048b2fe6dcSGreg Clayton // We are dumping at least one child 6058b2fe6dcSGreg Clayton while (separator_idx != std::string::npos) 6068b2fe6dcSGreg Clayton { 6078b2fe6dcSGreg Clayton // Calculate the next separator index ahead of time 6088b2fe6dcSGreg Clayton ValueObjectSP child_valobj_sp; 6098b2fe6dcSGreg Clayton const char separator_type = var_path[0]; 6108b2fe6dcSGreg Clayton switch (separator_type) 6118b2fe6dcSGreg Clayton { 6128b2fe6dcSGreg Clayton 6138b2fe6dcSGreg Clayton case '-': 6148b2fe6dcSGreg Clayton if (var_path.size() >= 2 && var_path[1] != '>') 6158b2fe6dcSGreg Clayton return ValueObjectSP(); 6168b2fe6dcSGreg Clayton 6176d5e68eaSGreg Clayton if (no_fragile_ivar) 6186d5e68eaSGreg Clayton { 6196d5e68eaSGreg Clayton // Make sure we aren't trying to deref an objective 6206d5e68eaSGreg Clayton // C ivar if this is not allowed 6216d5e68eaSGreg Clayton const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL); 6226d5e68eaSGreg Clayton if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) && 6236d5e68eaSGreg Clayton (pointer_type_flags & ClangASTContext::eTypeIsPointer)) 6246d5e68eaSGreg Clayton { 6256d5e68eaSGreg Clayton // This was an objective C object pointer and 6266d5e68eaSGreg Clayton // it was requested we skip any fragile ivars 6276d5e68eaSGreg Clayton // so return nothing here 6286d5e68eaSGreg Clayton return ValueObjectSP(); 6296d5e68eaSGreg Clayton } 6306d5e68eaSGreg Clayton } 6318b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '-' 6328b2fe6dcSGreg Clayton // Fall through 6338b2fe6dcSGreg Clayton case '.': 6348b2fe6dcSGreg Clayton { 63554979cddSGreg Clayton const bool expr_is_ptr = var_path[0] == '>'; 6368b2fe6dcSGreg Clayton 6378b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '.' or '>' 6388b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 6398b2fe6dcSGreg Clayton ConstString child_name; 6408b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 6418b2fe6dcSGreg Clayton child_name.SetCString (var_path.c_str()); 6428b2fe6dcSGreg Clayton else 6438b2fe6dcSGreg Clayton child_name.SetCStringWithLength(var_path.c_str(), separator_idx); 6448b2fe6dcSGreg Clayton 64554979cddSGreg Clayton if (check_ptr_vs_member) 64654979cddSGreg Clayton { 64754979cddSGreg Clayton // We either have a pointer type and need to verify 64854979cddSGreg Clayton // valobj_sp is a pointer, or we have a member of a 64954979cddSGreg Clayton // class/union/struct being accessed with the . syntax 65054979cddSGreg Clayton // and need to verify we don't have a pointer. 65154979cddSGreg Clayton const bool actual_is_ptr = valobj_sp->IsPointerType (); 65254979cddSGreg Clayton 65354979cddSGreg Clayton if (actual_is_ptr != expr_is_ptr) 65454979cddSGreg Clayton { 65554979cddSGreg Clayton // Incorrect use of "." with a pointer, or "->" with 65654979cddSGreg Clayton // a class/union/struct instance or reference. 6576beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 65854979cddSGreg Clayton if (actual_is_ptr) 65954979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", 66054979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 66154979cddSGreg Clayton child_name.GetCString(), 66254979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 66354979cddSGreg Clayton var_path.c_str()); 66454979cddSGreg Clayton else 66554979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", 66654979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 66754979cddSGreg Clayton child_name.GetCString(), 66854979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 66954979cddSGreg Clayton var_path.c_str()); 67054979cddSGreg Clayton return ValueObjectSP(); 67154979cddSGreg Clayton } 67254979cddSGreg Clayton } 6738b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); 6748b2fe6dcSGreg Clayton if (!child_valobj_sp) 6758b2fe6dcSGreg Clayton { 6768c9d3560SEnrico Granata if (no_synth_child == false) 67786cc9829SEnrico Granata { 67886cc9829SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticValue(); 67986cc9829SEnrico Granata if (child_valobj_sp) 68086cc9829SEnrico Granata child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true); 68186cc9829SEnrico Granata } 6828c9d3560SEnrico Granata 6838c9d3560SEnrico Granata if (no_synth_child || !child_valobj_sp) 6848c9d3560SEnrico Granata { 6858b2fe6dcSGreg Clayton // No child member with name "child_name" 686685c88c5SGreg Clayton if (synthetically_added_instance_object) 687685c88c5SGreg Clayton { 688685c88c5SGreg Clayton // We added a "this->" or "self->" to the beginning of the expression 689685c88c5SGreg Clayton // and this is the first pointer ivar access, so just return the normal 690685c88c5SGreg Clayton // error 691685c88c5SGreg Clayton error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame", 692685c88c5SGreg Clayton name_const_string.GetCString()); 693685c88c5SGreg Clayton } 694685c88c5SGreg Clayton else 695685c88c5SGreg Clayton { 6966beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 69754979cddSGreg Clayton if (child_name) 69854979cddSGreg Clayton { 69954979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", 70054979cddSGreg Clayton child_name.GetCString(), 70154979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 70254979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 70354979cddSGreg Clayton } 70454979cddSGreg Clayton else 70554979cddSGreg Clayton { 70654979cddSGreg Clayton error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", 70754979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 70854979cddSGreg Clayton var_expr_cstr); 70954979cddSGreg Clayton } 710685c88c5SGreg Clayton } 7118b2fe6dcSGreg Clayton return ValueObjectSP(); 7128b2fe6dcSGreg Clayton } 7138c9d3560SEnrico Granata } 714685c88c5SGreg Clayton synthetically_added_instance_object = false; 7158b2fe6dcSGreg Clayton // Remove the child name from the path 7168b2fe6dcSGreg Clayton var_path.erase(0, child_name.GetLength()); 7174d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 71878a685aaSJim Ingham { 7192837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 72078a685aaSJim Ingham if (dynamic_value_sp) 72178a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 72278a685aaSJim Ingham } 7238b2fe6dcSGreg Clayton } 7248b2fe6dcSGreg Clayton break; 7258b2fe6dcSGreg Clayton 7268b2fe6dcSGreg Clayton case '[': 7278b2fe6dcSGreg Clayton // Array member access, or treating pointer as an array 7288b2fe6dcSGreg Clayton if (var_path.size() > 2) // Need at least two brackets and a number 7298b2fe6dcSGreg Clayton { 7308b2fe6dcSGreg Clayton char *end = NULL; 7311a65ae11SGreg Clayton long child_index = ::strtol (&var_path[1], &end, 0); 7329fc1944eSEnrico Granata if (end && *end == ']' 7339fc1944eSEnrico 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 7348b2fe6dcSGreg Clayton { 7359fc1944eSEnrico Granata if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) 7369fc1944eSEnrico Granata { 7379fc1944eSEnrico Granata // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr 7389fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 7399fc1944eSEnrico Granata // would be done by saying ptr[low], without a deref * sign 7409fc1944eSEnrico Granata Error error; 7419fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 7429fc1944eSEnrico Granata if (error.Fail()) 7439fc1944eSEnrico Granata { 7449fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 7459fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 7469fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 7479fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 7489fc1944eSEnrico Granata return ValueObjectSP(); 7499fc1944eSEnrico Granata } 7509fc1944eSEnrico Granata valobj_sp = temp; 7519fc1944eSEnrico Granata deref = false; 7529fc1944eSEnrico Granata } 7539fc1944eSEnrico Granata else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) 7549fc1944eSEnrico Granata { 7559fc1944eSEnrico Granata // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] 7569fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 7579fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 7589fc1944eSEnrico Granata // would be done by saying arr[low], without a deref * sign 7599fc1944eSEnrico Granata Error error; 7609fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 7619fc1944eSEnrico Granata if (error.Fail()) 7629fc1944eSEnrico Granata { 7639fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 7649fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 7659fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 7669fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 7679fc1944eSEnrico Granata return ValueObjectSP(); 7689fc1944eSEnrico Granata } 7699fc1944eSEnrico Granata valobj_sp = temp; 7709fc1944eSEnrico Granata deref = false; 7719fc1944eSEnrico Granata } 7728b2fe6dcSGreg Clayton 7738b2fe6dcSGreg Clayton if (valobj_sp->IsPointerType ()) 7748b2fe6dcSGreg Clayton { 775226b70c1SSean Callanan bool is_objc_pointer = true; 776226b70c1SSean Callanan 777226b70c1SSean Callanan if (ClangASTType::GetMinimumLanguage(valobj_sp->GetClangAST(), valobj_sp->GetClangType()) != eLanguageTypeObjC) 778226b70c1SSean Callanan is_objc_pointer = false; 779226b70c1SSean Callanan else if (!ClangASTContext::IsPointerType(valobj_sp->GetClangType())) 780226b70c1SSean Callanan is_objc_pointer = false; 781226b70c1SSean Callanan 782226b70c1SSean Callanan if (no_synth_child && is_objc_pointer) 783226b70c1SSean Callanan { 784226b70c1SSean Callanan error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted", 785226b70c1SSean Callanan valobj_sp->GetTypeName().AsCString("<invalid type>"), 786226b70c1SSean Callanan var_expr_path_strm.GetString().c_str()); 787226b70c1SSean Callanan 788226b70c1SSean Callanan return ValueObjectSP(); 789226b70c1SSean Callanan } 790226b70c1SSean Callanan else if (is_objc_pointer) 79127b625e1SEnrico Granata { 79227b625e1SEnrico Granata // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children 79386cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 79427b625e1SEnrico Granata if (synthetic.get() == NULL /* no synthetic */ 79527b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 79627b625e1SEnrico Granata { 79727b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 79827b625e1SEnrico Granata error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 79927b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 80027b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 80127b625e1SEnrico Granata } 80227b625e1SEnrico Granata else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 80327b625e1SEnrico Granata { 80427b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8057e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 80627b625e1SEnrico Granata child_index, 80727b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 80827b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 80927b625e1SEnrico Granata } 81027b625e1SEnrico Granata else 81127b625e1SEnrico Granata { 81227b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 81327b625e1SEnrico Granata if (!child_valobj_sp) 81427b625e1SEnrico Granata { 81527b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8167e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 81727b625e1SEnrico Granata child_index, 81827b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 81927b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 82027b625e1SEnrico Granata } 82127b625e1SEnrico Granata } 82227b625e1SEnrico Granata } 82327b625e1SEnrico Granata else 82427b625e1SEnrico Granata { 8258b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); 82654979cddSGreg Clayton if (!child_valobj_sp) 82754979cddSGreg Clayton { 8286beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8297e589a60SJason Molenda error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"", 83054979cddSGreg Clayton child_index, 83154979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 83254979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 83354979cddSGreg Clayton } 83454979cddSGreg Clayton } 83527b625e1SEnrico Granata } 83654979cddSGreg Clayton else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL)) 83754979cddSGreg Clayton { 83878a685aaSJim Ingham // Pass false to dynamic_value here so we can tell the difference between 83978a685aaSJim Ingham // no dynamic value and no member of this type... 84054979cddSGreg Clayton child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); 84154979cddSGreg Clayton if (!child_valobj_sp) 84254979cddSGreg Clayton { 8436beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8447e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 84554979cddSGreg Clayton child_index, 84654979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 84754979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 84854979cddSGreg Clayton } 8498b2fe6dcSGreg Clayton } 8509fc1944eSEnrico Granata else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType())) 8519fc1944eSEnrico Granata { 8529fc1944eSEnrico Granata // this is a bitfield asking to display just one bit 8539fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); 8549fc1944eSEnrico Granata if (!child_valobj_sp) 8559fc1944eSEnrico Granata { 8569fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8577e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 8589fc1944eSEnrico Granata child_index, child_index, 8599fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8609fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8619fc1944eSEnrico Granata } 8629fc1944eSEnrico Granata } 8638b2fe6dcSGreg Clayton else 8648b2fe6dcSGreg Clayton { 86586cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 86627b625e1SEnrico Granata if (no_synth_child /* synthetic is forbidden */ || 86727b625e1SEnrico Granata synthetic.get() == NULL /* no synthetic */ 86827b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 86927b625e1SEnrico Granata { 8706beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 87154979cddSGreg Clayton error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 87254979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 87354979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 8748b2fe6dcSGreg Clayton } 87527b625e1SEnrico Granata else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 87627b625e1SEnrico Granata { 87727b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8787e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 87927b625e1SEnrico Granata child_index, 88027b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 88127b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 88227b625e1SEnrico Granata } 88327b625e1SEnrico Granata else 88427b625e1SEnrico Granata { 88527b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 88627b625e1SEnrico Granata if (!child_valobj_sp) 88727b625e1SEnrico Granata { 88827b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8897e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 89027b625e1SEnrico Granata child_index, 89127b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 89227b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 89327b625e1SEnrico Granata } 89427b625e1SEnrico Granata } 89527b625e1SEnrico Granata } 8968b2fe6dcSGreg Clayton 8978b2fe6dcSGreg Clayton if (!child_valobj_sp) 8988b2fe6dcSGreg Clayton { 8998b2fe6dcSGreg Clayton // Invalid array index... 9008b2fe6dcSGreg Clayton return ValueObjectSP(); 9018b2fe6dcSGreg Clayton } 9028b2fe6dcSGreg Clayton 9038b2fe6dcSGreg Clayton // Erase the array member specification '[%i]' where 9048b2fe6dcSGreg Clayton // %i is the array index 9058b2fe6dcSGreg Clayton var_path.erase(0, (end - var_path.c_str()) + 1); 9068b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 9074d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 90878a685aaSJim Ingham { 9092837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 91078a685aaSJim Ingham if (dynamic_value_sp) 91178a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 91278a685aaSJim Ingham } 9138b2fe6dcSGreg Clayton // Break out early from the switch since we were 9148b2fe6dcSGreg Clayton // able to find the child member 9158b2fe6dcSGreg Clayton break; 9168b2fe6dcSGreg Clayton } 9179fc1944eSEnrico Granata else if (end && *end == '-') 9189fc1944eSEnrico Granata { 9199fc1944eSEnrico Granata // this is most probably a BitField, let's take a look 9209fc1944eSEnrico Granata char *real_end = NULL; 9219fc1944eSEnrico Granata long final_index = ::strtol (end+1, &real_end, 0); 922d64d0bc0SEnrico Granata bool expand_bitfield = true; 9239fc1944eSEnrico Granata if (real_end && *real_end == ']') 9249fc1944eSEnrico Granata { 9259fc1944eSEnrico Granata // if the format given is [high-low], swap range 9269fc1944eSEnrico Granata if (child_index > final_index) 9279fc1944eSEnrico Granata { 9289fc1944eSEnrico Granata long temp = child_index; 9299fc1944eSEnrico Granata child_index = final_index; 9309fc1944eSEnrico Granata final_index = temp; 9319fc1944eSEnrico Granata } 9329fc1944eSEnrico Granata 9339fc1944eSEnrico Granata if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) 9349fc1944eSEnrico Granata { 9359fc1944eSEnrico Granata // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr 9369fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 9379fc1944eSEnrico Granata // would be done by saying ptr[low-high], without a deref * sign 9389fc1944eSEnrico Granata Error error; 9399fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 9409fc1944eSEnrico Granata if (error.Fail()) 9419fc1944eSEnrico Granata { 9429fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9439fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 9449fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 9459fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 9469fc1944eSEnrico Granata return ValueObjectSP(); 9479fc1944eSEnrico Granata } 9489fc1944eSEnrico Granata valobj_sp = temp; 9499fc1944eSEnrico Granata deref = false; 9509fc1944eSEnrico Granata } 9519fc1944eSEnrico Granata else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) 9529fc1944eSEnrico Granata { 9539fc1944eSEnrico Granata // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] 9549fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 9559fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 9569fc1944eSEnrico Granata // would be done by saying arr[low-high], without a deref * sign 9579fc1944eSEnrico Granata Error error; 9589fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 9599fc1944eSEnrico Granata if (error.Fail()) 9609fc1944eSEnrico Granata { 9619fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9629fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 9639fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 9649fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 9659fc1944eSEnrico Granata return ValueObjectSP(); 9669fc1944eSEnrico Granata } 9679fc1944eSEnrico Granata valobj_sp = temp; 9689fc1944eSEnrico Granata deref = false; 9699fc1944eSEnrico Granata } 970d64d0bc0SEnrico Granata /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType()) 971d64d0bc0SEnrico Granata { 972d64d0bc0SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true); 973d64d0bc0SEnrico Granata expand_bitfield = false; 974d64d0bc0SEnrico Granata if (!child_valobj_sp) 975d64d0bc0SEnrico Granata { 976d64d0bc0SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 977d64d0bc0SEnrico Granata error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"", 978d64d0bc0SEnrico Granata child_index, final_index, 979d64d0bc0SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 980d64d0bc0SEnrico Granata var_expr_path_strm.GetString().c_str()); 981d64d0bc0SEnrico Granata } 982d64d0bc0SEnrico Granata }*/ 9839fc1944eSEnrico Granata 984d64d0bc0SEnrico Granata if (expand_bitfield) 985d64d0bc0SEnrico Granata { 9869fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); 9879fc1944eSEnrico Granata if (!child_valobj_sp) 9889fc1944eSEnrico Granata { 9899fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9907e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 9919fc1944eSEnrico Granata child_index, final_index, 9929fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 9939fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 9949fc1944eSEnrico Granata } 9959fc1944eSEnrico Granata } 996d64d0bc0SEnrico Granata } 9979fc1944eSEnrico Granata 9989fc1944eSEnrico Granata if (!child_valobj_sp) 9999fc1944eSEnrico Granata { 10009fc1944eSEnrico Granata // Invalid bitfield range... 10019fc1944eSEnrico Granata return ValueObjectSP(); 10029fc1944eSEnrico Granata } 10039fc1944eSEnrico Granata 10049fc1944eSEnrico Granata // Erase the bitfield member specification '[%i-%i]' where 10059fc1944eSEnrico Granata // %i is the index 10069fc1944eSEnrico Granata var_path.erase(0, (real_end - var_path.c_str()) + 1); 10079fc1944eSEnrico Granata separator_idx = var_path.find_first_of(".-["); 10084d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 10099fc1944eSEnrico Granata { 10109fc1944eSEnrico Granata ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 10119fc1944eSEnrico Granata if (dynamic_value_sp) 10129fc1944eSEnrico Granata child_valobj_sp = dynamic_value_sp; 10139fc1944eSEnrico Granata } 10149fc1944eSEnrico Granata // Break out early from the switch since we were 10159fc1944eSEnrico Granata // able to find the child member 10169fc1944eSEnrico Granata break; 10179fc1944eSEnrico Granata 10189fc1944eSEnrico Granata } 10199fc1944eSEnrico Granata } 10209fc1944eSEnrico Granata else 10219fc1944eSEnrico Granata { 10229fc1944eSEnrico Granata error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", 10239fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str(), 10249fc1944eSEnrico Granata var_path.c_str()); 10258b2fe6dcSGreg Clayton } 10268b2fe6dcSGreg Clayton return ValueObjectSP(); 10278b2fe6dcSGreg Clayton 10288b2fe6dcSGreg Clayton default: 10298b2fe6dcSGreg Clayton // Failure... 103054979cddSGreg Clayton { 10316beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 103254979cddSGreg Clayton error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", 103354979cddSGreg Clayton separator_type, 103454979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 103554979cddSGreg Clayton var_path.c_str()); 103654979cddSGreg Clayton 10378b2fe6dcSGreg Clayton return ValueObjectSP(); 10388b2fe6dcSGreg Clayton } 103954979cddSGreg Clayton } 10408b2fe6dcSGreg Clayton 10418b2fe6dcSGreg Clayton if (child_valobj_sp) 10428b2fe6dcSGreg Clayton valobj_sp = child_valobj_sp; 10438b2fe6dcSGreg Clayton 10448b2fe6dcSGreg Clayton if (var_path.empty()) 10458b2fe6dcSGreg Clayton break; 10468b2fe6dcSGreg Clayton 10478b2fe6dcSGreg Clayton } 10488b2fe6dcSGreg Clayton if (valobj_sp) 10498b2fe6dcSGreg Clayton { 10508b2fe6dcSGreg Clayton if (deref) 10518b2fe6dcSGreg Clayton { 1052af67cecdSGreg Clayton ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); 10538b2fe6dcSGreg Clayton valobj_sp = deref_valobj_sp; 10548b2fe6dcSGreg Clayton } 10558b2fe6dcSGreg Clayton else if (address_of) 10568b2fe6dcSGreg Clayton { 105754979cddSGreg Clayton ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); 10588b2fe6dcSGreg Clayton valobj_sp = address_of_valobj_sp; 10598b2fe6dcSGreg Clayton } 10608b2fe6dcSGreg Clayton } 10618b2fe6dcSGreg Clayton return valobj_sp; 10628b2fe6dcSGreg Clayton } 106354979cddSGreg Clayton else 106454979cddSGreg Clayton { 10652837b766SJim Ingham error.SetErrorStringWithFormat("no variable named '%s' found in this frame", 10662837b766SJim Ingham name_const_string.GetCString()); 106754979cddSGreg Clayton } 106854979cddSGreg Clayton } 106954979cddSGreg Clayton } 107054979cddSGreg Clayton else 107154979cddSGreg Clayton { 107254979cddSGreg Clayton error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); 10738b2fe6dcSGreg Clayton } 10748b2fe6dcSGreg Clayton return ValueObjectSP(); 10758b2fe6dcSGreg Clayton } 107630fdc8d8SChris Lattner 107730fdc8d8SChris Lattner bool 107830fdc8d8SChris Lattner StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) 107930fdc8d8SChris Lattner { 108030fdc8d8SChris Lattner if (m_flags.IsClear(GOT_FRAME_BASE)) 108130fdc8d8SChris Lattner { 108230fdc8d8SChris Lattner if (m_sc.function) 108330fdc8d8SChris Lattner { 108430fdc8d8SChris Lattner m_frame_base.Clear(); 108530fdc8d8SChris Lattner m_frame_base_error.Clear(); 108630fdc8d8SChris Lattner 108730fdc8d8SChris Lattner m_flags.Set(GOT_FRAME_BASE); 1088d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 108930fdc8d8SChris Lattner Value expr_value; 1090016a95ebSGreg Clayton addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; 1091016a95ebSGreg Clayton if (m_sc.function->GetFrameBaseExpression().IsLocationList()) 1092d9e416c0SGreg Clayton loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr()); 1093016a95ebSGreg Clayton 10941a65ae11SGreg Clayton if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) 109530fdc8d8SChris Lattner { 109630fdc8d8SChris Lattner // We should really have an error if evaluate returns, but in case 109730fdc8d8SChris Lattner // we don't, lets set the error to something at least. 109830fdc8d8SChris Lattner if (m_frame_base_error.Success()) 109930fdc8d8SChris Lattner m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); 110030fdc8d8SChris Lattner } 110130fdc8d8SChris Lattner else 110230fdc8d8SChris Lattner { 110330fdc8d8SChris Lattner m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL); 110430fdc8d8SChris Lattner } 110530fdc8d8SChris Lattner } 110630fdc8d8SChris Lattner else 110730fdc8d8SChris Lattner { 110830fdc8d8SChris Lattner m_frame_base_error.SetErrorString ("No function in symbol context."); 110930fdc8d8SChris Lattner } 111030fdc8d8SChris Lattner } 111130fdc8d8SChris Lattner 111230fdc8d8SChris Lattner if (m_frame_base_error.Success()) 111330fdc8d8SChris Lattner frame_base = m_frame_base; 111430fdc8d8SChris Lattner 111530fdc8d8SChris Lattner if (error_ptr) 111630fdc8d8SChris Lattner *error_ptr = m_frame_base_error; 111730fdc8d8SChris Lattner return m_frame_base_error.Success(); 111830fdc8d8SChris Lattner } 111930fdc8d8SChris Lattner 11205ccbd294SGreg Clayton RegisterContextSP 112130fdc8d8SChris Lattner StackFrame::GetRegisterContext () 112230fdc8d8SChris Lattner { 11235ccbd294SGreg Clayton if (!m_reg_context_sp) 1124d9e416c0SGreg Clayton { 1125d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 1126d9e416c0SGreg Clayton if (thread_sp) 1127d9e416c0SGreg Clayton m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this); 1128d9e416c0SGreg Clayton } 11295ccbd294SGreg Clayton return m_reg_context_sp; 113030fdc8d8SChris Lattner } 113130fdc8d8SChris Lattner 113230fdc8d8SChris Lattner bool 113330fdc8d8SChris Lattner StackFrame::HasDebugInformation () 113430fdc8d8SChris Lattner { 113530fdc8d8SChris Lattner GetSymbolContext (eSymbolContextLineEntry); 113630fdc8d8SChris Lattner return m_sc.line_entry.IsValid(); 113730fdc8d8SChris Lattner } 113830fdc8d8SChris Lattner 1139288bdf9cSGreg Clayton 1140288bdf9cSGreg Clayton ValueObjectSP 11414d122c40SGreg Clayton StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 114230fdc8d8SChris Lattner { 1143288bdf9cSGreg Clayton ValueObjectSP valobj_sp; 1144288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1145288bdf9cSGreg Clayton if (var_list) 1146288bdf9cSGreg Clayton { 1147288bdf9cSGreg Clayton // Make sure the variable is a frame variable 1148288bdf9cSGreg Clayton const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); 1149288bdf9cSGreg Clayton const uint32_t num_variables = var_list->GetSize(); 1150288bdf9cSGreg Clayton if (var_idx < num_variables) 1151288bdf9cSGreg Clayton { 1152288bdf9cSGreg Clayton valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); 1153288bdf9cSGreg Clayton if (valobj_sp.get() == NULL) 1154288bdf9cSGreg Clayton { 1155288bdf9cSGreg Clayton if (m_variable_list_value_objects.GetSize() < num_variables) 1156288bdf9cSGreg Clayton m_variable_list_value_objects.Resize(num_variables); 115758b59f95SJim Ingham valobj_sp = ValueObjectVariable::Create (this, variable_sp); 1158288bdf9cSGreg Clayton m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); 1159288bdf9cSGreg Clayton } 1160288bdf9cSGreg Clayton } 1161288bdf9cSGreg Clayton } 11624d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues && valobj_sp) 116378a685aaSJim Ingham { 11642837b766SJim Ingham ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); 116578a685aaSJim Ingham if (dynamic_sp) 116678a685aaSJim Ingham return dynamic_sp; 116778a685aaSJim Ingham } 1168288bdf9cSGreg Clayton return valobj_sp; 1169288bdf9cSGreg Clayton } 1170288bdf9cSGreg Clayton 1171288bdf9cSGreg Clayton ValueObjectSP 11724d122c40SGreg Clayton StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 1173288bdf9cSGreg Clayton { 1174288bdf9cSGreg Clayton // Check to make sure we aren't already tracking this variable? 117578a685aaSJim Ingham ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 1176288bdf9cSGreg Clayton if (!valobj_sp) 1177288bdf9cSGreg Clayton { 1178288bdf9cSGreg Clayton // We aren't already tracking this global 1179288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1180288bdf9cSGreg Clayton // If this frame has no variables, create a new list 1181288bdf9cSGreg Clayton if (var_list == NULL) 1182288bdf9cSGreg Clayton m_variable_list_sp.reset (new VariableList()); 1183288bdf9cSGreg Clayton 1184288bdf9cSGreg Clayton // Add the global/static variable to this frame 1185288bdf9cSGreg Clayton m_variable_list_sp->AddVariable (variable_sp); 1186288bdf9cSGreg Clayton 1187288bdf9cSGreg Clayton // Now make a value object for it so we can track its changes 118878a685aaSJim Ingham valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 1189288bdf9cSGreg Clayton } 1190288bdf9cSGreg Clayton return valobj_sp; 119130fdc8d8SChris Lattner } 119230fdc8d8SChris Lattner 11936b8379c4SJim Ingham bool 11946b8379c4SJim Ingham StackFrame::IsInlined () 11956b8379c4SJim Ingham { 119659e8fc1cSGreg Clayton if (m_sc.block == NULL) 119759e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextBlock); 119859e8fc1cSGreg Clayton if (m_sc.block) 119959e8fc1cSGreg Clayton return m_sc.block->GetContainingInlinedBlock() != NULL; 120059e8fc1cSGreg Clayton return false; 12016b8379c4SJim Ingham } 12026b8379c4SJim Ingham 1203d9e416c0SGreg Clayton TargetSP 120430fdc8d8SChris Lattner StackFrame::CalculateTarget () 120530fdc8d8SChris Lattner { 1206d9e416c0SGreg Clayton TargetSP target_sp; 1207d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1208d9e416c0SGreg Clayton if (thread_sp) 1209d9e416c0SGreg Clayton { 1210d9e416c0SGreg Clayton ProcessSP process_sp (thread_sp->CalculateProcess()); 1211d9e416c0SGreg Clayton if (process_sp) 1212d9e416c0SGreg Clayton target_sp = process_sp->CalculateTarget(); 1213d9e416c0SGreg Clayton } 1214d9e416c0SGreg Clayton return target_sp; 121530fdc8d8SChris Lattner } 121630fdc8d8SChris Lattner 1217d9e416c0SGreg Clayton ProcessSP 121830fdc8d8SChris Lattner StackFrame::CalculateProcess () 121930fdc8d8SChris Lattner { 1220d9e416c0SGreg Clayton ProcessSP process_sp; 1221d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1222d9e416c0SGreg Clayton if (thread_sp) 1223d9e416c0SGreg Clayton process_sp = thread_sp->CalculateProcess(); 1224d9e416c0SGreg Clayton return process_sp; 122530fdc8d8SChris Lattner } 122630fdc8d8SChris Lattner 1227d9e416c0SGreg Clayton ThreadSP 122830fdc8d8SChris Lattner StackFrame::CalculateThread () 122930fdc8d8SChris Lattner { 1230d9e416c0SGreg Clayton return GetThread(); 123130fdc8d8SChris Lattner } 123230fdc8d8SChris Lattner 1233d9e416c0SGreg Clayton StackFrameSP 123430fdc8d8SChris Lattner StackFrame::CalculateStackFrame () 123530fdc8d8SChris Lattner { 1236d9e416c0SGreg Clayton return shared_from_this(); 123730fdc8d8SChris Lattner } 123830fdc8d8SChris Lattner 123930fdc8d8SChris Lattner 124030fdc8d8SChris Lattner void 12410603aa9dSGreg Clayton StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) 124230fdc8d8SChris Lattner { 1243d9e416c0SGreg Clayton exe_ctx.SetContext (shared_from_this()); 124430fdc8d8SChris Lattner } 124530fdc8d8SChris Lattner 124630fdc8d8SChris Lattner void 12470603aa9dSGreg Clayton StackFrame::DumpUsingSettingsFormat (Stream *strm) 12480603aa9dSGreg Clayton { 12490603aa9dSGreg Clayton if (strm == NULL) 12500603aa9dSGreg Clayton return; 12510603aa9dSGreg Clayton 12520603aa9dSGreg Clayton GetSymbolContext(eSymbolContextEverything); 1253d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 12540603aa9dSGreg Clayton const char *end = NULL; 12550603aa9dSGreg Clayton StreamString s; 1256d9e416c0SGreg Clayton const char *frame_format = NULL; 1257d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1258d9e416c0SGreg Clayton if (target) 1259d9e416c0SGreg Clayton frame_format = target->GetDebugger().GetFrameFormat(); 12600603aa9dSGreg Clayton if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end)) 12610603aa9dSGreg Clayton { 12620603aa9dSGreg Clayton strm->Write(s.GetData(), s.GetSize()); 12630603aa9dSGreg Clayton } 12640603aa9dSGreg Clayton else 12650603aa9dSGreg Clayton { 12660603aa9dSGreg Clayton Dump (strm, true, false); 12670603aa9dSGreg Clayton strm->EOL(); 12680603aa9dSGreg Clayton } 12690603aa9dSGreg Clayton } 12700603aa9dSGreg Clayton 12710603aa9dSGreg Clayton void 12726dadd508SGreg Clayton StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) 127330fdc8d8SChris Lattner { 127430fdc8d8SChris Lattner if (strm == NULL) 127530fdc8d8SChris Lattner return; 127630fdc8d8SChris Lattner 127730fdc8d8SChris Lattner if (show_frame_index) 12781b72fcb7SGreg Clayton strm->Printf("frame #%u: ", m_frame_index); 1279d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 1280d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1281d9e416c0SGreg Clayton strm->Printf("0x%0*llx ", 1282d9e416c0SGreg Clayton target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16, 1283d9e416c0SGreg Clayton GetFrameCodeAddress().GetLoadAddress(target)); 12849da7bd07SGreg Clayton GetSymbolContext(eSymbolContextEverything); 12851b72fcb7SGreg Clayton const bool show_module = true; 12861b72fcb7SGreg Clayton const bool show_inline = true; 1287d9e416c0SGreg Clayton m_sc.DumpStopContext (strm, 1288d9e416c0SGreg Clayton exe_ctx.GetBestExecutionContextScope(), 1289d9e416c0SGreg Clayton GetFrameCodeAddress(), 1290d9e416c0SGreg Clayton show_fullpaths, 1291d9e416c0SGreg Clayton show_module, 1292d9e416c0SGreg Clayton show_inline); 129330fdc8d8SChris Lattner } 129430fdc8d8SChris Lattner 12955082c5fdSGreg Clayton void 129659e8fc1cSGreg Clayton StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) 12975082c5fdSGreg Clayton { 129859e8fc1cSGreg Clayton assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing 129959e8fc1cSGreg Clayton m_variable_list_sp = prev_frame.m_variable_list_sp; 1300288bdf9cSGreg Clayton m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); 130168275d5eSGreg Clayton if (!m_disassembly.GetString().empty()) 130268275d5eSGreg Clayton m_disassembly.GetString().swap (m_disassembly.GetString()); 13035082c5fdSGreg Clayton } 130468275d5eSGreg Clayton 130568275d5eSGreg Clayton 130659e8fc1cSGreg Clayton void 130759e8fc1cSGreg Clayton StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) 130859e8fc1cSGreg Clayton { 130959e8fc1cSGreg Clayton assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing 13102cad65a5SGreg Clayton m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value 1311d9e416c0SGreg Clayton assert (GetThread() == curr_frame.GetThread()); 131259e8fc1cSGreg Clayton m_frame_index = curr_frame.m_frame_index; 13135ccbd294SGreg Clayton m_concrete_frame_index = curr_frame.m_concrete_frame_index; 131459e8fc1cSGreg Clayton m_reg_context_sp = curr_frame.m_reg_context_sp; 131559e8fc1cSGreg Clayton m_frame_code_addr = curr_frame.m_frame_code_addr; 131659e8fc1cSGreg 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()); 131759e8fc1cSGreg 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()); 131859e8fc1cSGreg Clayton assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); 131959e8fc1cSGreg Clayton assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function); 132059e8fc1cSGreg Clayton m_sc = curr_frame.m_sc; 132159e8fc1cSGreg Clayton m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); 132259e8fc1cSGreg Clayton m_flags.Set (m_sc.GetResolvedMask()); 132359e8fc1cSGreg Clayton m_frame_base.Clear(); 132459e8fc1cSGreg Clayton m_frame_base_error.Clear(); 132559e8fc1cSGreg Clayton } 132659e8fc1cSGreg Clayton 132759e8fc1cSGreg Clayton 13282cad65a5SGreg Clayton bool 13292cad65a5SGreg Clayton StackFrame::HasCachedData () const 13302cad65a5SGreg Clayton { 13312cad65a5SGreg Clayton if (m_variable_list_sp.get()) 13322cad65a5SGreg Clayton return true; 13332cad65a5SGreg Clayton if (m_variable_list_value_objects.GetSize() > 0) 13342cad65a5SGreg Clayton return true; 13352cad65a5SGreg Clayton if (!m_disassembly.GetString().empty()) 13362cad65a5SGreg Clayton return true; 13372cad65a5SGreg Clayton return false; 13382cad65a5SGreg Clayton } 1339e4284b71SJim Ingham 13407260f620SGreg Clayton bool 13417260f620SGreg Clayton StackFrame::GetStatus (Stream& strm, 13427260f620SGreg Clayton bool show_frame_info, 134353eb7ad2SGreg Clayton bool show_source) 13447260f620SGreg Clayton { 134553eb7ad2SGreg Clayton 13467260f620SGreg Clayton if (show_frame_info) 13477260f620SGreg Clayton { 13487260f620SGreg Clayton strm.Indent(); 13497260f620SGreg Clayton DumpUsingSettingsFormat (&strm); 13507260f620SGreg Clayton } 13517260f620SGreg Clayton 13527260f620SGreg Clayton if (show_source) 13537260f620SGreg Clayton { 1354d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 1355e372b98dSGreg Clayton bool have_source = false; 135667cc0636SGreg Clayton Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever; 1357d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 135853eb7ad2SGreg Clayton if (target) 135953eb7ad2SGreg Clayton { 136053eb7ad2SGreg Clayton Debugger &debugger = target->GetDebugger(); 136153eb7ad2SGreg Clayton const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true); 136253eb7ad2SGreg Clayton const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false); 136353eb7ad2SGreg Clayton disasm_display = debugger.GetStopDisassemblyDisplay (); 136453eb7ad2SGreg Clayton 136553eb7ad2SGreg Clayton if (source_lines_before > 0 || source_lines_after > 0) 1366e372b98dSGreg Clayton { 13677260f620SGreg Clayton GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); 13687260f620SGreg Clayton 13697260f620SGreg Clayton if (m_sc.comp_unit && m_sc.line_entry.IsValid()) 13707260f620SGreg Clayton { 1371d9e416c0SGreg Clayton if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, 13727260f620SGreg Clayton m_sc.line_entry.line, 1373d9e416c0SGreg Clayton source_lines_before, 1374d9e416c0SGreg Clayton source_lines_after, 13757260f620SGreg Clayton "->", 1376e372b98dSGreg Clayton &strm)) 1377e372b98dSGreg Clayton { 1378e372b98dSGreg Clayton have_source = true; 1379e372b98dSGreg Clayton } 1380e372b98dSGreg Clayton } 1381e372b98dSGreg Clayton } 1382e372b98dSGreg Clayton switch (disasm_display) 1383e372b98dSGreg Clayton { 138467cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNever: 1385e372b98dSGreg Clayton break; 1386e372b98dSGreg Clayton 138767cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNoSource: 1388e372b98dSGreg Clayton if (have_source) 1389e372b98dSGreg Clayton break; 1390e372b98dSGreg Clayton // Fall through to next case 139167cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeAlways: 1392d9e416c0SGreg Clayton if (target) 1393e372b98dSGreg Clayton { 139453eb7ad2SGreg Clayton const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); 1395e372b98dSGreg Clayton if (disasm_lines > 0) 1396e372b98dSGreg Clayton { 1397d9e416c0SGreg Clayton const ArchSpec &target_arch = target->GetArchitecture(); 1398e372b98dSGreg Clayton AddressRange pc_range; 1399e372b98dSGreg Clayton pc_range.GetBaseAddress() = GetFrameCodeAddress(); 1400e372b98dSGreg Clayton pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize()); 1401d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 1402e372b98dSGreg Clayton target_arch, 1403e372b98dSGreg Clayton NULL, 1404e372b98dSGreg Clayton exe_ctx, 1405e372b98dSGreg Clayton pc_range, 1406e372b98dSGreg Clayton disasm_lines, 1407e372b98dSGreg Clayton 0, 1408e372b98dSGreg Clayton Disassembler::eOptionMarkPCAddress, 1409e372b98dSGreg Clayton strm); 1410e372b98dSGreg Clayton } 1411e372b98dSGreg Clayton } 1412e372b98dSGreg Clayton break; 14137260f620SGreg Clayton } 14147260f620SGreg Clayton } 141553eb7ad2SGreg Clayton } 14167260f620SGreg Clayton return true; 14177260f620SGreg Clayton } 14187260f620SGreg Clayton 1419