[Lldb-commits] [lldb] r301993 - Fixed a bug where we did not properly use the complete versions of Objective-C classes.

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Tue May 2 17:41:44 PDT 2017


Author: spyffe
Date: Tue May  2 19:41:43 2017
New Revision: 301993

URL: http://llvm.org/viewvc/llvm-project?rev=301993&view=rev
Log:
Fixed a bug where we did not properly use the complete versions of Objective-C classes.
Also added a test case, thanks to Greg Clayton.

<rdar://problem/18913551>

Added:
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Foo.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.m
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestConflictingDefinition.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/Foo.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.h
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.m
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/main.m
Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Makefile?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Makefile Tue May  2 19:41:43 2017
@@ -0,0 +1,24 @@
+LEVEL = ../../../make
+
+CFLAGS = -g -O0
+LDFLAGS = $(CFLAGS) -lobjc -framework Foundation
+
+all: a.out libTest.dylib libTestExt.dylib
+
+libTest.dylib:	Test/Test.m
+	$(CC) $(CFLAGS) -I. -c -o Test.o Test/Test.m
+	$(CC) $(LDFLAGS) -shared -o libTest.dylib Test.o
+	dsymutil libTest.dylib
+
+libTestExt.dylib: TestExt/TestExt.m
+	$(CC) $(CFLAGS) -I. -c -o TestExt.o TestExt/TestExt.m
+	$(CC) $(LDFLAGS) -L. -lTest -shared -o libTestExt.dylib TestExt.o
+	dsymutil libTestExt.dylib
+
+a.out: main.m libTest.dylib libTestExt.dylib
+	$(CC) $(LDFLAGS) -I. -L. -lTest -lTestExt -o a.out main.m 
+
+.PHONY: clean
+
+clean:
+	rm -rf *.dylib a.out *.o *.dSYM *.d

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Foo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Foo.h?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Foo.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Foo.h Tue May  2 19:41:43 2017
@@ -0,0 +1,9 @@
+#ifndef __Foo_h__
+#define __Foo_h__
+
+typedef struct {
+    float start;
+    float duration;
+} CMTimeRange;
+
+#endif

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.h?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.h Tue May  2 19:41:43 2017
@@ -0,0 +1,10 @@
+#import <Foundation/Foundation.h>
+#import <Test/Foo.h>
+
+ at interface Test : NSObject {
+ at public
+    CMTimeRange _range;
+}
+- (void) doTest;
+ at end
+

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.m?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.m (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/Test/Test.m Tue May  2 19:41:43 2017
@@ -0,0 +1,8 @@
+#import "Test.h"
+
+ at implementation Test
+- (void) doTest {
+    NSLog(@"-[Test doTest]");
+}
+ at end
+

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestConflictingDefinition.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestConflictingDefinition.py?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestConflictingDefinition.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestConflictingDefinition.py Tue May  2 19:41:43 2017
@@ -0,0 +1,49 @@
+"""Test that types defined in shared libraries work correctly."""
+
+from __future__ import print_function
+
+
+import os
+import time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestRealDefinition(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @skipUnlessDarwin
+    def test_frame_var_after_stop_at_implementation(self):
+        """Test that we can find the implementation for an objective C type"""
+        if self.getArchitecture() == 'i386':
+            self.skipTest("requires modern objc runtime")
+        self.build()
+        self.common_setup()
+
+        line = line_number('TestExt/TestExt.m', '// break here')
+        lldbutil.run_break_set_by_file_and_line(
+            self, 'TestExt.m', line, num_expected_locations=1, loc_exact=True)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+                    substrs=['stopped',
+                             'stop reason = breakpoint'])
+
+        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+                    substrs=[' resolved, hit count = 1'])
+
+        # This should display correctly.
+        self.expect(
+            "expr 42",
+            "A simple expression should execute correctly",
+            substrs=[
+                "42"])
+
+    def common_setup(self):
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/Foo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/Foo.h?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/Foo.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/Foo.h Tue May  2 19:41:43 2017
@@ -0,0 +1,9 @@
+#ifndef __Foo_h__
+#define __Foo_h__
+
+typedef struct {
+    float s;
+    float d;
+} CMTimeRange;
+
+#endif

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.h?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.h (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.h Tue May  2 19:41:43 2017
@@ -0,0 +1,7 @@
+#import <TestExt/Foo.h>
+#import <Test/Test.h>
+struct CMTimeRange;
+
+ at interface Test (Stuff)
+- (void)doSomethingElse: (CMTimeRange *)range_ptr;
+ at end

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.m?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.m (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/TestExt/TestExt.m Tue May  2 19:41:43 2017
@@ -0,0 +1,8 @@
+#import "TestExt.h"
+#import "Foo.h"
+
+ at implementation Test (Stuff)
+- (void)doSomethingElse: (CMTimeRange *)range_ptr {
+    NSLog(@"doSomethingElse: %p", range_ptr); // break here
+}
+ at end

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/main.m?rev=301993&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/main.m (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/conflicting-definition/main.m Tue May  2 19:41:43 2017
@@ -0,0 +1,10 @@
+#import <Test/Test.h>
+#import <TestExt/TestExt.h>
+
+int main() {
+  @autoreleasepool {
+    Test *test = [[Test alloc] init];
+    [test doSomethingElse:&test->_range];
+  }
+}    
+

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=301993&r1=301992&r2=301993&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue May  2 19:41:43 2017
@@ -348,7 +348,7 @@ void ClangASTSource::CompleteType(clang:
           GetCompleteObjCInterface(original_iface_decl);
 
       if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
-        m_ast_importer_sp->SetDeclOrigin(interface_decl, original_iface_decl);
+        m_ast_importer_sp->SetDeclOrigin(interface_decl, complete_iface_decl);
       }
     }
   }
@@ -472,7 +472,7 @@ void ClangASTSource::FindExternalLexical
       original_decl = complete_iface_decl;
       original_ctx = &complete_iface_decl->getASTContext();
 
-      m_ast_importer_sp->SetDeclOrigin(context_decl, original_iface_decl);
+      m_ast_importer_sp->SetDeclOrigin(context_decl, complete_iface_decl);
     }
   }
 




More information about the lldb-commits mailing list