PDA

View Full Version : (sigbus) mystery :-)




mdeh
Jul 25, 2009, 08:57 PM
I am working ( or trying to) work my way through Apple's Core Data Utility Tutorial:


http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataUtilityTutorial/Articles/00_introduction.html#//apple_ref/doc/uid/TP40001800-CH202-TP1 in order to solve an earlier issue :)

But, from the very first change of code ie implementing GC, I am getting this error.

The Debugger has exited due to signal 10 (SIGBUS).The Debugger has exited due to signal 10 (SIGBUS). and stepping through the code, the line objc_startCollectorThread(); throws an EXC_BAD_ACCESS.

I am at a loss as to what is going on, as this is word for word from the tutorial.

For the sake of completeness, here is the code so far.




#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

NSManagedObjectModel *managedObjectModel();

int main (int argc, const char * argv[]) {
/* NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; */


objc_startCollectorThread();


NSManagedObjectModel *mom = managedObjectModel();
NSLog(@"The managed object model is defined as follows:\n%@", mom);

// insert code here...
NSLog(@"Hello, World!");
/* [pool drain]; */
return 0;
}



NSManagedObjectModel *managedObjectModel() {

static NSManagedObjectModel *mom = nil;

if (mom != nil) {
return mom;
}

mom = [[NSManagedObjectModel alloc] init];

NSEntityDescription *runEntity = [[NSEntityDescription alloc] init];
[runEntity setName:@"Run"];
[runEntity setManagedObjectClassName:@"Run"];
[mom setEntities:[NSArray arrayWithObject:runEntity]];

NSAttributeDescription *dateAttribute = [[NSAttributeDescription alloc] init];

[dateAttribute setName:@"date"];
[dateAttribute setAttributeType:NSDateAttributeType];
[dateAttribute setOptional:NO];


NSAttributeDescription *idAttribute = [[NSAttributeDescription alloc] init];

[idAttribute setName:@"processID"];
[idAttribute setAttributeType:NSInteger32AttributeType];
[idAttribute setOptional:NO];
[idAttribute setDefaultValue:[NSNumber numberWithInteger:-1]];

NSExpression *lhs = [NSExpression expressionForEvaluatedObject];
NSExpression *rhs = [NSExpression expressionForConstantValue:
[NSNumber numberWithInteger:0]];

NSPredicate *validationPredicate = [NSComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:NSDirectPredicateModifier
type:NSGreaterThanPredicateOperatorType
options:0];

NSString *validationWarning = @"Process ID < 1";
[idAttribute setValidationPredicates:[NSArray arrayWithObject:validationPredicate]
withValidationWarnings:[NSArray arrayWithObject:validationWarning]];


NSArray *properties = [NSArray arrayWithObjects: dateAttribute, idAttribute, nil];
[runEntity setProperties:properties];


NSMutableDictionary *localizationDictionary = [NSMutableDictionary dictionary];

[localizationDictionary setObject:@"Date" forKey:@"Property/date/Entity/Run"];
[localizationDictionary setObject:@"Process ID" forKey:@"Property/processID/Entity/Run"];
[localizationDictionary setObject:@"Process ID must not be less than 1" forKey:@"ErrorString/Process ID < 1"];

[mom setLocalizationDictionary:localizationDictionary];

return mom;
}


Any help as to how to approach this will be immensely appreciated.



lee1210
Jul 25, 2009, 11:13 PM
Did you compile with -fobjc-gc or -fobjc-gc-only?
Can you do a bt/backtrace from the gdb prompt when the program fails?

-Lee

mdeh
Jul 26, 2009, 03:53 AM
Did you compile with -fobjc-gc or -fobjc-gc-only?

The tutorial calls for "-fobjc-gc-only"

Can you do a bt/backtrace from the gdb prompt when the program fails?

Lee...not entirely sure how to do this, but the Console in Xcode gives me this.


7/26/09 1:43:04 AM Xcode[3055] Unable to load platform at path /Developer/Platforms/iPhoneOS.platform
7/26/09 1:43:05 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x36203e0, has non-zero refcount = 1
7/26/09 1:43:05 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x36475f0, has non-zero refcount = 1
7/26/09 1:43:10 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x38d78b0, has non-zero refcount = 1
7/26/09 1:43:10 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x38ddab0, has non-zero refcount = 1
7/26/09 1:43:11 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x3876540, has non-zero refcount = 1
7/26/09 1:43:11 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x3880480, has non-zero refcount = 1
7/26/09 1:43:11 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x38970b0, has non-zero refcount = 1
7/26/09 1:43:11 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x389c3a0, has non-zero refcount = 1
7/26/09 1:43:13 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x36c9c00, has non-zero refcount = 1
7/26/09 1:43:13 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x3842610, has non-zero refcount = 1



Does this help? Not quite sure if the ref to the iPhone OS is the issue? Maybe that's a clue? Not quite sure what to do with this in terms of fixing the problem.

gnasher729
Jul 26, 2009, 07:40 AM
Seems the tutorial is written for MacOS X. iPhone doesn't support garbage collection.

mdeh
Jul 26, 2009, 11:20 AM
Seems the tutorial is written for MacOS X. iPhone doesn't support garbage collection.

Hi Gnasher,
Well, as soon as I had thought about this, I realize that the app **was** written for Mac OS X, which now makes even less sense. Moreover, I have been unable to reproduce this line in the Console. But the following type of line is repeated much more consistently.

7/26/09 9:16:07 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x37af5c0, has non-zero refcount = 1
7/26/09 9:16:07 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x3841910, has non-zero refcount = 1
7/26/09 9:16:07 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x43a2de0, has non-zero refcount = 1
7/26/09 9:16:07 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x43c9380, has non-zero refcount = 1
7/26/09 9:16:07 AM [0x0-0xc60c6].com.apple.Xcode[3055] Xcode(3055,0xb0103000) malloc: free_garbage: garbage ptr = 0x43c9380, has non-zero refcount = 1

So, having said this, do you have any further insights.
Thanks

mdeh
Jul 28, 2009, 08:49 PM
Seems the tutorial is written for MacOS X. iPhone doesn't support garbage collection.

Solved!!

I am embarrassed to say that the reason was a real **newbie** error. I **thought** I had implemented GC for the debug version, but what I had done was implement it for the release version. So, the take home lesson ( for me!!) is to check one is setting GC for the correct version...obvious to people like gnasher, but a mistake I bet many have made :)