LoginSignup
54
54

More than 5 years have passed since last update.

SIGABRTやEXC_BAD_ACCESSでエラー内容が出ない時の対処法

Last updated at Posted at 2014-03-28

スクリーンショット 2014-03-27 18.09.32.png

これです。
スタックトレースとはなんだったのか。

スタックトレースする

スタックトレースしたいです。
その場合は、以下のようにAppDelegate.mに記述することでスタックトレースをすることができます。

AppDelegate.m
#import "AppDelegate.h"

@implementation AppDelegate

void uncaughtExceptionHandler(NSException *exception) 
{
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

    return YES;
}

その時のログが以下です。

log
2014-03-28 15:42:50.034 testapp[5721:60b] CRASH: *** -[__NSArrayI objectAtIndex:]: index 5 beyond bounds for empty array
2014-03-28 15:42:50.051 testapp[5721:60b] Stack Trace: (
    0   CoreFoundation                      0x2d8def1b <redacted> + 154
    1   libobjc.A.dylib                     0x38073ce7 objc_exception_throw + 38
    2   CoreFoundation                      0x2d815331 <redacted> + 176
    3   testapp                             0x00074001 -[ViewController configureNavigationBar] + 92
    4   testapp                             0x00073fa1 -[ViewController viewDidLoad] + 100
    5   UIKit                               0x30112a53 <redacted> + 518
    6   UIKit                               0x30112811 <redacted> + 24
    7   UIKit                               0x30119489 <redacted> + 64
    8   UIKit                               0x30116dd9 <redacted> + 304
    9   UIKit                               0x30180a51 <redacted> + 60
    10  UIKit                               0x3017d6e5 <redacted> + 1820
    11  UIKit                               0x30177cc9 <redacted> + 720
    12  UIKit                               0x30113c97 <redacted> + 3550
    13  UIKit                               0x30112df9 <redacted> + 72
    14  UIKit                               0x30177405 <redacted> + 616
    15  GraphicsServices                    0x32780b55 <redacted> + 608
    16  GraphicsServices                    0x3278073f <redacted> + 34
    17  CoreFoundation                      0x2d8a983f <redacted> + 34
    18  CoreFoundation                      0x2d8a97db <redacted> + 346
    19  CoreFoundation                      0x2d8a7fa7 <redacted> + 1406
    20  CoreFoundation                      0x2d8127a9 CFRunLoopRunSpecific + 524
    21  CoreFoundation                      0x2d81258b CFRunLoopRunInMode + 106
    22  UIKit                               0x3017662b <redacted> + 762
    23  UIKit                               0x30171891 UIApplicationMain + 1136
    24  testapp                             0x00074339 main + 116
    25  libdyld.dylib                       0x38571ab7 <redacted> + 2
)

ちなみに、以下の様なプログラムを実行しています。

ViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self configureNavigationBar];
}

- (void)configureNavigationBar
{
    NSArray *array = [NSArray new];

    NSLog(@"%@", array[5]);
}

ログからconfigureNavigationBarで例外が投げられていることが分かりました。

    3   testapp                             0x00074001 -[ViewController configureNavigationBar] + 92

例外が発生したときにBreakする

コメントで教えていただきました。

スクリーンショット 2014-03-28 16.00.44.png

ここから「Add Execption Breakpoint」を選択することで、例外が発生したときにBreakしてくれるというものです。

スクリーンショット 2014-03-28 16.00.53.png

これで設定完了。
実行してみると…

スクリーンショット 2014-03-28 16.01.25.png

ちゃんとBreakされました!
これでSIGABRTなどで悩むことは減りそうです。

参考文献

もう return UIApplicationMain で止まっても困らない! Xcodeでのデバッグ方法 | Zero4Racer PRO Developer's Blog)
ios - Xcode 4.2 debug doesn't symbolicate stack call - Stack Overflow
iOS - Xcodeで例外が発生したときにブレークする - Qiita

54
54
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
54