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 // C Includes 1130fdc8d8SChris Lattner // C++ Includes 1230fdc8d8SChris Lattner // Other libraries and framework includes 1330fdc8d8SChris Lattner // Project includes 14*d70a6e71SEugene Zelenko #include "lldb/Target/StackFrame.h" 1530fdc8d8SChris Lattner #include "lldb/Core/Module.h" 160603aa9dSGreg Clayton #include "lldb/Core/Debugger.h" 1730fdc8d8SChris Lattner #include "lldb/Core/Disassembler.h" 18554f68d3SGreg Clayton #include "lldb/Core/FormatEntity.h" 1930fdc8d8SChris Lattner #include "lldb/Core/Value.h" 20288bdf9cSGreg Clayton #include "lldb/Core/ValueObjectVariable.h" 2154979cddSGreg Clayton #include "lldb/Core/ValueObjectConstResult.h" 221f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h" 2330fdc8d8SChris Lattner #include "lldb/Symbol/Function.h" 241f746071SGreg Clayton #include "lldb/Symbol/Symbol.h" 251f746071SGreg Clayton #include "lldb/Symbol/SymbolContextScope.h" 2646252398SEnrico Granata #include "lldb/Symbol/Type.h" 27288bdf9cSGreg Clayton #include "lldb/Symbol/VariableList.h" 2830fdc8d8SChris Lattner #include "lldb/Target/ExecutionContext.h" 2930fdc8d8SChris Lattner #include "lldb/Target/Process.h" 3030fdc8d8SChris Lattner #include "lldb/Target/RegisterContext.h" 3130fdc8d8SChris Lattner #include "lldb/Target/Target.h" 3230fdc8d8SChris Lattner #include "lldb/Target/Thread.h" 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner using namespace lldb; 3530fdc8d8SChris Lattner using namespace lldb_private; 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner // The first bits in the flags are reserved for the SymbolContext::Scope bits 3830fdc8d8SChris Lattner // so we know if we have tried to look up information in our internal symbol 3930fdc8d8SChris Lattner // context (m_sc) already. 4059e8fc1cSGreg Clayton #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) 416dadd508SGreg Clayton #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) 4259e8fc1cSGreg Clayton #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) 4359e8fc1cSGreg Clayton #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) 447c0962dcSSean Callanan #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) 4530fdc8d8SChris Lattner 46d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 47d9e416c0SGreg Clayton user_id_t frame_idx, 484d122c40SGreg Clayton user_id_t unwind_frame_index, 494d122c40SGreg Clayton addr_t cfa, 5099618476SJason Molenda bool cfa_is_valid, 514d122c40SGreg Clayton addr_t pc, 5299618476SJason Molenda uint32_t stop_id, 5399618476SJason Molenda bool stop_id_is_valid, 5499618476SJason Molenda bool is_history_frame, 558f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 56d9e416c0SGreg Clayton m_thread_wp (thread_sp), 571b72fcb7SGreg Clayton m_frame_index (frame_idx), 585ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 5930fdc8d8SChris Lattner m_reg_context_sp (), 60*d70a6e71SEugene Zelenko m_id(pc, cfa, nullptr), 61e72dfb32SGreg Clayton m_frame_code_addr (pc), 6230fdc8d8SChris Lattner m_sc (), 6330fdc8d8SChris Lattner m_flags (), 6430fdc8d8SChris Lattner m_frame_base (), 6530fdc8d8SChris Lattner m_frame_base_error (), 6699618476SJason Molenda m_cfa_is_valid (cfa_is_valid), 6799618476SJason Molenda m_stop_id (stop_id), 6899618476SJason Molenda m_stop_id_is_valid (stop_id_is_valid), 6999618476SJason Molenda m_is_history_frame (is_history_frame), 7030fdc8d8SChris Lattner m_variable_list_sp (), 711a65ae11SGreg Clayton m_variable_list_value_objects (), 726a354705SJason Molenda m_disassembly (), 736a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 7430fdc8d8SChris Lattner { 7599618476SJason Molenda // If we don't have a CFA value, use the frame index for our StackID so that recursive 7699618476SJason Molenda // functions properly aren't confused with one another on a history stack. 77*d70a6e71SEugene Zelenko if (m_is_history_frame && !m_cfa_is_valid) 7899618476SJason Molenda { 7999618476SJason Molenda m_id.SetCFA (m_frame_index); 8099618476SJason Molenda } 8199618476SJason Molenda 82*d70a6e71SEugene Zelenko if (sc_ptr != nullptr) 831b72fcb7SGreg Clayton { 8430fdc8d8SChris Lattner m_sc = *sc_ptr; 851b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 861b72fcb7SGreg Clayton } 8730fdc8d8SChris Lattner } 8830fdc8d8SChris Lattner 89d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 90d9e416c0SGreg Clayton user_id_t frame_idx, 914d122c40SGreg Clayton user_id_t unwind_frame_index, 921b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 934d122c40SGreg Clayton addr_t cfa, 944d122c40SGreg Clayton addr_t pc, 958f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 96d9e416c0SGreg Clayton m_thread_wp (thread_sp), 971b72fcb7SGreg Clayton m_frame_index (frame_idx), 985ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 9930fdc8d8SChris Lattner m_reg_context_sp (reg_context_sp), 100*d70a6e71SEugene Zelenko m_id(pc, cfa, nullptr), 101e72dfb32SGreg Clayton m_frame_code_addr (pc), 10230fdc8d8SChris Lattner m_sc (), 10330fdc8d8SChris Lattner m_flags (), 10430fdc8d8SChris Lattner m_frame_base (), 10530fdc8d8SChris Lattner m_frame_base_error (), 10699618476SJason Molenda m_cfa_is_valid (true), 10799618476SJason Molenda m_stop_id (0), 10899618476SJason Molenda m_stop_id_is_valid (false), 10999618476SJason Molenda m_is_history_frame (false), 11030fdc8d8SChris Lattner m_variable_list_sp (), 1111a65ae11SGreg Clayton m_variable_list_value_objects (), 1126a354705SJason Molenda m_disassembly (), 1136a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 11430fdc8d8SChris Lattner { 115*d70a6e71SEugene Zelenko if (sc_ptr != nullptr) 1161b72fcb7SGreg Clayton { 11730fdc8d8SChris Lattner m_sc = *sc_ptr; 1181b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1191b72fcb7SGreg Clayton } 1201b72fcb7SGreg Clayton 1211b72fcb7SGreg Clayton if (reg_context_sp && !m_sc.target_sp) 1221b72fcb7SGreg Clayton { 123d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 124d9e416c0SGreg Clayton if (m_sc.target_sp) 1251b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1261b72fcb7SGreg Clayton } 1271b72fcb7SGreg Clayton } 1281b72fcb7SGreg Clayton 129d9e416c0SGreg Clayton StackFrame::StackFrame (const ThreadSP &thread_sp, 130d9e416c0SGreg Clayton user_id_t frame_idx, 1314d122c40SGreg Clayton user_id_t unwind_frame_index, 1321b72fcb7SGreg Clayton const RegisterContextSP ®_context_sp, 1334d122c40SGreg Clayton addr_t cfa, 1341b72fcb7SGreg Clayton const Address& pc_addr, 1358f7180b1SGreg Clayton const SymbolContext *sc_ptr) : 136d9e416c0SGreg Clayton m_thread_wp (thread_sp), 1371b72fcb7SGreg Clayton m_frame_index (frame_idx), 1385ccbd294SGreg Clayton m_concrete_frame_index (unwind_frame_index), 1391b72fcb7SGreg Clayton m_reg_context_sp (reg_context_sp), 140*d70a6e71SEugene Zelenko m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa, nullptr), 14112fc3e0fSGreg Clayton m_frame_code_addr (pc_addr), 1421b72fcb7SGreg Clayton m_sc (), 1431b72fcb7SGreg Clayton m_flags (), 1441b72fcb7SGreg Clayton m_frame_base (), 1451b72fcb7SGreg Clayton m_frame_base_error (), 14699618476SJason Molenda m_cfa_is_valid (true), 14799618476SJason Molenda m_stop_id (0), 14899618476SJason Molenda m_stop_id_is_valid (false), 14999618476SJason Molenda m_is_history_frame (false), 1501b72fcb7SGreg Clayton m_variable_list_sp (), 1511a65ae11SGreg Clayton m_variable_list_value_objects (), 1526a354705SJason Molenda m_disassembly (), 1536a354705SJason Molenda m_mutex (Mutex::eMutexTypeRecursive) 1541b72fcb7SGreg Clayton { 155*d70a6e71SEugene Zelenko if (sc_ptr != nullptr) 1561b72fcb7SGreg Clayton { 1571b72fcb7SGreg Clayton m_sc = *sc_ptr; 1581b72fcb7SGreg Clayton m_flags.Set(m_sc.GetResolvedMask ()); 1591b72fcb7SGreg Clayton } 1601b72fcb7SGreg Clayton 161*d70a6e71SEugene Zelenko if (!m_sc.target_sp && reg_context_sp) 1621b72fcb7SGreg Clayton { 163d9e416c0SGreg Clayton m_sc.target_sp = reg_context_sp->CalculateTarget(); 164d9e416c0SGreg Clayton if (m_sc.target_sp) 1651b72fcb7SGreg Clayton m_flags.Set (eSymbolContextTarget); 1661b72fcb7SGreg Clayton } 1671b72fcb7SGreg Clayton 168e72dfb32SGreg Clayton ModuleSP pc_module_sp (pc_addr.GetModule()); 169e72dfb32SGreg Clayton if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) 1701b72fcb7SGreg Clayton { 171e72dfb32SGreg Clayton if (pc_module_sp) 1721b72fcb7SGreg Clayton { 173e72dfb32SGreg Clayton m_sc.module_sp = pc_module_sp; 1741b72fcb7SGreg Clayton m_flags.Set (eSymbolContextModule); 1751b72fcb7SGreg Clayton } 176ffc1d667SGreg Clayton else 177ffc1d667SGreg Clayton { 178ffc1d667SGreg Clayton m_sc.module_sp.reset(); 179ffc1d667SGreg Clayton } 1801b72fcb7SGreg Clayton } 18130fdc8d8SChris Lattner } 18230fdc8d8SChris Lattner 183*d70a6e71SEugene Zelenko StackFrame::~StackFrame() = default; 18430fdc8d8SChris Lattner 18530fdc8d8SChris Lattner StackID& 18630fdc8d8SChris Lattner StackFrame::GetStackID() 18730fdc8d8SChris Lattner { 1886a354705SJason Molenda Mutex::Locker locker(m_mutex); 1896dadd508SGreg Clayton // Make sure we have resolved the StackID object's symbol context scope if 1906dadd508SGreg Clayton // we already haven't looked it up. 19159e8fc1cSGreg Clayton 19259e8fc1cSGreg Clayton if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) 19359e8fc1cSGreg Clayton { 1942cad65a5SGreg Clayton if (m_id.GetSymbolContextScope ()) 19559e8fc1cSGreg Clayton { 19695897c6aSGreg Clayton // We already have a symbol context scope, we just don't have our 19795897c6aSGreg Clayton // flag bit set. 19859e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 19959e8fc1cSGreg Clayton } 20059e8fc1cSGreg Clayton else 20159e8fc1cSGreg Clayton { 20295897c6aSGreg Clayton // Calculate the frame block and use this for the stack ID symbol 20395897c6aSGreg Clayton // context scope if we have one. 20495897c6aSGreg Clayton SymbolContextScope *scope = GetFrameBlock (); 205*d70a6e71SEugene Zelenko if (scope == nullptr) 20659e8fc1cSGreg Clayton { 20795897c6aSGreg Clayton // We don't have a block, so use the symbol 20895897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 20959e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextSymbol); 21095897c6aSGreg Clayton 211*d70a6e71SEugene Zelenko // It is ok if m_sc.symbol is nullptr here 21295897c6aSGreg Clayton scope = m_sc.symbol; 21359e8fc1cSGreg Clayton } 21495897c6aSGreg Clayton // Set the symbol context scope (the accessor will set the 21595897c6aSGreg Clayton // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). 21695897c6aSGreg Clayton SetSymbolContextScope (scope); 21759e8fc1cSGreg Clayton } 21859e8fc1cSGreg Clayton } 21930fdc8d8SChris Lattner return m_id; 22030fdc8d8SChris Lattner } 22130fdc8d8SChris Lattner 222513c6bb8SJim Ingham uint32_t 223513c6bb8SJim Ingham StackFrame::GetFrameIndex () const 224513c6bb8SJim Ingham { 225513c6bb8SJim Ingham ThreadSP thread_sp = GetThread(); 226513c6bb8SJim Ingham if (thread_sp) 227b57e4a1bSJason Molenda return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index); 228513c6bb8SJim Ingham else 229513c6bb8SJim Ingham return m_frame_index; 230513c6bb8SJim Ingham } 231513c6bb8SJim Ingham 23259e8fc1cSGreg Clayton void 23359e8fc1cSGreg Clayton StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) 23459e8fc1cSGreg Clayton { 2356a354705SJason Molenda Mutex::Locker locker(m_mutex); 23659e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); 23759e8fc1cSGreg Clayton m_id.SetSymbolContextScope (symbol_scope); 23859e8fc1cSGreg Clayton } 23959e8fc1cSGreg Clayton 24034132754SGreg Clayton const Address& 2419da7bd07SGreg Clayton StackFrame::GetFrameCodeAddress() 24230fdc8d8SChris Lattner { 2436a354705SJason Molenda Mutex::Locker locker(m_mutex); 24459e8fc1cSGreg Clayton if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) 24530fdc8d8SChris Lattner { 24659e8fc1cSGreg Clayton m_flags.Set (RESOLVED_FRAME_CODE_ADDR); 24730fdc8d8SChris Lattner 24830fdc8d8SChris Lattner // Resolve the PC into a temporary address because if ResolveLoadAddress 24930fdc8d8SChris Lattner // fails to resolve the address, it will clear the address object... 250d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 251d9e416c0SGreg Clayton if (thread_sp) 252d9e416c0SGreg Clayton { 253d9e416c0SGreg Clayton TargetSP target_sp (thread_sp->CalculateTarget()); 254d9e416c0SGreg Clayton if (target_sp) 255d9e416c0SGreg Clayton { 25625b9f7ebSTamas Berghammer if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode)) 25730fdc8d8SChris Lattner { 258e72dfb32SGreg Clayton ModuleSP module_sp (m_frame_code_addr.GetModule()); 259e72dfb32SGreg Clayton if (module_sp) 26030fdc8d8SChris Lattner { 261e72dfb32SGreg Clayton m_sc.module_sp = module_sp; 26230fdc8d8SChris Lattner m_flags.Set(eSymbolContextModule); 26330fdc8d8SChris Lattner } 26430fdc8d8SChris Lattner } 26530fdc8d8SChris Lattner } 26630fdc8d8SChris Lattner } 267d9e416c0SGreg Clayton } 26812fc3e0fSGreg Clayton return m_frame_code_addr; 26930fdc8d8SChris Lattner } 27030fdc8d8SChris Lattner 27199618476SJason Molenda bool 27230fdc8d8SChris Lattner StackFrame::ChangePC (addr_t pc) 27330fdc8d8SChris Lattner { 2746a354705SJason Molenda Mutex::Locker locker(m_mutex); 27599618476SJason Molenda // We can't change the pc value of a history stack frame - it is immutable. 27699618476SJason Molenda if (m_is_history_frame) 27799618476SJason Molenda return false; 278e72dfb32SGreg Clayton m_frame_code_addr.SetRawAddress(pc); 27972310355SGreg Clayton m_sc.Clear(false); 28073b472d4SGreg Clayton m_flags.Reset(0); 281d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 282d9e416c0SGreg Clayton if (thread_sp) 283d9e416c0SGreg Clayton thread_sp->ClearStackFrames (); 28499618476SJason Molenda return true; 28530fdc8d8SChris Lattner } 28630fdc8d8SChris Lattner 28730fdc8d8SChris Lattner const char * 28830fdc8d8SChris Lattner StackFrame::Disassemble () 28930fdc8d8SChris Lattner { 2906a354705SJason Molenda Mutex::Locker locker(m_mutex); 29130fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 29230fdc8d8SChris Lattner { 293d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 294d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 295d9e416c0SGreg Clayton if (target) 296d9e416c0SGreg Clayton { 297*d70a6e71SEugene Zelenko const char *plugin_name = nullptr; 298*d70a6e71SEugene Zelenko const char *flavor = nullptr; 299d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 300d9e416c0SGreg Clayton target->GetArchitecture(), 3010f063ba6SJim Ingham plugin_name, 3020f063ba6SJim Ingham flavor, 30330fdc8d8SChris Lattner exe_ctx, 30430fdc8d8SChris Lattner 0, 30537023b06SJim Ingham 0, 3061da6f9d7SGreg Clayton 0, 30730fdc8d8SChris Lattner m_disassembly); 308d9e416c0SGreg Clayton } 30930fdc8d8SChris Lattner if (m_disassembly.GetSize() == 0) 310*d70a6e71SEugene Zelenko return nullptr; 31130fdc8d8SChris Lattner } 31230fdc8d8SChris Lattner return m_disassembly.GetData(); 31330fdc8d8SChris Lattner } 31430fdc8d8SChris Lattner 31595897c6aSGreg Clayton Block * 31695897c6aSGreg Clayton StackFrame::GetFrameBlock () 31795897c6aSGreg Clayton { 318*d70a6e71SEugene Zelenko if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock)) 31995897c6aSGreg Clayton GetSymbolContext (eSymbolContextBlock); 32095897c6aSGreg Clayton 32195897c6aSGreg Clayton if (m_sc.block) 32295897c6aSGreg Clayton { 32395897c6aSGreg Clayton Block *inline_block = m_sc.block->GetContainingInlinedBlock(); 32495897c6aSGreg Clayton if (inline_block) 32595897c6aSGreg Clayton { 32695897c6aSGreg Clayton // Use the block with the inlined function info 32795897c6aSGreg Clayton // as the frame block we want this frame to have only the variables 32895897c6aSGreg Clayton // for the inlined function and its non-inlined block child blocks. 32995897c6aSGreg Clayton return inline_block; 33095897c6aSGreg Clayton } 33195897c6aSGreg Clayton else 33295897c6aSGreg Clayton { 33395897c6aSGreg Clayton // This block is not contained withing any inlined function blocks 33495897c6aSGreg Clayton // with so we want to use the top most function block. 33595897c6aSGreg Clayton return &m_sc.function->GetBlock (false); 33695897c6aSGreg Clayton } 33795897c6aSGreg Clayton } 338*d70a6e71SEugene Zelenko return nullptr; 33995897c6aSGreg Clayton } 34095897c6aSGreg Clayton 34130fdc8d8SChris Lattner //---------------------------------------------------------------------- 34230fdc8d8SChris Lattner // Get the symbol context if we already haven't done so by resolving the 34330fdc8d8SChris Lattner // PC address as much as possible. This way when we pass around a 34430fdc8d8SChris Lattner // StackFrame object, everyone will have as much information as 34530fdc8d8SChris Lattner // possible and no one will ever have to look things up manually. 34630fdc8d8SChris Lattner //---------------------------------------------------------------------- 34730fdc8d8SChris Lattner const SymbolContext& 34830fdc8d8SChris Lattner StackFrame::GetSymbolContext (uint32_t resolve_scope) 34930fdc8d8SChris Lattner { 3506a354705SJason Molenda Mutex::Locker locker(m_mutex); 35130fdc8d8SChris Lattner // Copy our internal symbol context into "sc". 35273b472d4SGreg Clayton if ((m_flags.Get() & resolve_scope) != resolve_scope) 35330fdc8d8SChris Lattner { 35475a0333bSGreg Clayton uint32_t resolved = 0; 35575a0333bSGreg Clayton 35675a0333bSGreg Clayton // If the target was requested add that: 35775a0333bSGreg Clayton if (!m_sc.target_sp) 35875a0333bSGreg Clayton { 35975a0333bSGreg Clayton m_sc.target_sp = CalculateTarget(); 36075a0333bSGreg Clayton if (m_sc.target_sp) 36175a0333bSGreg Clayton resolved |= eSymbolContextTarget; 36275a0333bSGreg Clayton } 36375a0333bSGreg Clayton 364aaa0ba31SBruce Mitchener // Resolve our PC to section offset if we haven't already done so 36530fdc8d8SChris Lattner // and if we don't have a module. The resolved address section will 36630fdc8d8SChris Lattner // contain the module to which it belongs 36759e8fc1cSGreg Clayton if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) 3689da7bd07SGreg Clayton GetFrameCodeAddress(); 36930fdc8d8SChris Lattner 37030fdc8d8SChris Lattner // If this is not frame zero, then we need to subtract 1 from the PC 37130fdc8d8SChris Lattner // value when doing address lookups since the PC will be on the 37230fdc8d8SChris Lattner // instruction following the function call instruction... 37330fdc8d8SChris Lattner 3749da7bd07SGreg Clayton Address lookup_addr(GetFrameCodeAddress()); 3751b72fcb7SGreg Clayton if (m_frame_index > 0 && lookup_addr.IsValid()) 37630fdc8d8SChris Lattner { 37730fdc8d8SChris Lattner addr_t offset = lookup_addr.GetOffset(); 37830fdc8d8SChris Lattner if (offset > 0) 379cf29675dSJason Molenda { 38030fdc8d8SChris Lattner lookup_addr.SetOffset(offset - 1); 381cf29675dSJason Molenda 382cf29675dSJason Molenda } 383cf29675dSJason Molenda else 384cf29675dSJason Molenda { 385cf29675dSJason Molenda // lookup_addr is the start of a section. We need 386cf29675dSJason Molenda // do the math on the actual load address and re-compute 387cf29675dSJason Molenda // the section. We're working with a 'noreturn' function 388cf29675dSJason Molenda // at the end of a section. 389cf29675dSJason Molenda ThreadSP thread_sp (GetThread()); 390cf29675dSJason Molenda if (thread_sp) 391cf29675dSJason Molenda { 392cf29675dSJason Molenda TargetSP target_sp (thread_sp->CalculateTarget()); 393cf29675dSJason Molenda if (target_sp) 394cf29675dSJason Molenda { 395cf29675dSJason Molenda addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1; 396cf29675dSJason Molenda lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get()); 397cf29675dSJason Molenda } 398cf29675dSJason Molenda else 399cf29675dSJason Molenda { 400cf29675dSJason Molenda lookup_addr.SetOffset(offset - 1); 401cf29675dSJason Molenda } 402cf29675dSJason Molenda } 403cf29675dSJason Molenda } 40430fdc8d8SChris Lattner } 40530fdc8d8SChris Lattner 40630fdc8d8SChris Lattner if (m_sc.module_sp) 40730fdc8d8SChris Lattner { 40830fdc8d8SChris Lattner // We have something in our stack frame symbol context, lets check 40930fdc8d8SChris Lattner // if we haven't already tried to lookup one of those things. If we 41030fdc8d8SChris Lattner // haven't then we will do the query. 4111b72fcb7SGreg Clayton 4121b72fcb7SGreg Clayton uint32_t actual_resolve_scope = 0; 4131b72fcb7SGreg Clayton 4141b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextCompUnit) 4151b72fcb7SGreg Clayton { 4161b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 4171b72fcb7SGreg Clayton { 4181b72fcb7SGreg Clayton if (m_sc.comp_unit) 4199da7bd07SGreg Clayton resolved |= eSymbolContextCompUnit; 4201b72fcb7SGreg Clayton else 4211b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextCompUnit; 4221b72fcb7SGreg Clayton } 4231b72fcb7SGreg Clayton } 4241b72fcb7SGreg Clayton 4251b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextFunction) 4261b72fcb7SGreg Clayton { 4271b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextFunction)) 4281b72fcb7SGreg Clayton { 4291b72fcb7SGreg Clayton if (m_sc.function) 4309da7bd07SGreg Clayton resolved |= eSymbolContextFunction; 4311b72fcb7SGreg Clayton else 4321b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextFunction; 4331b72fcb7SGreg Clayton } 4341b72fcb7SGreg Clayton } 4351b72fcb7SGreg Clayton 4361b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextBlock) 4371b72fcb7SGreg Clayton { 4381b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextBlock)) 4391b72fcb7SGreg Clayton { 4401b72fcb7SGreg Clayton if (m_sc.block) 4419da7bd07SGreg Clayton resolved |= eSymbolContextBlock; 4421b72fcb7SGreg Clayton else 4431b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextBlock; 4441b72fcb7SGreg Clayton } 4451b72fcb7SGreg Clayton } 4461b72fcb7SGreg Clayton 4471b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextSymbol) 4481b72fcb7SGreg Clayton { 4491b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextSymbol)) 4501b72fcb7SGreg Clayton { 4511b72fcb7SGreg Clayton if (m_sc.symbol) 4529da7bd07SGreg Clayton resolved |= eSymbolContextSymbol; 4531b72fcb7SGreg Clayton else 4541b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextSymbol; 4551b72fcb7SGreg Clayton } 4561b72fcb7SGreg Clayton } 4571b72fcb7SGreg Clayton 4581b72fcb7SGreg Clayton if (resolve_scope & eSymbolContextLineEntry) 4591b72fcb7SGreg Clayton { 4601b72fcb7SGreg Clayton if (m_flags.IsClear (eSymbolContextLineEntry)) 4611b72fcb7SGreg Clayton { 4621b72fcb7SGreg Clayton if (m_sc.line_entry.IsValid()) 4639da7bd07SGreg Clayton resolved |= eSymbolContextLineEntry; 4641b72fcb7SGreg Clayton else 4651b72fcb7SGreg Clayton actual_resolve_scope |= eSymbolContextLineEntry; 4661b72fcb7SGreg Clayton } 4671b72fcb7SGreg Clayton } 4681b72fcb7SGreg Clayton 4691b72fcb7SGreg Clayton if (actual_resolve_scope) 47030fdc8d8SChris Lattner { 47130fdc8d8SChris Lattner // We might be resolving less information than what is already 47230fdc8d8SChris Lattner // in our current symbol context so resolve into a temporary 47330fdc8d8SChris Lattner // symbol context "sc" so we don't clear out data we have 47430fdc8d8SChris Lattner // already found in "m_sc" 47530fdc8d8SChris Lattner SymbolContext sc; 47630fdc8d8SChris Lattner // Set flags that indicate what we have tried to resolve 4779da7bd07SGreg Clayton resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); 4781b72fcb7SGreg Clayton // Only replace what we didn't already have as we may have 4791b72fcb7SGreg Clayton // information for an inlined function scope that won't match 4801b72fcb7SGreg Clayton // what a standard lookup by address would match 481*d70a6e71SEugene Zelenko if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr) 4829da7bd07SGreg Clayton m_sc.comp_unit = sc.comp_unit; 483*d70a6e71SEugene Zelenko if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr) 4849da7bd07SGreg Clayton m_sc.function = sc.function; 485*d70a6e71SEugene Zelenko if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr) 4869da7bd07SGreg Clayton m_sc.block = sc.block; 487*d70a6e71SEugene Zelenko if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr) 4889da7bd07SGreg Clayton m_sc.symbol = sc.symbol; 4899da7bd07SGreg Clayton if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) 49075a0333bSGreg Clayton { 4919da7bd07SGreg Clayton m_sc.line_entry = sc.line_entry; 49275a0333bSGreg Clayton if (m_sc.target_sp) 49375a0333bSGreg Clayton { 49475a0333bSGreg Clayton // Be sure to apply and file remappings to our file and line 49575a0333bSGreg Clayton // entries when handing out a line entry 49675a0333bSGreg Clayton FileSpec new_file_spec; 49775a0333bSGreg Clayton if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec)) 49875a0333bSGreg Clayton m_sc.line_entry.file = new_file_spec; 49975a0333bSGreg Clayton } 50075a0333bSGreg Clayton } 50130fdc8d8SChris Lattner } 50230fdc8d8SChris Lattner } 50330fdc8d8SChris Lattner else 50430fdc8d8SChris Lattner { 50530fdc8d8SChris Lattner // If we don't have a module, then we can't have the compile unit, 50630fdc8d8SChris Lattner // function, block, line entry or symbol, so we can safely call 50730fdc8d8SChris Lattner // ResolveSymbolContextForAddress with our symbol context member m_sc. 5089da7bd07SGreg Clayton if (m_sc.target_sp) 509f4be227dSSean Callanan { 51075a0333bSGreg Clayton resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); 511f4be227dSSean Callanan } 5129da7bd07SGreg Clayton } 51330fdc8d8SChris Lattner 51430fdc8d8SChris Lattner // Update our internal flags so we remember what we have tried to locate so 51530fdc8d8SChris Lattner // we don't have to keep trying when more calls to this function are made. 5169da7bd07SGreg Clayton // We might have dug up more information that was requested (for example 5179da7bd07SGreg Clayton // if we were asked to only get the block, we will have gotten the 5189da7bd07SGreg Clayton // compile unit, and function) so set any additional bits that we resolved 5199da7bd07SGreg Clayton m_flags.Set (resolve_scope | resolved); 52030fdc8d8SChris Lattner } 52130fdc8d8SChris Lattner 52230fdc8d8SChris Lattner // Return the symbol context with everything that was possible to resolve 52330fdc8d8SChris Lattner // resolved. 52430fdc8d8SChris Lattner return m_sc; 52530fdc8d8SChris Lattner } 52630fdc8d8SChris Lattner 52730fdc8d8SChris Lattner VariableList * 528288bdf9cSGreg Clayton StackFrame::GetVariableList (bool get_file_globals) 52930fdc8d8SChris Lattner { 5306a354705SJason Molenda Mutex::Locker locker(m_mutex); 53130fdc8d8SChris Lattner if (m_flags.IsClear(RESOLVED_VARIABLES)) 53230fdc8d8SChris Lattner { 53330fdc8d8SChris Lattner m_flags.Set(RESOLVED_VARIABLES); 53430fdc8d8SChris Lattner 53595897c6aSGreg Clayton Block *frame_block = GetFrameBlock(); 536288bdf9cSGreg Clayton 53795897c6aSGreg Clayton if (frame_block) 53830fdc8d8SChris Lattner { 53995897c6aSGreg Clayton const bool get_child_variables = true; 54095897c6aSGreg Clayton const bool can_create = true; 541c662ec8bSGreg Clayton const bool stop_if_child_block_is_inlined_function = true; 542c662ec8bSGreg Clayton m_variable_list_sp.reset(new VariableList()); 543c662ec8bSGreg Clayton frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); 54430fdc8d8SChris Lattner } 5457c0962dcSSean Callanan } 546288bdf9cSGreg Clayton 5477c0962dcSSean Callanan if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && 5487c0962dcSSean Callanan get_file_globals) 54995897c6aSGreg Clayton { 5507c0962dcSSean Callanan m_flags.Set(RESOLVED_GLOBAL_VARIABLES); 5517c0962dcSSean Callanan 55295897c6aSGreg Clayton if (m_flags.IsClear (eSymbolContextCompUnit)) 55395897c6aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit); 55495897c6aSGreg Clayton 55595897c6aSGreg Clayton if (m_sc.comp_unit) 556288bdf9cSGreg Clayton { 557288bdf9cSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 558288bdf9cSGreg Clayton if (m_variable_list_sp) 559288bdf9cSGreg Clayton m_variable_list_sp->AddVariables (global_variable_list_sp.get()); 560288bdf9cSGreg Clayton else 561288bdf9cSGreg Clayton m_variable_list_sp = global_variable_list_sp; 562288bdf9cSGreg Clayton } 56330fdc8d8SChris Lattner } 5647c0962dcSSean Callanan 56530fdc8d8SChris Lattner return m_variable_list_sp.get(); 56630fdc8d8SChris Lattner } 56730fdc8d8SChris Lattner 568d41f032aSGreg Clayton VariableListSP 569d41f032aSGreg Clayton StackFrame::GetInScopeVariableList (bool get_file_globals) 570d41f032aSGreg Clayton { 5716a354705SJason Molenda Mutex::Locker locker(m_mutex); 57299618476SJason Molenda // We can't fetch variable information for a history stack frame. 57399618476SJason Molenda if (m_is_history_frame) 57499618476SJason Molenda return VariableListSP(); 57599618476SJason Molenda 576d41f032aSGreg Clayton VariableListSP var_list_sp(new VariableList); 577d41f032aSGreg Clayton GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); 578d41f032aSGreg Clayton 579d41f032aSGreg Clayton if (m_sc.block) 580d41f032aSGreg Clayton { 581d41f032aSGreg Clayton const bool can_create = true; 582d41f032aSGreg Clayton const bool get_parent_variables = true; 583d41f032aSGreg Clayton const bool stop_if_block_is_inlined_function = true; 584d41f032aSGreg Clayton m_sc.block->AppendVariables (can_create, 585d41f032aSGreg Clayton get_parent_variables, 586d41f032aSGreg Clayton stop_if_block_is_inlined_function, 587d41f032aSGreg Clayton var_list_sp.get()); 588d41f032aSGreg Clayton } 589d41f032aSGreg Clayton 590b90168ffSSiva Chandra if (m_sc.comp_unit && get_file_globals) 591d41f032aSGreg Clayton { 592d41f032aSGreg Clayton VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); 593d41f032aSGreg Clayton if (global_variable_list_sp) 594d41f032aSGreg Clayton var_list_sp->AddVariables (global_variable_list_sp.get()); 595d41f032aSGreg Clayton } 596d41f032aSGreg Clayton 597d41f032aSGreg Clayton return var_list_sp; 598d41f032aSGreg Clayton } 599d41f032aSGreg Clayton 6008b2fe6dcSGreg Clayton ValueObjectSP 6012837b766SJim Ingham StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, 6024d122c40SGreg Clayton DynamicValueType use_dynamic, 6032837b766SJim Ingham uint32_t options, 6044d122c40SGreg Clayton VariableSP &var_sp, 6052837b766SJim Ingham Error &error) 6068b2fe6dcSGreg Clayton { 60799618476SJason Molenda // We can't fetch variable information for a history stack frame. 60899618476SJason Molenda if (m_is_history_frame) 60999618476SJason Molenda return ValueObjectSP(); 61054979cddSGreg Clayton 61154979cddSGreg Clayton if (var_expr_cstr && var_expr_cstr[0]) 61254979cddSGreg Clayton { 6136d5e68eaSGreg Clayton const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; 6146d5e68eaSGreg Clayton const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; 61527b625e1SEnrico Granata const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0; 61658ad3344SEnrico Granata //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0; 61754979cddSGreg Clayton error.Clear(); 6188b2fe6dcSGreg Clayton bool deref = false; 6198b2fe6dcSGreg Clayton bool address_of = false; 6208b2fe6dcSGreg Clayton ValueObjectSP valobj_sp; 6218b2fe6dcSGreg Clayton const bool get_file_globals = true; 622d41f032aSGreg Clayton // When looking up a variable for an expression, we need only consider the 623d41f032aSGreg Clayton // variables that are in scope. 624d41f032aSGreg Clayton VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); 625d41f032aSGreg Clayton VariableList *variable_list = var_list_sp.get(); 6268b2fe6dcSGreg Clayton 6278b2fe6dcSGreg Clayton if (variable_list) 6288b2fe6dcSGreg Clayton { 6298b2fe6dcSGreg Clayton // If first character is a '*', then show pointer contents 63054979cddSGreg Clayton const char *var_expr = var_expr_cstr; 6318b2fe6dcSGreg Clayton if (var_expr[0] == '*') 6328b2fe6dcSGreg Clayton { 6338b2fe6dcSGreg Clayton deref = true; 6348b2fe6dcSGreg Clayton var_expr++; // Skip the '*' 6358b2fe6dcSGreg Clayton } 6368b2fe6dcSGreg Clayton else if (var_expr[0] == '&') 6378b2fe6dcSGreg Clayton { 6388b2fe6dcSGreg Clayton address_of = true; 6398b2fe6dcSGreg Clayton var_expr++; // Skip the '&' 6408b2fe6dcSGreg Clayton } 6418b2fe6dcSGreg Clayton 6428b2fe6dcSGreg Clayton std::string var_path (var_expr); 64354979cddSGreg Clayton size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); 64454979cddSGreg Clayton StreamString var_expr_path_strm; 6458b2fe6dcSGreg Clayton 6468b2fe6dcSGreg Clayton ConstString name_const_string; 6478b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 6488b2fe6dcSGreg Clayton name_const_string.SetCString (var_path.c_str()); 6498b2fe6dcSGreg Clayton else 6508b2fe6dcSGreg Clayton name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); 6518b2fe6dcSGreg Clayton 65210bc1a4eSPaul Herman var_sp = variable_list->FindVariable(name_const_string, false); 653685c88c5SGreg Clayton 654685c88c5SGreg Clayton bool synthetically_added_instance_object = false; 655685c88c5SGreg Clayton 656685c88c5SGreg Clayton if (var_sp) 657685c88c5SGreg Clayton { 658685c88c5SGreg Clayton var_path.erase (0, name_const_string.GetLength ()); 659685c88c5SGreg Clayton } 66046252398SEnrico Granata 66146252398SEnrico Granata if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) 662685c88c5SGreg Clayton { 663685c88c5SGreg Clayton // Check for direct ivars access which helps us with implicit 664685c88c5SGreg Clayton // access to ivars with the "this->" or "self->" 665685c88c5SGreg Clayton GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock); 666685c88c5SGreg Clayton lldb::LanguageType method_language = eLanguageTypeUnknown; 667685c88c5SGreg Clayton bool is_instance_method = false; 668685c88c5SGreg Clayton ConstString method_object_name; 669685c88c5SGreg Clayton if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name)) 670685c88c5SGreg Clayton { 671685c88c5SGreg Clayton if (is_instance_method && method_object_name) 672685c88c5SGreg Clayton { 673685c88c5SGreg Clayton var_sp = variable_list->FindVariable(method_object_name); 674685c88c5SGreg Clayton if (var_sp) 675685c88c5SGreg Clayton { 676685c88c5SGreg Clayton separator_idx = 0; 677685c88c5SGreg Clayton var_path.insert(0, "->"); 678685c88c5SGreg Clayton synthetically_added_instance_object = true; 679685c88c5SGreg Clayton } 680685c88c5SGreg Clayton } 681685c88c5SGreg Clayton } 682685c88c5SGreg Clayton } 683685c88c5SGreg Clayton 68446252398SEnrico Granata if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) 68546252398SEnrico Granata { 68646252398SEnrico Granata // Check if any anonymous unions are there which contain a variable with the name we need 68746252398SEnrico Granata for (size_t i = 0; 68846252398SEnrico Granata i < variable_list->GetSize(); 68946252398SEnrico Granata i++) 69046252398SEnrico Granata { 69146252398SEnrico Granata if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i)) 69246252398SEnrico Granata { 69346252398SEnrico Granata if (variable_sp->GetName().IsEmpty()) 69446252398SEnrico Granata { 69546252398SEnrico Granata if (Type *var_type = variable_sp->GetType()) 69646252398SEnrico Granata { 69746252398SEnrico Granata if (var_type->GetForwardCompilerType().IsAnonymousType()) 69846252398SEnrico Granata { 69946252398SEnrico Granata valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 70046252398SEnrico Granata if (!valobj_sp) 70146252398SEnrico Granata return valobj_sp; 70246252398SEnrico Granata valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true); 70346252398SEnrico Granata if (valobj_sp) 70446252398SEnrico Granata break; 70546252398SEnrico Granata } 70646252398SEnrico Granata } 70746252398SEnrico Granata } 70846252398SEnrico Granata } 70946252398SEnrico Granata } 71046252398SEnrico Granata } 71146252398SEnrico Granata 71246252398SEnrico Granata if (var_sp && !valobj_sp) 7138b2fe6dcSGreg Clayton { 7142837b766SJim Ingham valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); 71578a685aaSJim Ingham if (!valobj_sp) 71678a685aaSJim Ingham return valobj_sp; 71746252398SEnrico Granata } 71846252398SEnrico Granata if (valobj_sp) 71946252398SEnrico Granata { 7208b2fe6dcSGreg Clayton // We are dumping at least one child 7218b2fe6dcSGreg Clayton while (separator_idx != std::string::npos) 7228b2fe6dcSGreg Clayton { 7238b2fe6dcSGreg Clayton // Calculate the next separator index ahead of time 7248b2fe6dcSGreg Clayton ValueObjectSP child_valobj_sp; 7258b2fe6dcSGreg Clayton const char separator_type = var_path[0]; 7268b2fe6dcSGreg Clayton switch (separator_type) 7278b2fe6dcSGreg Clayton { 7288b2fe6dcSGreg Clayton case '-': 7298b2fe6dcSGreg Clayton if (var_path.size() >= 2 && var_path[1] != '>') 7308b2fe6dcSGreg Clayton return ValueObjectSP(); 7318b2fe6dcSGreg Clayton 7326d5e68eaSGreg Clayton if (no_fragile_ivar) 7336d5e68eaSGreg Clayton { 7346d5e68eaSGreg Clayton // Make sure we aren't trying to deref an objective 7356d5e68eaSGreg Clayton // C ivar if this is not allowed 736*d70a6e71SEugene Zelenko const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo(nullptr); 737622be238SEnrico Granata if ((pointer_type_flags & eTypeIsObjC) && 738622be238SEnrico Granata (pointer_type_flags & eTypeIsPointer)) 7396d5e68eaSGreg Clayton { 7406d5e68eaSGreg Clayton // This was an objective C object pointer and 7416d5e68eaSGreg Clayton // it was requested we skip any fragile ivars 7426d5e68eaSGreg Clayton // so return nothing here 7436d5e68eaSGreg Clayton return ValueObjectSP(); 7446d5e68eaSGreg Clayton } 7456d5e68eaSGreg Clayton } 7468b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '-' 74762e0681aSJason Molenda LLVM_FALLTHROUGH; 7488b2fe6dcSGreg Clayton case '.': 7498b2fe6dcSGreg Clayton { 75054979cddSGreg Clayton const bool expr_is_ptr = var_path[0] == '>'; 7518b2fe6dcSGreg Clayton 7528b2fe6dcSGreg Clayton var_path.erase (0, 1); // Remove the '.' or '>' 7538b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 7548b2fe6dcSGreg Clayton ConstString child_name; 7558b2fe6dcSGreg Clayton if (separator_idx == std::string::npos) 7568b2fe6dcSGreg Clayton child_name.SetCString (var_path.c_str()); 7578b2fe6dcSGreg Clayton else 7588b2fe6dcSGreg Clayton child_name.SetCStringWithLength(var_path.c_str(), separator_idx); 7598b2fe6dcSGreg Clayton 76054979cddSGreg Clayton if (check_ptr_vs_member) 76154979cddSGreg Clayton { 76254979cddSGreg Clayton // We either have a pointer type and need to verify 76354979cddSGreg Clayton // valobj_sp is a pointer, or we have a member of a 76454979cddSGreg Clayton // class/union/struct being accessed with the . syntax 76554979cddSGreg Clayton // and need to verify we don't have a pointer. 76654979cddSGreg Clayton const bool actual_is_ptr = valobj_sp->IsPointerType (); 76754979cddSGreg Clayton 76854979cddSGreg Clayton if (actual_is_ptr != expr_is_ptr) 76954979cddSGreg Clayton { 77054979cddSGreg Clayton // Incorrect use of "." with a pointer, or "->" with 77154979cddSGreg Clayton // a class/union/struct instance or reference. 7726beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 77354979cddSGreg Clayton if (actual_is_ptr) 77454979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", 77554979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 77654979cddSGreg Clayton child_name.GetCString(), 77754979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 77854979cddSGreg Clayton var_path.c_str()); 77954979cddSGreg Clayton else 78054979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", 78154979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 78254979cddSGreg Clayton child_name.GetCString(), 78354979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 78454979cddSGreg Clayton var_path.c_str()); 78554979cddSGreg Clayton return ValueObjectSP(); 78654979cddSGreg Clayton } 78754979cddSGreg Clayton } 7888b2fe6dcSGreg Clayton child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); 7898b2fe6dcSGreg Clayton if (!child_valobj_sp) 7908b2fe6dcSGreg Clayton { 791*d70a6e71SEugene Zelenko if (!no_synth_child) 79286cc9829SEnrico Granata { 79386cc9829SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticValue(); 79486cc9829SEnrico Granata if (child_valobj_sp) 79586cc9829SEnrico Granata child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true); 79686cc9829SEnrico Granata } 7978c9d3560SEnrico Granata 7988c9d3560SEnrico Granata if (no_synth_child || !child_valobj_sp) 7998c9d3560SEnrico Granata { 8008b2fe6dcSGreg Clayton // No child member with name "child_name" 801685c88c5SGreg Clayton if (synthetically_added_instance_object) 802685c88c5SGreg Clayton { 803685c88c5SGreg Clayton // We added a "this->" or "self->" to the beginning of the expression 804685c88c5SGreg Clayton // and this is the first pointer ivar access, so just return the normal 805685c88c5SGreg Clayton // error 806685c88c5SGreg Clayton error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame", 807685c88c5SGreg Clayton name_const_string.GetCString()); 808685c88c5SGreg Clayton } 809685c88c5SGreg Clayton else 810685c88c5SGreg Clayton { 8116beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 81254979cddSGreg Clayton if (child_name) 81354979cddSGreg Clayton { 81454979cddSGreg Clayton error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", 81554979cddSGreg Clayton child_name.GetCString(), 81654979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 81754979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 81854979cddSGreg Clayton } 81954979cddSGreg Clayton else 82054979cddSGreg Clayton { 82154979cddSGreg Clayton error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", 82254979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 82354979cddSGreg Clayton var_expr_cstr); 82454979cddSGreg Clayton } 825685c88c5SGreg Clayton } 8268b2fe6dcSGreg Clayton return ValueObjectSP(); 8278b2fe6dcSGreg Clayton } 8288c9d3560SEnrico Granata } 829685c88c5SGreg Clayton synthetically_added_instance_object = false; 8308b2fe6dcSGreg Clayton // Remove the child name from the path 8318b2fe6dcSGreg Clayton var_path.erase(0, child_name.GetLength()); 8324d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 83378a685aaSJim Ingham { 8342837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 83578a685aaSJim Ingham if (dynamic_value_sp) 83678a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 83778a685aaSJim Ingham } 8388b2fe6dcSGreg Clayton } 8398b2fe6dcSGreg Clayton break; 8408b2fe6dcSGreg Clayton 8418b2fe6dcSGreg Clayton case '[': 8428b2fe6dcSGreg Clayton // Array member access, or treating pointer as an array 8438b2fe6dcSGreg Clayton if (var_path.size() > 2) // Need at least two brackets and a number 8448b2fe6dcSGreg Clayton { 845*d70a6e71SEugene Zelenko char *end = nullptr; 8461a65ae11SGreg Clayton long child_index = ::strtol (&var_path[1], &end, 0); 8479fc1944eSEnrico Granata if (end && *end == ']' 8489fc1944eSEnrico 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 8498b2fe6dcSGreg Clayton { 85099558cc4SGreg Clayton if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) 8519fc1944eSEnrico Granata { 8529fc1944eSEnrico Granata // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr 8539fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 8549fc1944eSEnrico Granata // would be done by saying ptr[low], without a deref * sign 8559fc1944eSEnrico Granata Error error; 8569fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 8579fc1944eSEnrico Granata if (error.Fail()) 8589fc1944eSEnrico Granata { 8599fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8609fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 8619fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8629fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8639fc1944eSEnrico Granata return ValueObjectSP(); 8649fc1944eSEnrico Granata } 8659fc1944eSEnrico Granata valobj_sp = temp; 8669fc1944eSEnrico Granata deref = false; 8679fc1944eSEnrico Granata } 86899558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) 8699fc1944eSEnrico Granata { 8709fc1944eSEnrico Granata // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] 8719fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 8729fc1944eSEnrico Granata // and extract bit low out of it. reading array item low 8739fc1944eSEnrico Granata // would be done by saying arr[low], without a deref * sign 8749fc1944eSEnrico Granata Error error; 8759fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 8769fc1944eSEnrico Granata if (error.Fail()) 8779fc1944eSEnrico Granata { 8789fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 8799fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 8809fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 8819fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 8829fc1944eSEnrico Granata return ValueObjectSP(); 8839fc1944eSEnrico Granata } 8849fc1944eSEnrico Granata valobj_sp = temp; 8859fc1944eSEnrico Granata deref = false; 8869fc1944eSEnrico Granata } 8878b2fe6dcSGreg Clayton 8884ef877f5SGreg Clayton bool is_incomplete_array = false; 8898b2fe6dcSGreg Clayton if (valobj_sp->IsPointerType ()) 8908b2fe6dcSGreg Clayton { 891226b70c1SSean Callanan bool is_objc_pointer = true; 892226b70c1SSean Callanan 89399558cc4SGreg Clayton if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC) 894226b70c1SSean Callanan is_objc_pointer = false; 89599558cc4SGreg Clayton else if (!valobj_sp->GetCompilerType().IsPointerType()) 896226b70c1SSean Callanan is_objc_pointer = false; 897226b70c1SSean Callanan 898226b70c1SSean Callanan if (no_synth_child && is_objc_pointer) 899226b70c1SSean Callanan { 900226b70c1SSean Callanan error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted", 901226b70c1SSean Callanan valobj_sp->GetTypeName().AsCString("<invalid type>"), 902226b70c1SSean Callanan var_expr_path_strm.GetString().c_str()); 903226b70c1SSean Callanan 904226b70c1SSean Callanan return ValueObjectSP(); 905226b70c1SSean Callanan } 906226b70c1SSean Callanan else if (is_objc_pointer) 90727b625e1SEnrico Granata { 90827b625e1SEnrico Granata // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children 90986cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 910*d70a6e71SEugene Zelenko if (!synthetic /* no synthetic */ 91127b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 91227b625e1SEnrico Granata { 91327b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 91427b625e1SEnrico Granata error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 91527b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 91627b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 91727b625e1SEnrico Granata } 9183985c8c6SSaleem Abdulrasool else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 91927b625e1SEnrico Granata { 92027b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9217e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 92227b625e1SEnrico Granata child_index, 92327b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 92427b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 92527b625e1SEnrico Granata } 92627b625e1SEnrico Granata else 92727b625e1SEnrico Granata { 92827b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 92927b625e1SEnrico Granata if (!child_valobj_sp) 93027b625e1SEnrico Granata { 93127b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9327e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 93327b625e1SEnrico Granata child_index, 93427b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 93527b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 93627b625e1SEnrico Granata } 93727b625e1SEnrico Granata } 93827b625e1SEnrico Granata } 93927b625e1SEnrico Granata else 94027b625e1SEnrico Granata { 94111d86362SBruce Mitchener child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); 94254979cddSGreg Clayton if (!child_valobj_sp) 94354979cddSGreg Clayton { 9446beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9457e589a60SJason Molenda error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"", 94654979cddSGreg Clayton child_index, 94754979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 94854979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 94954979cddSGreg Clayton } 95054979cddSGreg Clayton } 95127b625e1SEnrico Granata } 952*d70a6e71SEugene Zelenko else if (valobj_sp->GetCompilerType().IsArrayType(nullptr, nullptr, &is_incomplete_array)) 95354979cddSGreg Clayton { 95478a685aaSJim Ingham // Pass false to dynamic_value here so we can tell the difference between 95578a685aaSJim Ingham // no dynamic value and no member of this type... 95654979cddSGreg Clayton child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); 957*d70a6e71SEugene Zelenko if (!child_valobj_sp && (is_incomplete_array || !no_synth_child)) 9584ef877f5SGreg Clayton child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); 9594ef877f5SGreg Clayton 96054979cddSGreg Clayton if (!child_valobj_sp) 96154979cddSGreg Clayton { 9626beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9637e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 96454979cddSGreg Clayton child_index, 96554979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 96654979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 96754979cddSGreg Clayton } 9688b2fe6dcSGreg Clayton } 96999558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsScalarType()) 9709fc1944eSEnrico Granata { 9719fc1944eSEnrico Granata // this is a bitfield asking to display just one bit 9729fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); 9739fc1944eSEnrico Granata if (!child_valobj_sp) 9749fc1944eSEnrico Granata { 9759fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9767e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 9779fc1944eSEnrico Granata child_index, child_index, 9789fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 9799fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 9809fc1944eSEnrico Granata } 9819fc1944eSEnrico Granata } 9828b2fe6dcSGreg Clayton else 9838b2fe6dcSGreg Clayton { 98486cc9829SEnrico Granata ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); 98527b625e1SEnrico Granata if (no_synth_child /* synthetic is forbidden */ || 986*d70a6e71SEugene Zelenko !synthetic /* no synthetic */ 98727b625e1SEnrico Granata || synthetic == valobj_sp) /* synthetic is the same as the original object */ 98827b625e1SEnrico Granata { 9896beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 99054979cddSGreg Clayton error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", 99154979cddSGreg Clayton valobj_sp->GetTypeName().AsCString("<invalid type>"), 99254979cddSGreg Clayton var_expr_path_strm.GetString().c_str()); 9938b2fe6dcSGreg Clayton } 9943985c8c6SSaleem Abdulrasool else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) 99527b625e1SEnrico Granata { 99627b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 9977e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 99827b625e1SEnrico Granata child_index, 99927b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 100027b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 100127b625e1SEnrico Granata } 100227b625e1SEnrico Granata else 100327b625e1SEnrico Granata { 100427b625e1SEnrico Granata child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); 100527b625e1SEnrico Granata if (!child_valobj_sp) 100627b625e1SEnrico Granata { 100727b625e1SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10087e589a60SJason Molenda error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", 100927b625e1SEnrico Granata child_index, 101027b625e1SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 101127b625e1SEnrico Granata var_expr_path_strm.GetString().c_str()); 101227b625e1SEnrico Granata } 101327b625e1SEnrico Granata } 101427b625e1SEnrico Granata } 10158b2fe6dcSGreg Clayton 10168b2fe6dcSGreg Clayton if (!child_valobj_sp) 10178b2fe6dcSGreg Clayton { 10188b2fe6dcSGreg Clayton // Invalid array index... 10198b2fe6dcSGreg Clayton return ValueObjectSP(); 10208b2fe6dcSGreg Clayton } 10218b2fe6dcSGreg Clayton 10228b2fe6dcSGreg Clayton // Erase the array member specification '[%i]' where 10238b2fe6dcSGreg Clayton // %i is the array index 10248b2fe6dcSGreg Clayton var_path.erase(0, (end - var_path.c_str()) + 1); 10258b2fe6dcSGreg Clayton separator_idx = var_path.find_first_of(".-["); 10264d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 102778a685aaSJim Ingham { 10282837b766SJim Ingham ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 102978a685aaSJim Ingham if (dynamic_value_sp) 103078a685aaSJim Ingham child_valobj_sp = dynamic_value_sp; 103178a685aaSJim Ingham } 10328b2fe6dcSGreg Clayton // Break out early from the switch since we were 10338b2fe6dcSGreg Clayton // able to find the child member 10348b2fe6dcSGreg Clayton break; 10358b2fe6dcSGreg Clayton } 10369fc1944eSEnrico Granata else if (end && *end == '-') 10379fc1944eSEnrico Granata { 10389fc1944eSEnrico Granata // this is most probably a BitField, let's take a look 1039*d70a6e71SEugene Zelenko char *real_end = nullptr; 10409fc1944eSEnrico Granata long final_index = ::strtol (end+1, &real_end, 0); 1041d64d0bc0SEnrico Granata bool expand_bitfield = true; 10429fc1944eSEnrico Granata if (real_end && *real_end == ']') 10439fc1944eSEnrico Granata { 10449fc1944eSEnrico Granata // if the format given is [high-low], swap range 10459fc1944eSEnrico Granata if (child_index > final_index) 10469fc1944eSEnrico Granata { 10479fc1944eSEnrico Granata long temp = child_index; 10489fc1944eSEnrico Granata child_index = final_index; 10499fc1944eSEnrico Granata final_index = temp; 10509fc1944eSEnrico Granata } 10519fc1944eSEnrico Granata 105299558cc4SGreg Clayton if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) 10539fc1944eSEnrico Granata { 10549fc1944eSEnrico Granata // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr 10559fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 10569fc1944eSEnrico Granata // would be done by saying ptr[low-high], without a deref * sign 10579fc1944eSEnrico Granata Error error; 10589fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->Dereference(error)); 10599fc1944eSEnrico Granata if (error.Fail()) 10609fc1944eSEnrico Granata { 10619fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10629fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", 10639fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 10649fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 10659fc1944eSEnrico Granata return ValueObjectSP(); 10669fc1944eSEnrico Granata } 10679fc1944eSEnrico Granata valobj_sp = temp; 10689fc1944eSEnrico Granata deref = false; 10699fc1944eSEnrico Granata } 107099558cc4SGreg Clayton else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) 10719fc1944eSEnrico Granata { 10729fc1944eSEnrico Granata // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] 10739fc1944eSEnrico Granata // (an operation that is equivalent to deref-ing arr) 10749fc1944eSEnrico Granata // and extract bits low thru high out of it. reading array items low thru high 10759fc1944eSEnrico Granata // would be done by saying arr[low-high], without a deref * sign 10769fc1944eSEnrico Granata Error error; 10779fc1944eSEnrico Granata ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); 10789fc1944eSEnrico Granata if (error.Fail()) 10799fc1944eSEnrico Granata { 10809fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 10819fc1944eSEnrico Granata error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", 10829fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 10839fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 10849fc1944eSEnrico Granata return ValueObjectSP(); 10859fc1944eSEnrico Granata } 10869fc1944eSEnrico Granata valobj_sp = temp; 10879fc1944eSEnrico Granata deref = false; 10889fc1944eSEnrico Granata } 1089d64d0bc0SEnrico Granata /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType()) 1090d64d0bc0SEnrico Granata { 1091d64d0bc0SEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true); 1092d64d0bc0SEnrico Granata expand_bitfield = false; 1093d64d0bc0SEnrico Granata if (!child_valobj_sp) 1094d64d0bc0SEnrico Granata { 1095d64d0bc0SEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 1096d64d0bc0SEnrico Granata error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"", 1097d64d0bc0SEnrico Granata child_index, final_index, 1098d64d0bc0SEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 1099d64d0bc0SEnrico Granata var_expr_path_strm.GetString().c_str()); 1100d64d0bc0SEnrico Granata } 1101d64d0bc0SEnrico Granata }*/ 11029fc1944eSEnrico Granata 1103d64d0bc0SEnrico Granata if (expand_bitfield) 1104d64d0bc0SEnrico Granata { 11059fc1944eSEnrico Granata child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); 11069fc1944eSEnrico Granata if (!child_valobj_sp) 11079fc1944eSEnrico Granata { 11089fc1944eSEnrico Granata valobj_sp->GetExpressionPath (var_expr_path_strm, false); 11097e589a60SJason Molenda error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", 11109fc1944eSEnrico Granata child_index, final_index, 11119fc1944eSEnrico Granata valobj_sp->GetTypeName().AsCString("<invalid type>"), 11129fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str()); 11139fc1944eSEnrico Granata } 11149fc1944eSEnrico Granata } 1115d64d0bc0SEnrico Granata } 11169fc1944eSEnrico Granata 11179fc1944eSEnrico Granata if (!child_valobj_sp) 11189fc1944eSEnrico Granata { 11199fc1944eSEnrico Granata // Invalid bitfield range... 11209fc1944eSEnrico Granata return ValueObjectSP(); 11219fc1944eSEnrico Granata } 11229fc1944eSEnrico Granata 11239fc1944eSEnrico Granata // Erase the bitfield member specification '[%i-%i]' where 11249fc1944eSEnrico Granata // %i is the index 11259fc1944eSEnrico Granata var_path.erase(0, (real_end - var_path.c_str()) + 1); 11269fc1944eSEnrico Granata separator_idx = var_path.find_first_of(".-["); 11274d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues) 11289fc1944eSEnrico Granata { 11299fc1944eSEnrico Granata ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); 11309fc1944eSEnrico Granata if (dynamic_value_sp) 11319fc1944eSEnrico Granata child_valobj_sp = dynamic_value_sp; 11329fc1944eSEnrico Granata } 11339fc1944eSEnrico Granata // Break out early from the switch since we were 11349fc1944eSEnrico Granata // able to find the child member 11359fc1944eSEnrico Granata break; 11369fc1944eSEnrico Granata 11379fc1944eSEnrico Granata } 11389fc1944eSEnrico Granata } 11399fc1944eSEnrico Granata else 11409fc1944eSEnrico Granata { 11419fc1944eSEnrico Granata error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", 11429fc1944eSEnrico Granata var_expr_path_strm.GetString().c_str(), 11439fc1944eSEnrico Granata var_path.c_str()); 11448b2fe6dcSGreg Clayton } 11458b2fe6dcSGreg Clayton return ValueObjectSP(); 11468b2fe6dcSGreg Clayton 11478b2fe6dcSGreg Clayton default: 11488b2fe6dcSGreg Clayton // Failure... 114954979cddSGreg Clayton { 11506beaaa68SGreg Clayton valobj_sp->GetExpressionPath (var_expr_path_strm, false); 115154979cddSGreg Clayton error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", 115254979cddSGreg Clayton separator_type, 115354979cddSGreg Clayton var_expr_path_strm.GetString().c_str(), 115454979cddSGreg Clayton var_path.c_str()); 115554979cddSGreg Clayton 11568b2fe6dcSGreg Clayton return ValueObjectSP(); 11578b2fe6dcSGreg Clayton } 115854979cddSGreg Clayton } 11598b2fe6dcSGreg Clayton 11608b2fe6dcSGreg Clayton if (child_valobj_sp) 11618b2fe6dcSGreg Clayton valobj_sp = child_valobj_sp; 11628b2fe6dcSGreg Clayton 11638b2fe6dcSGreg Clayton if (var_path.empty()) 11648b2fe6dcSGreg Clayton break; 11658b2fe6dcSGreg Clayton } 11668b2fe6dcSGreg Clayton if (valobj_sp) 11678b2fe6dcSGreg Clayton { 11688b2fe6dcSGreg Clayton if (deref) 11698b2fe6dcSGreg Clayton { 1170af67cecdSGreg Clayton ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); 11718b2fe6dcSGreg Clayton valobj_sp = deref_valobj_sp; 11728b2fe6dcSGreg Clayton } 11738b2fe6dcSGreg Clayton else if (address_of) 11748b2fe6dcSGreg Clayton { 117554979cddSGreg Clayton ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); 11768b2fe6dcSGreg Clayton valobj_sp = address_of_valobj_sp; 11778b2fe6dcSGreg Clayton } 11788b2fe6dcSGreg Clayton } 11798b2fe6dcSGreg Clayton return valobj_sp; 11808b2fe6dcSGreg Clayton } 118154979cddSGreg Clayton else 118254979cddSGreg Clayton { 11832837b766SJim Ingham error.SetErrorStringWithFormat("no variable named '%s' found in this frame", 11842837b766SJim Ingham name_const_string.GetCString()); 118554979cddSGreg Clayton } 118654979cddSGreg Clayton } 118754979cddSGreg Clayton } 118854979cddSGreg Clayton else 118954979cddSGreg Clayton { 119054979cddSGreg Clayton error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); 11918b2fe6dcSGreg Clayton } 11928b2fe6dcSGreg Clayton return ValueObjectSP(); 11938b2fe6dcSGreg Clayton } 119430fdc8d8SChris Lattner 119530fdc8d8SChris Lattner bool 119630fdc8d8SChris Lattner StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) 119730fdc8d8SChris Lattner { 11986a354705SJason Molenda Mutex::Locker locker(m_mutex); 1199*d70a6e71SEugene Zelenko if (!m_cfa_is_valid) 120099618476SJason Molenda { 120199618476SJason Molenda m_frame_base_error.SetErrorString("No frame base available for this historical stack frame."); 120299618476SJason Molenda return false; 120399618476SJason Molenda } 120499618476SJason Molenda 120530fdc8d8SChris Lattner if (m_flags.IsClear(GOT_FRAME_BASE)) 120630fdc8d8SChris Lattner { 120730fdc8d8SChris Lattner if (m_sc.function) 120830fdc8d8SChris Lattner { 120930fdc8d8SChris Lattner m_frame_base.Clear(); 121030fdc8d8SChris Lattner m_frame_base_error.Clear(); 121130fdc8d8SChris Lattner 121230fdc8d8SChris Lattner m_flags.Set(GOT_FRAME_BASE); 1213d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 121430fdc8d8SChris Lattner Value expr_value; 1215016a95ebSGreg Clayton addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; 1216016a95ebSGreg Clayton if (m_sc.function->GetFrameBaseExpression().IsLocationList()) 1217d9e416c0SGreg Clayton loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr()); 1218016a95ebSGreg Clayton 1219*d70a6e71SEugene Zelenko if (!m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, nullptr, nullptr, nullptr, loclist_base_addr, 1220*d70a6e71SEugene Zelenko nullptr, expr_value, &m_frame_base_error)) 122130fdc8d8SChris Lattner { 122230fdc8d8SChris Lattner // We should really have an error if evaluate returns, but in case 122330fdc8d8SChris Lattner // we don't, lets set the error to something at least. 122430fdc8d8SChris Lattner if (m_frame_base_error.Success()) 122530fdc8d8SChris Lattner m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); 122630fdc8d8SChris Lattner } 122730fdc8d8SChris Lattner else 122830fdc8d8SChris Lattner { 122957ee3067SGreg Clayton m_frame_base = expr_value.ResolveValue(&exe_ctx); 123030fdc8d8SChris Lattner } 123130fdc8d8SChris Lattner } 123230fdc8d8SChris Lattner else 123330fdc8d8SChris Lattner { 123430fdc8d8SChris Lattner m_frame_base_error.SetErrorString ("No function in symbol context."); 123530fdc8d8SChris Lattner } 123630fdc8d8SChris Lattner } 123730fdc8d8SChris Lattner 123830fdc8d8SChris Lattner if (m_frame_base_error.Success()) 123930fdc8d8SChris Lattner frame_base = m_frame_base; 124030fdc8d8SChris Lattner 124130fdc8d8SChris Lattner if (error_ptr) 124230fdc8d8SChris Lattner *error_ptr = m_frame_base_error; 124330fdc8d8SChris Lattner return m_frame_base_error.Success(); 124430fdc8d8SChris Lattner } 124530fdc8d8SChris Lattner 12465ccbd294SGreg Clayton RegisterContextSP 124730fdc8d8SChris Lattner StackFrame::GetRegisterContext () 124830fdc8d8SChris Lattner { 12496a354705SJason Molenda Mutex::Locker locker(m_mutex); 12505ccbd294SGreg Clayton if (!m_reg_context_sp) 1251d9e416c0SGreg Clayton { 1252d9e416c0SGreg Clayton ThreadSP thread_sp (GetThread()); 1253d9e416c0SGreg Clayton if (thread_sp) 1254d9e416c0SGreg Clayton m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this); 1255d9e416c0SGreg Clayton } 12565ccbd294SGreg Clayton return m_reg_context_sp; 125730fdc8d8SChris Lattner } 125830fdc8d8SChris Lattner 125930fdc8d8SChris Lattner bool 126030fdc8d8SChris Lattner StackFrame::HasDebugInformation () 126130fdc8d8SChris Lattner { 126230fdc8d8SChris Lattner GetSymbolContext (eSymbolContextLineEntry); 126330fdc8d8SChris Lattner return m_sc.line_entry.IsValid(); 126430fdc8d8SChris Lattner } 126530fdc8d8SChris Lattner 1266288bdf9cSGreg Clayton ValueObjectSP 12674d122c40SGreg Clayton StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 126830fdc8d8SChris Lattner { 12696a354705SJason Molenda Mutex::Locker locker(m_mutex); 1270288bdf9cSGreg Clayton ValueObjectSP valobj_sp; 127199618476SJason Molenda if (m_is_history_frame) 127299618476SJason Molenda { 127399618476SJason Molenda return valobj_sp; 127499618476SJason Molenda } 1275288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1276288bdf9cSGreg Clayton if (var_list) 1277288bdf9cSGreg Clayton { 1278288bdf9cSGreg Clayton // Make sure the variable is a frame variable 1279288bdf9cSGreg Clayton const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); 1280288bdf9cSGreg Clayton const uint32_t num_variables = var_list->GetSize(); 1281288bdf9cSGreg Clayton if (var_idx < num_variables) 1282288bdf9cSGreg Clayton { 1283288bdf9cSGreg Clayton valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); 1284*d70a6e71SEugene Zelenko if (!valobj_sp) 1285288bdf9cSGreg Clayton { 1286288bdf9cSGreg Clayton if (m_variable_list_value_objects.GetSize() < num_variables) 1287288bdf9cSGreg Clayton m_variable_list_value_objects.Resize(num_variables); 128858b59f95SJim Ingham valobj_sp = ValueObjectVariable::Create (this, variable_sp); 1289288bdf9cSGreg Clayton m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); 1290288bdf9cSGreg Clayton } 1291288bdf9cSGreg Clayton } 1292288bdf9cSGreg Clayton } 12934d122c40SGreg Clayton if (use_dynamic != eNoDynamicValues && valobj_sp) 129478a685aaSJim Ingham { 12952837b766SJim Ingham ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); 129678a685aaSJim Ingham if (dynamic_sp) 129778a685aaSJim Ingham return dynamic_sp; 129878a685aaSJim Ingham } 1299288bdf9cSGreg Clayton return valobj_sp; 1300288bdf9cSGreg Clayton } 1301288bdf9cSGreg Clayton 1302288bdf9cSGreg Clayton ValueObjectSP 13034d122c40SGreg Clayton StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) 1304288bdf9cSGreg Clayton { 13056a354705SJason Molenda Mutex::Locker locker(m_mutex); 130699618476SJason Molenda if (m_is_history_frame) 130799618476SJason Molenda return ValueObjectSP(); 130899618476SJason Molenda 1309288bdf9cSGreg Clayton // Check to make sure we aren't already tracking this variable? 131078a685aaSJim Ingham ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); 1311288bdf9cSGreg Clayton if (!valobj_sp) 1312288bdf9cSGreg Clayton { 1313288bdf9cSGreg Clayton // We aren't already tracking this global 1314288bdf9cSGreg Clayton VariableList *var_list = GetVariableList (true); 1315288bdf9cSGreg Clayton // If this frame has no variables, create a new list 1316*d70a6e71SEugene Zelenko if (var_list == nullptr) 1317288bdf9cSGreg Clayton m_variable_list_sp.reset (new VariableList()); 1318288bdf9cSGreg Clayton 1319288bdf9cSGreg Clayton // Add the global/static variable to this frame 1320288bdf9cSGreg Clayton m_variable_list_sp->AddVariable (variable_sp); 1321288bdf9cSGreg Clayton 1322288bdf9cSGreg Clayton // Now make a value object for it so we can track its changes 132378a685aaSJim Ingham valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); 1324288bdf9cSGreg Clayton } 1325288bdf9cSGreg Clayton return valobj_sp; 132630fdc8d8SChris Lattner } 132730fdc8d8SChris Lattner 13286b8379c4SJim Ingham bool 13296b8379c4SJim Ingham StackFrame::IsInlined () 13306b8379c4SJim Ingham { 1331*d70a6e71SEugene Zelenko if (m_sc.block == nullptr) 133259e8fc1cSGreg Clayton GetSymbolContext (eSymbolContextBlock); 133359e8fc1cSGreg Clayton if (m_sc.block) 1334*d70a6e71SEugene Zelenko return m_sc.block->GetContainingInlinedBlock() != nullptr; 133559e8fc1cSGreg Clayton return false; 13366b8379c4SJim Ingham } 13376b8379c4SJim Ingham 1338009d110dSDawn Perchik lldb::LanguageType 1339009d110dSDawn Perchik StackFrame::GetLanguage () 1340009d110dSDawn Perchik { 1341009d110dSDawn Perchik CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; 1342009d110dSDawn Perchik if (cu) 1343009d110dSDawn Perchik return cu->GetLanguage(); 1344009d110dSDawn Perchik return lldb::eLanguageTypeUnknown; 1345009d110dSDawn Perchik } 1346009d110dSDawn Perchik 1347d9e416c0SGreg Clayton TargetSP 134830fdc8d8SChris Lattner StackFrame::CalculateTarget () 134930fdc8d8SChris Lattner { 1350d9e416c0SGreg Clayton TargetSP target_sp; 1351d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1352d9e416c0SGreg Clayton if (thread_sp) 1353d9e416c0SGreg Clayton { 1354d9e416c0SGreg Clayton ProcessSP process_sp (thread_sp->CalculateProcess()); 1355d9e416c0SGreg Clayton if (process_sp) 1356d9e416c0SGreg Clayton target_sp = process_sp->CalculateTarget(); 1357d9e416c0SGreg Clayton } 1358d9e416c0SGreg Clayton return target_sp; 135930fdc8d8SChris Lattner } 136030fdc8d8SChris Lattner 1361d9e416c0SGreg Clayton ProcessSP 136230fdc8d8SChris Lattner StackFrame::CalculateProcess () 136330fdc8d8SChris Lattner { 1364d9e416c0SGreg Clayton ProcessSP process_sp; 1365d9e416c0SGreg Clayton ThreadSP thread_sp(GetThread()); 1366d9e416c0SGreg Clayton if (thread_sp) 1367d9e416c0SGreg Clayton process_sp = thread_sp->CalculateProcess(); 1368d9e416c0SGreg Clayton return process_sp; 136930fdc8d8SChris Lattner } 137030fdc8d8SChris Lattner 1371d9e416c0SGreg Clayton ThreadSP 137230fdc8d8SChris Lattner StackFrame::CalculateThread () 137330fdc8d8SChris Lattner { 1374d9e416c0SGreg Clayton return GetThread(); 137530fdc8d8SChris Lattner } 137630fdc8d8SChris Lattner 1377b57e4a1bSJason Molenda StackFrameSP 1378b57e4a1bSJason Molenda StackFrame::CalculateStackFrame () 137930fdc8d8SChris Lattner { 1380d9e416c0SGreg Clayton return shared_from_this(); 138130fdc8d8SChris Lattner } 138230fdc8d8SChris Lattner 138330fdc8d8SChris Lattner void 13840603aa9dSGreg Clayton StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) 138530fdc8d8SChris Lattner { 1386d9e416c0SGreg Clayton exe_ctx.SetContext (shared_from_this()); 138730fdc8d8SChris Lattner } 138830fdc8d8SChris Lattner 138930fdc8d8SChris Lattner void 13908ec10efcSJim Ingham StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker) 13910603aa9dSGreg Clayton { 1392*d70a6e71SEugene Zelenko if (strm == nullptr) 13930603aa9dSGreg Clayton return; 13940603aa9dSGreg Clayton 13950603aa9dSGreg Clayton GetSymbolContext(eSymbolContextEverything); 1396d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 13970603aa9dSGreg Clayton StreamString s; 13988ec10efcSJim Ingham 13998ec10efcSJim Ingham if (frame_marker) 14008ec10efcSJim Ingham s.PutCString(frame_marker); 14018ec10efcSJim Ingham 1402*d70a6e71SEugene Zelenko const FormatEntity::Entry *frame_format = nullptr; 1403d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1404d9e416c0SGreg Clayton if (target) 1405d9e416c0SGreg Clayton frame_format = target->GetDebugger().GetFrameFormat(); 1406*d70a6e71SEugene Zelenko if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, nullptr, nullptr, false, false)) 14070603aa9dSGreg Clayton { 14080603aa9dSGreg Clayton strm->Write(s.GetData(), s.GetSize()); 14090603aa9dSGreg Clayton } 14100603aa9dSGreg Clayton else 14110603aa9dSGreg Clayton { 14120603aa9dSGreg Clayton Dump (strm, true, false); 14130603aa9dSGreg Clayton strm->EOL(); 14140603aa9dSGreg Clayton } 14150603aa9dSGreg Clayton } 14160603aa9dSGreg Clayton 14170603aa9dSGreg Clayton void 14186dadd508SGreg Clayton StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) 141930fdc8d8SChris Lattner { 1420*d70a6e71SEugene Zelenko if (strm == nullptr) 142130fdc8d8SChris Lattner return; 142230fdc8d8SChris Lattner 142330fdc8d8SChris Lattner if (show_frame_index) 14241b72fcb7SGreg Clayton strm->Printf("frame #%u: ", m_frame_index); 1425d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 1426d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 1427d01b2953SDaniel Malea strm->Printf("0x%0*" PRIx64 " ", 1428d9e416c0SGreg Clayton target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16, 1429d9e416c0SGreg Clayton GetFrameCodeAddress().GetLoadAddress(target)); 14309da7bd07SGreg Clayton GetSymbolContext(eSymbolContextEverything); 14311b72fcb7SGreg Clayton const bool show_module = true; 14321b72fcb7SGreg Clayton const bool show_inline = true; 1433aff1b357SJason Molenda const bool show_function_arguments = true; 1434c980fa92SJason Molenda const bool show_function_name = true; 1435d9e416c0SGreg Clayton m_sc.DumpStopContext (strm, 1436d9e416c0SGreg Clayton exe_ctx.GetBestExecutionContextScope(), 1437d9e416c0SGreg Clayton GetFrameCodeAddress(), 1438d9e416c0SGreg Clayton show_fullpaths, 1439d9e416c0SGreg Clayton show_module, 1440aff1b357SJason Molenda show_inline, 1441c980fa92SJason Molenda show_function_arguments, 1442c980fa92SJason Molenda show_function_name); 144330fdc8d8SChris Lattner } 144430fdc8d8SChris Lattner 14455082c5fdSGreg Clayton void 1446b57e4a1bSJason Molenda StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) 14475082c5fdSGreg Clayton { 14486a354705SJason Molenda Mutex::Locker locker(m_mutex); 144959e8fc1cSGreg Clayton assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing 1450b57e4a1bSJason Molenda m_variable_list_sp = prev_frame.m_variable_list_sp; 1451b57e4a1bSJason Molenda m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); 145268275d5eSGreg Clayton if (!m_disassembly.GetString().empty()) 145368275d5eSGreg Clayton m_disassembly.GetString().swap (m_disassembly.GetString()); 14545082c5fdSGreg Clayton } 145568275d5eSGreg Clayton 145659e8fc1cSGreg Clayton void 1457b57e4a1bSJason Molenda StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) 145859e8fc1cSGreg Clayton { 14596a354705SJason Molenda Mutex::Locker locker(m_mutex); 146059e8fc1cSGreg Clayton assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing 1461b57e4a1bSJason Molenda m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value 1462b57e4a1bSJason Molenda assert (GetThread() == curr_frame.GetThread()); 1463b57e4a1bSJason Molenda m_frame_index = curr_frame.m_frame_index; 1464b57e4a1bSJason Molenda m_concrete_frame_index = curr_frame.m_concrete_frame_index; 1465b57e4a1bSJason Molenda m_reg_context_sp = curr_frame.m_reg_context_sp; 1466b57e4a1bSJason Molenda m_frame_code_addr = curr_frame.m_frame_code_addr; 1467*d70a6e71SEugene Zelenko assert (!m_sc.target_sp || !curr_frame.m_sc.target_sp || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get()); 1468*d70a6e71SEugene Zelenko assert (!m_sc.module_sp || !curr_frame.m_sc.module_sp || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get()); 1469*d70a6e71SEugene Zelenko assert (m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr || m_sc.comp_unit == curr_frame.m_sc.comp_unit); 1470*d70a6e71SEugene Zelenko assert (m_sc.function == nullptr || curr_frame.m_sc.function == nullptr || m_sc.function == curr_frame.m_sc.function); 1471b57e4a1bSJason Molenda m_sc = curr_frame.m_sc; 147259e8fc1cSGreg Clayton m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); 147359e8fc1cSGreg Clayton m_flags.Set (m_sc.GetResolvedMask()); 147459e8fc1cSGreg Clayton m_frame_base.Clear(); 147559e8fc1cSGreg Clayton m_frame_base_error.Clear(); 147659e8fc1cSGreg Clayton } 1477e4284b71SJim Ingham 14787260f620SGreg Clayton bool 1479b57e4a1bSJason Molenda StackFrame::HasCachedData () const 1480b57e4a1bSJason Molenda { 1481*d70a6e71SEugene Zelenko if (m_variable_list_sp) 1482b57e4a1bSJason Molenda return true; 1483b57e4a1bSJason Molenda if (m_variable_list_value_objects.GetSize() > 0) 1484b57e4a1bSJason Molenda return true; 1485b57e4a1bSJason Molenda if (!m_disassembly.GetString().empty()) 1486b57e4a1bSJason Molenda return true; 1487b57e4a1bSJason Molenda return false; 1488b57e4a1bSJason Molenda } 1489b57e4a1bSJason Molenda 1490b57e4a1bSJason Molenda bool 14917260f620SGreg Clayton StackFrame::GetStatus (Stream& strm, 14927260f620SGreg Clayton bool show_frame_info, 14938ec10efcSJim Ingham bool show_source, 14948ec10efcSJim Ingham const char *frame_marker) 14957260f620SGreg Clayton { 149653eb7ad2SGreg Clayton 14977260f620SGreg Clayton if (show_frame_info) 14987260f620SGreg Clayton { 14997260f620SGreg Clayton strm.Indent(); 15008ec10efcSJim Ingham DumpUsingSettingsFormat (&strm, frame_marker); 15017260f620SGreg Clayton } 15027260f620SGreg Clayton 15037260f620SGreg Clayton if (show_source) 15047260f620SGreg Clayton { 1505d9e416c0SGreg Clayton ExecutionContext exe_ctx (shared_from_this()); 15068be74995SMohit K. Bhakkad bool have_source = false, have_debuginfo = false; 150767cc0636SGreg Clayton Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever; 1508d9e416c0SGreg Clayton Target *target = exe_ctx.GetTargetPtr(); 150953eb7ad2SGreg Clayton if (target) 151053eb7ad2SGreg Clayton { 151153eb7ad2SGreg Clayton Debugger &debugger = target->GetDebugger(); 151253eb7ad2SGreg Clayton const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true); 151353eb7ad2SGreg Clayton const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false); 151453eb7ad2SGreg Clayton disasm_display = debugger.GetStopDisassemblyDisplay (); 151553eb7ad2SGreg Clayton 15167260f620SGreg Clayton GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); 15177260f620SGreg Clayton if (m_sc.comp_unit && m_sc.line_entry.IsValid()) 15187260f620SGreg Clayton { 15198be74995SMohit K. Bhakkad have_debuginfo = true; 15206d1fbc9cSTodd Fiala if (source_lines_before > 0 || source_lines_after > 0) 15216d1fbc9cSTodd Fiala { 15228be74995SMohit K. Bhakkad size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, 15237260f620SGreg Clayton m_sc.line_entry.line, 1524d9e416c0SGreg Clayton source_lines_before, 1525d9e416c0SGreg Clayton source_lines_after, 15267260f620SGreg Clayton "->", 15277cd81c55SJason Molenda &strm); 15288be74995SMohit K. Bhakkad if (num_lines != 0) 15298be74995SMohit K. Bhakkad have_source = true; 15308be74995SMohit K. Bhakkad // TODO: Give here a one time warning if source file is missing. 1531e372b98dSGreg Clayton } 1532e372b98dSGreg Clayton } 1533e372b98dSGreg Clayton switch (disasm_display) 1534e372b98dSGreg Clayton { 153567cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNever: 1536e372b98dSGreg Clayton break; 1537e372b98dSGreg Clayton 15388be74995SMohit K. Bhakkad case Debugger::eStopDisassemblyTypeNoDebugInfo: 15398be74995SMohit K. Bhakkad if (have_debuginfo) 15408be74995SMohit K. Bhakkad break; 154162e0681aSJason Molenda LLVM_FALLTHROUGH; 15428be74995SMohit K. Bhakkad 154367cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeNoSource: 1544e372b98dSGreg Clayton if (have_source) 1545e372b98dSGreg Clayton break; 154662e0681aSJason Molenda LLVM_FALLTHROUGH; 15478be74995SMohit K. Bhakkad 154867cc0636SGreg Clayton case Debugger::eStopDisassemblyTypeAlways: 1549d9e416c0SGreg Clayton if (target) 1550e372b98dSGreg Clayton { 155153eb7ad2SGreg Clayton const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); 1552e372b98dSGreg Clayton if (disasm_lines > 0) 1553e372b98dSGreg Clayton { 1554d9e416c0SGreg Clayton const ArchSpec &target_arch = target->GetArchitecture(); 1555e372b98dSGreg Clayton AddressRange pc_range; 1556e372b98dSGreg Clayton pc_range.GetBaseAddress() = GetFrameCodeAddress(); 1557e372b98dSGreg Clayton pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize()); 1558*d70a6e71SEugene Zelenko const char *plugin_name = nullptr; 1559*d70a6e71SEugene Zelenko const char *flavor = nullptr; 1560d9e416c0SGreg Clayton Disassembler::Disassemble (target->GetDebugger(), 1561e372b98dSGreg Clayton target_arch, 15620f063ba6SJim Ingham plugin_name, 15630f063ba6SJim Ingham flavor, 1564e372b98dSGreg Clayton exe_ctx, 1565e372b98dSGreg Clayton pc_range, 1566e372b98dSGreg Clayton disasm_lines, 1567e372b98dSGreg Clayton 0, 1568e372b98dSGreg Clayton Disassembler::eOptionMarkPCAddress, 1569e372b98dSGreg Clayton strm); 1570e372b98dSGreg Clayton } 1571e372b98dSGreg Clayton } 1572e372b98dSGreg Clayton break; 15737260f620SGreg Clayton } 15747260f620SGreg Clayton } 157553eb7ad2SGreg Clayton } 15767260f620SGreg Clayton return true; 15777260f620SGreg Clayton } 1578