[Lldb-commits] [lldb] r285941 - Add support to the ObjC type scavenger for finding types via debug info

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 3 10:25:27 PDT 2016


Author: enrico
Date: Thu Nov  3 12:25:27 2016
New Revision: 285941

URL: http://llvm.org/viewvc/llvm-project?rev=285941&view=rev
Log:
Add support to the ObjC type scavenger for finding types via debug info


Modified:
    lldb/trunk/include/lldb/Target/Language.h
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/TestTypeLookup.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/main.mm
    lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp

Modified: lldb/trunk/include/lldb/Target/Language.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Language.h?rev=285941&r1=285940&r2=285941&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Language.h (original)
+++ lldb/trunk/include/lldb/Target/Language.h Thu Nov  3 12:25:27 2016
@@ -95,32 +95,51 @@ public:
                    ResultSet &results) override;
   };
 
-  template <typename TypeScavenger1, typename TypeScavenger2>
+  template <typename... ScavengerTypes>
   class EitherTypeScavenger : public TypeScavenger {
+  public:
+    EitherTypeScavenger() : TypeScavenger(), m_scavengers() {
+      for (std::shared_ptr<TypeScavenger> scavenger : { std::shared_ptr<TypeScavenger>(new ScavengerTypes())... }) {
+        if (scavenger)
+          m_scavengers.push_back(scavenger);
+      }
+    }
+  protected:
     bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
                    ResultSet &results) override {
       const bool append = false;
-      auto ts1 = TypeScavenger1();
-      if (ts1.Find(exe_scope, key, results, append))
-        return true;
-      auto ts2 = TypeScavenger2();
-      if (ts2.Find(exe_scope, key, results, append))
-        return true;
+      for (auto& scavenger : m_scavengers) {
+        if (scavenger && scavenger->Find(exe_scope, key, results, append))
+          return true;
+      }
       return false;
     }
+  private:
+    std::vector<std::shared_ptr<TypeScavenger>> m_scavengers;
   };
 
-  template <typename TypeScavenger1, typename TypeScavenger2>
-  class BothTypeScavenger : public TypeScavenger {
+  template <typename... ScavengerTypes>
+  class UnionTypeScavenger : public TypeScavenger {
+  public:
+    UnionTypeScavenger() : TypeScavenger(), m_scavengers() {
+      for (std::shared_ptr<TypeScavenger> scavenger : { std::shared_ptr<TypeScavenger>(new ScavengerTypes())... }) {
+        if (scavenger)
+          m_scavengers.push_back(scavenger);
+      }
+    }
+  protected:
     bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
                    ResultSet &results) override {
       const bool append = true;
-      auto ts1 = TypeScavenger1();
-      bool success = ts1.Find(exe_scope, key, results, append);
-      auto ts2 = TypeScavenger2();
-      success = ts2.Find(exe_scope, key, results, append) || success;
+      bool success = false;
+      for (auto& scavenger : m_scavengers) {
+        if (scavenger)
+          success = scavenger->Find(exe_scope, key, results, append) || success;
+      }
       return success;
     }
+  private:
+    std::vector<std::shared_ptr<TypeScavenger>> m_scavengers;
   };
 
   enum class FunctionNameRepresentation {

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/TestTypeLookup.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/TestTypeLookup.py?rev=285941&r1=285940&r2=285941&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/TestTypeLookup.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/TestTypeLookup.py Thu Nov  3 12:25:27 2016
@@ -52,3 +52,4 @@ class TypeLookupTestCase(TestBase):
                     "no type was found matching 'PleaseDontBeARealTypeThatExists'"])
         self.expect('type lookup MyCPPClass', substrs=['setF', 'float getF'])
         self.expect('type lookup MyClass', substrs=['setF', 'float getF'])
+        self.expect('type lookup MyObjCClass', substrs=['@interface MyObjCClass', 'int x', 'int y'])

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/main.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/main.mm?rev=285941&r1=285940&r2=285941&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/main.mm (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/type_lookup/main.mm Thu Nov  3 12:25:27 2016
@@ -28,6 +28,28 @@ private:
 
 typedef MyCPPClass MyClass;
 
+ at interface MyObjCClass : NSObject {
+  int x;
+}
+- (id)init;
+- (int)read;
+ at end
+
+ at implementation MyObjCClass {
+  int y;
+}
+- (id)init {
+  if (self = [super init]) {
+    self->x = 12;
+    self->y = 24;
+  }
+  return self;
+}
+- (int)read {
+  return self->x + self->y;
+}
+ at end
+
 int main (int argc, const char * argv[])
 {
   MyClass my_cpp(3.1415);

Modified: lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp?rev=285941&r1=285940&r2=285941&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp Thu Nov  3 12:25:27 2016
@@ -994,10 +994,23 @@ std::unique_ptr<Language::TypeScavenger>
 
     friend class lldb_private::ObjCLanguage;
   };
+  
+  class ObjCDebugInfoScavenger : public Language::ImageListTypeScavenger {
+  public:
+    virtual CompilerType AdjustForInclusion(CompilerType &candidate) override {
+      LanguageType lang_type(candidate.GetMinimumLanguage());
+      if (!Language::LanguageIsObjC(lang_type))
+        return CompilerType();
+      if (candidate.IsTypedefType())
+        return candidate.GetTypedefedType();
+      return candidate;
+    }
+  };
 
   return std::unique_ptr<TypeScavenger>(
       new Language::EitherTypeScavenger<ObjCModulesScavenger,
-                                        ObjCRuntimeScavenger>());
+                                        ObjCRuntimeScavenger,
+                                        ObjCDebugInfoScavenger>());
 }
 
 bool ObjCLanguage::GetFormatterPrefixSuffix(ValueObject &valobj,




More information about the lldb-commits mailing list