LLDB mainline
ExpressionVariable.cpp
Go to the documentation of this file.
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
11#include "lldb/Target/Target.h"
13#include "lldb/Utility/Log.h"
14#include <optional>
15
16using namespace lldb_private;
17
19
21
24 std::optional<uint64_t> byte_size =
25 llvm::expectedToOptional(valobj_sp->GetByteSize());
26 if (byte_size && *byte_size) {
27 if (valobj_sp->GetDataExtractor().GetByteSize() < *byte_size) {
28 valobj_sp->GetValue().ResizeData(*byte_size);
29 valobj_sp->GetValue().GetData(valobj_sp->GetDataExtractor());
30 }
31 return const_cast<uint8_t *>(valobj_sp->GetDataExtractor().GetDataStart());
32 }
33 return nullptr;
34}
35
37
39
41 if (!m_live_sp)
42 return;
43
44 if (!m_frozen_sp)
45 return;
46
47 if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS)) {
48 lldb::addr_t live_addr = m_live_sp->GetLiveAddress();
49 m_frozen_sp->SetLiveAddress(live_addr);
50 // One more detail, if there's an offset_to_top in the frozen_sp, then we
51 // need to appy that offset by hand. The live_sp can't compute this
52 // itself as its type is the type of the contained object which confuses
53 // the dynamic type calculation. So we have to update the contents of the
54 // m_live_sp with the dynamic value.
55 // Note: We could get this right when we originally write the address, but
56 // that happens in different ways for the various flavors of
57 // Entity*::Materialize, but everything comes through here, and it's just
58 // one extra memory write.
59
60 // You can only have an "offset_to_top" with pointers or references:
61 if (!m_frozen_sp->GetCompilerType().IsPointerOrReferenceType())
62 return;
63
64 lldb::ProcessSP process_sp = m_frozen_sp->GetProcessSP();
65 // If there's no dynamic value, then there can't be an offset_to_top:
66 if (!process_sp ||
67 !process_sp->IsPossibleDynamicValue(*(m_frozen_sp.get())))
68 return;
69
70 lldb::ValueObjectSP dyn_sp = m_frozen_sp->GetDynamicValue(m_dyn_option);
71 if (!dyn_sp)
72 return;
73 ValueObject::AddrAndType static_addr = m_frozen_sp->GetPointerValue();
74 if (static_addr.type != eAddressTypeLoad)
75 return;
76
77 ValueObject::AddrAndType dynamic_addr = dyn_sp->GetPointerValue();
78 if (dynamic_addr.type != eAddressTypeLoad ||
79 static_addr.address == dynamic_addr.address)
80 return;
81
84 lldb::addr_t cur_value =
85 process_sp->ReadPointerFromMemory(live_addr, error);
86 if (error.Fail())
87 return;
88
89 if (cur_value != static_addr.address) {
90 LLDB_LOG(log,
91 "Stored value: {0} read from {1} doesn't "
92 "match static addr: {2}",
93 cur_value, live_addr, static_addr.address);
94 return;
95 }
96
97 if (!process_sp->WritePointerToMemory(live_addr, dynamic_addr.address,
98 error)) {
99 LLDB_LOG(log, "Got error: {0} writing dynamic value: {1} to {2}", error,
100 dynamic_addr.address, live_addr);
101 return;
102 }
103 }
104}
105
107
109 SymbolMap::iterator si = m_symbol_map.find(name.GetCString());
110
111 if (si != m_symbol_map.end())
112 return si->second;
113 else
115}
116
118 lldb::IRExecutionUnitSP &execution_unit_sp) {
120
121 m_execution_units.insert(execution_unit_sp);
122
123 LLDB_LOGF(log, "Registering JITted Functions:\n");
124
125 for (const IRExecutionUnit::JittedFunction &jitted_function :
126 execution_unit_sp->GetJittedFunctions()) {
127 if (jitted_function.m_external &&
128 jitted_function.m_name != execution_unit_sp->GetFunctionName() &&
129 jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) {
130 m_symbol_map[jitted_function.m_name.GetCString()] =
131 jitted_function.m_remote_addr;
132 LLDB_LOGF(log, " Function: %s at 0x%" PRIx64 ".",
133 jitted_function.m_name.GetCString(),
134 jitted_function.m_remote_addr);
135 }
136 }
137
138 LLDB_LOGF(log, "Registering JIIted Symbols:\n");
139
140 for (const IRExecutionUnit::JittedGlobalVariable &global_var :
141 execution_unit_sp->GetJittedGlobalVariables()) {
142 if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS) {
143 // Demangle the name before inserting it, so that lookups by the ConstStr
144 // of the demangled name will find the mangled one (needed for looking up
145 // metadata pointers.)
146 Mangled mangler(global_var.m_name);
147 mangler.GetDemangledName();
148 m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr;
149 LLDB_LOGF(log, " Symbol: %s at 0x%" PRIx64 ".",
150 global_var.m_name.GetCString(), global_var.m_remote_addr);
151 }
152 }
153}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOGF(log,...)
Definition Log.h:376
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
lldb::ValueObjectSP m_live_sp
The ValueObject counterpart to m_frozen_sp that tracks the value in inferior memory.
void TransferAddress(bool force=false)
This function is used to copy the address-of m_live_sp into m_frozen_sp.
lldb::ValueObjectSP m_frozen_sp
These members should be private.
static char ID
LLVM RTTI support.
A class that handles mangled names.
Definition Mangled.h:34
ConstString GetDemangledName() const
Demangled name get accessor.
Definition Mangled.cpp:284
void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp)
ExecutionUnitSet m_execution_units
The execution units that contain valuable symbols.
SymbolMap m_symbol_map
The addresses of the symbols in m_execution_units.
virtual lldb::addr_t LookupSymbol(ConstString name)
An error handling class.
Definition Status.h:118
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
std::shared_ptr< lldb_private::IRExecutionUnit > IRExecutionUnitSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t addr_t
Definition lldb-types.h:80
"lldb/Expression/IRExecutionUnit.h" Encapsulates a single function that has been generated by the JIT...