Skip to content

Commit a280e7b

Browse files
committed
[lldb] Make ValueObjectDynamicValue::UpdateValue() point to a host buffer
ValueObjectDynamicValue::UpdateValue() assumes that the dynamic type found by GetDynamicTypeAndAddress() would return an address in the inferior. This commit makes it so it can deal with being passed a host address instead. This is needed downstream by the Swift fork. rdar://143357274
1 parent e1c63bb commit a280e7b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ class LanguageRuntime : public Runtime, public PluginInterface {
105105
"language doesn't support getting vtable information");
106106
}
107107

108-
// this call should return true if it could set the name and/or the type
108+
// This call should return true if it could set the name and/or the type.
109+
// address can be either a legitimate address on the inferior, or an address
110+
// in lldb, if value_type == HostAddress.
109111
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value,
110112
lldb::DynamicValueType use_dynamic,
111113
TypeAndOrName &class_type_or_name,

lldb/source/ValueObject/ValueObjectDynamicValue.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,19 @@ bool ValueObjectDynamicValue::UpdateValue() {
239239
if (m_address.IsValid())
240240
SetValueDidChange(true);
241241

242-
// We've moved, so we should be fine...
243-
m_address = dynamic_address;
244-
lldb::TargetSP target_sp(GetTargetSP());
245-
lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get());
246-
m_value.GetScalar() = load_address;
242+
// If we found a host address, point to the buffer in host memory.
243+
// Later on this function will copy the buffer over.
244+
if (value_type == Value::ValueType::HostAddress) {
245+
m_value.GetScalar() = dynamic_address.GetOffset();
246+
m_address = LLDB_INVALID_ADDRESS;
247+
} else {
248+
// Otherwise we have a legitimate address on the target. Point to the load
249+
// address.
250+
m_address = dynamic_address;
251+
lldb::TargetSP target_sp(GetTargetSP());
252+
lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get());
253+
m_value.GetScalar() = load_address;
254+
}
247255
}
248256

249257
if (runtime)
@@ -258,7 +266,11 @@ bool ValueObjectDynamicValue::UpdateValue() {
258266
LLDB_LOGF(log, "[%s %p] has a new dynamic type %s", GetName().GetCString(),
259267
static_cast<void *>(this), GetTypeName().GetCString());
260268

261-
if (m_address.IsValid() && m_dynamic_type_info) {
269+
// m_address could be invalid but we could still have a local buffer
270+
// containing the dynamic value.
271+
if ((m_address.IsValid() ||
272+
m_value.GetValueType() == Value::ValueType::HostAddress) &&
273+
m_dynamic_type_info) {
262274
// The variable value is in the Scalar value inside the m_value. We can
263275
// point our m_data right to it.
264276
m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get());

0 commit comments

Comments
 (0)