[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-20 Thread Dave Lee via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe19339f5f8c1: [lldb] Identify Swift-implemented ObjC classes 
(authored by kastiglione).

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/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

Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -24,6 +24,7 @@
 #include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/ThreadSafeDenseMap.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 class CommandObjectObjC_ClassTable_Dump;
@@ -86,6 +87,11 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+/// Determine whether this class is implemented in Swift.
+virtual lldb::LanguageType GetImplementationLanguage() const {
+  return lldb::eLanguageTypeObjC;
+}
+
 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 _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
@@ -33,6 +33,7 @@
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
@@ -753,6 +754,19 @@
   RegisterObjCExceptionRecognizer(process);
 }
 
+LanguageRuntime *
+AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject _value) {
+  if (auto process_sp = in_value.GetProcessSP()) {
+assert(process_sp.get() == m_process);
+if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value)) {
+  LanguageType impl_lang = descriptor_sp->GetImplementationLanguage();
+  if (impl_lang != eLanguageTypeUnknown)
+return process_sp->GetLanguageRuntime(impl_lang);
+}
+  }
+  return nullptr;
+}
+
 bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
 ValueObject _value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName _type_or_name, 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
@@ -12,6 +12,7 @@
 #include 
 
 #include "AppleObjCRuntimeV2.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
@@ -34,6 +35,8 @@
 return true; // any Objective-C v2 runtime class descriptor we vend is valid
   }
 
+  lldb::LanguageType GetImplementationLanguage() 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
@@ -10,8 +10,10 @@
 
 #include "lldb/Expression/FunctionCaller.h"
 #include 

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-19 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 542169.
kastiglione added a comment.

Redo ValueObjectDynamicValue::UpdateValue changes based on upstream testing


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/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

Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -24,6 +24,7 @@
 #include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/ThreadSafeDenseMap.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 class CommandObjectObjC_ClassTable_Dump;
@@ -86,6 +87,11 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+/// Determine whether this class is implemented in Swift.
+virtual lldb::LanguageType GetImplementationLanguage() const {
+  return lldb::eLanguageTypeObjC;
+}
+
 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 _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
@@ -33,6 +33,7 @@
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
@@ -712,6 +713,19 @@
   RegisterObjCExceptionRecognizer(process);
 }
 
+LanguageRuntime *
+AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject _value) {
+  if (auto process_sp = in_value.GetProcessSP()) {
+assert(process_sp.get() == m_process);
+if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value)) {
+  LanguageType impl_lang = descriptor_sp->GetImplementationLanguage();
+  if (impl_lang != eLanguageTypeUnknown)
+return process_sp->GetLanguageRuntime(impl_lang);
+}
+  }
+  return nullptr;
+}
+
 bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
 ValueObject _value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName _type_or_name, 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
@@ -12,6 +12,7 @@
 #include 
 
 #include "AppleObjCRuntimeV2.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
@@ -34,6 +35,8 @@
 return true; // any Objective-C v2 runtime class descriptor we vend is valid
   }
 
+  lldb::LanguageType GetImplementationLanguage() 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
@@ -10,8 +10,10 @@
 
 #include "lldb/Expression/FunctionCaller.h"
 #include "lldb/Target/ABI.h"
+#include "lldb/Target/Language.h"
 #include "lldb/Utility/LLDBLog.h"
 #include 

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 539359.
kastiglione added a comment.

Change `bool IsSwift()` to `LanguageType GetImplementationLanguage()`


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 _value) {
+  auto language = in_value.GetObjectRuntimeLanguage();
+  if (auto *runtime = GetLanguageRuntime(language))
+return runtime->GetPreferredLanguageRuntime(in_value);
+  return nullptr;
+}
+
 bool Process::IsPossibleDynamicValue(ValueObject _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
@@ -24,6 +24,7 @@
 #include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/ThreadSafeDenseMap.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 class CommandObjectObjC_ClassTable_Dump;
@@ -86,6 +87,11 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+/// Determine whether this class is implemented in Swift.
+virtual lldb::LanguageType GetImplementationLanguage() const {
+  return lldb::eLanguageTypeObjC;
+}
+
 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 _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 _value) {
+  if (auto process_sp = in_value.GetProcessSP()) {
+assert(process_sp.get() == m_process);
+if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value)) {
+  LanguageType impl_lang = descriptor_sp->GetImplementationLanguage();
+  if (impl_lang != eLanguageTypeUnknown)
+if (auto *impl_runtime = process_sp->GetLanguageRuntime(impl_lang))
+  return impl_runtime;
+}
+  }
+  return this;
+}
+
 bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
 ValueObject _value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName _type_or_name, 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
@@ -12,6 +12,7 @@
 #include 
 
 #include "AppleObjCRuntimeV2.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
@@ -34,6 +35,8 @@
 return true; // any Objective-C v2 runtime class descriptor we vend is valid
   }
 
+  lldb::LanguageType 

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

My concerns have been addressed, LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152837/new/

