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" 2230fdc8d8SChris Lattner #include "lldb/Symbol/Function.h" 23288bdf9cSGreg Clayton #include "lldb/Symbol/VariableList.h" 2430fdc8d8SChris Lattner #include "lldb/Target/ExecutionContext.h" 2530fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2630fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h" 2730fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2830fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 2930fdc8d8SChris Lattner 3030fdc8d8SChris Lattner using namespace lldb; 3130fdc8d8SChris Lattner using namespace lldb_private; 3230fdc8d8SChris Lattner 3330fdc8d8SChris Lattner // The first bits in the flags are reserved for the SymbolContext::Scope bits 3430fdc8d8SChris Lattner // so we know if we have tried to look up information in our internal symbol 3530fdc8d8SChris Lattner // context (m_sc) already. 3659e8fc1cSGreg Clayton #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) 376dadd508SGreg Clayton #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) 3859e8fc1cSGreg Clayton #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) 3959e8fc1cSGreg Clayton #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) 407c0962dcSSean Callanan #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) 4130fdc8d8SChris Lattner 421b72fcb7SGreg Clayton StackFrame::StackFrame 431b72fcb7SGreg Clayton ( 441b72fcb7SGreg Clayton lldb::user_id_t frame_idx, 4559e8fc1cSGreg Clayton lldb::user_id_t unwind_frame_index, 461b72fcb7SGreg Clayton Thread &thread, 471b72fcb7SGreg Clayton lldb::addr_t cfa, 481b72fcb7SGreg Clayton lldb::addr_t pc, 491b72fcb7SGreg Clayton const SymbolContext *sc_ptr 501b72fcb7SGreg Clayton ) : 511a65ae11SGreg Clayton m_thread (thread), 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), 5612fc3e0fSGreg Clayton m_frame_code_addr (NULL, 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 721b72fcb7SGreg Clayton StackFrame::StackFrame 731b72fcb7SGreg Clayton ( 741b72fcb7SGreg Clayton lldb::user_id_t frame_idx, 7559e8fc1cSGreg Clayton lldb::user_id_t unwind_frame_index, 761b72fcb7SGreg Clayton Thread &thread, 771b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 781b72fcb7SGreg Clayton lldb::addr_t cfa, 791b72fcb7SGreg Clayton lldb::addr_t pc, 801b72fcb7SGreg Clayton const SymbolContext *sc_ptr 811b72fcb7SGreg Clayton ) : 821a65ae11SGreg Clayton m_thread (thread), 831b72fcb7SGreg Clayton m_frame_index (frame_idx), 845ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 8530fdc8d8SChris Lattner m_reg_context_sp (reg_context_sp), 866dadd508SGreg Clayton m_id (pc, cfa, NULL), 8712fc3e0fSGreg Clayton m_frame_code_addr (NULL, pc), 8830fdc8d8SChris Lattner m_sc (), 8930fdc8d8SChris Lattner m_flags (), 9030fdc8d8SChris Lattner m_frame_base (), 9130fdc8d8SChris Lattner m_frame_base_error (), 9230fdc8d8SChris Lattner m_variable_list_sp (), 931a65ae11SGreg Clayton m_variable_list_value_objects (), 941a65ae11SGreg Clayton m_disassembly () 9530fdc8d8SChris Lattner { 9630fdc8d8SChris Lattner if (sc_ptr != NULL) 971b72fcb7SGreg Clayton { 9830fdc8d8SChris Lattner m_sc = *sc_ptr; 991b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1001b72fcb7SGreg Clayton } 1011b72fcb7SGreg Clayton 1021b72fcb7SGreg Clayton if (reg_context_sp && !m_sc.target_sp) 1031b72fcb7SGreg Clayton { 1041b72fcb7SGreg Clayton m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP(); 1051b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1061b72fcb7SGreg Clayton } 1071b72fcb7SGreg Clayton } 1081b72fcb7SGreg Clayton 1091b72fcb7SGreg Clayton StackFrame::StackFrame 1101b72fcb7SGreg Clayton ( 1111b72fcb7SGreg Clayton lldb::user_id_t frame_idx, 11259e8fc1cSGreg Clayton lldb::user_id_t unwind_frame_index, 1131b72fcb7SGreg Clayton Thread &thread, 1141b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 1151b72fcb7SGreg Clayton lldb::addr_t cfa, 1161b72fcb7SGreg Clayton const Address& pc_addr, 1171b72fcb7SGreg Clayton const SymbolContext *sc_ptr 1181b72fcb7SGreg Clayton ) : 1191a65ae11SGreg Clayton m_thread (thread), 1201b72fcb7SGreg Clayton m_frame_index (frame_idx), 1215ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 1221b72fcb7SGreg Clayton m_reg_context_sp (reg_context_sp), 123f5e56de0SGreg Clayton m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL), 12412fc3e0fSGreg Clayton m_frame_code_addr (pc_addr), 1251b72fcb7SGreg Clayton m_sc (), 1261b72fcb7SGreg Clayton m_flags (), 1271b72fcb7SGreg Clayton m_frame_base (), 1281b72fcb7SGreg Clayton m_frame_base_error (), 1291b72fcb7SGreg Clayton m_variable_list_sp (), 1301a65ae11SGreg Clayton m_variable_list_value_objects (), 1311a65ae11SGreg Clayton m_disassembly () 1321b72fcb7SGreg Clayton { 1331b72fcb7SGreg Clayton if (sc_ptr != NULL) 1341b72fcb7SGreg Clayton { 1351b72fcb7SGreg Clayton m_sc = *sc_ptr; 1361b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1371b72fcb7SGreg Clayton } 1381b72fcb7SGreg Clayton 1391b72fcb7SGreg Clayton if (m_sc.target_sp.get() == NULL && reg_context_sp) 1401b72fcb7SGreg Clayton { 1411b72fcb7SGreg Clayton m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().GetSP(); 1421b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1431b72fcb7SGreg Clayton } 1441b72fcb7SGreg Clayton 145ffc1d667SGreg Clayton Module *pc_module = pc_addr.GetModule(); 146ffc1d667SGreg Clayton if (m_sc.module_sp.get() == NULL || m_sc.module_sp.get() != pc_module) 1471b72fcb7SGreg Clayton { 1481b72fcb7SGreg Clayton if (pc_module) 1491b72fcb7SGreg Clayton { 1501b72fcb7SGreg Clayton m_sc.module_sp = pc_module->GetSP(); 1511b72fcb7SGreg Clayton m_flags.Set (eSymbolContextModule); 1521b72fcb7SGreg Clayton } 153ffc1d667SGreg Clayton else 154ffc1d667SGreg Clayton { 155ffc1d667SGreg Clayton m_sc.module_sp.reset(); 156ffc1d667SGreg Clayton } 157ffc1d667SGreg Clayton 1581b72fcb7SGreg Clayton } 15930fdc8d8SChris Lattner } 16030fdc8d8SChris Lattner 16130fdc8d8SChris Lattner 16230fdc8d8SChris Lattner //---------------------------------------------------------------------- 16330fdc8d8SChris Lattner // Destructor 16430fdc8d8SChris Lattner //---------------------------------------------------------------------- 16530fdc8d8SChris Lattner StackFrame::~StackFrame() 16630fdc8d8SChris Lattner { 16730fdc8d8SChris Lattner } 16830fdc8d8SChris Lattner 16930fdc8d8SChris Lattner StackID& 17030fdc8d8SChris Lattner StackFrame::GetStackID() 17130fdc8d8SChris Lattner { 1726dadd508SGreg Clayton // Make sure we have resolved the StackID object's symbol context scope if 1736dadd508SGreg Clayton // we already haven't looked it up. 17459e8fc1cSGreg Clayton 17559e8fc1cSGreg Clayton if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) 17659e8fc1cSGreg Clayton { 1772cad65a5SGreg Clayton if (m_id.GetSymbolContextScope ()) 17859e8fc1cSGreg Clayton { 17995897c6aSGreg Clayton // We already have a symbol context scope, we just don't have our 18095897c6aSGreg Clayton // flag bit set. 18159e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 18259e8fc1cSGreg Clayton } 18359e8fc1cSGreg Clayton else 18459e8fc1cSGreg Clayton { 18595897c6aSGreg Clayton // Calculate the frame block and use this for the stack ID symbol 18695897c6aSGreg Clayton // context scope if we have one. 18795897c6aSGreg Clayton SymbolContextScope *scope = GetFrameBlock (); 18895897c6aSGreg Clayton if (scope == NULL) 18959e8fc1cSGreg Clayton { 19095897c6aSGreg Clayton // We don't have a block, so use the symbol 19195897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 19259e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextSymbol); 19395897c6aSGreg Clayton 19495897c6aSGreg Clayton // It is ok if m_sc.symbol is NULL here 19595897c6aSGreg Clayton scope = m_sc.symbol; 19659e8fc1cSGreg Clayton } 19795897c6aSGreg Clayton // Set the symbol context scope (the accessor will set the 19895897c6aSGreg Clayton // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). 19995897c6aSGreg Clayton SetSymbolContextScope (scope); 20059e8fc1cSGreg Clayton } 20159e8fc1cSGreg Clayton } 20230fdc8d8SChris Lattner return m_id; 20330fdc8d8SChris Lattner } 20430fdc8d8SChris Lattner 20559e8fc1cSGreg Clayton void 20659e8fc1cSGreg Clayton StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) 20759e8fc1cSGreg Clayton { 20859e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 20959e8fc1cSGreg Clayton m_id.SetSymbolContextScope (symbol_scope); 21059e8fc1cSGreg Clayton } 21159e8fc1cSGreg Clayton 21234132754SGreg Clayton const Address& 2139da7bd07SGreg Clayton StackFrame::GetFrameCodeAddress() 21430fdc8d8SChris Lattner { 21559e8fc1cSGreg Clayton if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) 21630fdc8d8SChris Lattner { 21759e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_CODE_ADDR); 21830fdc8d8SChris Lattner 21930fdc8d8SChris Lattner // Resolve the PC into a temporary address because if ResolveLoadAddress 22030fdc8d8SChris Lattner // fails to resolve the address, it will clear the address object... 22134132754SGreg Clayton 22234132754SGreg Clayton if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), &m_thread.GetProcess().GetTarget())) 22330fdc8d8SChris Lattner { 22412fc3e0fSGreg Clayton const Section *section = m_frame_code_addr.GetSection(); 22530fdc8d8SChris Lattner if (section) 22630fdc8d8SChris Lattner { 22730fdc8d8SChris Lattner Module *module = section->GetModule(); 22830fdc8d8SChris Lattner if (module) 22930fdc8d8SChris Lattner { 23030fdc8d8SChris Lattner m_sc.module_sp = module->GetSP(); 23130fdc8d8SChris Lattner if (m_sc.module_sp) 23230fdc8d8SChris Lattner m_flags.Set(eSymbolContextModule); 23330fdc8d8SChris Lattner } 23430fdc8d8SChris Lattner } 23530fdc8d8SChris Lattner } 23630fdc8d8SChris Lattner } 23712fc3e0fSGreg Clayton return m_frame_code_addr; 23830fdc8d8SChris Lattner } 23930fdc8d8SChris Lattner 24030fdc8d8SChris Lattner void 24130fdc8d8SChris Lattner StackFrame::ChangePC (addr_t pc) 24230fdc8d8SChris Lattner { 24312fc3e0fSGreg Clayton m_frame_code_addr.SetOffset(pc); 24412fc3e0fSGreg Clayton m_frame_code_addr.SetSection(NULL); 24530fdc8d8SChris Lattner m_sc.Clear(); 24673b472d4SGreg Clayton m_flags.Reset(0); 24730fdc8d8SChris Lattner m_thread.ClearStackFrames (); 24830fdc8d8SChris Lattner } 24930fdc8d8SChris Lattner 25030fdc8d8SChris Lattner const char * 25130fdc8d8SChris Lattner StackFrame::Disassemble () 25230fdc8d8SChris Lattner { 25330fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 25430fdc8d8SChris Lattner { 25530fdc8d8SChris Lattner ExecutionContext exe_ctx; 2560603aa9dSGreg Clayton CalculateExecutionContext(exe_ctx); 2576611103cSGreg Clayton Target &target = m_thread.GetProcess().GetTarget(); 2586611103cSGreg Clayton Disassembler::Disassemble (target.GetDebugger(), 2596611103cSGreg Clayton target.GetArchitecture(), 2601080edbcSGreg Clayton NULL, 26130fdc8d8SChris Lattner exe_ctx, 26230fdc8d8SChris Lattner 0, 26337023b06SJim Ingham 0, 2641da6f9d7SGreg Clayton 0, 26530fdc8d8SChris Lattner m_disassembly); 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. 4239da7bd07SGreg Clayton resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); 42430fdc8d8SChris Lattner } 42530fdc8d8SChris Lattner 42630fdc8d8SChris Lattner // If the target was requested add that: 42730fdc8d8SChris Lattner if (m_sc.target_sp.get() == NULL) 4289da7bd07SGreg Clayton { 42930fdc8d8SChris Lattner m_sc.target_sp = CalculateProcess()->GetTarget().GetSP(); 4309da7bd07SGreg Clayton if (m_sc.target_sp) 4319da7bd07SGreg Clayton resolved |= eSymbolContextTarget; 4329da7bd07SGreg Clayton } 43330fdc8d8SChris Lattner 43430fdc8d8SChris Lattner // Update our internal flags so we remember what we have tried to locate so 43530fdc8d8SChris Lattner // we don't have to keep trying when more calls to this function are made. 4369da7bd07SGreg Clayton // We might have dug up more information that was requested (for example 4379da7bd07SGreg Clayton // if we were asked to only get the block, we will have gotten the 4389da7bd07SGreg Clayton // compile unit, and function) so set any additional bits that we resolved 4399da7bd07SGreg Clayton m_flags.Set (resolve_scope | resolved); 44030fdc8d8SChris Lattner } 44130fdc8d8SChris Lattner 44230fdc8d8SChris Lattner // Return the symbol context with everything that was possible to resolve 44330fdc8d8SChris Lattner // resolved. 44430fdc8d8SChris Lattner return m_sc; 44530fdc8d8SChris Lattner } 44630fdc8d8SChris Lattner 44730fdc8d8SChris Lattner 44830fdc8d8SChris Lattner VariableList * 449288bdf9cSGreg Clayton StackFrame::GetVariableList (bool get_file_globals) 45030fdc8d8SChris Lattner { 45130fdc8d8SChris Lattner if (m_flags.IsClear(RESOLVED_VARIABLES)) 45230fdc8d8SChris Lattner { 45330fdc8d8SChris Lattner m_flags.Set(RESOLVED_VARIABLES); 45430fdc8d8SChris Lattner 45595897c6aSGreg Clayton Block *frame_block = GetFrameBlock(); 456288bdf9cSGreg Clayton 45795897c6aSGreg Clayton if (frame_block) 45830fdc8d8SChris Lattner { 45995897c6aSGreg Clayton const bool get_child_variables = true; 46095897c6aSGreg Clayton const bool can_create = true; 461c662ec8bSGreg Clayton const bool stop_if_child_block_is_inlined_function = true; 462c662ec8bSGreg Clayton m_variable_list_sp.reset(new VariableList()); 463c662ec8bSGreg Clayton frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); 46430fdc8d8SChris Lattner } 4657c0962dcSSean Callanan } 466288bdf9cSGreg Clayton 4677c0962dcSSean Callanan if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && 4687c0962dcSSean Callanan get_file_globals) 46995897c6aSGreg Clayton { 4707c0962dcSSean Callanan m_flags.Set(RESOLVED_GLOBAL_VARIABLES); 4717c0962dcSSean Callanan 47295897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 47395897c6aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit); 47495897c6aSGreg Clayton 47595897c6aSGreg Clayton if (m_sc.comp_unit) 476288bdf9cSGreg Clayton { 477288bdf9cSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 478288bdf9cSGreg Clayton if (m_variable_list_sp) 479288bdf9cSGreg Clayton m_variable_list_sp->AddVariables (global_variable_list_sp.get()); 480288bdf9cSGreg Clayton else 481288bdf9cSGreg Clayton m_variable_list_sp = global_variable_list_sp; 482288bdf9cSGreg Clayton } 48330fdc8d8SChris Lattner } 4847c0962dcSSean Callanan 48530fdc8d8SChris Lattner return m_variable_list_sp.get(); 48630fdc8d8SChris Lattner } 48730fdc8d8SChris Lattner 488*d41f032aSGreg Clayton VariableListSP 489*d41f032aSGreg Clayton StackFrame::GetInScopeVariableList (bool get_file_globals) 490*d41f032aSGreg Clayton { 491*d41f032aSGreg Clayton VariableListSP var_list_sp(new VariableList); 492*d41f032aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); 493*d41f032aSGreg Clayton 494*d41f032aSGreg Clayton if (m_sc.block) 495*d41f032aSGreg Clayton { 496*d41f032aSGreg Clayton const bool can_create = true; 497*d41f032aSGreg Clayton const bool get_parent_variables = true; 498*d41f032aSGreg Clayton const bool stop_if_block_is_inlined_function = true; 499*d41f032aSGreg Clayton m_sc.block->AppendVariables (can_create, 500*d41f032aSGreg Clayton get_parent_variables, 501*d41f032aSGreg Clayton stop_if_block_is_inlined_function, 502*d41f032aSGreg Clayton var_list_sp.get()); 503*d41f032aSGreg Clayton } 504*d41f032aSGreg Clayton 505*d41f032aSGreg Clayton if (m_sc.comp_unit) 506*d41f032aSGreg Clayton { 507*d41f032aSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 508*d41f032aSGreg Clayton if (global_variable_list_sp) 509*d41f032aSGreg Clayton var_list_sp->AddVariables (global_variable_list_sp.get()); 510*d41f032aSGreg Clayton } 511*d41f032aSGreg Clayton 512*d41f032aSGreg Clayton return var_list_sp; 513*d41f032aSGreg Clayton } 514*d41f032aSGreg Clayton 515*d41f032aSGreg Clayton 5168b2fe6dcSGreg Clayton ValueObjectSP 5172837b766SJim Ingham StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, 5182837b766SJim Ingham lldb::DynamicValueType use_dynamic, 5192837b766SJim Ingham uint32_t options, 5202837b766SJim Ingham lldb::VariableSP &var_sp, 5212837b766SJim Ingham Error &error) 5228b2fe6dcSGreg Clayton { 52354979cddSGreg Clayton 52454979cddSGreg Clayton if (var_expr_cstr && var_expr_cstr[0]) 52554979cddSGreg Clayton { 5266d5e68eaSGreg Clayton const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; 5276d5e68eaSGreg Clayton const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; 52854979cddSGreg Clayton error.Clear(); 5298b2fe6dcSGreg Clayton bool deref = false; 5308b2fe6dcSGreg Clayton bool address_of = false; 5318b2fe6dcSGreg Clayton ValueObjectSP valobj_sp; 5328b2fe6dcSGreg Clayton const bool get_file_globals = true; 533*d41f032aSGreg Clayton // When looking up a variable for an expression, we need only consider the 534*d41f032aSGreg Clayton // variables that are in scope. 535*d41f032aSGreg Clayton VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); 536*d41f032aSGreg Clayton VariableList *variable_list = var_list_sp.get(); 5378b2fe6dcSGreg Clayton 5388b2fe6dcSGreg Clayton if (variable_list) 5398b2fe6dcSGreg Clayton { 5408b2fe6dcSGreg Clayton // If first character is a '*', then show pointer contents 54154979cddSGreg Clayton const char *var_expr = var_expr_cstr; 5428b2fe6dcSGreg Clayton if (var_expr[0] == '*') 5438b2fe6dcSGreg Clayton { 5448b2fe6dcSGreg Clayton deref = true; 5458b2fe6dcSGreg Clayton var_expr++; // Skip the '*' 5468b2fe6dcSGreg Clayton } 5478b2fe6dcSGreg Clayton else if (var_expr[0] == '&') 5488b2fe6dcSGreg Clayton { 5498b2fe6dcSGreg Clayton address_of = true; 5508b2fe6dcSGreg Clayton var_expr++; // Skip the '&' 5518b2fe6dcSGreg Clayton } 5528b2fe6dcSGreg Clayton 5538b2fe6dcSGreg Clayton std::string var_path (var_expr); 55454979cddSGreg Clayton size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); 55554979cddSGreg Clayton StreamString var_expr_path_strm; 5568b2fe6dcSGreg Clayton 5578b2fe6dcSGreg Clayton ConstString name_const_string; 5588b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 5598b2fe6dcSGreg Clayton name_const_string.SetCString (var_path.c_str()); 5608b2fe6dcSGreg Clayton else 5618b2fe6dcSGreg Clayton name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); 5628b2fe6dcSGreg Clayton 5632837b766SJim Ingham var_sp = variable_list->FindVariable(name_const_string); 5648b2fe6dcSGreg Clayton if (var_sp) 5658b2fe6dcSGreg Clayton { 5662837b766SJim Ingham valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); 56778a685aaSJim Ingham if (!valobj_sp) 56878a685aaSJim Ingham return valobj_sp; 5698b2fe6dcSGreg Clayton 5708b2fe6dcSGreg Clayton var_path.erase (0, name_const_string.GetLength ()); 5718b2fe6dcSGreg Clayton // We are dumping at least one child 5728b2fe6dcSGreg Clayton while (separator_idx != std::string::npos) 5738b2fe6dcSGreg Clayton { 5748b2fe6dcSGreg Clayton // Calculate the next separator index ahead of time 5758b2fe6dcSGreg Clayton ValueObjectSP child_valobj_sp; 5768b2fe6dcSGreg Clayton const char separator_type = var_path[0]; 5778b2fe6dcSGreg Clayton switch (separator_type) 5788b2fe6dcSGreg Clayton { 5798b2fe6dcSGreg Clayton 5808b2fe6dcSGreg Clayton case '-': 5818b2fe6dcSGreg Clayton if (var_path.size() >= 2 && var_path[1] != '>') 5828b2fe6dcSGreg Clayton return ValueObjectSP(); 5838b2fe6dcSGreg Clayton 5846d5e68eaSGreg Clayton if (no_fragile_ivar) 5856d5e68eaSGreg Clayton { 5866d5e68eaSGreg Clayton // Make sure we aren't trying to deref an objective 5876d5e68eaSGreg Clayton // C ivar if this is not allowed 5886d5e68eaSGreg Clayton const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL); 5896d5e68eaSGreg Clayton if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) && 5906d5e68eaSGreg Clayton (pointer_type_flags & ClangASTContext::eTypeIsPointer)) 5916d5e68eaSGreg Clayton { 5926d5e68eaSGreg Clayton // This was an objective C object pointer and 5936d5e68eaSGreg Clayton // it was requested we skip any fragile ivars 5946d5e68eaSGreg Clayton // so return nothing here 5956d5e68eaSGreg Clayton return ValueObjectSP(); 5966d5e68eaSGreg Clayton } 5976d5e68eaSGreg Clayton } 5988b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '-' 5998b2fe6dcSGreg Clayton // Fall through 6008b2fe6dcSGreg Clayton case '.': 6018b2fe6dcSGreg Clayton { 60254979cddSGreg Clayton const bool expr_is_ptr = var_path[0] == '>'; 6038b2fe6dcSGreg Clayton 6048b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '.' or '>' 6058b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 6068b2fe6dcSGreg Clayton ConstString child_name; 6078b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 6088b2fe6dcSGreg Clayton child_name.SetCString (var_path.c_str()); 6098b2fe6dcSGreg Clayton else 6108b2fe6dcSGreg Clayton child_name.SetCStringWithLength(var_path.c_str(), separator_idx); 6118b2fe6dcSGreg Clayton 61254979cddSGreg Clayton if (check_ptr_vs_member) 61354979cddSGreg Clayton { 61454979cddSGreg Clayton // We either have a pointer type and need to verify 61554979cddSGreg Clayton // valobj_sp is a pointer, or we have a member of a 61654979cddSGreg Clayton // class/union/struct being accessed with the . syntax 61754979cddSGreg Clayton // and need to verify we don't have a pointer. 61854979cddSGreg Clayton const bool actual_is_ptr = valobj_sp->IsPointerType (); 61954979cddSGreg Clayton 62054979cddSGreg Clayton if (actual_is_ptr != expr_is_ptr) 62154979cddSGreg Clayton { 62254979cddSGreg Clayton // Incorrect use of "." with a pointer, or "->" with 62354979cddSGreg Clayton // a class/union/struct instance or reference. 6246beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 62554979cddSGreg Clayton if (actual_is_ptr) 62654979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", 62754979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 62854979cddSGreg Clayton child_name.GetCString(), 62954979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 63054979cddSGreg Clayton var_path.c_str()); 63154979cddSGreg Clayton else 63254979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", 63354979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 63454979cddSGreg Clayton child_name.GetCString(), 63554979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 63654979cddSGreg Clayton var_path.c_str()); 63754979cddSGreg Clayton return ValueObjectSP(); 63854979cddSGreg Clayton } 63954979cddSGreg Clayton } 6408b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); 6418b2fe6dcSGreg Clayton if (!child_valobj_sp) 6428b2fe6dcSGreg Clayton { 6438b2fe6dcSGreg Clayton // No child member with name "child_name" 6446beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 64554979cddSGreg Clayton if (child_name) 64654979cddSGreg Clayton { 64754979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", 64854979cddSGreg Clayton child_name.GetCString(), 64954979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 65054979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 65154979cddSGreg Clayton } 65254979cddSGreg Clayton else 65354979cddSGreg Clayton { 65454979cddSGreg Clayton error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", 65554979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 65654979cddSGreg Clayton var_expr_cstr); 65754979cddSGreg Clayton } 65854979cddSGreg Clayton 6598b2fe6dcSGreg Clayton return ValueObjectSP(); 6608b2fe6dcSGreg Clayton } 6618b2fe6dcSGreg Clayton // Remove the child name from the path 6628b2fe6dcSGreg Clayton var_path.erase(0, child_name.GetLength()); 6632837b766SJim Ingham if (use_dynamic != lldb::eNoDynamicValues) 66478a685aaSJim Ingham { 6652837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 66678a685aaSJim Ingham if (dynamic_value_sp) 66778a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 66878a685aaSJim Ingham } 6698b2fe6dcSGreg Clayton } 6708b2fe6dcSGreg Clayton break; 6718b2fe6dcSGreg Clayton 6728b2fe6dcSGreg Clayton case '[': 6738b2fe6dcSGreg Clayton // Array member access, or treating pointer as an array 6748b2fe6dcSGreg Clayton if (var_path.size() > 2) // Need at least two brackets and a number 6758b2fe6dcSGreg Clayton { 6768b2fe6dcSGreg Clayton char *end = NULL; 6771a65ae11SGreg Clayton long child_index = ::strtol (&var_path[1], &end, 0); 6789fc1944eSEnrico Granata if (end && *end == ']' 6799fc1944eSEnrico 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 6808b2fe6dcSGreg Clayton { 6819fc1944eSEnrico Granata if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) 6829fc1944eSEnrico Granata { 6839fc1944eSEnrico Granata // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr 6849fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 6859fc1944eSEnrico Granata // would be done by saying ptr[low], without a deref * sign 6869fc1944eSEnrico Granata Error error; 6879fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 6889fc1944eSEnrico Granata if (error.Fail()) 6899fc1944eSEnrico Granata { 6909fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 6919fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 6929fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 6939fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 6949fc1944eSEnrico Granata return ValueObjectSP(); 6959fc1944eSEnrico Granata } 6969fc1944eSEnrico Granata valobj_sp = temp; 6979fc1944eSEnrico Granata deref = false; 6989fc1944eSEnrico Granata } 6999fc1944eSEnrico Granata else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) 7009fc1944eSEnrico Granata { 7019fc1944eSEnrico Granata // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] 7029fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 7039fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 7049fc1944eSEnrico Granata // would be done by saying arr[low], without a deref * sign 7059fc1944eSEnrico Granata Error error; 7069fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 7079fc1944eSEnrico Granata if (error.Fail()) 7089fc1944eSEnrico Granata { 7099fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 7109fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 7119fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 7129fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 7139fc1944eSEnrico Granata return ValueObjectSP(); 7149fc1944eSEnrico Granata } 7159fc1944eSEnrico Granata valobj_sp = temp; 7169fc1944eSEnrico Granata deref = false; 7179fc1944eSEnrico Granata } 7188b2fe6dcSGreg Clayton 7198b2fe6dcSGreg Clayton if (valobj_sp->IsPointerType ()) 7208b2fe6dcSGreg Clayton { 7218b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetSyntheticArrayMemberFromPointer (child_index, true); 72254979cddSGreg Clayton if (!child_valobj_sp) 72354979cddSGreg Clayton { 7246beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 72554979cddSGreg Clayton error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"", 72654979cddSGreg Clayton child_index, 72754979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 72854979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 72954979cddSGreg Clayton } 73054979cddSGreg Clayton } 73154979cddSGreg Clayton else if (ClangASTContext::IsArrayType (valobj_sp->GetClangType(), NULL, NULL)) 73254979cddSGreg Clayton { 73378a685aaSJim Ingham // Pass false to dynamic_value here so we can tell the difference between 73478a685aaSJim Ingham // no dynamic value and no member of this type... 73554979cddSGreg Clayton child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); 73654979cddSGreg Clayton if (!child_valobj_sp) 73754979cddSGreg Clayton { 7386beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 73954979cddSGreg Clayton error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"", 74054979cddSGreg Clayton child_index, 74154979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 74254979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 74354979cddSGreg Clayton } 7448b2fe6dcSGreg Clayton } 7459fc1944eSEnrico Granata else if (ClangASTContext::IsScalarType(valobj_sp->GetClangType())) 7469fc1944eSEnrico Granata { 7479fc1944eSEnrico Granata // this is a bitfield asking to display just one bit 7489fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); 7499fc1944eSEnrico Granata if (!child_valobj_sp) 7509fc1944eSEnrico Granata { 7519fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 7529fc1944eSEnrico Granata error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"", 7539fc1944eSEnrico Granata child_index, child_index, 7549fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 7559fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 7569fc1944eSEnrico Granata } 7579fc1944eSEnrico Granata } 7588b2fe6dcSGreg Clayton else 7598b2fe6dcSGreg Clayton { 7606beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 76154979cddSGreg Clayton error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 76254979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 76354979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 7648b2fe6dcSGreg Clayton } 7658b2fe6dcSGreg Clayton 7668b2fe6dcSGreg Clayton if (!child_valobj_sp) 7678b2fe6dcSGreg Clayton { 7688b2fe6dcSGreg Clayton // Invalid array index... 7698b2fe6dcSGreg Clayton return ValueObjectSP(); 7708b2fe6dcSGreg Clayton } 7718b2fe6dcSGreg Clayton 7728b2fe6dcSGreg Clayton // Erase the array member specification '[%i]' where 7738b2fe6dcSGreg Clayton // %i is the array index 7748b2fe6dcSGreg Clayton var_path.erase(0, (end - var_path.c_str()) + 1); 7758b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 7762837b766SJim Ingham if (use_dynamic != lldb::eNoDynamicValues) 77778a685aaSJim Ingham { 7782837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 77978a685aaSJim Ingham if (dynamic_value_sp) 78078a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 78178a685aaSJim Ingham } 7828b2fe6dcSGreg Clayton // Break out early from the switch since we were 7838b2fe6dcSGreg Clayton // able to find the child member 7848b2fe6dcSGreg Clayton break; 7858b2fe6dcSGreg Clayton } 7869fc1944eSEnrico Granata else if (end && *end == '-') 7879fc1944eSEnrico Granata { 7889fc1944eSEnrico Granata // this is most probably a BitField, let's take a look 7899fc1944eSEnrico Granata char *real_end = NULL; 7909fc1944eSEnrico Granata long final_index = ::strtol (end+1, &real_end, 0); 7919fc1944eSEnrico Granata if (real_end && *real_end == ']') 7929fc1944eSEnrico Granata { 7939fc1944eSEnrico Granata // if the format given is [high-low], swap range 7949fc1944eSEnrico Granata if (child_index > final_index) 7959fc1944eSEnrico Granata { 7969fc1944eSEnrico Granata long temp = child_index; 7979fc1944eSEnrico Granata child_index = final_index; 7989fc1944eSEnrico Granata final_index = temp; 7999fc1944eSEnrico Granata } 8009fc1944eSEnrico Granata 8019fc1944eSEnrico Granata if (ClangASTContext::IsPointerToScalarType(valobj_sp->GetClangType()) && deref) 8029fc1944eSEnrico Granata { 8039fc1944eSEnrico Granata // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr 8049fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 8059fc1944eSEnrico Granata // would be done by saying ptr[low-high], without a deref * sign 8069fc1944eSEnrico Granata Error error; 8079fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 8089fc1944eSEnrico Granata if (error.Fail()) 8099fc1944eSEnrico Granata { 8109fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8119fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 8129fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8139fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8149fc1944eSEnrico Granata return ValueObjectSP(); 8159fc1944eSEnrico Granata } 8169fc1944eSEnrico Granata valobj_sp = temp; 8179fc1944eSEnrico Granata deref = false; 8189fc1944eSEnrico Granata } 8199fc1944eSEnrico Granata else if (ClangASTContext::IsArrayOfScalarType(valobj_sp->GetClangType()) && deref) 8209fc1944eSEnrico Granata { 8219fc1944eSEnrico Granata // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] 8229fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 8239fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 8249fc1944eSEnrico Granata // would be done by saying arr[low-high], without a deref * sign 8259fc1944eSEnrico Granata Error error; 8269fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 8279fc1944eSEnrico Granata if (error.Fail()) 8289fc1944eSEnrico Granata { 8299fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8309fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 8319fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8329fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8339fc1944eSEnrico Granata return ValueObjectSP(); 8349fc1944eSEnrico Granata } 8359fc1944eSEnrico Granata valobj_sp = temp; 8369fc1944eSEnrico Granata deref = false; 8379fc1944eSEnrico Granata } 8389fc1944eSEnrico Granata 8399fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); 8409fc1944eSEnrico Granata if (!child_valobj_sp) 8419fc1944eSEnrico Granata { 8429fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8439fc1944eSEnrico Granata error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"", 8449fc1944eSEnrico Granata child_index, final_index, 8459fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8469fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8479fc1944eSEnrico Granata } 8489fc1944eSEnrico Granata } 8499fc1944eSEnrico Granata 8509fc1944eSEnrico Granata if (!child_valobj_sp) 8519fc1944eSEnrico Granata { 8529fc1944eSEnrico Granata // Invalid bitfield range... 8539fc1944eSEnrico Granata return ValueObjectSP(); 8549fc1944eSEnrico Granata } 8559fc1944eSEnrico Granata 8569fc1944eSEnrico Granata // Erase the bitfield member specification '[%i-%i]' where 8579fc1944eSEnrico Granata // %i is the index 8589fc1944eSEnrico Granata var_path.erase(0, (real_end - var_path.c_str()) + 1); 8599fc1944eSEnrico Granata separator_idx = var_path.find_first_of(".-["); 8609fc1944eSEnrico Granata if (use_dynamic != lldb::eNoDynamicValues) 8619fc1944eSEnrico Granata { 8629fc1944eSEnrico Granata ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 8639fc1944eSEnrico Granata if (dynamic_value_sp) 8649fc1944eSEnrico Granata child_valobj_sp = dynamic_value_sp; 8659fc1944eSEnrico Granata } 8669fc1944eSEnrico Granata // Break out early from the switch since we were 8679fc1944eSEnrico Granata // able to find the child member 8689fc1944eSEnrico Granata break; 8699fc1944eSEnrico Granata 8709fc1944eSEnrico Granata } 8719fc1944eSEnrico Granata } 8729fc1944eSEnrico Granata else 8739fc1944eSEnrico Granata { 8749fc1944eSEnrico Granata error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", 8759fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str(), 8769fc1944eSEnrico Granata var_path.c_str()); 8778b2fe6dcSGreg Clayton } 8788b2fe6dcSGreg Clayton return ValueObjectSP(); 8798b2fe6dcSGreg Clayton 8808b2fe6dcSGreg Clayton default: 8818b2fe6dcSGreg Clayton // Failure... 88254979cddSGreg Clayton { 8836beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 88454979cddSGreg Clayton error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", 88554979cddSGreg Clayton separator_type, 88654979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 88754979cddSGreg Clayton var_path.c_str()); 88854979cddSGreg Clayton 8898b2fe6dcSGreg Clayton return ValueObjectSP(); 8908b2fe6dcSGreg Clayton } 89154979cddSGreg Clayton } 8928b2fe6dcSGreg Clayton 8938b2fe6dcSGreg Clayton if (child_valobj_sp) 8948b2fe6dcSGreg Clayton valobj_sp = child_valobj_sp; 8958b2fe6dcSGreg Clayton 8968b2fe6dcSGreg Clayton if (var_path.empty()) 8978b2fe6dcSGreg Clayton break; 8988b2fe6dcSGreg Clayton 8998b2fe6dcSGreg Clayton } 9008b2fe6dcSGreg Clayton if (valobj_sp) 9018b2fe6dcSGreg Clayton { 9028b2fe6dcSGreg Clayton if (deref) 9038b2fe6dcSGreg Clayton { 904af67cecdSGreg Clayton ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); 9058b2fe6dcSGreg Clayton valobj_sp = deref_valobj_sp; 9068b2fe6dcSGreg Clayton } 9078b2fe6dcSGreg Clayton else if (address_of) 9088b2fe6dcSGreg Clayton { 90954979cddSGreg Clayton ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); 9108b2fe6dcSGreg Clayton valobj_sp = address_of_valobj_sp; 9118b2fe6dcSGreg Clayton } 9128b2fe6dcSGreg Clayton } 9138b2fe6dcSGreg Clayton return valobj_sp; 9148b2fe6dcSGreg Clayton } 91554979cddSGreg Clayton else 91654979cddSGreg Clayton { 9172837b766SJim Ingham error.SetErrorStringWithFormat("no variable named '%s' found in this frame", 9182837b766SJim Ingham name_const_string.GetCString()); 91954979cddSGreg Clayton } 92054979cddSGreg Clayton } 92154979cddSGreg Clayton } 92254979cddSGreg Clayton else 92354979cddSGreg Clayton { 92454979cddSGreg Clayton error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); 9258b2fe6dcSGreg Clayton } 9268b2fe6dcSGreg Clayton return ValueObjectSP(); 9278b2fe6dcSGreg Clayton } 92830fdc8d8SChris Lattner 92930fdc8d8SChris Lattner bool 93030fdc8d8SChris Lattner StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) 93130fdc8d8SChris Lattner { 93230fdc8d8SChris Lattner if (m_flags.IsClear(GOT_FRAME_BASE)) 93330fdc8d8SChris Lattner { 93430fdc8d8SChris Lattner if (m_sc.function) 93530fdc8d8SChris Lattner { 93630fdc8d8SChris Lattner m_frame_base.Clear(); 93730fdc8d8SChris Lattner m_frame_base_error.Clear(); 93830fdc8d8SChris Lattner 93930fdc8d8SChris Lattner m_flags.Set(GOT_FRAME_BASE); 94030fdc8d8SChris Lattner ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this); 94130fdc8d8SChris Lattner Value expr_value; 942016a95ebSGreg Clayton addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; 943016a95ebSGreg Clayton if (m_sc.function->GetFrameBaseExpression().IsLocationList()) 944f5e56de0SGreg Clayton loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget()); 945016a95ebSGreg Clayton 9461a65ae11SGreg Clayton if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) 94730fdc8d8SChris Lattner { 94830fdc8d8SChris Lattner // We should really have an error if evaluate returns, but in case 94930fdc8d8SChris Lattner // we don't, lets set the error to something at least. 95030fdc8d8SChris Lattner if (m_frame_base_error.Success()) 95130fdc8d8SChris Lattner m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); 95230fdc8d8SChris Lattner } 95330fdc8d8SChris Lattner else 95430fdc8d8SChris Lattner { 95530fdc8d8SChris Lattner m_frame_base = expr_value.ResolveValue(&exe_ctx, NULL); 95630fdc8d8SChris Lattner } 95730fdc8d8SChris Lattner } 95830fdc8d8SChris Lattner else 95930fdc8d8SChris Lattner { 96030fdc8d8SChris Lattner m_frame_base_error.SetErrorString ("No function in symbol context."); 96130fdc8d8SChris Lattner } 96230fdc8d8SChris Lattner } 96330fdc8d8SChris Lattner 96430fdc8d8SChris Lattner if (m_frame_base_error.Success()) 96530fdc8d8SChris Lattner frame_base = m_frame_base; 96630fdc8d8SChris Lattner 96730fdc8d8SChris Lattner if (error_ptr) 96830fdc8d8SChris Lattner *error_ptr = m_frame_base_error; 96930fdc8d8SChris Lattner return m_frame_base_error.Success(); 97030fdc8d8SChris Lattner } 97130fdc8d8SChris Lattner 9725ccbd294SGreg Clayton RegisterContextSP 97330fdc8d8SChris Lattner StackFrame::GetRegisterContext () 97430fdc8d8SChris Lattner { 9755ccbd294SGreg Clayton if (!m_reg_context_sp) 9765ccbd294SGreg Clayton m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this); 9775ccbd294SGreg Clayton return m_reg_context_sp; 97830fdc8d8SChris Lattner } 97930fdc8d8SChris Lattner 98030fdc8d8SChris Lattner bool 98130fdc8d8SChris Lattner StackFrame::HasDebugInformation () 98230fdc8d8SChris Lattner { 98330fdc8d8SChris Lattner GetSymbolContext (eSymbolContextLineEntry); 98430fdc8d8SChris Lattner return m_sc.line_entry.IsValid(); 98530fdc8d8SChris Lattner } 98630fdc8d8SChris Lattner 987288bdf9cSGreg Clayton 988288bdf9cSGreg Clayton ValueObjectSP 9892837b766SJim Ingham StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) 99030fdc8d8SChris Lattner { 991288bdf9cSGreg Clayton ValueObjectSP valobj_sp; 992288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 993288bdf9cSGreg Clayton if (var_list) 994288bdf9cSGreg Clayton { 995288bdf9cSGreg Clayton // Make sure the variable is a frame variable 996288bdf9cSGreg Clayton const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); 997288bdf9cSGreg Clayton const uint32_t num_variables = var_list->GetSize(); 998288bdf9cSGreg Clayton if (var_idx < num_variables) 999288bdf9cSGreg Clayton { 1000288bdf9cSGreg Clayton valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); 1001288bdf9cSGreg Clayton if (valobj_sp.get() == NULL) 1002288bdf9cSGreg Clayton { 1003288bdf9cSGreg Clayton if (m_variable_list_value_objects.GetSize() < num_variables) 1004288bdf9cSGreg Clayton m_variable_list_value_objects.Resize(num_variables); 100558b59f95SJim Ingham valobj_sp = ValueObjectVariable::Create (this, variable_sp); 1006288bdf9cSGreg Clayton m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); 1007288bdf9cSGreg Clayton } 1008288bdf9cSGreg Clayton } 1009288bdf9cSGreg Clayton } 10102837b766SJim Ingham if (use_dynamic != lldb::eNoDynamicValues && valobj_sp) 101178a685aaSJim Ingham { 10122837b766SJim Ingham ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); 101378a685aaSJim Ingham if (dynamic_sp) 101478a685aaSJim Ingham return dynamic_sp; 101578a685aaSJim Ingham } 1016288bdf9cSGreg Clayton return valobj_sp; 1017288bdf9cSGreg Clayton } 1018288bdf9cSGreg Clayton 1019288bdf9cSGreg Clayton ValueObjectSP 10202837b766SJim Ingham StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, lldb::DynamicValueType use_dynamic) 1021288bdf9cSGreg Clayton { 1022288bdf9cSGreg Clayton // Check to make sure we aren't already tracking this variable? 102378a685aaSJim Ingham ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 1024288bdf9cSGreg Clayton if (!valobj_sp) 1025288bdf9cSGreg Clayton { 1026288bdf9cSGreg Clayton // We aren't already tracking this global 1027288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1028288bdf9cSGreg Clayton // If this frame has no variables, create a new list 1029288bdf9cSGreg Clayton if (var_list == NULL) 1030288bdf9cSGreg Clayton m_variable_list_sp.reset (new VariableList()); 1031288bdf9cSGreg Clayton 1032288bdf9cSGreg Clayton // Add the global/static variable to this frame 1033288bdf9cSGreg Clayton m_variable_list_sp->AddVariable (variable_sp); 1034288bdf9cSGreg Clayton 1035288bdf9cSGreg Clayton // Now make a value object for it so we can track its changes 103678a685aaSJim Ingham valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 1037288bdf9cSGreg Clayton } 1038288bdf9cSGreg Clayton return valobj_sp; 103930fdc8d8SChris Lattner } 104030fdc8d8SChris Lattner 10416b8379c4SJim Ingham bool 10426b8379c4SJim Ingham StackFrame::IsInlined () 10436b8379c4SJim Ingham { 104459e8fc1cSGreg Clayton if (m_sc.block == NULL) 104559e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextBlock); 104659e8fc1cSGreg Clayton if (m_sc.block) 104759e8fc1cSGreg Clayton return m_sc.block->GetContainingInlinedBlock() != NULL; 104859e8fc1cSGreg Clayton return false; 10496b8379c4SJim Ingham } 10506b8379c4SJim Ingham 105130fdc8d8SChris Lattner Target * 105230fdc8d8SChris Lattner StackFrame::CalculateTarget () 105330fdc8d8SChris Lattner { 105430fdc8d8SChris Lattner return m_thread.CalculateTarget(); 105530fdc8d8SChris Lattner } 105630fdc8d8SChris Lattner 105730fdc8d8SChris Lattner Process * 105830fdc8d8SChris Lattner StackFrame::CalculateProcess () 105930fdc8d8SChris Lattner { 106030fdc8d8SChris Lattner return m_thread.CalculateProcess(); 106130fdc8d8SChris Lattner } 106230fdc8d8SChris Lattner 106330fdc8d8SChris Lattner Thread * 106430fdc8d8SChris Lattner StackFrame::CalculateThread () 106530fdc8d8SChris Lattner { 106630fdc8d8SChris Lattner return &m_thread; 106730fdc8d8SChris Lattner } 106830fdc8d8SChris Lattner 106930fdc8d8SChris Lattner StackFrame * 107030fdc8d8SChris Lattner StackFrame::CalculateStackFrame () 107130fdc8d8SChris Lattner { 107230fdc8d8SChris Lattner return this; 107330fdc8d8SChris Lattner } 107430fdc8d8SChris Lattner 107530fdc8d8SChris Lattner 107630fdc8d8SChris Lattner void 10770603aa9dSGreg Clayton StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) 107830fdc8d8SChris Lattner { 10790603aa9dSGreg Clayton m_thread.CalculateExecutionContext (exe_ctx); 108030fdc8d8SChris Lattner exe_ctx.frame = this; 108130fdc8d8SChris Lattner } 108230fdc8d8SChris Lattner 108330fdc8d8SChris Lattner void 10840603aa9dSGreg Clayton StackFrame::DumpUsingSettingsFormat (Stream *strm) 10850603aa9dSGreg Clayton { 10860603aa9dSGreg Clayton if (strm == NULL) 10870603aa9dSGreg Clayton return; 10880603aa9dSGreg Clayton 10890603aa9dSGreg Clayton GetSymbolContext(eSymbolContextEverything); 10900603aa9dSGreg Clayton ExecutionContext exe_ctx; 10910603aa9dSGreg Clayton CalculateExecutionContext(exe_ctx); 10920603aa9dSGreg Clayton const char *end = NULL; 10930603aa9dSGreg Clayton StreamString s; 10940603aa9dSGreg Clayton const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat(); 10950603aa9dSGreg Clayton if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end)) 10960603aa9dSGreg Clayton { 10970603aa9dSGreg Clayton strm->Write(s.GetData(), s.GetSize()); 10980603aa9dSGreg Clayton } 10990603aa9dSGreg Clayton else 11000603aa9dSGreg Clayton { 11010603aa9dSGreg Clayton Dump (strm, true, false); 11020603aa9dSGreg Clayton strm->EOL(); 11030603aa9dSGreg Clayton } 11040603aa9dSGreg Clayton } 11050603aa9dSGreg Clayton 11060603aa9dSGreg Clayton void 11076dadd508SGreg Clayton StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) 110830fdc8d8SChris Lattner { 110930fdc8d8SChris Lattner if (strm == NULL) 111030fdc8d8SChris Lattner return; 111130fdc8d8SChris Lattner 111230fdc8d8SChris Lattner if (show_frame_index) 11131b72fcb7SGreg Clayton strm->Printf("frame #%u: ", m_frame_index); 1114514487e8SGreg Clayton strm->Printf("0x%0*llx ", m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget())); 11159da7bd07SGreg Clayton GetSymbolContext(eSymbolContextEverything); 11161b72fcb7SGreg Clayton const bool show_module = true; 11171b72fcb7SGreg Clayton const bool show_inline = true; 11186dadd508SGreg Clayton m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline); 111930fdc8d8SChris Lattner } 112030fdc8d8SChris Lattner 11215082c5fdSGreg Clayton void 112259e8fc1cSGreg Clayton StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) 11235082c5fdSGreg Clayton { 112459e8fc1cSGreg Clayton assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing 112559e8fc1cSGreg Clayton m_variable_list_sp = prev_frame.m_variable_list_sp; 1126288bdf9cSGreg Clayton m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); 112768275d5eSGreg Clayton if (!m_disassembly.GetString().empty()) 112868275d5eSGreg Clayton m_disassembly.GetString().swap (m_disassembly.GetString()); 11295082c5fdSGreg Clayton } 113068275d5eSGreg Clayton 113168275d5eSGreg Clayton 113259e8fc1cSGreg Clayton void 113359e8fc1cSGreg Clayton StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) 113459e8fc1cSGreg Clayton { 113559e8fc1cSGreg Clayton assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing 11362cad65a5SGreg Clayton m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value 113759e8fc1cSGreg Clayton assert (&m_thread == &curr_frame.m_thread); 113859e8fc1cSGreg Clayton m_frame_index = curr_frame.m_frame_index; 11395ccbd294SGreg Clayton m_concrete_frame_index = curr_frame.m_concrete_frame_index; 114059e8fc1cSGreg Clayton m_reg_context_sp = curr_frame.m_reg_context_sp; 114159e8fc1cSGreg Clayton m_frame_code_addr = curr_frame.m_frame_code_addr; 114259e8fc1cSGreg 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()); 114359e8fc1cSGreg 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()); 114459e8fc1cSGreg Clayton assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); 114559e8fc1cSGreg Clayton assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function); 114659e8fc1cSGreg Clayton m_sc = curr_frame.m_sc; 114759e8fc1cSGreg Clayton m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); 114859e8fc1cSGreg Clayton m_flags.Set (m_sc.GetResolvedMask()); 114959e8fc1cSGreg Clayton m_frame_base.Clear(); 115059e8fc1cSGreg Clayton m_frame_base_error.Clear(); 115159e8fc1cSGreg Clayton } 115259e8fc1cSGreg Clayton 115359e8fc1cSGreg Clayton 11542cad65a5SGreg Clayton bool 11552cad65a5SGreg Clayton StackFrame::HasCachedData () const 11562cad65a5SGreg Clayton { 11572cad65a5SGreg Clayton if (m_variable_list_sp.get()) 11582cad65a5SGreg Clayton return true; 11592cad65a5SGreg Clayton if (m_variable_list_value_objects.GetSize() > 0) 11602cad65a5SGreg Clayton return true; 11612cad65a5SGreg Clayton if (!m_disassembly.GetString().empty()) 11622cad65a5SGreg Clayton return true; 11632cad65a5SGreg Clayton return false; 11642cad65a5SGreg Clayton } 1165e4284b71SJim Ingham 1166e4284b71SJim Ingham lldb::StackFrameSP 1167e4284b71SJim Ingham StackFrame::GetSP () 1168e4284b71SJim Ingham { 1169e4284b71SJim Ingham return m_thread.GetStackFrameSPForStackFramePtr (this); 1170e4284b71SJim Ingham } 11717260f620SGreg Clayton 11727260f620SGreg Clayton 11737260f620SGreg Clayton 11747260f620SGreg Clayton bool 11757260f620SGreg Clayton StackFrame::GetStatus (Stream& strm, 11767260f620SGreg Clayton bool show_frame_info, 11777260f620SGreg Clayton bool show_source, 11787260f620SGreg Clayton uint32_t source_lines_before, 11797260f620SGreg Clayton uint32_t source_lines_after) 11807260f620SGreg Clayton { 11817260f620SGreg Clayton if (show_frame_info) 11827260f620SGreg Clayton { 11837260f620SGreg Clayton strm.Indent(); 11847260f620SGreg Clayton DumpUsingSettingsFormat (&strm); 11857260f620SGreg Clayton } 11867260f620SGreg Clayton 11877260f620SGreg Clayton if (show_source) 11887260f620SGreg Clayton { 11897260f620SGreg Clayton GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); 11907260f620SGreg Clayton 11917260f620SGreg Clayton if (m_sc.comp_unit && m_sc.line_entry.IsValid()) 11927260f620SGreg Clayton { 11937e14f91dSGreg Clayton Target &target = GetThread().GetProcess().GetTarget(); 11947e14f91dSGreg Clayton target.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers ( 11957e14f91dSGreg Clayton &target, 11967260f620SGreg Clayton m_sc.line_entry.file, 11977260f620SGreg Clayton m_sc.line_entry.line, 11987260f620SGreg Clayton 3, 11997260f620SGreg Clayton 3, 12007260f620SGreg Clayton "->", 12017260f620SGreg Clayton &strm); 12027260f620SGreg Clayton 12037260f620SGreg Clayton } 12047260f620SGreg Clayton } 12057260f620SGreg Clayton return true; 12067260f620SGreg Clayton } 12077260f620SGreg Clayton 1208