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

0 commit comments

Comments
 (0)