Skip to content

[lldb] Make GetDynamicTypeAndAddress() use host address if available #9975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lldb/include/lldb/Target/LanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ class LanguageRuntime : public Runtime, public PluginInterface {
"language doesn't support getting vtable information");
}

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

// This call should return a CompilerType given a generic type name and an
// ExecutionContextScope in which one can actually fetch any specialization
Expand Down
13 changes: 13 additions & 0 deletions lldb/include/lldb/ValueObject/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,19 @@ class ValueObject {

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

/// Returns the local buffer that this ValueObject points to if it's
/// available.
/// \return
/// The local buffer if this value object's value points to a
/// host address, and if that buffer can be determined. Otherwise, returns
/// an empty ArrayRef.
///
/// TODO: Because a ValueObject's Value can point to any arbitrary memory
/// location, it is possible that we can't find what what buffer we're
/// pointing to, and thus also can't know its size. See the comment in
/// Value::m_value for a more thorough explanation of why that is.
llvm::ArrayRef<uint8_t> GetLocalBuffer() const;

protected:
typedef ClusterManager<ValueObject> ValueObjectManager;

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,14 @@ SwiftLanguage::GetHardcodedSynthetics() {
TypeAndOrName type_or_name;
Address address;
Value::ValueType value_type;
llvm::ArrayRef<uint8_t> local_buffer;
// Try to find the dynamic type of the Swift type.
// TODO: find a way to get the dyamic value type from the
// command.
if (swift_runtime->GetDynamicTypeAndAddress(
*casted_to_swift.get(),
lldb::DynamicValueType::eDynamicCanRunTarget, type_or_name,
address, value_type)) {
address, value_type, local_buffer)) {
if (type_or_name.HasCompilerType()) {
swift_type = type_or_name.GetCompilerType();
// Cast it to the more specific type.
Expand Down Expand Up @@ -1248,8 +1249,9 @@ SwiftLanguage::GetPossibleFormattersMatches(
TypeAndOrName type_and_or_name;
Address address;
Value::ValueType value_type;
llvm::ArrayRef<uint8_t> local_buffer;
if (!runtime->GetDynamicTypeAndAddress(valobj, use_dynamic, type_and_or_name,
address, value_type))
address, value_type, local_buffer))
return result;
if (ConstString name = type_and_or_name.GetName())
result.push_back(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ llvm::Expected<LanguageRuntime::VTableInfo>
bool ItaniumABILanguageRuntime::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &dynamic_address,
Value::ValueType &value_type) {
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
// For Itanium, if the type has a vtable pointer in the object, it will be at
// offset 0 in the object. That will point to the "address point" within the
// vtable (not the beginning of the vtable.) We can then look up the symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ItaniumABILanguageRuntime : public lldb_private::CPPLanguageRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
ValueObject &static_value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ bool AppleObjCRuntime::CouldHaveDynamicValue(ValueObject &in_value) {
bool AppleObjCRuntime::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type) {
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class AppleObjCRuntime : public lldb_private::ObjCLanguageRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
ValueObject &static_value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AppleObjCRuntimeV1::AppleObjCRuntimeV1(Process *process)
bool AppleObjCRuntimeV1::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type) {
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
class_type_or_name.Clear();
value_type = Value::ValueType::Scalar;
if (CouldHaveDynamicValue(in_value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class AppleObjCRuntimeV1 : public AppleObjCRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

llvm::Expected<std::unique_ptr<UtilityFunction>>
CreateObjectChecker(std::string, ExecutionContext &exe_ctx) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type) {
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
// We should never get here with a null process...
assert(m_process != nullptr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

llvm::Expected<std::unique_ptr<UtilityFunction>>
CreateObjectChecker(std::string name, ExecutionContext &exe_ctx) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool GNUstepObjCRuntime::CouldHaveDynamicValue(ValueObject &in_value) {
bool GNUstepObjCRuntime::GetDynamicTypeAndAddress(
ValueObject &in_value, DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type) {
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class GNUstepObjCRuntime : public lldb_private::ObjCLanguageRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name,
ValueObject &static_value) override;
Expand Down
24 changes: 13 additions & 11 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type) override;
Address &address, Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer) override;

CompilerType BindGenericTypeParameters(
CompilerType unbound_type,
Expand Down Expand Up @@ -569,7 +569,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type);
Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer);
#ifndef NDEBUG
ConstString GetDynamicTypeName_ClassRemoteAST(ValueObject &in_value,
lldb::addr_t instance_ptr);
Expand All @@ -596,18 +597,18 @@ class SwiftLanguageRuntime : public LanguageRuntime {
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type);
Value::ValueType &value_type,
llvm::ArrayRef<uint8_t> &local_buffer);

bool GetDynamicTypeAndAddress_IndirectEnumCase(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type);
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer);

bool GetDynamicTypeAndAddress_ClangType(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name,
Address &address,
Value::ValueType &value_type);
bool GetDynamicTypeAndAddress_ClangType(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Value::ValueType &value_type, llvm::ArrayRef<uint8_t> &local_buffer);

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

lldb::UnwindPlanSP
GetRuntimeUnwindPlan(lldb::ProcessSP process_sp,
Expand Down
Loading