Skip to content

Commit f29572a

Browse files
authored
Merge pull request #9975 from augusto2112/fix-gen-local-buffer
[lldb] Make GetDynamicTypeAndAddress() use host address if available
2 parents f507642 + dd87dff commit f29572a

File tree

22 files changed

+441
-88
lines changed

22 files changed

+441
-88
lines changed

lldb/include/lldb/Target/LanguageRuntime.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ class LanguageRuntime : public Runtime, public PluginInterface {
106106
"language doesn't support getting vtable information");
107107
}
108108

109-
// this call should return true if it could set the name and/or the type
110-
virtual bool GetDynamicTypeAndAddress(ValueObject &in_value,
111-
lldb::DynamicValueType use_dynamic,
112-
TypeAndOrName &class_type_or_name,
113-
Address &address,
114-
Value::ValueType &value_type) = 0;
109+
/// This call should return true if it could set the name and/or the type
110+
/// Sets address to the address of the dynamic type if value_type is set to
111+
/// a file or load address. Sets local_buffer to a buffer containing the data
112+
/// of the dynamic type if value_type is set to a host address. Callers should
113+
/// copy local_buffer over into their own buffer if they want to keep the data
114+
/// alive.
115+
virtual bool GetDynamicTypeAndAddress(
116+
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
117+
TypeAndOrName &class_type_or_name, Address &address,
118+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) = 0;
115119

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

lldb/include/lldb/ValueObject/ValueObject.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,19 @@ class ValueObject {
869869

870870
virtual void SetLanguageFlags(uint64_t flags) { m_language_flags = flags; }
871871

872+
/// Returns the local buffer that this ValueObject points to if it's
873+
/// available.
874+
/// \return
875+
/// The local buffer if this value object's value points to a
876+
/// host address, and if that buffer can be determined. Otherwise, returns
877+
/// an empty ArrayRef.
878+
///
879+
/// TODO: Because a ValueObject's Value can point to any arbitrary memory
880+
/// location, it is possible that we can't find what what buffer we're
881+
/// pointing to, and thus also can't know its size. See the comment in
882+
/// Value::m_value for a more thorough explanation of why that is.
883+
llvm::ArrayRef<uint8_t> GetLocalBuffer() const;
884+
872885
protected:
873886
typedef ClusterManager<ValueObject> ValueObjectManager;
874887

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,14 @@ SwiftLanguage::GetHardcodedSynthetics() {
11141114
TypeAndOrName type_or_name;
11151115
Address address;
11161116
Value::ValueType value_type;
1117+
llvm::ArrayRef<uint8_t> local_buffer;
11171118
// Try to find the dynamic type of the Swift type.
11181119
// TODO: find a way to get the dyamic value type from the
11191120
// command.
11201121
if (swift_runtime->GetDynamicTypeAndAddress(
11211122
*casted_to_swift.get(),
11221123
lldb::DynamicValueType::eDynamicCanRunTarget, type_or_name,
1123-
address, value_type)) {
1124+
address, value_type, local_buffer)) {
11241125
if (type_or_name.HasCompilerType()) {
11251126
swift_type = type_or_name.GetCompilerType();
11261127
// Cast it to the more specific type.
@@ -1248,8 +1249,9 @@ SwiftLanguage::GetPossibleFormattersMatches(
12481249
TypeAndOrName type_and_or_name;
12491250
Address address;
12501251
Value::ValueType value_type;
1252+
llvm::ArrayRef<uint8_t> local_buffer;
12511253
if (!runtime->GetDynamicTypeAndAddress(valobj, use_dynamic, type_and_or_name,
1252-
address, value_type))
1254+
address, value_type, local_buffer))
12531255
return result;
12541256
if (ConstString name = type_and_or_name.GetName())
12551257
result.push_back(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ llvm::Expected<LanguageRuntime::VTableInfo>
288288
bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress(
289289
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
290290
TypeAndOrName &class_type_or_name, Address &dynamic_address,
291-
Value::ValueType &value_type) {
291+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
292292
// For Itanium, if the type has a vtable pointer in the object, it will be at
293293
// offset 0 in the object. That will point to the "address point" within the
294294
// 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
@@ -775,7 +775,7 @@ AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
775775
bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
776776
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
777777
TypeAndOrName &class_type_or_name, Address &address,
778-
Value::ValueType &value_type) {
778+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
779779
// We should never get here with a null process...
780780
assert(m_process != nullptr);
781781

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/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
242242
bool GetDynamicTypeAndAddress(ValueObject &in_value,
243243
lldb::DynamicValueType use_dynamic,
244244
TypeAndOrName &class_type_or_name,
245-
Address &address,
246-
Value::ValueType &value_type) override;
245+
Address &address, Value::ValueType &value_type,
246+
llvm::ArrayRef<uint8_t> &local_buffer) override;
247247

248248
CompilerType BindGenericTypeParameters(
249249
CompilerType unbound_type,
@@ -569,7 +569,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
569569
lldb::DynamicValueType use_dynamic,
570570
TypeAndOrName &class_type_or_name,
571571
Address &address,
572-
Value::ValueType &value_type);
572+
Value::ValueType &value_type,
573+
llvm::ArrayRef<uint8_t> &local_buffer);
573574
#ifndef NDEBUG
574575
ConstString GetDynamicTypeName_ClassRemoteAST(ValueObject &in_value,
575576
lldb::addr_t instance_ptr);
@@ -596,18 +597,18 @@ class SwiftLanguageRuntime : public LanguageRuntime {
596597
lldb::DynamicValueType use_dynamic,
597598
TypeAndOrName &class_type_or_name,
598599
Address &address,
599-
Value::ValueType &value_type);
600+
Value::ValueType &value_type,
601+
llvm::ArrayRef<uint8_t> &local_buffer);
600602

601603
bool GetDynamicTypeAndAddress_IndirectEnumCase(
602604
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
603605
TypeAndOrName &class_type_or_name, Address &address,
604-
Value::ValueType &value_type);
606+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer);
605607

606-
bool GetDynamicTypeAndAddress_ClangType(ValueObject &in_value,
607-
lldb::DynamicValueType use_dynamic,
608-
TypeAndOrName &class_type_or_name,
609-
Address &address,
610-
Value::ValueType &value_type);
608+
bool GetDynamicTypeAndAddress_ClangType(
609+
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
610+
TypeAndOrName &class_type_or_name, Address &address,
611+
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer);
611612

612613
/// Dynamic type resolution tends to want to generate scalar data -
613614
/// but there are caveats Per original comment here "Our address is
@@ -618,7 +619,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
618619
Value::ValueType GetValueType(ValueObject &in_value,
619620
CompilerType dynamic_type,
620621
Value::ValueType static_value_type,
621-
bool is_indirect_enum_case);
622+
bool is_indirect_enum_case,
623+
llvm::ArrayRef<uint8_t> &local_buffer);
622624

623625
lldb::UnwindPlanSP
624626
GetRuntimeUnwindPlan(lldb::ProcessSP process_sp,

0 commit comments

Comments
 (0)