Skip to content

Commit

Permalink
And show the Objective-C Garbage Collection status.
Browse files Browse the repository at this point in the history
  • Loading branch information
nygard committed Jun 30, 2009
1 parent c60e3d7 commit 71d534e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
5 changes: 4 additions & 1 deletion CDClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ - (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
[identifier formattedCurrentVersion], [identifier formattedCompatibilityVersion]];
}

[resultString appendFormat:@" *\n"];
[resultString appendFormat:@" * Objective-C Garbage Collection: %@\n", [aProcessor garbageCollectionStatus]];

for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
if ([loadCommand isKindOfClass:[CDLCRunPath class]]) {
CDLCRunPath *runPath = (CDLCRunPath *)loadCommand;

[resultString appendFormat:@" * Run path: %@\n", [runPath path]];
[resultString appendFormat:@" * Run path: %@\n", [runPath path]];
}
}

Expand Down
2 changes: 1 addition & 1 deletion CDObjectiveCProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
- (void)createUniquedProtocols;

- (NSData *)objcImageInfoData;
- (void)logGCStatus;
- (NSString *)garbageCollectionStatus;

@end
47 changes: 25 additions & 22 deletions CDObjectiveCProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ - (void)process;
// Load classes before categories, so we can get a dictionary of classes by address.
[self loadClasses];
[self loadCategories];

[self logGCStatus];
}

- (void)loadProtocols;
Expand Down Expand Up @@ -209,32 +207,37 @@ - (NSData *)objcImageInfoData;
return [[[machOFile segmentWithName:@"__DATA"] sectionWithName:@"__objc_imageinfo"] data];
}

- (void)logGCStatus;
- (NSString *)garbageCollectionStatus;
{
NSData *sectionData;

//NSLog(@" > %s", _cmd);
CDDataCursor *cursor;
uint32_t v1, v2;

sectionData = [self objcImageInfoData];
if ([sectionData length] >= 8) {
CDDataCursor *cursor;
uint32_t v1, v2;

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];

v1 = [cursor readInt32];
v2 = [cursor readInt32];
NSLog(@"%s: %08x %08x", _cmd, v1, v2);
// v2 == 0 -> Objective-C Garbage Collection: Unsupported
// v2 == 2 -> Supported
// v2 == 6 -> Required
NSParameterAssert(v2 == 0 || v2 == 2 || v2 == 6);

[cursor release];
if ([sectionData length] < 8)
return @"Unknown";

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];

v1 = [cursor readInt32];
v2 = [cursor readInt32];
//NSLog(@"%s: %08x %08x", _cmd, v1, v2);
// v2 == 0 -> Objective-C Garbage Collection: Unsupported
// v2 == 2 -> Supported
// v2 == 6 -> Required
NSParameterAssert(v2 == 0 || v2 == 2 || v2 == 6);

[cursor release];

// These are probably bitfields that should be tested/masked...
switch (v2) {
case 0: return @"Unsupported";
case 2: return @"Supported";
case 6: return @"Required";
}

//NSLog(@"< %s", _cmd);
return [NSString stringWithFormat:@"Unknown (0x%08x)", v2];
}

@end

0 comments on commit 71d534e

Please sign in to comment.