views:

2550

answers:

2

I'm getting this message each time I compile my project:

RunIPhoneUnitTest.sh: line 92: 31389 Abort trap              "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents

I understand is a problem in my code, but then I don't figure how solve or found it.

The strange thing, is that I get this with this call:

-- This is the interface
@interface DbObject : NSObject {
    NSInteger Id;
    NSDate* timeStamp;
}

@property (nonatomic) NSInteger Id;
@property (nonatomic, retain) NSDate *timeStamp;
----
This fail with above error
----
NSString * filter = [NSString stringWithFormat:"id = %@", ds.Id, nil];

BUT the wird thing is that I delete that line, that method and still get it! Is making my crazy.

Currently, I'm thinking in delete code until not get a error & start adding it, but wonder if exist a more pragmatic solution...

+3  A: 

An abort trap usually means that abort was called somewhere. This is most likely happening because your unit test harness code is throwing an exception that it's not expecting and simply handling this by calling abort(3). The abort call is not very easy to debug because it provides no information regarding who called it or why, never returns and generates a SIGABRT. You could install a new handler for SIGABRT and place a breakpoint there and then at least examine the current call stack... but read the rest for information on why this is happening in the first place.

However, the problem with your code above is that NSInteger is not an object type, it's a regular primitive. To correct your error, replace the failing line with this:

NSString *filter = [NSString stringWithFormat:@"id = %lld", (long long)ds.Id];

First, stringWithFormat takes an NSString object as a parameter, so you need to use the '@' character to specify that the string literal is an NSString. This is very important since @"blah blah" is actually translated into an object. The call you're making to stringWithFormat is expecting the NSString object information to be resident at that memory address, but instead it's getting a string of characters and is most likely exploding there. Make sure that all your string literals are @"blah blah" where an NSString type is expected and that they're not simple c-strings.

Second, the '@' character in the format string specifies an object. Since NSInteger is not an object, you can't use this format character. Instead use %lld to specify a long long integer. Finally, you don't need to add the nil at the end of the parameter list when using stringWithFormat since the format string itself specifies how many parameters to expect.

As an aside, the reason that %lld is used instead of just %d is that NSInteger changes size depending on whether you're compiling for a 32-bit or 64-bit target. By promoting the NSInteger to the long long type and using the %lld specifier you make sure that you won't have truncation issues in the future if you compile for 64-bit and your NSInteger value requires more than 32 bits to store.

EDIT: Added a little bit more information about abort(3) and the NSString string literal.

Jason Coco
A: 

Thank you, very clear your explanation.

mamcx