1 //===-- ExpressionVariable.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
16 using namespace lldb_private
;
18 char ExpressionVariable::ID
;
20 ExpressionVariable::ExpressionVariable() : m_flags(0) {}
22 uint8_t *ExpressionVariable::GetValueBytes() {
23 std::optional
<uint64_t> byte_size
= m_frozen_sp
->GetByteSize();
24 if (byte_size
&& *byte_size
) {
25 if (m_frozen_sp
->GetDataExtractor().GetByteSize() < *byte_size
) {
26 m_frozen_sp
->GetValue().ResizeData(*byte_size
);
27 m_frozen_sp
->GetValue().GetData(m_frozen_sp
->GetDataExtractor());
29 return const_cast<uint8_t *>(
30 m_frozen_sp
->GetDataExtractor().GetDataStart());
35 char PersistentExpressionState::ID
;
37 PersistentExpressionState::PersistentExpressionState() = default;
39 PersistentExpressionState::~PersistentExpressionState() = default;
41 lldb::addr_t
PersistentExpressionState::LookupSymbol(ConstString name
) {
42 SymbolMap::iterator si
= m_symbol_map
.find(name
.GetCString());
44 if (si
!= m_symbol_map
.end())
47 return LLDB_INVALID_ADDRESS
;
50 void PersistentExpressionState::RegisterExecutionUnit(
51 lldb::IRExecutionUnitSP
&execution_unit_sp
) {
52 Log
*log
= GetLog(LLDBLog::Expressions
);
54 m_execution_units
.insert(execution_unit_sp
);
56 LLDB_LOGF(log
, "Registering JITted Functions:\n");
58 for (const IRExecutionUnit::JittedFunction
&jitted_function
:
59 execution_unit_sp
->GetJittedFunctions()) {
60 if (jitted_function
.m_external
&&
61 jitted_function
.m_name
!= execution_unit_sp
->GetFunctionName() &&
62 jitted_function
.m_remote_addr
!= LLDB_INVALID_ADDRESS
) {
63 m_symbol_map
[jitted_function
.m_name
.GetCString()] =
64 jitted_function
.m_remote_addr
;
65 LLDB_LOGF(log
, " Function: %s at 0x%" PRIx64
".",
66 jitted_function
.m_name
.GetCString(),
67 jitted_function
.m_remote_addr
);
71 LLDB_LOGF(log
, "Registering JIIted Symbols:\n");
73 for (const IRExecutionUnit::JittedGlobalVariable
&global_var
:
74 execution_unit_sp
->GetJittedGlobalVariables()) {
75 if (global_var
.m_remote_addr
!= LLDB_INVALID_ADDRESS
) {
76 // Demangle the name before inserting it, so that lookups by the ConstStr
77 // of the demangled name will find the mangled one (needed for looking up
78 // metadata pointers.)
79 Mangled
mangler(global_var
.m_name
);
80 mangler
.GetDemangledName();
81 m_symbol_map
[global_var
.m_name
.GetCString()] = global_var
.m_remote_addr
;
82 LLDB_LOGF(log
, " Symbol: %s at 0x%" PRIx64
".",
83 global_var
.m_name
.GetCString(), global_var
.m_remote_addr
);