Skip to content

Commit f914d61

Browse files
committed
Added a new local_buffer parameter to GetDynamicTypeAndAddress
1 parent a280e7b commit f914d61

File tree

14 files changed

+58
-29
lines changed

14 files changed

+58
-29
lines changed

lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ 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.
109-
// address can be either a legitimate address on the inferior, or an address
110-
// in lldb, if value_type == HostAddress.
111-
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value,
112-
lldb::DynamicValueType use_dynamic,
113-
TypeAndOrName &class_type_or_name,
114-
Address &address,
115-
Value::ValueType &value_type) = 0;
108+
/// This call should return true if it could set the name and/or the type
109+
/// Sets address to the address of the dynamic type if value_type is set to
110+
/// a file or load address. Sets local_buffer to a buffer containing the data
111+
/// of the dynamic type if value_type is set to a host address.
112+
virtual bool GetDynamicTypeAndAddress(
113+
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
114+
TypeAndOrName &class_type_or_name, Address &address,
115+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) = 0;
116116

117117
// This call should return a CompilerType given a generic type name and an
118118
// ExecutionContextScope in which one can actually fetch any specialization

lldb/include/lldb/ValueObject/ValueObject.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,18 @@ class ValueObject {
865865

866866
virtual void SetLanguageFlags(uint64_t flags) { m_language_flags = flags; }
867867

868+
/// Returns the size of the local buffer if it's available.
869+
/// \return
870+
/// The size of the local buffer if this value object's value points to a
871+
/// host address, and if that size can be determined. Otherwise, returns
872+
/// LLDB_INVALID_ADDRESS.
873+
///
874+
/// TODO: Because a ValueObject's Value can point to any arbitrary memory
875+
/// location, it is possible that the size of the local buffer can't be
876+
/// determined at all. See the comment in Value::m_value for a more thorough
877+
/// explanation of why that is.
878+
uint64_t GetLocalBufferSize();
879+
868880
protected:
869881
typedef ClusterManager<ValueObject> ValueObjectManager;
870882

lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ llvm::Expected<LanguageRuntime::VTableInfo>
289289
bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress(
290290
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
291291
TypeAndOrName &class_type_or_name, Address &dynamic_address,
292-
Value::ValueType &value_type) {
292+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
293293
// For Itanium, if the type has a vtable pointer in the object, it will be at
294294
// offset 0 in the object. That will point to the "address point" within the
295295
// vtable (not the beginning of the vtable.) We can then look up the symbol

lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class ItaniumABILanguageRuntime : public lldb_private::CPPLanguageRuntime {
5454
bool GetDynamicTypeAndAddress(ValueObject &in_value,
5555
lldb::DynamicValueType use_dynamic,
5656
TypeAndOrName &class_type_or_name,
57-
Address &address,
58-
Value::ValueType &value_type) override;
57+
Address &address, Value::ValueType &value_type,
58+
llvm::ArrayRef<uint8_t> &local_buffer) override;
5959

6060
TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
6161
ValueObject &static_value) override;

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ bool AppleObjCRuntime::CouldHaveDynamicValue(ValueObject &in_value) {
276276
bool AppleObjCRuntime::GetDynamicTypeAndAddress(
277277
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
278278
TypeAndOrName &class_type_or_name, Address &address,
279-
Value::ValueType &value_type) {
279+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
280280
return false;
281281
}
282282

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class AppleObjCRuntime : public lldb_private::ObjCLanguageRuntime {
5454
bool GetDynamicTypeAndAddress(ValueObject &in_value,
5555
lldb::DynamicValueType use_dynamic,
5656
TypeAndOrName &class_type_or_name,
57-
Address &address,
58-
Value::ValueType &value_type) override;
57+
Address &address, Value::ValueType &value_type,
58+
llvm::ArrayRef<uint8_t> &local_buffer) override;
5959

6060
TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
6161
ValueObject &static_value) override;

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ AppleObjCRuntimeV1::AppleObjCRuntimeV1(Process *process)
4848
bool AppleObjCRuntimeV1::GetDynamicTypeAndAddress(
4949
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
5050
TypeAndOrName &class_type_or_name, Address &address,
51-
Value::ValueType &value_type) {
51+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
5252
class_type_or_name.Clear();
5353
value_type = Value::ValueType::Scalar;
5454
if (CouldHaveDynamicValue(in_value)) {

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class AppleObjCRuntimeV1 : public AppleObjCRuntime {
100100
bool GetDynamicTypeAndAddress(ValueObject &in_value,
101101
lldb::DynamicValueType use_dynamic,
102102
TypeAndOrName &class_type_or_name,
103-
Address &address,
104-
Value::ValueType &value_type) override;
103+
Address &address, Value::ValueType &value_type,
104+
llvm::ArrayRef<uint8_t> &local_buffer) override;
105105

106106
llvm::Expected<std::unique_ptr<UtilityFunction>>
107107
CreateObjectChecker(std::string, ExecutionContext &exe_ctx) override;

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
770770
bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
771771
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
772772
TypeAndOrName &class_type_or_name, Address &address,
773-
Value::ValueType &value_type) {
773+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
774774
// We should never get here with a null process...
775775
assert(m_process != nullptr);
776776

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
5353
bool GetDynamicTypeAndAddress(ValueObject &in_value,
5454
lldb::DynamicValueType use_dynamic,
5555
TypeAndOrName &class_type_or_name,
56-
Address &address,
57-
Value::ValueType &value_type) override;
56+
Address &address, Value::ValueType &value_type,
57+
llvm::ArrayRef<uint8_t> &local_buffer) override;
5858

5959
llvm::Expected<std::unique_ptr<UtilityFunction>>
6060
CreateObjectChecker(std::string name, ExecutionContext &exe_ctx) override;

lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool GNUstepObjCRuntime::CouldHaveDynamicValue(ValueObject &in_value) {
127127
bool GNUstepObjCRuntime::GetDynamicTypeAndAddress(
128128
ValueObject &in_value, DynamicValueType use_dynamic,
129129
TypeAndOrName &class_type_or_name, Address &address,
130-
Value::ValueType &value_type) {
130+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
131131
return false;
132132
}
133133

lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class GNUstepObjCRuntime : public lldb_private::ObjCLanguageRuntime {
6767
bool GetDynamicTypeAndAddress(ValueObject &in_value,
6868
lldb::DynamicValueType use_dynamic,
6969
TypeAndOrName &class_type_or_name,
70-
Address &address,
71-
Value::ValueType &value_type) override;
70+
Address &address, Value::ValueType &value_type,
71+
llvm::ArrayRef<uint8_t> &local_buffer) override;
7272

7373
TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
7474
ValueObject &static_value) override;

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,22 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
849849
return true;
850850
}
851851

852+
uint64_t ValueObject::GetLocalBufferSize() {
853+
if (m_value.GetValueType() != Value::ValueType::HostAddress)
854+
return LLDB_INVALID_ADDRESS;
855+
auto start = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
856+
if (start == LLDB_INVALID_ADDRESS)
857+
return LLDB_INVALID_ADDRESS;
858+
// Does our pointer point to this value object's m_data buffer?
859+
if ((uint64_t)m_data.GetDataStart() == start)
860+
return m_data.GetByteSize();
861+
// Does our pointer point to the value's buffer?
862+
if ((uint64_t)m_value.GetBuffer().GetBytes() == start)
863+
return m_value.GetBuffer().GetByteSize();
864+
// Our pointer points to something else. We can't know what the size is.
865+
return LLDB_INVALID_ADDRESS;
866+
}
867+
852868
static bool CopyStringDataToBufferSP(const StreamString &source,
853869
lldb::WritableDataBufferSP &destination) {
854870
llvm::StringRef src = source.GetString();

lldb/source/ValueObject/ValueObjectDynamicValue.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
145145
Address dynamic_address;
146146
bool found_dynamic_type = false;
147147
Value::ValueType value_type;
148+
llvm::ArrayRef<uint8_t> local_buffer;
148149

149150
LanguageRuntime *runtime = nullptr;
150151

@@ -157,7 +158,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
157158
// Try the preferred runtime first.
158159
found_dynamic_type = preferred_runtime->GetDynamicTypeAndAddress(
159160
*m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
160-
value_type);
161+
value_type, local_buffer);
161162
if (found_dynamic_type)
162163
// Set the operative `runtime` for later use in this function.
163164
runtime = preferred_runtime;
@@ -166,20 +167,20 @@ bool ValueObjectDynamicValue::UpdateValue() {
166167
// Fallback to the runtime for `known_type`.
167168
found_dynamic_type = runtime->GetDynamicTypeAndAddress(
168169
*m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
169-
value_type);
170+
value_type, local_buffer);
170171
} else {
171172
runtime = process->GetLanguageRuntime(lldb::eLanguageTypeC_plus_plus);
172173
if (runtime)
173174
found_dynamic_type = runtime->GetDynamicTypeAndAddress(
174175
*m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
175-
value_type);
176+
value_type, local_buffer);
176177

177178
if (!found_dynamic_type) {
178179
runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC);
179180
if (runtime)
180181
found_dynamic_type = runtime->GetDynamicTypeAndAddress(
181182
*m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
182-
value_type);
183+
value_type, local_buffer);
183184
}
184185
}
185186

@@ -241,8 +242,8 @@ bool ValueObjectDynamicValue::UpdateValue() {
241242

242243
// If we found a host address, point to the buffer in host memory.
243244
// Later on this function will copy the buffer over.
244-
if (value_type == Value::ValueType::HostAddress) {
245-
m_value.GetScalar() = dynamic_address.GetOffset();
245+
if (value_type == Value::ValueType::HostAddress && !local_buffer.empty()) {
246+
m_value.GetScalar() = (uint64_t)local_buffer.data();
246247
m_address = LLDB_INVALID_ADDRESS;
247248
} else {
248249
// Otherwise we have a legitimate address on the target. Point to the load

0 commit comments

Comments
 (0)