+// TEST_CFLAGS -Wno-deprecated-declarations
+
#include "test.h"
+#include "testroot.i"
#include <objc/objc-gdb.h>
#include <objc/runtime.h>
-@interface Super { @public id isa; } @end
-@implementation Super
-+(void)initialize { }
-+class { return self; }
-@end
-
+#define SwiftV1MangledName4 "_TtC6Swiftt13SwiftV1Class4"
+__attribute__((objc_runtime_name(SwiftV1MangledName4)))
+@interface SwiftV1Class4 : TestRoot @end
+@implementation SwiftV1Class4 @end
int main()
{
// Class hashes
-#if __OBJC2__
-
Class result;
// Class should not be realized yet
// fixme not true during class hash rearrangement
- // result = NXMapGet(gdb_objc_realized_classes, "Super");
+ // result = NXMapGet(gdb_objc_realized_classes, "TestRoot");
// testassert(!result);
- [Super class];
+ [TestRoot class];
// Now class should be realized
- result = NXMapGet(gdb_objc_realized_classes, "Super");
- testassert(result);
- testassert(result == [Super class]);
-
- result = NXMapGet(gdb_objc_realized_classes, "DoesNotExist");
- testassert(!result);
-
-#else
-
- struct objc_class query;
- struct objc_class *result;
+ if (!testdyld3()) {
+ // In dyld3 mode, the class will be in the launch closure and not in our table.
+ result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "TestRoot"));
+ testassert(result);
+ testassert(result == [TestRoot class]);
+ }
- query.name = "Super";
- result = NXHashGet(_objc_debug_class_hash, &query);
+ Class dynamic = objc_allocateClassPair([TestRoot class], "Dynamic", 0);
+ objc_registerClassPair(dynamic);
+ result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "Dynamic"));
testassert(result);
- testassert(result == [Super class]);
+ testassert(result == dynamic);
- query.name = "DoesNotExist";
- result = NXHashGet(_objc_debug_class_hash, &query);
+ Class *realizedClasses = objc_copyRealizedClassList(NULL);
+ bool foundTestRoot = false;
+ bool foundDynamic = false;
+ for (Class *cursor = realizedClasses; *cursor; cursor++) {
+ if (*cursor == [TestRoot class])
+ foundTestRoot = true;
+ if (*cursor == dynamic)
+ foundDynamic = true;
+ }
+ free(realizedClasses);
+ testassert(foundTestRoot);
+ testassert(foundDynamic);
+
+ result = (__bridge Class)(NXMapGet(gdb_objc_realized_classes, "DoesNotExist"));
testassert(!result);
-#endif
+ // Class structure decoding
+
+ uintptr_t *maskp = (uintptr_t *)dlsym(RTLD_DEFAULT, "objc_debug_class_rw_data_mask");
+ testassert(maskp);
+
+ // Raw class names
+ testassert(strcmp(objc_debug_class_getNameRaw([SwiftV1Class4 class]), SwiftV1MangledName4) == 0);
+ testassert(strcmp(objc_debug_class_getNameRaw([TestRoot class]), "TestRoot") == 0);
+
succeed(__FILE__);
}