开发者

Xcode 4: Exceptions not being logged to the console

开发者 https://www.devze.com 2023-03-23 19:07 出处:网络
I recently upgraded to Xcode 4 and have not yet figured out how to have exceptions and error messages logged to the run console.

I recently upgraded to Xcode 4 and have not yet figured out how to have exceptions and error messages logged to the run console.

Example: In Xcode 3, [[NSArray array] objectAtIndex:1] results in the following being logged to the console.

2011开发者_如何学Python-08-10 10:27:22.061 App[28662:40b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 1 beyond bounds for empty array'
    *** Call stack at first throw:
(
    0   CoreFoundation                      0x015babe9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0170f5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x015b080c -[__NSArrayI objectAtIndex:] + 236
    3   App                                 0x00002514 -[AppDelegate application:didFinishLaunchingWithOptions:] + 357
    4   UIKit                               0x003fc1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    5   UIKit                               0x003fe55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    6   UIKit                               0x00408db2 -[UIApplication handleEvent:withNewEvent:] + 1533
    7   UIKit                               0x00401202 -[UIApplication sendEvent:] + 71
    8   UIKit                               0x00406732 _UIApplicationHandleEvent + 7576
    9   GraphicsServices                    0x01c24a36 PurpleEventCallback + 1550
    10  CoreFoundation                      0x0159c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    11  CoreFoundation                      0x014fc6f7 __CFRunLoopDoSource1 + 215
    12  CoreFoundation                      0x014f9983 __CFRunLoopRun + 979
    13  CoreFoundation                      0x014f9240 CFRunLoopRunSpecific + 208
    14  CoreFoundation                      0x014f9161 CFRunLoopRunInMode + 97
    15  UIKit                               0x003fdfa8 -[UIApplication _run] + 636
    16  UIKit                               0x0040a42e UIApplicationMain + 1160
    17  App                                 0x00002393 main + 85

This exception does not log anything to the console in Xcode 4.

I am able to view the call stack by adding an exception breakpoint - however, continuing past the exception breakpoint does not log anything to the console (not even a vague SIGABRT or EXC_BAD_ACCESS message).

I have "Log Exceptions" and "Enable Zombie Objects" checked in the Edit Scheme window's Diagnostics tab, but it hasn't helped. Are there any other settings I could possibly be missing?

Thanks so much.


Please consider to enhance your gdbinit file with the following :

How do I set these break points in ~/.gdbinit?

fb -[NSException raise]
fb -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:]
fb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]

#define NSZombies
# this will give you help messages.  Set to NO to turn them off.
set env MallocHelp=YES
# might also be set in launch arguments.
set env NSZombieEnabled=YES
set env NSDeallocateZombies=NO
set env MallocCheckHeapEach=100000
set env MallocCheckHeapStart=100000
set env MallocScribble=YES
set env MallocGuardEdges=YES
set env MallocCheckHeapAbort=1

set env CFZombie 5

fb -[_NSZombie init]
fb -[_NSZombie retainCount]
fb -[_NSZombie retain]
fb -[_NSZombie release]
fb -[_NSZombie autorelease]
fb -[_NSZombie methodSignatureForSelector:]
fb -[_NSZombie respondsToSelector:]
fb -[_NSZombie forwardInvocation:]
fb -[_NSZombie class]
fb -[_NSZombie dealloc]

fb szone_error

As stated by Kendal in a comment within this original post : If you don't have a gdbinit file yet, You need to create a new file called .gdbinit - put it in your home directory and fill it with provided content. Now every time gdb starts it will execute the commands in this file.

Hope this helps.


In all of followings shareKit has memory leaks!

All of my codes has no sign of leak but part in shareKit!

Leaked Object # Address Size Responsible Library Responsible Frame NSMallocBlock,1 0xf641c50 32 Bytes Twitter -[TWInFlightSessionCallInfo setRemoteCall:] TWInFlightSessionCallInfo,1 0xf676380 16 Bytes Twitter -[TWSession emptyCallInfo] Malloc 16 Bytes,1 0xf6457c0 16 Bytes Twitter -[TWSession recordAndIssueCallInfo:] Malloc 128 Bytes,2 < multiple > 256 Bytes libdispatch.dylib dispatch_queue_create$VARIANT$up NSLock,1 0xf64b450 64 Bytes Twitter -[TWSession init] TWSession,1 0xf62c3e0 32 Bytes Twitter -[TWTweetComposeViewController session] NSMutableArray,1 0x2c8540 32 Bytes Twitter -[TWSession init] NSMallocBlock,1 0x1084ebb0 32 Bytes Twitter -[TWInFlightSessionCallInfo setRemoteCall:]


You can get this by establishing a uncaught exception handler in your App Delegate.

void uncaughtExceptionHandler(NSException *exception)
{
   if ( exception )
   {
      NSLog(@"Exception %@", exception);
      NSLog(@"Exception Call Stack %@", [exception callStackSymbols]);
   }

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   ...

   NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);


I catch the exceptions in my main.m Here is what I have coded in my recent app. I also enable the Zombie objects in Edit Scheme and I also find it helpful to add a exception breakpoint to my app.

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    int retVal;
    @autoreleasepool {
        @try 
        {
            retVal = UIApplicationMain(argc, argv, nil,        NSStringFromClass([AppDelegate class]));
           }
        @catch (NSException *exception) 
       {
           NSLog(@"CRASH===> %@", [exception callStackSymbols]);
            @throw;
        }  
       @finally 
       {

       }
       return retVal;
    }
}


I tried exactly your example in XCode 4.6, and I get the following log:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:
(0x1cd0012 0x110de7e 0x1c85b44 0x4547 0x1121705 0x552c0 0x291a64 0x1121705 0x552c0 0x55258 0x116021 0x11657f 0x1156e8 0x84cef 0x84f02 0x62d4a 0x54698 0x1c2bdf9 0x1c2bad0 0x1c45bf5 0x1c45962 0x1c76bb6 0x1c75f44 0x1c75e1b 0x1c2a7e3 0x1c2a668 0x51ffc 0x285d 0x2785 0x1) libc++abi.dylib: terminate called throwing an exception

0

精彩评论

暂无评论...
验证码 换一张
取 消