https://reviews.llvm.org/D152837

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added a comment.

@bulbazord  @augusto2112 hopefully this is a quick review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152837/new/

https://reviews.llvm.org/D152837

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
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 _value) {
+  auto language = in_value.GetObjectRuntimeLanguage();
+  if (auto *runtime = GetLanguageRuntime(language))
+return runtime->GetPreferredLanguageRuntime(in_value);
+  return nullptr;
+}
+
 bool Process::IsPossibleDynamicValue(ValueObject _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 _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 _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 _value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName _type_or_name, 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 @@
  

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-06-13 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/source/Core/ValueObjectDynamicValue.cpp:169
+  if (known_type == lldb::eLanguageTypeObjC &&
+  UseSwiftRuntime(*m_parent, exe_ctx)) {
+runtime = process->GetLanguageRuntime(lldb::eLanguageTypeSwift);

This is a bit of a layering violation. Could the ObjC language runtime perform 
this check in `GetDynamicTypeAndAddress` and dispatch to the Swift runtime 
there?

If you do this, we need to ensure we can't get into an infinite loop between 
the runtimes.

Alternatively, we could add a virtual GetPreferredLanguageRuntime() method to 
LanguageRuntime that we call here, maybe?



Comment at: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h:89
 
+virtual bool IsSwift() const { return false; }
+

Can you add a Doxygen commen?
/// Determine whether this class is implemented in Swift.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152837/new/

https://reviews.llvm.org/D152837

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-06-13 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.



Comment at: lldb/source/Core/ValueObjectDynamicValue.cpp:119-123
+if (auto *runtime = llvm::dyn_cast_or_null(
+process->GetLanguageRuntime(lldb::eLanguageTypeObjC)))
+  if (auto class_sp = runtime->GetClassDescriptor(valobj))
+if (class_sp->IsSwift())
+  return true;

@bulbazord this is where it's used, to work with `ClassDescriptor` which is 
part of the `ObjCLanguageRuntime`. I don't think it would make sense to lift 
that into the generic `LangaugeRuntime`. What other courses might there be?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152837/new/

https://reviews.llvm.org/D152837

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-06-13 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: lldb/source/Core/ValueObjectDynamicValue.cpp:10
 #include "lldb/Core/ValueObjectDynamicValue.h"
+#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
 #include "lldb/Core/Value.h"

Is there a way we can avoid using a plugin in non-plugin code?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152837/new/

https://reviews.llvm.org/D152837

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-06-13 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: aprantl, jingham, augusto2112.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Classes implemented in Swift can be exposed to ObjC. For those classes, the ObjC
metadata is incomplete (the types of the ivars are incomplete), but as one 
would expect
the Swift metadata is complete. In such cases, the Swift runtime should be 
consulted
first when determining the dynamic type of a value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152837

Files:
  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/ObjCLanguageRuntime.h

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,8 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+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/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
@@ -530,6 +530,18 @@
   return 0;
 }
 
+// From the ObjC runtime.
+static uint8_t IS_SWIFT_STABLE = 1U << 1;
+
+bool ClassDescriptorV2::IsSwift() const {
+  std::unique_ptr 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
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Core/ValueObjectDynamicValue.h"
+#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Symbol/CompilerType.h"
@@ -108,6 +109,22 @@
   return m_parent->GetValueType();
 }
 
+static bool UseSwiftRuntime(ValueObject ,
+const ExecutionContext _ctx) {
+  if (auto *frame = exe_ctx.GetFramePtr())
+if (frame->GetLanguage() == lldb::eLanguageTypeSwift)
+  return true;
+
+  if (auto *process = exe_ctx.GetProcessPtr())
+if (auto *runtime = llvm::dyn_cast_or_null(
+process->GetLanguageRuntime(lldb::eLanguageTypeObjC)))
+  if (auto class_sp = runtime->GetClassDescriptor(valobj))
+if (class_sp->IsSwift())
+  return true;
+
+  return false;
+}
+
 bool ValueObjectDynamicValue::UpdateValue() {
   SetValueIsValid(false);
   m_error.Clear();
@@ -146,6 +163,17 @@
   LanguageRuntime *runtime = nullptr;
 
   lldb::LanguageType known_type = m_parent->GetObjectRuntimeLanguage();
+
+  // An ObjC object in a Swift context, or a ObjC object implemented in Swift.
+  if (known_type == lldb::eLanguageTypeObjC &&
+  UseSwiftRuntime(*m_parent, exe_ctx)) {
+runtime = process->GetLanguageRuntime(lldb::eLanguageTypeSwift);
+if (runtime)
+  found_dynamic_type = runtime->GetDynamicTypeAndAddress(
+  *m_parent, m_use_dynamic, class_type_or_name, dynamic_address,
+  value_type);
+  }
+
   if (known_type != lldb::eLanguageTypeUnknown &&
   known_type != lldb::eLanguageTypeC) {
 runtime = process->GetLanguageRuntime(known_type);
___
lldb-commits mailing list