[Lldb-commits] [lldb] r192255 - <rdar://problem/15180638>

Enrico Granata egranata at apple.com
Tue Oct 8 17:13:17 PDT 2013


Author: enrico
Date: Tue Oct  8 19:13:17 2013
New Revision: 192255

URL: http://llvm.org/viewvc/llvm-project?rev=192255&view=rev
Log:
<rdar://problem/15180638>

Making GetNumberOfDirectBaseClasses() work for ObjC pointers, and for classes for which we don't have full debug info


Added:
    lldb/trunk/test/lang/objc/objc-baseclass-sbtype/
    lldb/trunk/test/lang/objc/objc-baseclass-sbtype/Makefile
    lldb/trunk/test/lang/objc/objc-baseclass-sbtype/TestObjCBaseClassSBType.py
    lldb/trunk/test/lang/objc/objc-baseclass-sbtype/main.m
Modified:
    lldb/trunk/source/Symbol/ClangASTType.cpp

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=192255&r1=192254&r2=192255&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Tue Oct  8 19:13:17 2013
@@ -2281,26 +2281,29 @@ ClangASTType::GetNumDirectBaseClasses ()
             break;
             
         case clang::Type::ObjCObjectPointer:
+            count = GetPointeeType().GetNumDirectBaseClasses();
+            break;
+            
+        case clang::Type::ObjCObject:
             if (GetCompleteType())
             {
-                const ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+                const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
                 if (objc_class_type)
                 {
-                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+                    
                     if (class_interface_decl && class_interface_decl->getSuperClass())
                         count = 1;
                 }
             }
             break;
-            
-        case clang::Type::ObjCObject:
         case clang::Type::ObjCInterface:
             if (GetCompleteType())
             {
-                const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
-                if (objc_class_type)
+                const ObjCInterfaceType *objc_interface_type = qual_type->getAs<ObjCInterfaceType>();
+                if (objc_interface_type)
                 {
-                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+                    ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
                     
                     if (class_interface_decl && class_interface_decl->getSuperClass())
                         count = 1;
@@ -2482,12 +2485,16 @@ ClangASTType::GetDirectBaseClassAtIndex
             break;
             
         case clang::Type::ObjCObjectPointer:
+            return GetPointeeType().GetDirectBaseClassAtIndex(idx,bit_offset_ptr);
+            
+        case clang::Type::ObjCObject:
             if (idx == 0 && GetCompleteType())
             {
-                const ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
+                const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
                 if (objc_class_type)
                 {
-                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
+                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+                    
                     if (class_interface_decl)
                     {
                         ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
@@ -2501,15 +2508,13 @@ ClangASTType::GetDirectBaseClassAtIndex
                 }
             }
             break;
-            
-        case clang::Type::ObjCObject:
         case clang::Type::ObjCInterface:
             if (idx == 0 && GetCompleteType())
             {
-                const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
-                if (objc_class_type)
+                const ObjCObjectType *objc_interface_type = qual_type->getAs<ObjCInterfaceType>();
+                if (objc_interface_type)
                 {
-                    ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
+                    ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
                     
                     if (class_interface_decl)
                     {

Added: lldb/trunk/test/lang/objc/objc-baseclass-sbtype/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-baseclass-sbtype/Makefile?rev=192255&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-baseclass-sbtype/Makefile (added)
+++ lldb/trunk/test/lang/objc/objc-baseclass-sbtype/Makefile Tue Oct  8 19:13:17 2013
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := main.m
+LDFLAGS = $(CFLAGS) -lobjc -framework AppKit
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/lang/objc/objc-baseclass-sbtype/TestObjCBaseClassSBType.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-baseclass-sbtype/TestObjCBaseClassSBType.py?rev=192255&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-baseclass-sbtype/TestObjCBaseClassSBType.py (added)
+++ lldb/trunk/test/lang/objc/objc-baseclass-sbtype/TestObjCBaseClassSBType.py Tue Oct  8 19:13:17 2013
@@ -0,0 +1,75 @@
+"""
+Use lldb Python API to test base class resolution for ObjC classes
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class ObjCDynamicValueTestCase(TestBase):
+
+    mydir = os.path.join("lang", "objc", "objc-baseclass-sbtype")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    @dsym_test
+    def test_get_baseclass_with_dsym(self):
+        """Test fetching ObjC base class info."""
+        if self.getArchitecture() == 'i386':
+            # rdar://problem/9946499
+            self.skipTest("Dynamic types for ObjC V1 runtime not implemented")
+        self.buildDsym()
+        self.do_get_baseclass_info()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    @dwarf_test
+    def test_get_baseclass_with_dwarf(self):
+        """Test fetching ObjC dynamic values."""
+        if self.getArchitecture() == 'i386':
+            # rdar://problem/9946499
+            self.skipTest("Dynamic types for ObjC V1 runtime not implemented")
+        self.buildDwarf()
+        self.do_get_baseclass_info()
+
+    def setUp(self):
+        # Call super's setUp().                                                                                                           
+        TestBase.setUp(self)
+
+        self.line = line_number('main.m', '// Set breakpoint here.')
+
+    def do_get_baseclass_info(self):
+        """Make sure we get dynamic values correctly both for compiled in classes and dynamic ones"""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        # Create a target from the debugger.
+
+        target = self.dbg.CreateTarget (exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Set up our breakpoints:
+
+        target.BreakpointCreateByLocation('main.m', self.line)
+        process = target.LaunchSimple (None, None, os.getcwd())
+
+        self.assertTrue(process.GetState() == lldb.eStateStopped,
+                        PROCESS_STOPPED)
+
+        button = self.frame().FindVariable("button")
+        button_ptr_type = button.GetType()
+        button_pte_type = button_ptr_type.GetPointeeType()
+        self.assertTrue(button_ptr_type.GetNumberOfDirectBaseClasses() == 1, "NSButton * has one base class")
+        self.assertTrue(button_pte_type.GetNumberOfDirectBaseClasses() == 1, "NSButton has one base class")
+
+        self.assertTrue(button_ptr_type.GetDirectBaseClassAtIndex(0).IsValid(), "NSButton * has a valid base class")
+        self.assertTrue(button_pte_type.GetDirectBaseClassAtIndex(0).IsValid(), "NSButton * has a valid base class")
+
+        self.assertTrue(button_ptr_type.GetDirectBaseClassAtIndex(0).GetName() == button_pte_type.GetDirectBaseClassAtIndex(0).GetName(), "NSButton and its pointer type don't agree on their base class")
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/lang/objc/objc-baseclass-sbtype/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-baseclass-sbtype/main.m?rev=192255&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-baseclass-sbtype/main.m (added)
+++ lldb/trunk/test/lang/objc/objc-baseclass-sbtype/main.m Tue Oct  8 19:13:17 2013
@@ -0,0 +1,9 @@
+#import <AppKit/AppKit.h>
+
+int main ()
+{
+	NSButton *button = [NSButton new];
+	NSLog(@"a"); // Set breakpoint here.
+	return 0;
+}
+





More information about the lldb-commits mailing list