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
15#include "llvm/Support/Error.h"
16
17#include <optional>
18
19using namespace lldb_private;
20
22
24
27 std::optional<uint64_t> byte_size =
28 llvm::expectedToOptional(valobj_sp->GetByteSize());
29 if (byte_size && *byte_size) {
30 if (valobj_sp->GetDataExtractor().GetByteSize() < *byte_size) {
31 valobj_sp->GetValue().ResizeData(*byte_size);
32 valobj_sp->GetValue().GetData(valobj_sp->GetDataExtractor());
33 }
34 return const_cast<uint8_t *>(valobj_sp->GetDataExtractor().GetDataStart());
35 }
36 return nullptr;
37}
38
40
42
44 if (!m_live_sp)
45 return;
46
47 if (!m_frozen_sp)
48 return;
49
50 if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS)) {
51 lldb::addr_t live_addr = m_live_sp->GetLiveAddress();
52 m_frozen_sp->SetLiveAddress(live_addr);
53 // One more detail, if there's an offset_to_top in the frozen_sp, then we
54 // need to appy that offset by hand. The live_sp can't compute this
55 // itself as its type is the type of the contained object which confuses
56 // the dynamic type calculation. So we have to update the contents of the
57 // m_live_sp with the dynamic value.
58 // Note: We could get this right when we originally write the address, but
59 // that happens in different ways for the various flavors of
60 // Entity*::Materialize, but everything comes through here, and it's just
61 // one extra memory write.
62
63 // You can only have an "offset_to_top" with pointers or references:
64 if (!m_frozen_sp->GetCompilerType().IsPointerOrReferenceType())
65 return;
66
67 lldb::ProcessSP process_sp = m_frozen_sp->GetProcessSP();
68 // If there's no dynamic value, then there can't be an offset_to_top:
69 if (!process_sp ||
70 !process_sp->IsPossibleDynamicValue(*(m_frozen_sp.get())))
71 return;
72
73 lldb::ValueObjectSP dyn_sp = m_frozen_sp->GetDynamicValue(m_dyn_option);
74 if (!dyn_sp)
75 return;
76 ValueObject::AddrAndType static_addr = m_frozen_sp->GetPointerValue();
77 if (static_addr.type != eAddressTypeLoad)
78 return;
79
80 ValueObject::AddrAndType dynamic_addr = dyn_sp->GetPointerValue();
81 if (dynamic_addr.type != eAddressTypeLoad ||
82 static_addr.address == dynamic_addr.address)
83 return;
84
87 llvm::Expected<lldb::addr_t> cur_value =
88 process_sp->ReadPointerFromMemory(live_addr);
89 if (!cur_value) {
90 llvm::consumeError(cur_value.takeError());
91 return;
92 }
93
94 if (*cur_value != static_addr.address) {
95 LLDB_LOG(log,
96 "Stored value: {0} read from {1} doesn't "
97 "match static addr: {2}",
98 *cur_value, live_addr, static_addr.address);
99 return;
100 }
101
102 if (!process_sp->WritePointerToMemory(live_addr, dynamic_addr.address,
103 error)) {
104 LLDB_LOG(log, "Got error: {0} writing dynamic value: {1} to {2}", error,
105 dynamic_addr.address, live_addr);
106 return;
107 }
108 }
109}
110
112
114 SymbolMap::iterator si = m_symbol_map.find(name.GetCString());
115
116 if (si != m_symbol_map.end())
117 return si->second;
118 else
120}
121
123 lldb::IRExecutionUnitSP &execution_unit_sp) {
125
126 m_execution_units.insert(execution_unit_sp);
127
128 LLDB_LOGF(log, "Registering JITted Functions:\n");
129
130 for (const IRExecutionUnit::JittedFunction &jitted_function :
131 execution_unit_sp->GetJittedFunctions()) {
132 if (jitted_function.m_external &&
133 jitted_function.m_name != execution_unit_sp->GetFunctionName() &&
134 jitted_function.m_remote_addr != LLDB_INVALID_ADDRESS) {
135 m_symbol_map[jitted_function.m_name.GetCString()] =
136 jitted_function.m_remote_addr;
137 LLDB_LOGF(log, " Function: %s at 0x%" PRIx64 ".",
138 jitted_function.m_name.GetCString(),
139 jitted_function.m_remote_addr);
140 }
141 }
142
143 LLDB_LOGF(log, "Registering JIIted Symbols:\n");
144
145 for (const IRExecutionUnit::JittedGlobalVariable &global_var :
146 execution_unit_sp->GetJittedGlobalVariables()) {
147 if (global_var.m_remote_addr != LLDB_INVALID_ADDRESS) {
148 // Demangle the name before inserting it, so that lookups by the ConstStr
149 // of the demangled name will find the mangled one (needed for looking up
150 // metadata pointers.)
151 Mangled mangler(global_var.m_name);
152 mangler.GetDemangledName();
153 m_symbol_map[global_var.m_name.GetCString()] = global_var.m_remote_addr;
154 LLDB_LOGF(log, " Symbol: %s at 0x%" PRIx64 ".",
155 global_var.m_name.GetCString(), global_var.m_remote_addr);
156 }
157 }
158}
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:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
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:338
@ 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...