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" 19554f68d3SGreg Clayton #include "lldb/Core/FormatEntity.h" 2030fdc8d8SChris Lattner #include "lldb/Core/Value.h" 21288bdf9cSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 2254979cddSGreg Clayton #include "lldb/Core/ValueObjectConstResult.h" 231f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h" 2430fdc8d8SChris Lattner #include "lldb/Symbol/Function.h" 251f746071SGreg Clayton #include "lldb/Symbol/Symbol.h" 261f746071SGreg Clayton #include "lldb/Symbol/SymbolContextScope.h" 2746252398SEnrico Granata #include "lldb/Symbol/Type.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, 5199618476SJason Molenda bool cfa_is_valid, 524d122c40SGreg Clayton addr_t pc, 5399618476SJason Molenda uint32_t stop_id, 5499618476SJason Molenda bool stop_id_is_valid, 5599618476SJason Molenda bool is_history_frame, 568f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 57d9e416c0SGreg Clayton m_thread_wp (thread_sp), 581b72fcb7SGreg Clayton m_frame_index (frame_idx), 595ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 6030fdc8d8SChris Lattner m_reg_context_sp (), 616dadd508SGreg Clayton m_id (pc, cfa, NULL), 62e72dfb32SGreg Clayton m_frame_code_addr (pc), 6330fdc8d8SChris Lattner m_sc (), 6430fdc8d8SChris Lattner m_flags (), 6530fdc8d8SChris Lattner m_frame_base (), 6630fdc8d8SChris Lattner m_frame_base_error (), 6799618476SJason Molenda m_cfa_is_valid (cfa_is_valid), 6899618476SJason Molenda m_stop_id (stop_id), 6999618476SJason Molenda m_stop_id_is_valid (stop_id_is_valid), 7099618476SJason Molenda m_is_history_frame (is_history_frame), 7130fdc8d8SChris Lattner m_variable_list_sp (), 721a65ae11SGreg Clayton m_variable_list_value_objects (), 736a354705SJason Molenda m_disassembly (), 746a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 7530fdc8d8SChris Lattner { 7699618476SJason Molenda // If we don't have a CFA value, use the frame index for our StackID so that recursive 7799618476SJason Molenda // functions properly aren't confused with one another on a history stack. 7899618476SJason Molenda if (m_is_history_frame && m_cfa_is_valid == false) 7999618476SJason Molenda { 8099618476SJason Molenda m_id.SetCFA (m_frame_index); 8199618476SJason Molenda } 8299618476SJason Molenda 8330fdc8d8SChris Lattner if (sc_ptr != NULL) 841b72fcb7SGreg Clayton { 8530fdc8d8SChris Lattner m_sc = *sc_ptr; 861b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 871b72fcb7SGreg Clayton } 8830fdc8d8SChris Lattner } 8930fdc8d8SChris Lattner 90d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 91d9e416c0SGreg Clayton user_id_t frame_idx, 924d122c40SGreg Clayton user_id_t unwind_frame_index, 931b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 944d122c40SGreg Clayton addr_t cfa, 954d122c40SGreg Clayton addr_t pc, 968f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 97d9e416c0SGreg Clayton m_thread_wp (thread_sp), 981b72fcb7SGreg Clayton m_frame_index (frame_idx), 995ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 10030fdc8d8SChris Lattner m_reg_context_sp (reg_context_sp), 1016dadd508SGreg Clayton m_id (pc, cfa, NULL), 102e72dfb32SGreg Clayton m_frame_code_addr (pc), 10330fdc8d8SChris Lattner m_sc (), 10430fdc8d8SChris Lattner m_flags (), 10530fdc8d8SChris Lattner m_frame_base (), 10630fdc8d8SChris Lattner m_frame_base_error (), 10799618476SJason Molenda m_cfa_is_valid (true), 10899618476SJason Molenda m_stop_id (0), 10999618476SJason Molenda m_stop_id_is_valid (false), 11099618476SJason Molenda m_is_history_frame (false), 11130fdc8d8SChris Lattner m_variable_list_sp (), 1121a65ae11SGreg Clayton m_variable_list_value_objects (), 1136a354705SJason Molenda m_disassembly (), 1146a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 11530fdc8d8SChris Lattner { 11630fdc8d8SChris Lattner if (sc_ptr != NULL) 1171b72fcb7SGreg Clayton { 11830fdc8d8SChris Lattner m_sc = *sc_ptr; 1191b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1201b72fcb7SGreg Clayton } 1211b72fcb7SGreg Clayton 1221b72fcb7SGreg Clayton if (reg_context_sp && !m_sc.target_sp) 1231b72fcb7SGreg Clayton { 124d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 125d9e416c0SGreg Clayton if (m_sc.target_sp) 1261b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1271b72fcb7SGreg Clayton } 1281b72fcb7SGreg Clayton } 1291b72fcb7SGreg Clayton 130d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 131d9e416c0SGreg Clayton user_id_t frame_idx, 1324d122c40SGreg Clayton user_id_t unwind_frame_index, 1331b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 1344d122c40SGreg Clayton addr_t cfa, 1351b72fcb7SGreg Clayton const Address& pc_addr, 1368f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 137d9e416c0SGreg Clayton m_thread_wp (thread_sp), 1381b72fcb7SGreg Clayton m_frame_index (frame_idx), 1395ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 1401b72fcb7SGreg Clayton m_reg_context_sp (reg_context_sp), 1411ac04c30SGreg Clayton m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL), 14212fc3e0fSGreg Clayton m_frame_code_addr (pc_addr), 1431b72fcb7SGreg Clayton m_sc (), 1441b72fcb7SGreg Clayton m_flags (), 1451b72fcb7SGreg Clayton m_frame_base (), 1461b72fcb7SGreg Clayton m_frame_base_error (), 14799618476SJason Molenda m_cfa_is_valid (true), 14899618476SJason Molenda m_stop_id (0), 14999618476SJason Molenda m_stop_id_is_valid (false), 15099618476SJason Molenda m_is_history_frame (false), 1511b72fcb7SGreg Clayton m_variable_list_sp (), 1521a65ae11SGreg Clayton m_variable_list_value_objects (), 1536a354705SJason Molenda m_disassembly (), 1546a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 1551b72fcb7SGreg Clayton { 1561b72fcb7SGreg Clayton if (sc_ptr != NULL) 1571b72fcb7SGreg Clayton { 1581b72fcb7SGreg Clayton m_sc = *sc_ptr; 1591b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1601b72fcb7SGreg Clayton } 1611b72fcb7SGreg Clayton 1621b72fcb7SGreg Clayton if (m_sc.target_sp.get() == NULL && reg_context_sp) 1631b72fcb7SGreg Clayton { 164d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 165d9e416c0SGreg Clayton if (m_sc.target_sp) 1661b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1671b72fcb7SGreg Clayton } 1681b72fcb7SGreg Clayton 169e72dfb32SGreg Clayton ModuleSP pc_module_sp (pc_addr.GetModule()); 170e72dfb32SGreg Clayton if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) 1711b72fcb7SGreg Clayton { 172e72dfb32SGreg Clayton if (pc_module_sp) 1731b72fcb7SGreg Clayton { 174e72dfb32SGreg Clayton m_sc.module_sp = pc_module_sp; 1751b72fcb7SGreg Clayton m_flags.Set (eSymbolContextModule); 1761b72fcb7SGreg Clayton } 177ffc1d667SGreg Clayton else 178ffc1d667SGreg Clayton { 179ffc1d667SGreg Clayton m_sc.module_sp.reset(); 180ffc1d667SGreg Clayton } 1811b72fcb7SGreg Clayton } 18230fdc8d8SChris Lattner } 18330fdc8d8SChris Lattner 18430fdc8d8SChris Lattner 18530fdc8d8SChris Lattner //---------------------------------------------------------------------- 18630fdc8d8SChris Lattner // Destructor 18730fdc8d8SChris Lattner //---------------------------------------------------------------------- 18830fdc8d8SChris Lattner StackFrame::~StackFrame() 18930fdc8d8SChris Lattner { 19030fdc8d8SChris Lattner } 19130fdc8d8SChris Lattner 19230fdc8d8SChris Lattner StackID& 19330fdc8d8SChris Lattner StackFrame::GetStackID() 19430fdc8d8SChris Lattner { 1956a354705SJason Molenda Mutex::Locker locker(m_mutex); 1966dadd508SGreg Clayton // Make sure we have resolved the StackID object's symbol context scope if 1976dadd508SGreg Clayton // we already haven't looked it up. 19859e8fc1cSGreg Clayton 19959e8fc1cSGreg Clayton if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) 20059e8fc1cSGreg Clayton { 2012cad65a5SGreg Clayton if (m_id.GetSymbolContextScope ()) 20259e8fc1cSGreg Clayton { 20395897c6aSGreg Clayton // We already have a symbol context scope, we just don't have our 20495897c6aSGreg Clayton // flag bit set. 20559e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 20659e8fc1cSGreg Clayton } 20759e8fc1cSGreg Clayton else 20859e8fc1cSGreg Clayton { 20995897c6aSGreg Clayton // Calculate the frame block and use this for the stack ID symbol 21095897c6aSGreg Clayton // context scope if we have one. 21195897c6aSGreg Clayton SymbolContextScope *scope = GetFrameBlock (); 21295897c6aSGreg Clayton if (scope == NULL) 21359e8fc1cSGreg Clayton { 21495897c6aSGreg Clayton // We don't have a block, so use the symbol 21595897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 21659e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextSymbol); 21795897c6aSGreg Clayton 21895897c6aSGreg Clayton // It is ok if m_sc.symbol is NULL here 21995897c6aSGreg Clayton scope = m_sc.symbol; 22059e8fc1cSGreg Clayton } 22195897c6aSGreg Clayton // Set the symbol context scope (the accessor will set the 22295897c6aSGreg Clayton // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). 22395897c6aSGreg Clayton SetSymbolContextScope (scope); 22459e8fc1cSGreg Clayton } 22559e8fc1cSGreg Clayton } 22630fdc8d8SChris Lattner return m_id; 22730fdc8d8SChris Lattner } 22830fdc8d8SChris Lattner 229513c6bb8SJim Ingham uint32_t 230513c6bb8SJim Ingham StackFrame::GetFrameIndex () const 231513c6bb8SJim Ingham { 232513c6bb8SJim Ingham ThreadSP thread_sp = GetThread(); 233513c6bb8SJim Ingham if (thread_sp) 234b57e4a1bSJason Molenda return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index); 235513c6bb8SJim Ingham else 236513c6bb8SJim Ingham return m_frame_index; 237513c6bb8SJim Ingham } 238513c6bb8SJim Ingham 23959e8fc1cSGreg Clayton void 24059e8fc1cSGreg Clayton StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) 24159e8fc1cSGreg Clayton { 2426a354705SJason Molenda Mutex::Locker locker(m_mutex); 24359e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 24459e8fc1cSGreg Clayton m_id.SetSymbolContextScope (symbol_scope); 24559e8fc1cSGreg Clayton } 24659e8fc1cSGreg Clayton 24734132754SGreg Clayton const Address& 2489da7bd07SGreg Clayton StackFrame::GetFrameCodeAddress() 24930fdc8d8SChris Lattner { 2506a354705SJason Molenda Mutex::Locker locker(m_mutex); 25159e8fc1cSGreg Clayton if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) 25230fdc8d8SChris Lattner { 25359e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_CODE_ADDR); 25430fdc8d8SChris Lattner 25530fdc8d8SChris Lattner // Resolve the PC into a temporary address because if ResolveLoadAddress 25630fdc8d8SChris Lattner // fails to resolve the address, it will clear the address object... 257d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 258d9e416c0SGreg Clayton if (thread_sp) 259d9e416c0SGreg Clayton { 260d9e416c0SGreg Clayton TargetSP target_sp (thread_sp->CalculateTarget()); 261d9e416c0SGreg Clayton if (target_sp) 262d9e416c0SGreg Clayton { 26325b9f7ebSTamas Berghammer if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode)) 26430fdc8d8SChris Lattner { 265e72dfb32SGreg Clayton ModuleSP module_sp (m_frame_code_addr.GetModule()); 266e72dfb32SGreg Clayton if (module_sp) 26730fdc8d8SChris Lattner { 268e72dfb32SGreg Clayton m_sc.module_sp = module_sp; 26930fdc8d8SChris Lattner m_flags.Set(eSymbolContextModule); 27030fdc8d8SChris Lattner } 27130fdc8d8SChris Lattner } 27230fdc8d8SChris Lattner } 27330fdc8d8SChris Lattner } 274d9e416c0SGreg Clayton } 27512fc3e0fSGreg Clayton return m_frame_code_addr; 27630fdc8d8SChris Lattner } 27730fdc8d8SChris Lattner 27899618476SJason Molenda bool 27930fdc8d8SChris Lattner StackFrame::ChangePC (addr_t pc) 28030fdc8d8SChris Lattner { 2816a354705SJason Molenda Mutex::Locker locker(m_mutex); 28299618476SJason Molenda // We can't change the pc value of a history stack frame - it is immutable. 28399618476SJason Molenda if (m_is_history_frame) 28499618476SJason Molenda return false; 285e72dfb32SGreg Clayton m_frame_code_addr.SetRawAddress(pc); 28672310355SGreg Clayton m_sc.Clear(false); 28773b472d4SGreg Clayton m_flags.Reset(0); 288d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 289d9e416c0SGreg Clayton if (thread_sp) 290d9e416c0SGreg Clayton thread_sp->ClearStackFrames (); 29199618476SJason Molenda return true; 29230fdc8d8SChris Lattner } 29330fdc8d8SChris Lattner 29430fdc8d8SChris Lattner const char * 29530fdc8d8SChris Lattner StackFrame::Disassemble () 29630fdc8d8SChris Lattner { 2976a354705SJason Molenda Mutex::Locker locker(m_mutex); 29830fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 29930fdc8d8SChris Lattner { 300d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 301d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 302d9e416c0SGreg Clayton if (target) 303d9e416c0SGreg Clayton { 3040f063ba6SJim Ingham const char *plugin_name = NULL; 3050f063ba6SJim Ingham const char *flavor = NULL; 306d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 307d9e416c0SGreg Clayton target->GetArchitecture(), 3080f063ba6SJim Ingham plugin_name, 3090f063ba6SJim Ingham flavor, 31030fdc8d8SChris Lattner exe_ctx, 31130fdc8d8SChris Lattner 0, 31237023b06SJim Ingham 0, 3131da6f9d7SGreg Clayton 0, 31430fdc8d8SChris Lattner m_disassembly); 315d9e416c0SGreg Clayton } 31630fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 31730fdc8d8SChris Lattner return NULL; 31830fdc8d8SChris Lattner } 31930fdc8d8SChris Lattner return m_disassembly.GetData(); 32030fdc8d8SChris Lattner } 32130fdc8d8SChris Lattner 32295897c6aSGreg Clayton Block * 32395897c6aSGreg Clayton StackFrame::GetFrameBlock () 32495897c6aSGreg Clayton { 32595897c6aSGreg Clayton if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock)) 32695897c6aSGreg Clayton GetSymbolContext (eSymbolContextBlock); 32795897c6aSGreg Clayton 32895897c6aSGreg Clayton if (m_sc.block) 32995897c6aSGreg Clayton { 33095897c6aSGreg Clayton Block *inline_block = m_sc.block->GetContainingInlinedBlock(); 33195897c6aSGreg Clayton if (inline_block) 33295897c6aSGreg Clayton { 33395897c6aSGreg Clayton // Use the block with the inlined function info 33495897c6aSGreg Clayton // as the frame block we want this frame to have only the variables 33595897c6aSGreg Clayton // for the inlined function and its non-inlined block child blocks. 33695897c6aSGreg Clayton return inline_block; 33795897c6aSGreg Clayton } 33895897c6aSGreg Clayton else 33995897c6aSGreg Clayton { 34095897c6aSGreg Clayton // This block is not contained withing any inlined function blocks 34195897c6aSGreg Clayton // with so we want to use the top most function block. 34295897c6aSGreg Clayton return &m_sc.function->GetBlock (false); 34395897c6aSGreg Clayton } 34495897c6aSGreg Clayton } 34595897c6aSGreg Clayton return NULL; 34695897c6aSGreg Clayton } 34795897c6aSGreg Clayton 34830fdc8d8SChris Lattner //---------------------------------------------------------------------- 34930fdc8d8SChris Lattner // Get the symbol context if we already haven't done so by resolving the 35030fdc8d8SChris Lattner // PC address as much as possible. This way when we pass around a 35130fdc8d8SChris Lattner // StackFrame object, everyone will have as much information as 35230fdc8d8SChris Lattner // possible and no one will ever have to look things up manually. 35330fdc8d8SChris Lattner //---------------------------------------------------------------------- 35430fdc8d8SChris Lattner const SymbolContext& 35530fdc8d8SChris Lattner StackFrame::GetSymbolContext (uint32_t resolve_scope) 35630fdc8d8SChris Lattner { 3576a354705SJason Molenda Mutex::Locker locker(m_mutex); 35830fdc8d8SChris Lattner // Copy our internal symbol context into "sc". 35973b472d4SGreg Clayton if ((m_flags.Get() & resolve_scope) != resolve_scope) 36030fdc8d8SChris Lattner { 36175a0333bSGreg Clayton uint32_t resolved = 0; 36275a0333bSGreg Clayton 36375a0333bSGreg Clayton // If the target was requested add that: 36475a0333bSGreg Clayton if (!m_sc.target_sp) 36575a0333bSGreg Clayton { 36675a0333bSGreg Clayton m_sc.target_sp = CalculateTarget(); 36775a0333bSGreg Clayton if (m_sc.target_sp) 36875a0333bSGreg Clayton resolved |= eSymbolContextTarget; 36975a0333bSGreg Clayton } 37075a0333bSGreg Clayton 37175a0333bSGreg Clayton 372aaa0ba31SBruce Mitchener // Resolve our PC to section offset if we haven't already done so 37330fdc8d8SChris Lattner // and if we don't have a module. The resolved address section will 37430fdc8d8SChris Lattner // contain the module to which it belongs 37559e8fc1cSGreg Clayton if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) 3769da7bd07SGreg Clayton GetFrameCodeAddress(); 37730fdc8d8SChris Lattner 37830fdc8d8SChris Lattner // If this is not frame zero, then we need to subtract 1 from the PC 37930fdc8d8SChris Lattner // value when doing address lookups since the PC will be on the 38030fdc8d8SChris Lattner // instruction following the function call instruction... 38130fdc8d8SChris Lattner 3829da7bd07SGreg Clayton Address lookup_addr(GetFrameCodeAddress()); 3831b72fcb7SGreg Clayton if (m_frame_index > 0 && lookup_addr.IsValid()) 38430fdc8d8SChris Lattner { 38530fdc8d8SChris Lattner addr_t offset = lookup_addr.GetOffset(); 38630fdc8d8SChris Lattner if (offset > 0) 387cf29675dSJason Molenda { 38830fdc8d8SChris Lattner lookup_addr.SetOffset(offset - 1); 389cf29675dSJason Molenda 390cf29675dSJason Molenda } 391cf29675dSJason Molenda else 392cf29675dSJason Molenda { 393cf29675dSJason Molenda // lookup_addr is the start of a section. We need 394cf29675dSJason Molenda // do the math on the actual load address and re-compute 395cf29675dSJason Molenda // the section. We're working with a 'noreturn' function 396cf29675dSJason Molenda // at the end of a section. 397cf29675dSJason Molenda ThreadSP thread_sp (GetThread()); 398cf29675dSJason Molenda if (thread_sp) 399cf29675dSJason Molenda { 400cf29675dSJason Molenda TargetSP target_sp (thread_sp->CalculateTarget()); 401cf29675dSJason Molenda if (target_sp) 402cf29675dSJason Molenda { 403cf29675dSJason Molenda addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1; 404cf29675dSJason Molenda lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get()); 405cf29675dSJason Molenda } 406cf29675dSJason Molenda else 407cf29675dSJason Molenda { 408cf29675dSJason Molenda lookup_addr.SetOffset(offset - 1); 409cf29675dSJason Molenda } 410cf29675dSJason Molenda } 411cf29675dSJason Molenda } 41230fdc8d8SChris Lattner } 41330fdc8d8SChris Lattner 4149da7bd07SGreg Clayton 41530fdc8d8SChris Lattner if (m_sc.module_sp) 41630fdc8d8SChris Lattner { 41730fdc8d8SChris Lattner // We have something in our stack frame symbol context, lets check 41830fdc8d8SChris Lattner // if we haven't already tried to lookup one of those things. If we 41930fdc8d8SChris Lattner // haven't then we will do the query. 4201b72fcb7SGreg Clayton 4211b72fcb7SGreg Clayton uint32_t actual_resolve_scope = 0; 4221b72fcb7SGreg Clayton 4231b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextCompUnit) 4241b72fcb7SGreg Clayton { 4251b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 4261b72fcb7SGreg Clayton { 4271b72fcb7SGreg Clayton if (m_sc.comp_unit) 4289da7bd07SGreg Clayton resolved |= eSymbolContextCompUnit; 4291b72fcb7SGreg Clayton else 4301b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextCompUnit; 4311b72fcb7SGreg Clayton } 4321b72fcb7SGreg Clayton } 4331b72fcb7SGreg Clayton 4341b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextFunction) 4351b72fcb7SGreg Clayton { 4361b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextFunction)) 4371b72fcb7SGreg Clayton { 4381b72fcb7SGreg Clayton if (m_sc.function) 4399da7bd07SGreg Clayton resolved |= eSymbolContextFunction; 4401b72fcb7SGreg Clayton else 4411b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextFunction; 4421b72fcb7SGreg Clayton } 4431b72fcb7SGreg Clayton } 4441b72fcb7SGreg Clayton 4451b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextBlock) 4461b72fcb7SGreg Clayton { 4471b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextBlock)) 4481b72fcb7SGreg Clayton { 4491b72fcb7SGreg Clayton if (m_sc.block) 4509da7bd07SGreg Clayton resolved |= eSymbolContextBlock; 4511b72fcb7SGreg Clayton else 4521b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextBlock; 4531b72fcb7SGreg Clayton } 4541b72fcb7SGreg Clayton } 4551b72fcb7SGreg Clayton 4561b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextSymbol) 4571b72fcb7SGreg Clayton { 4581b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 4591b72fcb7SGreg Clayton { 4601b72fcb7SGreg Clayton if (m_sc.symbol) 4619da7bd07SGreg Clayton resolved |= eSymbolContextSymbol; 4621b72fcb7SGreg Clayton else 4631b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextSymbol; 4641b72fcb7SGreg Clayton } 4651b72fcb7SGreg Clayton } 4661b72fcb7SGreg Clayton 4671b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextLineEntry) 4681b72fcb7SGreg Clayton { 4691b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextLineEntry)) 4701b72fcb7SGreg Clayton { 4711b72fcb7SGreg Clayton if (m_sc.line_entry.IsValid()) 4729da7bd07SGreg Clayton resolved |= eSymbolContextLineEntry; 4731b72fcb7SGreg Clayton else 4741b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextLineEntry; 4751b72fcb7SGreg Clayton } 4761b72fcb7SGreg Clayton } 4771b72fcb7SGreg Clayton 4781b72fcb7SGreg Clayton if (actual_resolve_scope) 47930fdc8d8SChris Lattner { 48030fdc8d8SChris Lattner // We might be resolving less information than what is already 48130fdc8d8SChris Lattner // in our current symbol context so resolve into a temporary 48230fdc8d8SChris Lattner // symbol context "sc" so we don't clear out data we have 48330fdc8d8SChris Lattner // already found in "m_sc" 48430fdc8d8SChris Lattner SymbolContext sc; 48530fdc8d8SChris Lattner // Set flags that indicate what we have tried to resolve 4869da7bd07SGreg Clayton resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); 4871b72fcb7SGreg Clayton // Only replace what we didn't already have as we may have 4881b72fcb7SGreg Clayton // information for an inlined function scope that won't match 4891b72fcb7SGreg Clayton // what a standard lookup by address would match 4909da7bd07SGreg Clayton if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL) 4919da7bd07SGreg Clayton m_sc.comp_unit = sc.comp_unit; 4929da7bd07SGreg Clayton if ((resolved & eSymbolContextFunction) && m_sc.function == NULL) 4939da7bd07SGreg Clayton m_sc.function = sc.function; 4949da7bd07SGreg Clayton if ((resolved & eSymbolContextBlock) && m_sc.block == NULL) 4959da7bd07SGreg Clayton m_sc.block = sc.block; 4969da7bd07SGreg Clayton if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL) 4979da7bd07SGreg Clayton m_sc.symbol = sc.symbol; 4989da7bd07SGreg Clayton if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) 49975a0333bSGreg Clayton { 5009da7bd07SGreg Clayton m_sc.line_entry = sc.line_entry; 50175a0333bSGreg Clayton if (m_sc.target_sp) 50275a0333bSGreg Clayton { 50375a0333bSGreg Clayton // Be sure to apply and file remappings to our file and line 50475a0333bSGreg Clayton // entries when handing out a line entry 50575a0333bSGreg Clayton FileSpec new_file_spec; 50675a0333bSGreg Clayton if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec)) 50775a0333bSGreg Clayton m_sc.line_entry.file = new_file_spec; 50875a0333bSGreg Clayton } 50975a0333bSGreg Clayton } 51030fdc8d8SChris Lattner } 51130fdc8d8SChris Lattner } 51230fdc8d8SChris Lattner else 51330fdc8d8SChris Lattner { 51430fdc8d8SChris Lattner // If we don't have a module, then we can't have the compile unit, 51530fdc8d8SChris Lattner // function, block, line entry or symbol, so we can safely call 51630fdc8d8SChris Lattner // ResolveSymbolContextForAddress with our symbol context member m_sc. 5179da7bd07SGreg Clayton if (m_sc.target_sp) 518f4be227dSSean Callanan { 51975a0333bSGreg Clayton resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); 520f4be227dSSean Callanan } 5219da7bd07SGreg Clayton } 52230fdc8d8SChris Lattner 52330fdc8d8SChris Lattner // Update our internal flags so we remember what we have tried to locate so 52430fdc8d8SChris Lattner // we don't have to keep trying when more calls to this function are made. 5259da7bd07SGreg Clayton // We might have dug up more information that was requested (for example 5269da7bd07SGreg Clayton // if we were asked to only get the block, we will have gotten the 5279da7bd07SGreg Clayton // compile unit, and function) so set any additional bits that we resolved 5289da7bd07SGreg Clayton m_flags.Set (resolve_scope | resolved); 52930fdc8d8SChris Lattner } 53030fdc8d8SChris Lattner 53130fdc8d8SChris Lattner // Return the symbol context with everything that was possible to resolve 53230fdc8d8SChris Lattner // resolved. 53330fdc8d8SChris Lattner return m_sc; 53430fdc8d8SChris Lattner } 53530fdc8d8SChris Lattner 53630fdc8d8SChris Lattner 53730fdc8d8SChris Lattner VariableList * 538288bdf9cSGreg Clayton StackFrame::GetVariableList (bool get_file_globals) 53930fdc8d8SChris Lattner { 5406a354705SJason Molenda Mutex::Locker locker(m_mutex); 54130fdc8d8SChris Lattner if (m_flags.IsClear(RESOLVED_VARIABLES)) 54230fdc8d8SChris Lattner { 54330fdc8d8SChris Lattner m_flags.Set(RESOLVED_VARIABLES); 54430fdc8d8SChris Lattner 54595897c6aSGreg Clayton Block *frame_block = GetFrameBlock(); 546288bdf9cSGreg Clayton 54795897c6aSGreg Clayton if (frame_block) 54830fdc8d8SChris Lattner { 54995897c6aSGreg Clayton const bool get_child_variables = true; 55095897c6aSGreg Clayton const bool can_create = true; 551c662ec8bSGreg Clayton const bool stop_if_child_block_is_inlined_function = true; 552c662ec8bSGreg Clayton m_variable_list_sp.reset(new VariableList()); 553c662ec8bSGreg Clayton frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); 55430fdc8d8SChris Lattner } 5557c0962dcSSean Callanan } 556288bdf9cSGreg Clayton 5577c0962dcSSean Callanan if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && 5587c0962dcSSean Callanan get_file_globals) 55995897c6aSGreg Clayton { 5607c0962dcSSean Callanan m_flags.Set(RESOLVED_GLOBAL_VARIABLES); 5617c0962dcSSean Callanan 56295897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 56395897c6aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit); 56495897c6aSGreg Clayton 56595897c6aSGreg Clayton if (m_sc.comp_unit) 566288bdf9cSGreg Clayton { 567288bdf9cSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 568288bdf9cSGreg Clayton if (m_variable_list_sp) 569288bdf9cSGreg Clayton m_variable_list_sp->AddVariables (global_variable_list_sp.get()); 570288bdf9cSGreg Clayton else 571288bdf9cSGreg Clayton m_variable_list_sp = global_variable_list_sp; 572288bdf9cSGreg Clayton } 57330fdc8d8SChris Lattner } 5747c0962dcSSean Callanan 57530fdc8d8SChris Lattner return m_variable_list_sp.get(); 57630fdc8d8SChris Lattner } 57730fdc8d8SChris Lattner 578d41f032aSGreg Clayton VariableListSP 579d41f032aSGreg Clayton StackFrame::GetInScopeVariableList (bool get_file_globals) 580d41f032aSGreg Clayton { 5816a354705SJason Molenda Mutex::Locker locker(m_mutex); 58299618476SJason Molenda // We can't fetch variable information for a history stack frame. 58399618476SJason Molenda if (m_is_history_frame) 58499618476SJason Molenda return VariableListSP(); 58599618476SJason Molenda 586d41f032aSGreg Clayton VariableListSP var_list_sp(new VariableList); 587d41f032aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); 588d41f032aSGreg Clayton 589d41f032aSGreg Clayton if (m_sc.block) 590d41f032aSGreg Clayton { 591d41f032aSGreg Clayton const bool can_create = true; 592d41f032aSGreg Clayton const bool get_parent_variables = true; 593d41f032aSGreg Clayton const bool stop_if_block_is_inlined_function = true; 594d41f032aSGreg Clayton m_sc.block->AppendVariables (can_create, 595d41f032aSGreg Clayton get_parent_variables, 596d41f032aSGreg Clayton stop_if_block_is_inlined_function, 597d41f032aSGreg Clayton var_list_sp.get()); 598d41f032aSGreg Clayton } 599d41f032aSGreg Clayton 600*b90168ffSSiva Chandra if (m_sc.comp_unit && get_file_globals) 601d41f032aSGreg Clayton { 602d41f032aSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 603d41f032aSGreg Clayton if (global_variable_list_sp) 604d41f032aSGreg Clayton var_list_sp->AddVariables (global_variable_list_sp.get()); 605d41f032aSGreg Clayton } 606d41f032aSGreg Clayton 607d41f032aSGreg Clayton return var_list_sp; 608d41f032aSGreg Clayton } 609d41f032aSGreg Clayton 610d41f032aSGreg Clayton 6118b2fe6dcSGreg Clayton ValueObjectSP 6122837b766SJim Ingham StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, 6134d122c40SGreg Clayton DynamicValueType use_dynamic, 6142837b766SJim Ingham uint32_t options, 6154d122c40SGreg Clayton VariableSP &var_sp, 6162837b766SJim Ingham Error &error) 6178b2fe6dcSGreg Clayton { 61899618476SJason Molenda // We can't fetch variable information for a history stack frame. 61999618476SJason Molenda if (m_is_history_frame) 62099618476SJason Molenda return ValueObjectSP(); 62154979cddSGreg Clayton 62254979cddSGreg Clayton if (var_expr_cstr && var_expr_cstr[0]) 62354979cddSGreg Clayton { 6246d5e68eaSGreg Clayton const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; 6256d5e68eaSGreg Clayton const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; 62627b625e1SEnrico Granata const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0; 62758ad3344SEnrico Granata //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0; 62854979cddSGreg Clayton error.Clear(); 6298b2fe6dcSGreg Clayton bool deref = false; 6308b2fe6dcSGreg Clayton bool address_of = false; 6318b2fe6dcSGreg Clayton ValueObjectSP valobj_sp; 6328b2fe6dcSGreg Clayton const bool get_file_globals = true; 633d41f032aSGreg Clayton // When looking up a variable for an expression, we need only consider the 634d41f032aSGreg Clayton // variables that are in scope. 635d41f032aSGreg Clayton VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); 636d41f032aSGreg Clayton VariableList *variable_list = var_list_sp.get(); 6378b2fe6dcSGreg Clayton 6388b2fe6dcSGreg Clayton if (variable_list) 6398b2fe6dcSGreg Clayton { 6408b2fe6dcSGreg Clayton // If first character is a '*', then show pointer contents 64154979cddSGreg Clayton const char *var_expr = var_expr_cstr; 6428b2fe6dcSGreg Clayton if (var_expr[0] == '*') 6438b2fe6dcSGreg Clayton { 6448b2fe6dcSGreg Clayton deref = true; 6458b2fe6dcSGreg Clayton var_expr++; // Skip the '*' 6468b2fe6dcSGreg Clayton } 6478b2fe6dcSGreg Clayton else if (var_expr[0] == '&') 6488b2fe6dcSGreg Clayton { 6498b2fe6dcSGreg Clayton address_of = true; 6508b2fe6dcSGreg Clayton var_expr++; // Skip the '&' 6518b2fe6dcSGreg Clayton } 6528b2fe6dcSGreg Clayton 6538b2fe6dcSGreg Clayton std::string var_path (var_expr); 65454979cddSGreg Clayton size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); 65554979cddSGreg Clayton StreamString var_expr_path_strm; 6568b2fe6dcSGreg Clayton 6578b2fe6dcSGreg Clayton ConstString name_const_string; 6588b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 6598b2fe6dcSGreg Clayton name_const_string.SetCString (var_path.c_str()); 6608b2fe6dcSGreg Clayton else 6618b2fe6dcSGreg Clayton name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); 6628b2fe6dcSGreg Clayton 66310bc1a4eSPaul Herman var_sp = variable_list->FindVariable(name_const_string, false); 664685c88c5SGreg Clayton 665685c88c5SGreg Clayton bool synthetically_added_instance_object = false; 666685c88c5SGreg Clayton 667685c88c5SGreg Clayton if (var_sp) 668685c88c5SGreg Clayton { 669685c88c5SGreg Clayton var_path.erase (0, name_const_string.GetLength ()); 670685c88c5SGreg Clayton } 67146252398SEnrico Granata 67246252398SEnrico Granata if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) 673685c88c5SGreg Clayton { 674685c88c5SGreg Clayton // Check for direct ivars access which helps us with implicit 675685c88c5SGreg Clayton // access to ivars with the "this->" or "self->" 676685c88c5SGreg Clayton GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock); 677685c88c5SGreg Clayton lldb::LanguageType method_language = eLanguageTypeUnknown; 678685c88c5SGreg Clayton bool is_instance_method = false; 679685c88c5SGreg Clayton ConstString method_object_name; 680685c88c5SGreg Clayton if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name)) 681685c88c5SGreg Clayton { 682685c88c5SGreg Clayton if (is_instance_method && method_object_name) 683685c88c5SGreg Clayton { 684685c88c5SGreg Clayton var_sp = variable_list->FindVariable(method_object_name); 685685c88c5SGreg Clayton if (var_sp) 686685c88c5SGreg Clayton { 687685c88c5SGreg Clayton separator_idx = 0; 688685c88c5SGreg Clayton var_path.insert(0, "->"); 689685c88c5SGreg Clayton synthetically_added_instance_object = true; 690685c88c5SGreg Clayton } 691685c88c5SGreg Clayton } 692685c88c5SGreg Clayton } 693685c88c5SGreg Clayton } 694685c88c5SGreg Clayton 69546252398SEnrico Granata if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) 69646252398SEnrico Granata { 69746252398SEnrico Granata // Check if any anonymous unions are there which contain a variable with the name we need 69846252398SEnrico Granata for (size_t i = 0; 69946252398SEnrico Granata i < variable_list->GetSize(); 70046252398SEnrico Granata i++) 70146252398SEnrico Granata { 70246252398SEnrico Granata if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i)) 70346252398SEnrico Granata { 70446252398SEnrico Granata if (variable_sp->GetName().IsEmpty()) 70546252398SEnrico Granata { 70646252398SEnrico Granata if (Type *var_type = variable_sp->GetType()) 70746252398SEnrico Granata { 70846252398SEnrico Granata if (var_type->GetForwardCompilerType().IsAnonymousType()) 70946252398SEnrico Granata { 71046252398SEnrico Granata valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 71146252398SEnrico Granata if (!valobj_sp) 71246252398SEnrico Granata return valobj_sp; 71346252398SEnrico Granata valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true); 71446252398SEnrico Granata if (valobj_sp) 71546252398SEnrico Granata break; 71646252398SEnrico Granata } 71746252398SEnrico Granata } 71846252398SEnrico Granata } 71946252398SEnrico Granata } 72046252398SEnrico Granata } 72146252398SEnrico Granata } 72246252398SEnrico Granata 72346252398SEnrico Granata if (var_sp && !valobj_sp) 7248b2fe6dcSGreg Clayton { 7252837b766SJim Ingham valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); 72678a685aaSJim Ingham if (!valobj_sp) 72778a685aaSJim Ingham return valobj_sp; 72846252398SEnrico Granata } 72946252398SEnrico Granata if (valobj_sp) 73046252398SEnrico Granata { 7318b2fe6dcSGreg Clayton // We are dumping at least one child 7328b2fe6dcSGreg Clayton while (separator_idx != std::string::npos) 7338b2fe6dcSGreg Clayton { 7348b2fe6dcSGreg Clayton // Calculate the next separator index ahead of time 7358b2fe6dcSGreg Clayton ValueObjectSP child_valobj_sp; 7368b2fe6dcSGreg Clayton const char separator_type = var_path[0]; 7378b2fe6dcSGreg Clayton switch (separator_type) 7388b2fe6dcSGreg Clayton { 7398b2fe6dcSGreg Clayton 7408b2fe6dcSGreg Clayton case '-': 7418b2fe6dcSGreg Clayton if (var_path.size() >= 2 && var_path[1] != '>') 7428b2fe6dcSGreg Clayton return ValueObjectSP(); 7438b2fe6dcSGreg Clayton 7446d5e68eaSGreg Clayton if (no_fragile_ivar) 7456d5e68eaSGreg Clayton { 7466d5e68eaSGreg Clayton // Make sure we aren't trying to deref an objective 7476d5e68eaSGreg Clayton // C ivar if this is not allowed 74899558cc4SGreg Clayton const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo (NULL); 749622be238SEnrico Granata if ((pointer_type_flags & eTypeIsObjC) && 750622be238SEnrico Granata (pointer_type_flags & eTypeIsPointer)) 7516d5e68eaSGreg Clayton { 7526d5e68eaSGreg Clayton // This was an objective C object pointer and 7536d5e68eaSGreg Clayton // it was requested we skip any fragile ivars 7546d5e68eaSGreg Clayton // so return nothing here 7556d5e68eaSGreg Clayton return ValueObjectSP(); 7566d5e68eaSGreg Clayton } 7576d5e68eaSGreg Clayton } 7588b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '-' 7598b2fe6dcSGreg Clayton // Fall through 7608b2fe6dcSGreg Clayton case '.': 7618b2fe6dcSGreg Clayton { 76254979cddSGreg Clayton const bool expr_is_ptr = var_path[0] == '>'; 7638b2fe6dcSGreg Clayton 7648b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '.' or '>' 7658b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 7668b2fe6dcSGreg Clayton ConstString child_name; 7678b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 7688b2fe6dcSGreg Clayton child_name.SetCString (var_path.c_str()); 7698b2fe6dcSGreg Clayton else 7708b2fe6dcSGreg Clayton child_name.SetCStringWithLength(var_path.c_str(), separator_idx); 7718b2fe6dcSGreg Clayton 77254979cddSGreg Clayton if (check_ptr_vs_member) 77354979cddSGreg Clayton { 77454979cddSGreg Clayton // We either have a pointer type and need to verify 77554979cddSGreg Clayton // valobj_sp is a pointer, or we have a member of a 77654979cddSGreg Clayton // class/union/struct being accessed with the . syntax 77754979cddSGreg Clayton // and need to verify we don't have a pointer. 77854979cddSGreg Clayton const bool actual_is_ptr = valobj_sp->IsPointerType (); 77954979cddSGreg Clayton 78054979cddSGreg Clayton if (actual_is_ptr != expr_is_ptr) 78154979cddSGreg Clayton { 78254979cddSGreg Clayton // Incorrect use of "." with a pointer, or "->" with 78354979cddSGreg Clayton // a class/union/struct instance or reference. 7846beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 78554979cddSGreg Clayton if (actual_is_ptr) 78654979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", 78754979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 78854979cddSGreg Clayton child_name.GetCString(), 78954979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 79054979cddSGreg Clayton var_path.c_str()); 79154979cddSGreg Clayton else 79254979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", 79354979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 79454979cddSGreg Clayton child_name.GetCString(), 79554979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 79654979cddSGreg Clayton var_path.c_str()); 79754979cddSGreg Clayton return ValueObjectSP(); 79854979cddSGreg Clayton } 79954979cddSGreg Clayton } 8008b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); 8018b2fe6dcSGreg Clayton if (!child_valobj_sp) 8028b2fe6dcSGreg Clayton { 8038c9d3560SEnrico Granata if (no_synth_child == false) 80486cc9829SEnrico Granata { 80586cc9829SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticValue(); 80686cc9829SEnrico Granata if (child_valobj_sp) 80786cc9829SEnrico Granata child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true); 80886cc9829SEnrico Granata } 8098c9d3560SEnrico Granata 8108c9d3560SEnrico Granata if (no_synth_child || !child_valobj_sp) 8118c9d3560SEnrico Granata { 8128b2fe6dcSGreg Clayton // No child member with name "child_name" 813685c88c5SGreg Clayton if (synthetically_added_instance_object) 814685c88c5SGreg Clayton { 815685c88c5SGreg Clayton // We added a "this->" or "self->" to the beginning of the expression 816685c88c5SGreg Clayton // and this is the first pointer ivar access, so just return the normal 817685c88c5SGreg Clayton // error 818685c88c5SGreg Clayton error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame", 819685c88c5SGreg Clayton name_const_string.GetCString()); 820685c88c5SGreg Clayton } 821685c88c5SGreg Clayton else 822685c88c5SGreg Clayton { 8236beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 82454979cddSGreg Clayton if (child_name) 82554979cddSGreg Clayton { 82654979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", 82754979cddSGreg Clayton child_name.GetCString(), 82854979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 82954979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 83054979cddSGreg Clayton } 83154979cddSGreg Clayton else 83254979cddSGreg Clayton { 83354979cddSGreg Clayton error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", 83454979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 83554979cddSGreg Clayton var_expr_cstr); 83654979cddSGreg Clayton } 837685c88c5SGreg Clayton } 8388b2fe6dcSGreg Clayton return ValueObjectSP(); 8398b2fe6dcSGreg Clayton } 8408c9d3560SEnrico Granata } 841685c88c5SGreg Clayton synthetically_added_instance_object = false; 8428b2fe6dcSGreg Clayton // Remove the child name from the path 8438b2fe6dcSGreg Clayton var_path.erase(0, child_name.GetLength()); 8444d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 84578a685aaSJim Ingham { 8462837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 84778a685aaSJim Ingham if (dynamic_value_sp) 84878a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 84978a685aaSJim Ingham } 8508b2fe6dcSGreg Clayton } 8518b2fe6dcSGreg Clayton break; 8528b2fe6dcSGreg Clayton 8538b2fe6dcSGreg Clayton case '[': 8548b2fe6dcSGreg Clayton // Array member access, or treating pointer as an array 8558b2fe6dcSGreg Clayton if (var_path.size() > 2) // Need at least two brackets and a number 8568b2fe6dcSGreg Clayton { 8578b2fe6dcSGreg Clayton char *end = NULL; 8581a65ae11SGreg Clayton long child_index = ::strtol (&var_path[1], &end, 0); 8599fc1944eSEnrico Granata if (end && *end == ']' 8609fc1944eSEnrico 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 8618b2fe6dcSGreg Clayton { 86299558cc4SGreg Clayton if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) 8639fc1944eSEnrico Granata { 8649fc1944eSEnrico Granata // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr 8659fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 8669fc1944eSEnrico Granata // would be done by saying ptr[low], without a deref * sign 8679fc1944eSEnrico Granata Error error; 8689fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 8699fc1944eSEnrico Granata if (error.Fail()) 8709fc1944eSEnrico Granata { 8719fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8729fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 8739fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8749fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8759fc1944eSEnrico Granata return ValueObjectSP(); 8769fc1944eSEnrico Granata } 8779fc1944eSEnrico Granata valobj_sp = temp; 8789fc1944eSEnrico Granata deref = false; 8799fc1944eSEnrico Granata } 88099558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) 8819fc1944eSEnrico Granata { 8829fc1944eSEnrico Granata // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] 8839fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 8849fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 8859fc1944eSEnrico Granata // would be done by saying arr[low], without a deref * sign 8869fc1944eSEnrico Granata Error error; 8879fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 8889fc1944eSEnrico Granata if (error.Fail()) 8899fc1944eSEnrico Granata { 8909fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8919fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 8929fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8939fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8949fc1944eSEnrico Granata return ValueObjectSP(); 8959fc1944eSEnrico Granata } 8969fc1944eSEnrico Granata valobj_sp = temp; 8979fc1944eSEnrico Granata deref = false; 8989fc1944eSEnrico Granata } 8998b2fe6dcSGreg Clayton 9004ef877f5SGreg Clayton bool is_incomplete_array = false; 9018b2fe6dcSGreg Clayton if (valobj_sp->IsPointerType ()) 9028b2fe6dcSGreg Clayton { 903226b70c1SSean Callanan bool is_objc_pointer = true; 904226b70c1SSean Callanan 90599558cc4SGreg Clayton if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC) 906226b70c1SSean Callanan is_objc_pointer = false; 90799558cc4SGreg Clayton else if (!valobj_sp->GetCompilerType().IsPointerType()) 908226b70c1SSean Callanan is_objc_pointer = false; 909226b70c1SSean Callanan 910226b70c1SSean Callanan if (no_synth_child && is_objc_pointer) 911226b70c1SSean Callanan { 912226b70c1SSean Callanan error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted", 913226b70c1SSean Callanan valobj_sp->GetTypeName().AsCString("<invalid type>"), 914226b70c1SSean Callanan var_expr_path_strm.GetString().c_str()); 915226b70c1SSean Callanan 916226b70c1SSean Callanan return ValueObjectSP(); 917226b70c1SSean Callanan } 918226b70c1SSean Callanan else if (is_objc_pointer) 91927b625e1SEnrico Granata { 92027b625e1SEnrico Granata // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children 92186cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 92227b625e1SEnrico Granata if (synthetic.get() == NULL /* no synthetic */ 92327b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 92427b625e1SEnrico Granata { 92527b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 92627b625e1SEnrico Granata error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 92727b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 92827b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 92927b625e1SEnrico Granata } 9303985c8c6SSaleem Abdulrasool else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 93127b625e1SEnrico Granata { 93227b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9337e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 93427b625e1SEnrico Granata child_index, 93527b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 93627b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 93727b625e1SEnrico Granata } 93827b625e1SEnrico Granata else 93927b625e1SEnrico Granata { 94027b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 94127b625e1SEnrico Granata if (!child_valobj_sp) 94227b625e1SEnrico Granata { 94327b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9447e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 94527b625e1SEnrico Granata child_index, 94627b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 94727b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 94827b625e1SEnrico Granata } 94927b625e1SEnrico Granata } 95027b625e1SEnrico Granata } 95127b625e1SEnrico Granata else 95227b625e1SEnrico Granata { 95311d86362SBruce Mitchener child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); 95454979cddSGreg Clayton if (!child_valobj_sp) 95554979cddSGreg Clayton { 9566beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9577e589a60SJason Molenda error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"", 95854979cddSGreg Clayton child_index, 95954979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 96054979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 96154979cddSGreg Clayton } 96254979cddSGreg Clayton } 96327b625e1SEnrico Granata } 96499558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsArrayType (NULL, NULL, &is_incomplete_array)) 96554979cddSGreg Clayton { 96678a685aaSJim Ingham // Pass false to dynamic_value here so we can tell the difference between 96778a685aaSJim Ingham // no dynamic value and no member of this type... 96854979cddSGreg Clayton child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); 9694ef877f5SGreg Clayton if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false)) 9704ef877f5SGreg Clayton child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); 9714ef877f5SGreg Clayton 97254979cddSGreg Clayton if (!child_valobj_sp) 97354979cddSGreg Clayton { 9746beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9757e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 97654979cddSGreg Clayton child_index, 97754979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 97854979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 97954979cddSGreg Clayton } 9808b2fe6dcSGreg Clayton } 98199558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsScalarType()) 9829fc1944eSEnrico Granata { 9839fc1944eSEnrico Granata // this is a bitfield asking to display just one bit 9849fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); 9859fc1944eSEnrico Granata if (!child_valobj_sp) 9869fc1944eSEnrico Granata { 9879fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9887e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 9899fc1944eSEnrico Granata child_index, child_index, 9909fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 9919fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 9929fc1944eSEnrico Granata } 9939fc1944eSEnrico Granata } 9948b2fe6dcSGreg Clayton else 9958b2fe6dcSGreg Clayton { 99686cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 99727b625e1SEnrico Granata if (no_synth_child /* synthetic is forbidden */ || 99827b625e1SEnrico Granata synthetic.get() == NULL /* no synthetic */ 99927b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 100027b625e1SEnrico Granata { 10016beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 100254979cddSGreg Clayton error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 100354979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 100454979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 10058b2fe6dcSGreg Clayton } 10063985c8c6SSaleem Abdulrasool else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 100727b625e1SEnrico Granata { 100827b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10097e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 101027b625e1SEnrico Granata child_index, 101127b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 101227b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 101327b625e1SEnrico Granata } 101427b625e1SEnrico Granata else 101527b625e1SEnrico Granata { 101627b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 101727b625e1SEnrico Granata if (!child_valobj_sp) 101827b625e1SEnrico Granata { 101927b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10207e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 102127b625e1SEnrico Granata child_index, 102227b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 102327b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 102427b625e1SEnrico Granata } 102527b625e1SEnrico Granata } 102627b625e1SEnrico Granata } 10278b2fe6dcSGreg Clayton 10288b2fe6dcSGreg Clayton if (!child_valobj_sp) 10298b2fe6dcSGreg Clayton { 10308b2fe6dcSGreg Clayton // Invalid array index... 10318b2fe6dcSGreg Clayton return ValueObjectSP(); 10328b2fe6dcSGreg Clayton } 10338b2fe6dcSGreg Clayton 10348b2fe6dcSGreg Clayton // Erase the array member specification '[%i]' where 10358b2fe6dcSGreg Clayton // %i is the array index 10368b2fe6dcSGreg Clayton var_path.erase(0, (end - var_path.c_str()) + 1); 10378b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 10384d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 103978a685aaSJim Ingham { 10402837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 104178a685aaSJim Ingham if (dynamic_value_sp) 104278a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 104378a685aaSJim Ingham } 10448b2fe6dcSGreg Clayton // Break out early from the switch since we were 10458b2fe6dcSGreg Clayton // able to find the child member 10468b2fe6dcSGreg Clayton break; 10478b2fe6dcSGreg Clayton } 10489fc1944eSEnrico Granata else if (end && *end == '-') 10499fc1944eSEnrico Granata { 10509fc1944eSEnrico Granata // this is most probably a BitField, let's take a look 10519fc1944eSEnrico Granata char *real_end = NULL; 10529fc1944eSEnrico Granata long final_index = ::strtol (end+1, &real_end, 0); 1053d64d0bc0SEnrico Granata bool expand_bitfield = true; 10549fc1944eSEnrico Granata if (real_end && *real_end == ']') 10559fc1944eSEnrico Granata { 10569fc1944eSEnrico Granata // if the format given is [high-low], swap range 10579fc1944eSEnrico Granata if (child_index > final_index) 10589fc1944eSEnrico Granata { 10599fc1944eSEnrico Granata long temp = child_index; 10609fc1944eSEnrico Granata child_index = final_index; 10619fc1944eSEnrico Granata final_index = temp; 10629fc1944eSEnrico Granata } 10639fc1944eSEnrico Granata 106499558cc4SGreg Clayton if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) 10659fc1944eSEnrico Granata { 10669fc1944eSEnrico Granata // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr 10679fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 10689fc1944eSEnrico Granata // would be done by saying ptr[low-high], without a deref * sign 10699fc1944eSEnrico Granata Error error; 10709fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 10719fc1944eSEnrico Granata if (error.Fail()) 10729fc1944eSEnrico Granata { 10739fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10749fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 10759fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 10769fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 10779fc1944eSEnrico Granata return ValueObjectSP(); 10789fc1944eSEnrico Granata } 10799fc1944eSEnrico Granata valobj_sp = temp; 10809fc1944eSEnrico Granata deref = false; 10819fc1944eSEnrico Granata } 108299558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) 10839fc1944eSEnrico Granata { 10849fc1944eSEnrico Granata // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] 10859fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 10869fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 10879fc1944eSEnrico Granata // would be done by saying arr[low-high], without a deref * sign 10889fc1944eSEnrico Granata Error error; 10899fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 10909fc1944eSEnrico Granata if (error.Fail()) 10919fc1944eSEnrico Granata { 10929fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10939fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 10949fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 10959fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 10969fc1944eSEnrico Granata return ValueObjectSP(); 10979fc1944eSEnrico Granata } 10989fc1944eSEnrico Granata valobj_sp = temp; 10999fc1944eSEnrico Granata deref = false; 11009fc1944eSEnrico Granata } 1101d64d0bc0SEnrico Granata /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType()) 1102d64d0bc0SEnrico Granata { 1103d64d0bc0SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true); 1104d64d0bc0SEnrico Granata expand_bitfield = false; 1105d64d0bc0SEnrico Granata if (!child_valobj_sp) 1106d64d0bc0SEnrico Granata { 1107d64d0bc0SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 1108d64d0bc0SEnrico Granata error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"", 1109d64d0bc0SEnrico Granata child_index, final_index, 1110d64d0bc0SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 1111d64d0bc0SEnrico Granata var_expr_path_strm.GetString().c_str()); 1112d64d0bc0SEnrico Granata } 1113d64d0bc0SEnrico Granata }*/ 11149fc1944eSEnrico Granata 1115d64d0bc0SEnrico Granata if (expand_bitfield) 1116d64d0bc0SEnrico Granata { 11179fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); 11189fc1944eSEnrico Granata if (!child_valobj_sp) 11199fc1944eSEnrico Granata { 11209fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 11217e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 11229fc1944eSEnrico Granata child_index, final_index, 11239fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 11249fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 11259fc1944eSEnrico Granata } 11269fc1944eSEnrico Granata } 1127d64d0bc0SEnrico Granata } 11289fc1944eSEnrico Granata 11299fc1944eSEnrico Granata if (!child_valobj_sp) 11309fc1944eSEnrico Granata { 11319fc1944eSEnrico Granata // Invalid bitfield range... 11329fc1944eSEnrico Granata return ValueObjectSP(); 11339fc1944eSEnrico Granata } 11349fc1944eSEnrico Granata 11359fc1944eSEnrico Granata // Erase the bitfield member specification '[%i-%i]' where 11369fc1944eSEnrico Granata // %i is the index 11379fc1944eSEnrico Granata var_path.erase(0, (real_end - var_path.c_str()) + 1); 11389fc1944eSEnrico Granata separator_idx = var_path.find_first_of(".-["); 11394d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 11409fc1944eSEnrico Granata { 11419fc1944eSEnrico Granata ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 11429fc1944eSEnrico Granata if (dynamic_value_sp) 11439fc1944eSEnrico Granata child_valobj_sp = dynamic_value_sp; 11449fc1944eSEnrico Granata } 11459fc1944eSEnrico Granata // Break out early from the switch since we were 11469fc1944eSEnrico Granata // able to find the child member 11479fc1944eSEnrico Granata break; 11489fc1944eSEnrico Granata 11499fc1944eSEnrico Granata } 11509fc1944eSEnrico Granata } 11519fc1944eSEnrico Granata else 11529fc1944eSEnrico Granata { 11539fc1944eSEnrico Granata error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", 11549fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str(), 11559fc1944eSEnrico Granata var_path.c_str()); 11568b2fe6dcSGreg Clayton } 11578b2fe6dcSGreg Clayton return ValueObjectSP(); 11588b2fe6dcSGreg Clayton 11598b2fe6dcSGreg Clayton default: 11608b2fe6dcSGreg Clayton // Failure... 116154979cddSGreg Clayton { 11626beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 116354979cddSGreg Clayton error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", 116454979cddSGreg Clayton separator_type, 116554979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 116654979cddSGreg Clayton var_path.c_str()); 116754979cddSGreg Clayton 11688b2fe6dcSGreg Clayton return ValueObjectSP(); 11698b2fe6dcSGreg Clayton } 117054979cddSGreg Clayton } 11718b2fe6dcSGreg Clayton 11728b2fe6dcSGreg Clayton if (child_valobj_sp) 11738b2fe6dcSGreg Clayton valobj_sp = child_valobj_sp; 11748b2fe6dcSGreg Clayton 11758b2fe6dcSGreg Clayton if (var_path.empty()) 11768b2fe6dcSGreg Clayton break; 11778b2fe6dcSGreg Clayton 11788b2fe6dcSGreg Clayton } 11798b2fe6dcSGreg Clayton if (valobj_sp) 11808b2fe6dcSGreg Clayton { 11818b2fe6dcSGreg Clayton if (deref) 11828b2fe6dcSGreg Clayton { 1183af67cecdSGreg Clayton ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); 11848b2fe6dcSGreg Clayton valobj_sp = deref_valobj_sp; 11858b2fe6dcSGreg Clayton } 11868b2fe6dcSGreg Clayton else if (address_of) 11878b2fe6dcSGreg Clayton { 118854979cddSGreg Clayton ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); 11898b2fe6dcSGreg Clayton valobj_sp = address_of_valobj_sp; 11908b2fe6dcSGreg Clayton } 11918b2fe6dcSGreg Clayton } 11928b2fe6dcSGreg Clayton return valobj_sp; 11938b2fe6dcSGreg Clayton } 119454979cddSGreg Clayton else 119554979cddSGreg Clayton { 11962837b766SJim Ingham error.SetErrorStringWithFormat("no variable named '%s' found in this frame", 11972837b766SJim Ingham name_const_string.GetCString()); 119854979cddSGreg Clayton } 119954979cddSGreg Clayton } 120054979cddSGreg Clayton } 120154979cddSGreg Clayton else 120254979cddSGreg Clayton { 120354979cddSGreg Clayton error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); 12048b2fe6dcSGreg Clayton } 12058b2fe6dcSGreg Clayton return ValueObjectSP(); 12068b2fe6dcSGreg Clayton } 120730fdc8d8SChris Lattner 120830fdc8d8SChris Lattner bool 120930fdc8d8SChris Lattner StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) 121030fdc8d8SChris Lattner { 12116a354705SJason Molenda Mutex::Locker locker(m_mutex); 121299618476SJason Molenda if (m_cfa_is_valid == false) 121399618476SJason Molenda { 121499618476SJason Molenda m_frame_base_error.SetErrorString("No frame base available for this historical stack frame."); 121599618476SJason Molenda return false; 121699618476SJason Molenda } 121799618476SJason Molenda 121830fdc8d8SChris Lattner if (m_flags.IsClear(GOT_FRAME_BASE)) 121930fdc8d8SChris Lattner { 122030fdc8d8SChris Lattner if (m_sc.function) 122130fdc8d8SChris Lattner { 122230fdc8d8SChris Lattner m_frame_base.Clear(); 122330fdc8d8SChris Lattner m_frame_base_error.Clear(); 122430fdc8d8SChris Lattner 122530fdc8d8SChris Lattner m_flags.Set(GOT_FRAME_BASE); 1226d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 122730fdc8d8SChris Lattner Value expr_value; 1228016a95ebSGreg Clayton addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; 1229016a95ebSGreg Clayton if (m_sc.function->GetFrameBaseExpression().IsLocationList()) 1230d9e416c0SGreg Clayton loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr()); 1231016a95ebSGreg Clayton 123257ee3067SGreg Clayton if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) 123330fdc8d8SChris Lattner { 123430fdc8d8SChris Lattner // We should really have an error if evaluate returns, but in case 123530fdc8d8SChris Lattner // we don't, lets set the error to something at least. 123630fdc8d8SChris Lattner if (m_frame_base_error.Success()) 123730fdc8d8SChris Lattner m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); 123830fdc8d8SChris Lattner } 123930fdc8d8SChris Lattner else 124030fdc8d8SChris Lattner { 124157ee3067SGreg Clayton m_frame_base = expr_value.ResolveValue(&exe_ctx); 124230fdc8d8SChris Lattner } 124330fdc8d8SChris Lattner } 124430fdc8d8SChris Lattner else 124530fdc8d8SChris Lattner { 124630fdc8d8SChris Lattner m_frame_base_error.SetErrorString ("No function in symbol context."); 124730fdc8d8SChris Lattner } 124830fdc8d8SChris Lattner } 124930fdc8d8SChris Lattner 125030fdc8d8SChris Lattner if (m_frame_base_error.Success()) 125130fdc8d8SChris Lattner frame_base = m_frame_base; 125230fdc8d8SChris Lattner 125330fdc8d8SChris Lattner if (error_ptr) 125430fdc8d8SChris Lattner *error_ptr = m_frame_base_error; 125530fdc8d8SChris Lattner return m_frame_base_error.Success(); 125630fdc8d8SChris Lattner } 125730fdc8d8SChris Lattner 12585ccbd294SGreg Clayton RegisterContextSP 125930fdc8d8SChris Lattner StackFrame::GetRegisterContext () 126030fdc8d8SChris Lattner { 12616a354705SJason Molenda Mutex::Locker locker(m_mutex); 12625ccbd294SGreg Clayton if (!m_reg_context_sp) 1263d9e416c0SGreg Clayton { 1264d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 1265d9e416c0SGreg Clayton if (thread_sp) 1266d9e416c0SGreg Clayton m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this); 1267d9e416c0SGreg Clayton } 12685ccbd294SGreg Clayton return m_reg_context_sp; 126930fdc8d8SChris Lattner } 127030fdc8d8SChris Lattner 127130fdc8d8SChris Lattner bool 127230fdc8d8SChris Lattner StackFrame::HasDebugInformation () 127330fdc8d8SChris Lattner { 127430fdc8d8SChris Lattner GetSymbolContext (eSymbolContextLineEntry); 127530fdc8d8SChris Lattner return m_sc.line_entry.IsValid(); 127630fdc8d8SChris Lattner } 127730fdc8d8SChris Lattner 1278288bdf9cSGreg Clayton 1279288bdf9cSGreg Clayton ValueObjectSP 12804d122c40SGreg Clayton StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 128130fdc8d8SChris Lattner { 12826a354705SJason Molenda Mutex::Locker locker(m_mutex); 1283288bdf9cSGreg Clayton ValueObjectSP valobj_sp; 128499618476SJason Molenda if (m_is_history_frame) 128599618476SJason Molenda { 128699618476SJason Molenda return valobj_sp; 128799618476SJason Molenda } 1288288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1289288bdf9cSGreg Clayton if (var_list) 1290288bdf9cSGreg Clayton { 1291288bdf9cSGreg Clayton // Make sure the variable is a frame variable 1292288bdf9cSGreg Clayton const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); 1293288bdf9cSGreg Clayton const uint32_t num_variables = var_list->GetSize(); 1294288bdf9cSGreg Clayton if (var_idx < num_variables) 1295288bdf9cSGreg Clayton { 1296288bdf9cSGreg Clayton valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); 1297288bdf9cSGreg Clayton if (valobj_sp.get() == NULL) 1298288bdf9cSGreg Clayton { 1299288bdf9cSGreg Clayton if (m_variable_list_value_objects.GetSize() < num_variables) 1300288bdf9cSGreg Clayton m_variable_list_value_objects.Resize(num_variables); 130158b59f95SJim Ingham valobj_sp = ValueObjectVariable::Create (this, variable_sp); 1302288bdf9cSGreg Clayton m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); 1303288bdf9cSGreg Clayton } 1304288bdf9cSGreg Clayton } 1305288bdf9cSGreg Clayton } 13064d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues && valobj_sp) 130778a685aaSJim Ingham { 13082837b766SJim Ingham ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); 130978a685aaSJim Ingham if (dynamic_sp) 131078a685aaSJim Ingham return dynamic_sp; 131178a685aaSJim Ingham } 1312288bdf9cSGreg Clayton return valobj_sp; 1313288bdf9cSGreg Clayton } 1314288bdf9cSGreg Clayton 1315288bdf9cSGreg Clayton ValueObjectSP 13164d122c40SGreg Clayton StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 1317288bdf9cSGreg Clayton { 13186a354705SJason Molenda Mutex::Locker locker(m_mutex); 131999618476SJason Molenda if (m_is_history_frame) 132099618476SJason Molenda return ValueObjectSP(); 132199618476SJason Molenda 1322288bdf9cSGreg Clayton // Check to make sure we aren't already tracking this variable? 132378a685aaSJim Ingham ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 1324288bdf9cSGreg Clayton if (!valobj_sp) 1325288bdf9cSGreg Clayton { 1326288bdf9cSGreg Clayton // We aren't already tracking this global 1327288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1328288bdf9cSGreg Clayton // If this frame has no variables, create a new list 1329288bdf9cSGreg Clayton if (var_list == NULL) 1330288bdf9cSGreg Clayton m_variable_list_sp.reset (new VariableList()); 1331288bdf9cSGreg Clayton 1332288bdf9cSGreg Clayton // Add the global/static variable to this frame 1333288bdf9cSGreg Clayton m_variable_list_sp->AddVariable (variable_sp); 1334288bdf9cSGreg Clayton 1335288bdf9cSGreg Clayton // Now make a value object for it so we can track its changes 133678a685aaSJim Ingham valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 1337288bdf9cSGreg Clayton } 1338288bdf9cSGreg Clayton return valobj_sp; 133930fdc8d8SChris Lattner } 134030fdc8d8SChris Lattner 13416b8379c4SJim Ingham bool 13426b8379c4SJim Ingham StackFrame::IsInlined () 13436b8379c4SJim Ingham { 134459e8fc1cSGreg Clayton if (m_sc.block == NULL) 134559e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextBlock); 134659e8fc1cSGreg Clayton if (m_sc.block) 134759e8fc1cSGreg Clayton return m_sc.block->GetContainingInlinedBlock() != NULL; 134859e8fc1cSGreg Clayton return false; 13496b8379c4SJim Ingham } 13506b8379c4SJim Ingham 1351009d110dSDawn Perchik lldb::LanguageType 1352009d110dSDawn Perchik StackFrame::GetLanguage () 1353009d110dSDawn Perchik { 1354009d110dSDawn Perchik CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; 1355009d110dSDawn Perchik if (cu) 1356009d110dSDawn Perchik return cu->GetLanguage(); 1357009d110dSDawn Perchik return lldb::eLanguageTypeUnknown; 1358009d110dSDawn Perchik } 1359009d110dSDawn Perchik 1360d9e416c0SGreg Clayton TargetSP 136130fdc8d8SChris Lattner StackFrame::CalculateTarget () 136230fdc8d8SChris Lattner { 1363d9e416c0SGreg Clayton TargetSP target_sp; 1364d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1365d9e416c0SGreg Clayton if (thread_sp) 1366d9e416c0SGreg Clayton { 1367d9e416c0SGreg Clayton ProcessSP process_sp (thread_sp->CalculateProcess()); 1368d9e416c0SGreg Clayton if (process_sp) 1369d9e416c0SGreg Clayton target_sp = process_sp->CalculateTarget(); 1370d9e416c0SGreg Clayton } 1371d9e416c0SGreg Clayton return target_sp; 137230fdc8d8SChris Lattner } 137330fdc8d8SChris Lattner 1374d9e416c0SGreg Clayton ProcessSP 137530fdc8d8SChris Lattner StackFrame::CalculateProcess () 137630fdc8d8SChris Lattner { 1377d9e416c0SGreg Clayton ProcessSP process_sp; 1378d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1379d9e416c0SGreg Clayton if (thread_sp) 1380d9e416c0SGreg Clayton process_sp = thread_sp->CalculateProcess(); 1381d9e416c0SGreg Clayton return process_sp; 138230fdc8d8SChris Lattner } 138330fdc8d8SChris Lattner 1384d9e416c0SGreg Clayton ThreadSP 138530fdc8d8SChris Lattner StackFrame::CalculateThread () 138630fdc8d8SChris Lattner { 1387d9e416c0SGreg Clayton return GetThread(); 138830fdc8d8SChris Lattner } 138930fdc8d8SChris Lattner 1390b57e4a1bSJason Molenda StackFrameSP 1391b57e4a1bSJason Molenda StackFrame::CalculateStackFrame () 139230fdc8d8SChris Lattner { 1393d9e416c0SGreg Clayton return shared_from_this(); 139430fdc8d8SChris Lattner } 139530fdc8d8SChris Lattner 139630fdc8d8SChris Lattner 139730fdc8d8SChris Lattner void 13980603aa9dSGreg Clayton StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) 139930fdc8d8SChris Lattner { 1400d9e416c0SGreg Clayton exe_ctx.SetContext (shared_from_this()); 140130fdc8d8SChris Lattner } 140230fdc8d8SChris Lattner 140330fdc8d8SChris Lattner void 14048ec10efcSJim Ingham StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker) 14050603aa9dSGreg Clayton { 14060603aa9dSGreg Clayton if (strm == NULL) 14070603aa9dSGreg Clayton return; 14080603aa9dSGreg Clayton 14090603aa9dSGreg Clayton GetSymbolContext(eSymbolContextEverything); 1410d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 14110603aa9dSGreg Clayton StreamString s; 14128ec10efcSJim Ingham 14138ec10efcSJim Ingham if (frame_marker) 14148ec10efcSJim Ingham s.PutCString(frame_marker); 14158ec10efcSJim Ingham 1416554f68d3SGreg Clayton const FormatEntity::Entry *frame_format = NULL; 1417d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1418d9e416c0SGreg Clayton if (target) 1419d9e416c0SGreg Clayton frame_format = target->GetDebugger().GetFrameFormat(); 1420554f68d3SGreg Clayton if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, NULL, NULL, false, false)) 14210603aa9dSGreg Clayton { 14220603aa9dSGreg Clayton strm->Write(s.GetData(), s.GetSize()); 14230603aa9dSGreg Clayton } 14240603aa9dSGreg Clayton else 14250603aa9dSGreg Clayton { 14260603aa9dSGreg Clayton Dump (strm, true, false); 14270603aa9dSGreg Clayton strm->EOL(); 14280603aa9dSGreg Clayton } 14290603aa9dSGreg Clayton } 14300603aa9dSGreg Clayton 14310603aa9dSGreg Clayton void 14326dadd508SGreg Clayton StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) 143330fdc8d8SChris Lattner { 143430fdc8d8SChris Lattner if (strm == NULL) 143530fdc8d8SChris Lattner return; 143630fdc8d8SChris Lattner 143730fdc8d8SChris Lattner if (show_frame_index) 14381b72fcb7SGreg Clayton strm->Printf("frame #%u: ", m_frame_index); 1439d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 1440d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1441d01b2953SDaniel Malea strm->Printf("0x%0*" PRIx64 " ", 1442d9e416c0SGreg Clayton target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16, 1443d9e416c0SGreg Clayton GetFrameCodeAddress().GetLoadAddress(target)); 14449da7bd07SGreg Clayton GetSymbolContext(eSymbolContextEverything); 14451b72fcb7SGreg Clayton const bool show_module = true; 14461b72fcb7SGreg Clayton const bool show_inline = true; 1447aff1b357SJason Molenda const bool show_function_arguments = true; 1448c980fa92SJason Molenda const bool show_function_name = true; 1449d9e416c0SGreg Clayton m_sc.DumpStopContext (strm, 1450d9e416c0SGreg Clayton exe_ctx.GetBestExecutionContextScope(), 1451d9e416c0SGreg Clayton GetFrameCodeAddress(), 1452d9e416c0SGreg Clayton show_fullpaths, 1453d9e416c0SGreg Clayton show_module, 1454aff1b357SJason Molenda show_inline, 1455c980fa92SJason Molenda show_function_arguments, 1456c980fa92SJason Molenda show_function_name); 145730fdc8d8SChris Lattner } 145830fdc8d8SChris Lattner 14595082c5fdSGreg Clayton void 1460b57e4a1bSJason Molenda StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) 14615082c5fdSGreg Clayton { 14626a354705SJason Molenda Mutex::Locker locker(m_mutex); 146359e8fc1cSGreg Clayton assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing 1464b57e4a1bSJason Molenda m_variable_list_sp = prev_frame.m_variable_list_sp; 1465b57e4a1bSJason Molenda m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); 146668275d5eSGreg Clayton if (!m_disassembly.GetString().empty()) 146768275d5eSGreg Clayton m_disassembly.GetString().swap (m_disassembly.GetString()); 14685082c5fdSGreg Clayton } 146968275d5eSGreg Clayton 147068275d5eSGreg Clayton 147159e8fc1cSGreg Clayton void 1472b57e4a1bSJason Molenda StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) 147359e8fc1cSGreg Clayton { 14746a354705SJason Molenda Mutex::Locker locker(m_mutex); 147559e8fc1cSGreg Clayton assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing 1476b57e4a1bSJason Molenda m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value 1477b57e4a1bSJason Molenda assert (GetThread() == curr_frame.GetThread()); 1478b57e4a1bSJason Molenda m_frame_index = curr_frame.m_frame_index; 1479b57e4a1bSJason Molenda m_concrete_frame_index = curr_frame.m_concrete_frame_index; 1480b57e4a1bSJason Molenda m_reg_context_sp = curr_frame.m_reg_context_sp; 1481b57e4a1bSJason Molenda m_frame_code_addr = curr_frame.m_frame_code_addr; 1482b57e4a1bSJason Molenda 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()); 1483b57e4a1bSJason Molenda 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()); 1484b57e4a1bSJason Molenda assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); 1485b57e4a1bSJason Molenda assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function); 1486b57e4a1bSJason Molenda m_sc = curr_frame.m_sc; 148759e8fc1cSGreg Clayton m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); 148859e8fc1cSGreg Clayton m_flags.Set (m_sc.GetResolvedMask()); 148959e8fc1cSGreg Clayton m_frame_base.Clear(); 149059e8fc1cSGreg Clayton m_frame_base_error.Clear(); 149159e8fc1cSGreg Clayton } 1492e4284b71SJim Ingham 1493f23bf743SJason Molenda 14947260f620SGreg Clayton bool 1495b57e4a1bSJason Molenda StackFrame::HasCachedData () const 1496b57e4a1bSJason Molenda { 1497b57e4a1bSJason Molenda if (m_variable_list_sp.get()) 1498b57e4a1bSJason Molenda return true; 1499b57e4a1bSJason Molenda if (m_variable_list_value_objects.GetSize() > 0) 1500b57e4a1bSJason Molenda return true; 1501b57e4a1bSJason Molenda if (!m_disassembly.GetString().empty()) 1502b57e4a1bSJason Molenda return true; 1503b57e4a1bSJason Molenda return false; 1504b57e4a1bSJason Molenda } 1505b57e4a1bSJason Molenda 1506b57e4a1bSJason Molenda bool 15077260f620SGreg Clayton StackFrame::GetStatus (Stream& strm, 15087260f620SGreg Clayton bool show_frame_info, 15098ec10efcSJim Ingham bool show_source, 15108ec10efcSJim Ingham const char *frame_marker) 15117260f620SGreg Clayton { 151253eb7ad2SGreg Clayton 15137260f620SGreg Clayton if (show_frame_info) 15147260f620SGreg Clayton { 15157260f620SGreg Clayton strm.Indent(); 15168ec10efcSJim Ingham DumpUsingSettingsFormat (&strm, frame_marker); 15177260f620SGreg Clayton } 15187260f620SGreg Clayton 15197260f620SGreg Clayton if (show_source) 15207260f620SGreg Clayton { 1521d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 15228be74995SMohit K. Bhakkad bool have_source = false, have_debuginfo = false; 152367cc0636SGreg Clayton Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever; 1524d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 152553eb7ad2SGreg Clayton if (target) 152653eb7ad2SGreg Clayton { 152753eb7ad2SGreg Clayton Debugger &debugger = target->GetDebugger(); 152853eb7ad2SGreg Clayton const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true); 152953eb7ad2SGreg Clayton const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false); 153053eb7ad2SGreg Clayton disasm_display = debugger.GetStopDisassemblyDisplay (); 153153eb7ad2SGreg Clayton 15327260f620SGreg Clayton GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); 15337260f620SGreg Clayton if (m_sc.comp_unit && m_sc.line_entry.IsValid()) 15347260f620SGreg Clayton { 15358be74995SMohit K. Bhakkad have_debuginfo = true; 15366d1fbc9cSTodd Fiala if (source_lines_before > 0 || source_lines_after > 0) 15376d1fbc9cSTodd Fiala { 15388be74995SMohit K. Bhakkad size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, 15397260f620SGreg Clayton m_sc.line_entry.line, 1540d9e416c0SGreg Clayton source_lines_before, 1541d9e416c0SGreg Clayton source_lines_after, 15427260f620SGreg Clayton "->", 15437cd81c55SJason Molenda &strm); 15448be74995SMohit K. Bhakkad if (num_lines != 0) 15458be74995SMohit K. Bhakkad have_source = true; 15468be74995SMohit K. Bhakkad // TODO: Give here a one time warning if source file is missing. 1547e372b98dSGreg Clayton } 1548e372b98dSGreg Clayton } 1549e372b98dSGreg Clayton switch (disasm_display) 1550e372b98dSGreg Clayton { 155167cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNever: 1552e372b98dSGreg Clayton break; 1553e372b98dSGreg Clayton 15548be74995SMohit K. Bhakkad case Debugger::eStopDisassemblyTypeNoDebugInfo: 15558be74995SMohit K. Bhakkad if (have_debuginfo) 15568be74995SMohit K. Bhakkad break; 15578be74995SMohit K. Bhakkad // Fall through to next case 15588be74995SMohit K. Bhakkad 155967cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNoSource: 1560e372b98dSGreg Clayton if (have_source) 1561e372b98dSGreg Clayton break; 1562e372b98dSGreg Clayton // Fall through to next case 15638be74995SMohit K. Bhakkad 156467cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeAlways: 1565d9e416c0SGreg Clayton if (target) 1566e372b98dSGreg Clayton { 156753eb7ad2SGreg Clayton const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); 1568e372b98dSGreg Clayton if (disasm_lines > 0) 1569e372b98dSGreg Clayton { 1570d9e416c0SGreg Clayton const ArchSpec &target_arch = target->GetArchitecture(); 1571e372b98dSGreg Clayton AddressRange pc_range; 1572e372b98dSGreg Clayton pc_range.GetBaseAddress() = GetFrameCodeAddress(); 1573e372b98dSGreg Clayton pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize()); 15740f063ba6SJim Ingham const char *plugin_name = NULL; 15750f063ba6SJim Ingham const char *flavor = NULL; 1576d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 1577e372b98dSGreg Clayton target_arch, 15780f063ba6SJim Ingham plugin_name, 15790f063ba6SJim Ingham flavor, 1580e372b98dSGreg Clayton exe_ctx, 1581e372b98dSGreg Clayton pc_range, 1582e372b98dSGreg Clayton disasm_lines, 1583e372b98dSGreg Clayton 0, 1584e372b98dSGreg Clayton Disassembler::eOptionMarkPCAddress, 1585e372b98dSGreg Clayton strm); 1586e372b98dSGreg Clayton } 1587e372b98dSGreg Clayton } 1588e372b98dSGreg Clayton break; 15897260f620SGreg Clayton } 15907260f620SGreg Clayton } 159153eb7ad2SGreg Clayton } 15927260f620SGreg Clayton return true; 15937260f620SGreg Clayton } 15947260f620SGreg Clayton 1595