| 1 | //===-- ExpressionVariable.cpp --------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Expression/ExpressionVariable.h" |
| 10 | #include "lldb/Expression/IRExecutionUnit.h" |
| 11 | #include "lldb/Target/Target.h" |
| 12 | #include "lldb/Utility/LLDBLog.h" |
| 13 | #include "lldb/Utility/Log.h" |
| 14 | #include <optional> |
| 15 | |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | char ExpressionVariable::ID; |
| 19 | |
| 20 | ExpressionVariable::ExpressionVariable() : m_flags(0) {} |
| 21 | |
| 22 | uint8_t *ExpressionVariable::GetValueBytes() { |
| 23 | std::optional<uint64_t> byte_size = |
| 24 | llvm::expectedToOptional(E: m_frozen_sp->GetByteSize()); |
| 25 | if (byte_size && *byte_size) { |
| 26 | if (m_frozen_sp->GetDataExtractor().GetByteSize() < *byte_size) { |
| 27 | m_frozen_sp->GetValue().ResizeData(len: *byte_size); |
| 28 | m_frozen_sp->GetValue().GetData(data&: m_frozen_sp->GetDataExtractor()); |
| 29 | } |
| 30 | return const_cast<uint8_t *>( |
| 31 | m_frozen_sp->GetDataExtractor().GetDataStart()); |
| 32 | } |
| 33 | return nullptr; |
| 34 | } |
| 35 | |
| 36 | char PersistentExpressionState::ID; |
| 37 | |
| 38 | PersistentExpressionState::PersistentExpressionState() = default; |
| 39 | |
| 40 | PersistentExpressionState::~PersistentExpressionState() = default; |
| 41 | |
| 42 | lldb::addr_t PersistentExpressionState::LookupSymbol(ConstString name) { |
| 43 | SymbolMap::iterator si = m_symbol_map.find(Val: name.GetCString()); |
| 44 | |
| 45 | if (si != m_symbol_map.end()) |
| 46 | return si->second; |
| 47 | else |
| 48 | return LLDB_INVALID_ADDRESS; |
| 49 | } |
| 50 | |
| 51 | void PersistentExpressionState::RegisterExecutionUnit( |
| 52 | lldb::IRExecutionUnitSP &execution_unit_sp) { |
| 53 | Log *log = GetLog(mask: LLDBLog::Expressions); |
| 54 | |
| 55 | m_execution_units.insert(x: execution_unit_sp); |
| 56 | |
| 57 | LLDB_LOGF(log, "Registering JITted Functions:\n" ); |
| 58 | |
| 59 | for (const IRExecutionUnit::JittedFunction &jitted_function : |
| 60 | execution_unit_sp->GetJittedFunctions()) { |
| 61 | if (jitted_function.m_external && |
| 62 | jitted_function.m_name != execution_unit_sp->GetFunctionName() && |
| 63 | jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) { |
| 64 | m_symbol_map[jitted_function.m_name.GetCString()] = |
| 65 | jitted_function.m_remote_addr; |
| 66 | LLDB_LOGF(log, " Function: %s at 0x%" PRIx64 "." , |
| 67 | jitted_function.m_name.GetCString(), |
| 68 | jitted_function.m_remote_addr); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | LLDB_LOGF(log, "Registering JIIted Symbols:\n" ); |
| 73 | |
| 74 | for (const IRExecutionUnit::JittedGlobalVariable &global_var : |
| 75 | execution_unit_sp->GetJittedGlobalVariables()) { |
| 76 | if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS) { |
| 77 | // Demangle the name before inserting it, so that lookups by the ConstStr |
| 78 | // of the demangled name will find the mangled one (needed for looking up |
| 79 | // metadata pointers.) |
| 80 | Mangled mangler(global_var.m_name); |
| 81 | mangler.GetDemangledName(); |
| 82 | m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr; |
| 83 | LLDB_LOGF(log, " Symbol: %s at 0x%" PRIx64 "." , |
| 84 | global_var.m_name.GetCString(), global_var.m_remote_addr); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |