Skip to content

Commit 40d067c

Browse files
committed
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> llvm-svn: 301993
1 parent e37391c commit 40d067c

File tree

10 files changed

+136
-2
lines changed

10 files changed

+136
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LEVEL = ../../../make
2+
3+
CFLAGS = -g -O0
4+
LDFLAGS = $(CFLAGS) -lobjc -framework Foundation
5+
6+
all: a.out libTest.dylib libTestExt.dylib
7+
8+
libTest.dylib: Test/Test.m
9+
$(CC) $(CFLAGS) -I. -c -o Test.o Test/Test.m
10+
$(CC) $(LDFLAGS) -shared -o libTest.dylib Test.o
11+
dsymutil libTest.dylib
12+
13+
libTestExt.dylib: TestExt/TestExt.m
14+
$(CC) $(CFLAGS) -I. -c -o TestExt.o TestExt/TestExt.m
15+
$(CC) $(LDFLAGS) -L. -lTest -shared -o libTestExt.dylib TestExt.o
16+
dsymutil libTestExt.dylib
17+
18+
a.out: main.m libTest.dylib libTestExt.dylib
19+
$(CC) $(LDFLAGS) -I. -L. -lTest -lTestExt -o a.out main.m
20+
21+
.PHONY: clean
22+
23+
clean:
24+
rm -rf *.dylib a.out *.o *.dSYM *.d
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef __Foo_h__
2+
#define __Foo_h__
3+
4+
typedef struct {
5+
float start;
6+
float duration;
7+
} CMTimeRange;
8+
9+
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <Foundation/Foundation.h>
2+
#import <Test/Foo.h>
3+
4+
@interface Test : NSObject {
5+
@public
6+
CMTimeRange _range;
7+
}
8+
- (void) doTest;
9+
@end
10+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import "Test.h"
2+
3+
@implementation Test
4+
- (void) doTest {
5+
NSLog(@"-[Test doTest]");
6+
}
7+
@end
8+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""Test that types defined in shared libraries work correctly."""
2+
3+
from __future__ import print_function
4+
5+
6+
import os
7+
import time
8+
import lldb
9+
from lldbsuite.test.decorators import *
10+
from lldbsuite.test.lldbtest import *
11+
from lldbsuite.test import lldbutil
12+
13+
14+
class TestRealDefinition(TestBase):
15+
16+
mydir = TestBase.compute_mydir(__file__)
17+
18+
@skipUnlessDarwin
19+
def test_frame_var_after_stop_at_implementation(self):
20+
"""Test that we can find the implementation for an objective C type"""
21+
if self.getArchitecture() == 'i386':
22+
self.skipTest("requires modern objc runtime")
23+
self.build()
24+
self.common_setup()
25+
26+
line = line_number('TestExt/TestExt.m', '// break here')
27+
lldbutil.run_break_set_by_file_and_line(
28+
self, 'TestExt.m', line, num_expected_locations=1, loc_exact=True)
29+
30+
self.runCmd("run", RUN_SUCCEEDED)
31+
32+
# The stop reason of the thread should be breakpoint.
33+
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
34+
substrs=['stopped',
35+
'stop reason = breakpoint'])
36+
37+
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
38+
substrs=[' resolved, hit count = 1'])
39+
40+
# This should display correctly.
41+
self.expect(
42+
"expr 42",
43+
"A simple expression should execute correctly",
44+
substrs=[
45+
"42"])
46+
47+
def common_setup(self):
48+
exe = os.path.join(os.getcwd(), "a.out")
49+
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef __Foo_h__
2+
#define __Foo_h__
3+
4+
typedef struct {
5+
float s;
6+
float d;
7+
} CMTimeRange;
8+
9+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <TestExt/Foo.h>
2+
#import <Test/Test.h>
3+
struct CMTimeRange;
4+
5+
@interface Test (Stuff)
6+
- (void)doSomethingElse: (CMTimeRange *)range_ptr;
7+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import "TestExt.h"
2+
#import "Foo.h"
3+
4+
@implementation Test (Stuff)
5+
- (void)doSomethingElse: (CMTimeRange *)range_ptr {
6+
NSLog(@"doSomethingElse: %p", range_ptr); // break here
7+
}
8+
@end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <Test/Test.h>
2+
#import <TestExt/TestExt.h>
3+
4+
int main() {
5+
@autoreleasepool {
6+
Test *test = [[Test alloc] init];
7+
[test doSomethingElse:&test->_range];
8+
}
9+
}
10+

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) {
348348
GetCompleteObjCInterface(original_iface_decl);
349349

350350
if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) {
351-
m_ast_importer_sp->SetDeclOrigin(interface_decl, original_iface_decl);
351+
m_ast_importer_sp->SetDeclOrigin(interface_decl, complete_iface_decl);
352352
}
353353
}
354354
}
@@ -472,7 +472,7 @@ void ClangASTSource::FindExternalLexicalDecls(
472472
original_decl = complete_iface_decl;
473473
original_ctx = &complete_iface_decl->getASTContext();
474474

475-
m_ast_importer_sp->SetDeclOrigin(context_decl, original_iface_decl);
475+
m_ast_importer_sp->SetDeclOrigin(context_decl, complete_iface_decl);
476476
}
477477
}
478478

0 commit comments

Comments
 (0)