1 //===-- ExpressionVariable.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Expression/ExpressionVariable.h"
11 #include "lldb/Expression/IRExecutionUnit.h"
12 #include "lldb/Target/Target.h"
13 #include "lldb/Utility/Log.h"
15 using namespace lldb_private;
17 ExpressionVariable::~ExpressionVariable() {}
19 uint8_t *ExpressionVariable::GetValueBytes() {
20 const size_t byte_size = m_frozen_sp->GetByteSize();
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());
26 return const_cast<uint8_t *>(
27 m_frozen_sp->GetDataExtractor().GetDataStart());
32 PersistentExpressionState::~PersistentExpressionState() {}
34 lldb::addr_t PersistentExpressionState::LookupSymbol(const ConstString &name) {
35 SymbolMap::iterator si = m_symbol_map.find(name.GetCString());
37 if (si != m_symbol_map.end())
40 return LLDB_INVALID_ADDRESS;
43 void PersistentExpressionState::RegisterExecutionUnit(
44 lldb::IRExecutionUnitSP &execution_unit_sp) {
45 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
47 m_execution_units.insert(execution_unit_sp);
50 log->Printf("Registering JITted Functions:\n");
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;
60 log->Printf(" Function: %s at 0x%" PRIx64 ".",
61 jitted_function.m_name.GetCString(),
62 jitted_function.m_remote_addr);
67 log->Printf("Registering JIIted Symbols:\n");
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;
79 log->Printf(" Symbol: %s at 0x%" PRIx64 ".",
80 global_var.m_name.GetCString(), global_var.m_remote_addr);
85 ConstString PersistentExpressionState::GetNextPersistentVariableName(
86 Target &target, llvm::StringRef Prefix) {
87 llvm::SmallString<64> name;
89 llvm::raw_svector_ostream os(name);
90 os << Prefix << target.GetNextPersistentVariableIndex();
92 return ConstString(name);