[Lldb-commits] [lldb] r193631 - Fixing an issue in yesterday's dynamic type changes where we would not craft a valid SBType given debug information

Enrico Granata egranata at apple.com
Tue Oct 29 10:42:02 PDT 2013


Author: enrico
Date: Tue Oct 29 12:42:02 2013
New Revision: 193631

URL: http://llvm.org/viewvc/llvm-project?rev=193631&view=rev
Log:
Fixing an issue in yesterday's dynamic type changes where we would not craft a valid SBType given debug information
Added a test case to help us detect regression in this realm


Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
    lldb/trunk/source/Symbol/ClangASTType.cpp
    lldb/trunk/test/lang/objc/objc-dyn-sbtype/TestObjCDynamicSBType.py
    lldb/trunk/test/lang/objc/objc-dyn-sbtype/main.m

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=193631&r1=193630&r2=193631&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Tue Oct 29 12:42:02 2013
@@ -201,6 +201,9 @@ public:
     IsPointerToScalarType () const;
     
     bool
+    IsRuntimeGeneratedType () const;
+    
+    bool
     IsPointerType (ClangASTType *pointee_type = NULL) const;
     
     bool

Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=193631&r1=193630&r2=193631&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Tue Oct 29 12:42:02 2013
@@ -81,7 +81,7 @@ TypeImpl
 ValueObjectDynamicValue::GetTypeImpl ()
 {
     const bool success = UpdateValueIfNeeded(false);
-    if (success)
+    if (success && m_type_impl.IsValid())
     {
         return m_type_impl;
     }
@@ -225,12 +225,29 @@ ValueObjectDynamicValue::UpdateValue ()
     
     m_update_point.SetUpdated();
 
-    // if the runtime only vended a ClangASTType, then we have an hollow type that we don't want to use
-    // but we save it for the TypeImpl, which can still use an hollow type for some questions
-    if (found_dynamic_type && class_type_or_name.HasType() && !class_type_or_name.HasTypeSP())
+    if (found_dynamic_type)
+    {
+        if (class_type_or_name.HasType())
+        {
+            // TypeSP are always generated from debug info
+            if (!class_type_or_name.HasTypeSP() && class_type_or_name.GetClangASTType().IsRuntimeGeneratedType())
+            {
+                m_type_impl = TypeImpl(m_parent->GetClangType(),FixupTypeAndOrName(class_type_or_name, *m_parent).GetClangASTType());
+                class_type_or_name.SetClangASTType(ClangASTType());
+            }
+            else
+            {
+                m_type_impl = TypeImpl(FixupTypeAndOrName(class_type_or_name, *m_parent).GetClangASTType());
+            }
+        }
+        else
+        {
+            m_type_impl.Clear();
+        }
+    }
+    else
     {
-        m_type_impl = TypeImpl(m_parent->GetClangType(),FixupTypeAndOrName(class_type_or_name, *m_parent).GetClangASTType());
-        class_type_or_name.SetClangASTType(ClangASTType());
+        m_type_impl.Clear();
     }
     
     // If we don't have a dynamic type, then make ourselves just a echo of our parent.

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=193631&r1=193630&r2=193631&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Tue Oct 29 12:42:02 2013
@@ -288,6 +288,21 @@ ClangASTType::IsArrayType (ClangASTType
     return 0;
 }
 
+bool
+ClangASTType::IsRuntimeGeneratedType () const
+{
+    if (!IsValid())
+        return false;
+    clang::DeclContext* decl_ctx = GetDeclContextForType();
+    if (!decl_ctx)
+        return false;
+    if (!llvm::isa<ObjCContainerDecl>(decl_ctx))
+        return false;
+    ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(m_ast, decl_ctx);
+    if (!ast_metadata)
+        return false;
+    return (ast_metadata->GetISAPtr() != 0);
+}
 
 bool
 ClangASTType::IsCharType () const

Modified: lldb/trunk/test/lang/objc/objc-dyn-sbtype/TestObjCDynamicSBType.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-dyn-sbtype/TestObjCDynamicSBType.py?rev=193631&r1=193630&r2=193631&view=diff
==============================================================================
--- lldb/trunk/test/lang/objc/objc-dyn-sbtype/TestObjCDynamicSBType.py (original)
+++ lldb/trunk/test/lang/objc/objc-dyn-sbtype/TestObjCDynamicSBType.py Tue Oct 29 12:42:02 2013
@@ -1,5 +1,5 @@
 """
-Test that we are able to properly report a usable dynamic type for NSImage
+Test that we are able to properly report a usable dynamic type
 """
 
 import os, time
@@ -16,7 +16,7 @@ class ObjCDynamicSBTypeTestCase(TestBase
     @dsym_test
     @skipIfi386
     def test_nsimage_dyn_with_dsym(self):
-        """Test that we are able to properly report a usable dynamic type for NSImage."""
+        """Test that we are able to properly report a usable dynamic type."""
         d = {'EXE': self.exe_name}
         self.buildDsym(dictionary=d)
         self.setTearDownCleanup(dictionary=d)
@@ -25,7 +25,7 @@ class ObjCDynamicSBTypeTestCase(TestBase
     @dwarf_test
     @skipIfi386
     def test_nsimage_dyn_with_dwarf(self):
-        """Test that we are able to properly report a usable dynamic type for NSImage."""
+        """Test that we are able to properly report a usable dynamic type."""
         d = {'EXE': self.exe_name}
         self.buildDwarf(dictionary=d)
         self.setTearDownCleanup(dictionary=d)
@@ -41,7 +41,7 @@ class ObjCDynamicSBTypeTestCase(TestBase
         self.line = line_number(self.main_source, '// Set breakpoint here.')
 
     def nsimage_dyn(self, exe_name):
-        """Test that we are able to properly report a usable dynamic type for NSImage."""
+        """Test that we are able to properly report a usable dynamic type."""
         exe = os.path.join(os.getcwd(), exe_name)
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
@@ -57,6 +57,27 @@ class ObjCDynamicSBTypeTestCase(TestBase
         self.assertTrue(image_pointee_type.GetName() == "NSImage", "The dynamic type figures out its pointee type just fine")
         self.assertTrue(image_pointee_type.GetDirectBaseClassAtIndex(0).GetName() == "NSObject", "The dynamic type can go back to its base class")
 
+        v_object = self.frame().FindVariable("object").GetDynamicValue(lldb.eDynamicCanRunTarget)
+        v_base = self.frame().FindVariable("base").GetDynamicValue(lldb.eDynamicCanRunTarget)
+        self.assertTrue(v_object.GetTypeName() == "MyDerivedClass *", "The NSObject is properly type-named")
+        self.assertTrue(v_base.GetTypeName() == "MyDerivedClass *", "The Base is properly type-named")
+        object_type = v_object.GetType()
+        base_type = v_base.GetType()
+        self.assertTrue(object_type.GetName() == "MyDerivedClass *", "The dynamic SBType for NSObject is for the correct type")
+        self.assertTrue(base_type.GetName() == "MyDerivedClass *", "The dynamic SBType for Base is for the correct type")
+        object_pointee_type = object_type.GetPointeeType()
+        base_pointee_type = base_type.GetPointeeType()
+        self.assertTrue(object_pointee_type.GetName() == "MyDerivedClass", "The dynamic type for NSObject figures out its pointee type just fine")
+        self.assertTrue(base_pointee_type.GetName() == "MyDerivedClass", "The dynamic type for Base figures out its pointee type just fine")
+
+        self.assertTrue(object_pointee_type.GetDirectBaseClassAtIndex(0).GetName() == "MyBaseClass", "The dynamic type for NSObject can go back to its base class")
+        self.assertTrue(base_pointee_type.GetDirectBaseClassAtIndex(0).GetName() == "MyBaseClass", "The dynamic type for Base can go back to its base class")
+
+        self.assertTrue(object_pointee_type.GetDirectBaseClassAtIndex(0).GetType().GetDirectBaseClassAtIndex(0).GetName() == "NSObject", "The dynamic type for NSObject can go up the hierarchy")
+        self.assertTrue(base_pointee_type.GetDirectBaseClassAtIndex(0).GetType().GetDirectBaseClassAtIndex(0).GetName() == "NSObject", "The dynamic type for Base can go up the hierarchy")
+
+        self.assertTrue(object_pointee_type.GetNumberOfFields() == 2, "The dynamic type for NSObject has 2 fields")
+        self.assertTrue(base_pointee_type.GetNumberOfFields() == 2, "The dynamic type for Base has 2 fields")
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/lang/objc/objc-dyn-sbtype/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-dyn-sbtype/main.m?rev=193631&r1=193630&r2=193631&view=diff
==============================================================================
--- lldb/trunk/test/lang/objc/objc-dyn-sbtype/main.m (original)
+++ lldb/trunk/test/lang/objc/objc-dyn-sbtype/main.m Tue Oct 29 12:42:02 2013
@@ -1,12 +1,58 @@
 #import <Foundation/Foundation.h>
 #import <Cocoa/Cocoa.h>
 
+ at interface MyBaseClass : NSObject
+{}
+-(id) init;
+-(int) getInt;
+ at end
+
+ at implementation MyBaseClass
+- (id) init {
+	return (self = [super init]);
+}
+
+- (int) getInt {
+	return 1;
+}
+ at end
+
+ at interface MyDerivedClass : MyBaseClass
+{
+	int x;
+	int y;
+}
+-(id) init;
+-(int) getInt;
+ at end
+
+ at implementation MyDerivedClass
+- (id) init {
+	self = [super init];
+	if (self) {
+		self-> x = 0;
+		self->y = 1;
+	}
+	return self;
+}
+
+- (int) getInt {
+	y = x++;
+	return x;
+}
+ at end
+
+
 int main (int argc, char const *argv[])
 {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
 	NSSize size = {10,10};
 	NSImage *image = [[NSImage alloc] initWithSize:size];
+	
+	NSObject* object = [[MyDerivedClass alloc] init];
+	MyBaseClass* base = [[MyDerivedClass alloc] init];
+	
     [pool release]; // Set breakpoint here.
     return 0;
 }





More information about the lldb-commits mailing list