1 //===-- ExpressionVariable.cpp ----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Expression/ExpressionVariable.h" 11 #include "lldb/Expression/IRExecutionUnit.h" 12 #include "lldb/Target/Target.h" 13 #include "lldb/Utility/Log.h" 14 15 using namespace lldb_private; 16 17 ExpressionVariable::~ExpressionVariable() {} 18 19 uint8_t *ExpressionVariable::GetValueBytes() { 20 const size_t byte_size = m_frozen_sp->GetByteSize(); 21 if (byte_size > 0) { 22 if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size) { 23 m_frozen_sp->GetValue().ResizeData(byte_size); 24 m_frozen_sp->GetValue().GetData(m_frozen_sp->GetDataExtractor()); 25 } 26 return const_cast<uint8_t *>( 27 m_frozen_sp->GetDataExtractor().GetDataStart()); 28 } 29 return NULL; 30 } 31 32 PersistentExpressionState::~PersistentExpressionState() {} 33 34 lldb::addr_t PersistentExpressionState::LookupSymbol(const ConstString &name) { 35 SymbolMap::iterator si = m_symbol_map.find(name.GetCString()); 36 37 if (si != m_symbol_map.end()) 38 return si->second; 39 else 40 return LLDB_INVALID_ADDRESS; 41 } 42 43 void PersistentExpressionState::RegisterExecutionUnit( 44 lldb::IRExecutionUnitSP &execution_unit_sp) { 45 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); 46 47 m_execution_units.insert(execution_unit_sp); 48 49 if (log) 50 log->Printf("Registering JITted Functions:\n"); 51 52 for (const IRExecutionUnit::JittedFunction &jitted_function : 53 execution_unit_sp->GetJittedFunctions()) { 54 if (jitted_function.m_external && 55 jitted_function.m_name != execution_unit_sp->GetFunctionName() && 56 jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) { 57 m_symbol_map[jitted_function.m_name.GetCString()] = 58 jitted_function.m_remote_addr; 59 if (log) 60 log->Printf(" Function: %s at 0x%" PRIx64 ".", 61 jitted_function.m_name.GetCString(), 62 jitted_function.m_remote_addr); 63 } 64 } 65 66 if (log) 67 log->Printf("Registering JIIted Symbols:\n"); 68 69 for (const IRExecutionUnit::JittedGlobalVariable &global_var : 70 execution_unit_sp->GetJittedGlobalVariables()) { 71 if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS) { 72 // Demangle the name before inserting it, so that lookups by the ConstStr 73 // of the demangled name will find the mangled one (needed for looking up 74 // metadata pointers.) 75 Mangled mangler(global_var.m_name); 76 mangler.GetDemangledName(lldb::eLanguageTypeUnknown); 77 m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr; 78 if (log) 79 log->Printf(" Symbol: %s at 0x%" PRIx64 ".", 80 global_var.m_name.GetCString(), global_var.m_remote_addr); 81 } 82 } 83 } 84 85 ConstString PersistentExpressionState::GetNextPersistentVariableName( 86 Target &target, llvm::StringRef Prefix) { 87 llvm::SmallString<64> name; 88 { 89 llvm::raw_svector_ostream os(name); 90 os << Prefix << target.GetNextPersistentVariableIndex(); 91 } 92 return ConstString(name); 93 } 94