]> git.saurik.com Git - apple/objc4.git/blob - test/gdb.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / gdb.m
1 // TEST_CFLAGS -Wno-deprecated-declarations
2
3 #include "test.h"
4 #include "testroot.i"
5 #include <objc/objc-gdb.h>
6 #include <objc/runtime.h>
7
8 #define SwiftV1MangledName4 "_TtC6Swiftt13SwiftV1Class4"
9 __attribute__((objc_runtime_name(SwiftV1MangledName4)))
10 @interface SwiftV1Class4 : TestRoot @end
11 @implementation SwiftV1Class4 @end
12
13 int main()
14 {
15 // Class hashes
16 Class result;
17
18 // Class should not be realized yet
19 // fixme not true during class hash rearrangement
20 // result = NXMapGet(gdb_objc_realized_classes, "TestRoot");
21 // testassert(!result);
22
23 [TestRoot class];
24 // Now class should be realized
25
26 if (!testdyld3()) {
27 // In dyld3 mode, the class will be in the launch closure and not in our table.
28 result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "TestRoot"));
29 testassert(result);
30 testassert(result == [TestRoot class]);
31 }
32
33 Class dynamic = objc_allocateClassPair([TestRoot class], "Dynamic", 0);
34 objc_registerClassPair(dynamic);
35 result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "Dynamic"));
36 testassert(result);
37 testassert(result == dynamic);
38
39 Class *realizedClasses = objc_copyRealizedClassList(NULL);
40 bool foundTestRoot = false;
41 bool foundDynamic = false;
42 for (Class *cursor = realizedClasses; *cursor; cursor++) {
43 if (*cursor == [TestRoot class])
44 foundTestRoot = true;
45 if (*cursor == dynamic)
46 foundDynamic = true;
47 }
48 free(realizedClasses);
49 testassert(foundTestRoot);
50 testassert(foundDynamic);
51
52 result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "DoesNotExist"));
53 testassert(!result);
54
55 // Class structure decoding
56
57 uintptr_t *maskp = (uintptr_t *)dlsym(RTLD_DEFAULT, "objc_debug_class_rw_data_mask");
58 testassert(maskp);
59
60 // Raw class names
61 testassert(strcmp(objc_debug_class_getNameRaw([SwiftV1Class4 class]), SwiftV1MangledName4) == 0);
62 testassert(strcmp(objc_debug_class_getNameRaw([TestRoot class]), "TestRoot") == 0);
63
64
65 succeed(__FILE__);
66 }