kastiglione updated this revision to Diff 539268.
kastiglione added a comment.
Refactor for better API layering
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152837/new/
https://reviews.llvm.org/D152837
Files:
lldb/include/lldb/Target/LanguageRuntime.h
lldb/include/lldb/Target/Process.h
lldb/source/Core/ValueObjectDynamicValue.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
lldb/source/Target/Process.cpp
Index: lldb/source/Target/Process.cpp
===================================================================
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -22,6 +22,7 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/ValueObject.h"
#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Expression/DynamicCheckerFunctions.h"
#include "lldb/Expression/UserExpression.h"
@@ -1553,6 +1554,13 @@
return runtime;
}
+LanguageRuntime *Process::GetLanguageRuntime(ValueObject &in_value) {
+ auto language = in_value.GetObjectRuntimeLanguage();
+ if (auto *runtime = GetLanguageRuntime(language))
+ return runtime->GetPreferredLanguageRuntime(in_value);
+ return nullptr;
+}
+
bool Process::IsPossibleDynamicValue(ValueObject &in_value) {
if (m_finalizing)
return false;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -86,6 +86,9 @@
return (m_is_cf == eLazyBoolYes);
}
+ /// Determine whether this class is implemented in Swift.
+ virtual bool IsSwift() const { return false; }
+
virtual bool IsValid() = 0;
/// There are two routines in the ObjC runtime that tagged pointer clients
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -38,6 +38,8 @@
static llvm::StringRef GetPluginNameStatic() { return "apple-objc-v2"; }
+ LanguageRuntime *GetPreferredLanguageRuntime(ValueObject &in_value) override;
+
static char ID;
bool isA(const void *ClassID) const override {
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -712,6 +712,20 @@
RegisterObjCExceptionRecognizer(process);
}
+LanguageRuntime *
+AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
+ if (auto process_sp = in_value.GetProcessSP()) {
+ assert(process_sp.get() == m_process);
+ if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value))
+ if (descriptor_sp->IsSwift())
+ // This class is implemented in Swift, making it the preferred runtime.
+ if (auto *swift_runtime =
+ process_sp->GetLanguageRuntime(lldb::eLanguageTypeSwift))
+ return swift_runtime;
+ }
+ return this;
+}
+
bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
TypeAndOrName &class_type_or_name, Address &address,
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
@@ -34,6 +34,8 @@
return true; // any Objective-C v2 runtime class descriptor we vend is valid
}
+ bool IsSwift() const override;
+
// a custom descriptor is used for tagged pointers
bool GetTaggedPointerInfo(uint64_t *info_bits = nullptr,
uint64_t *value_bits = nullptr,
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
@@ -668,6 +668,18 @@
return 0;
}
+// From the ObjC runtime.
+static uint8_t IS_SWIFT_STABLE = 1U << 1;
+
+bool ClassDescriptorV2::IsSwift() const {
+ std::unique_ptr<objc_class_t> objc_class;
+ if (auto *process = m_runtime.GetProcess())
+ if (Read_objc_class(process, objc_class))
+ return objc_class->m_flags & IS_SWIFT_STABLE;
+
+ return false;
+}
+
ClassDescriptorV2::iVarsStorage::iVarsStorage() : m_ivars(), m_mutex() {}
size_t ClassDescriptorV2::iVarsStorage::size() { return m_ivars.size(); }
Index: lldb/source/Core/ValueObjectDynamicValue.cpp
===================================================================
--- lldb/source/Core/ValueObjectDynamicValue.cpp
+++ lldb/source/Core/ValueObjectDynamicValue.cpp
@@ -148,7 +148,7 @@
lldb::LanguageType known_type = m_parent->GetObjectRuntimeLanguage();
if (known_type != lldb::eLanguageTypeUnknown &&
known_type != lldb::eLanguageTypeC) {
- runtime = process->GetLanguageRuntime(known_type);
+ runtime = process->GetLanguageRuntime(*m_parent);
if (runtime)
found_dynamic_type = runtime->GetDynamicTypeAndAddress(
*m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
Index: lldb/include/lldb/Target/Process.h
===================================================================
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2276,6 +2276,9 @@
LanguageRuntime *GetLanguageRuntime(lldb::LanguageType language);
+ /// Get the relevant runtime for the given value.
+ LanguageRuntime *GetLanguageRuntime(ValueObject &in_value);
+
bool IsPossibleDynamicValue(ValueObject &in_value);
bool IsRunning() const;
Index: lldb/include/lldb/Target/LanguageRuntime.h
===================================================================
--- lldb/include/lldb/Target/LanguageRuntime.h
+++ lldb/include/lldb/Target/LanguageRuntime.h
@@ -67,6 +67,12 @@
virtual lldb::LanguageType GetLanguageType() const = 0;
+ /// Return the preferred language runtime instance, which in most cases will
+ /// be the current instance.
+ virtual LanguageRuntime *GetPreferredLanguageRuntime(ValueObject &in_value) {
+ return this;
+ }
+
virtual bool GetObjectDescription(Stream &str, ValueObject &object) = 0;
virtual bool GetObjectDescription(Stream &str, Value &value,
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits