xcode 如何调试 EXC_CRASH (SIGTRAP)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8597953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:48:41  来源:igfitidea点击:

how to debug EXC_CRASH (SIGTRAP)

iphoneiosxcodedebugging

提问by Desmond

i'm running my app are running fine until i resume from background or with out location services, the app will crash.

我正在运行我的应用程序运行良好,直到我从后台恢复或没有定位服务,应用程序将崩溃。

the crash log shows Exception Type: EXC_CRASH (SIGTRAP)

崩溃日志显示异常类型:EXC_CRASH (SIGTRAP)

Anybody know how to debug it ?

有人知道如何调试吗?

Exception Type:  EXC_CRASH (SIGTRAP)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x36398848 __kill + 8
1   FrogFinder                      0x000b5034 0x69000 + 311348
2   CoreFoundation                  0x3447e980 __handleUncaughtException + 68
3   libobjc.A.dylib                 0x346ce2ca _objc_terminate + 122
4   libc++abi.dylib                 0x338a33be _ZL19safe_handler_callerPFvvE + 70
5   libc++abi.dylib                 0x338a344a std::terminate() + 14
6   libc++abi.dylib                 0x338a481e __cxa_rethrow + 82
7   libobjc.A.dylib                 0x346ce22e objc_exception_rethrow + 6
8   CoreFoundation                  0x343d453e CFRunLoopRunSpecific + 398
9   CoreFoundation                  0x343d439e CFRunLoopRunInMode + 98
10  GraphicsServices                0x30c58fc6 GSEventRunModal + 150
11  UIKit                           0x3785573c UIApplicationMain + 1084
12  FrogFinder                      0x0006a7e6 0x69000 + 6118
13  FrogFinder                      0x0006a7a4 0x69000 + 6052

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x363893b4 kevent + 24
1   libdispatch.dylib               0x370b3e78 _dispatch_mgr_invoke + 708
2   libdispatch.dylib               0x370b3b96 _dispatch_mgr_thread + 30

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x36389010 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x36389206 mach_msg + 50
2   CoreFoundation                  0x3445241c __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x34451154 __CFRunLoopRun + 876
4   CoreFoundation                  0x343d44d6 CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x343d439e CFRunLoopRunInMode + 98
6   WebCore                         0x368a8128 _ZL12RunWebThreadPv + 396
7   libsystem_c.dylib               0x33224c16 _pthread_start + 314
8   libsystem_c.dylib               0x33224ad0 thread_start + 0

Thread 3 name:  com.apple.NSURLConnectionLoader
Thread 3:
0   libsystem_kernel.dylib          0x36389010 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x36389206 mach_msg + 50
2   CoreFoundation                  0x3445241c __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x34451154 __CFRunLoopRun + 876
4   CoreFoundation                  0x343d44d6 CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x343d439e CFRunLoopRunInMode + 98
6   Foundation                      0x35dd4bc2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 302
7   Foundation                      0x35dd4a8a -[NSThread main] + 66
8   Foundation                      0x35e6859a __NSThread__main__ + 1042
9   libsystem_c.dylib               0x33224c16 _pthread_start + 314
10  libsystem_c.dylib               0x33224ad0 thread_start + 0

Thread 4:
0   libsystem_kernel.dylib          0x36389010 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x36389206 mach_msg + 50
2   CoreFoundation                  0x3445241c __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x34451154 __CFRunLoopRun + 876
4   CoreFoundation                  0x343d44d6 CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x343d439e CFRunLoopRunInMode + 98
6   Foundation                      0x35dc8b7e -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7   Foundation                      0x35de252c -[NSRunLoop(NSRunLoop) run] + 72
8   FrogFinder                      0x000c8da6 0x69000 + 392614
9   Foundation                      0x35dd4a8a -[NSThread main] + 66
10  Foundation                      0x35e6859a __NSThread__main__ + 1042
11  libsystem_c.dylib               0x33224c16 _pthread_start + 314
12  libsystem_c.dylib               0x33224ad0 thread_start + 0

Thread 5 name:  NetworkIO
Thread 5:
0   libsystem_kernel.dylib          0x36389010 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x36389206 mach_msg + 50
2   CoreFoundation                  0x3445241c __CFRunLoopServiceMachPort + 120
3   CoreFoundation                  0x34451154 __CFRunLoopRun + 876
4   CoreFoundation                  0x343d44d6 CFRunLoopRunSpecific + 294
5   CoreFoundation                  0x343d439e CFRunLoopRunInMode + 98
6   MapKit                          0x38030412 0x38022000 + 58386
7   Foundation                      0x35dd4a8a -[NSThread main] + 66
8   Foundation                      0x35e6859a __NSThread__main__ + 1042
9   libsystem_c.dylib               0x33224c16 _pthread_start + 314
10  libsystem_c.dylib               0x33224ad0 thread_start + 0

回答by Anne-Lise Hassenklover

You can also turn on Exception breakpoints. In XCode 4 click your project and choose the breakpoints tab. At the bottom of that tab is | + | - | search bar. Choose the + item and "Add Exeception Breakpoint". You can leave it at All or choose Objective-C. This way you will break in the debugger and be able to see what caused the exeception.

您还可以打开异常断点。在 XCode 4 中单击您的项目并选择断点选项卡。该选项卡的底部是 | + | - | 搜索栏。选择 + 项和“添加异常断点”。您可以完全保留它或选择 Objective-C。通过这种方式,您将中断调试器并能够查看导致异常的原因。

回答by Evan

With Xcode 4.2 and iOS 5 uncaught exceptions do not seem to show in the console anymore. I would recommend adding the following or modifying your existing uncaught exception handler to dump the exceptions callstack for you.

对于 Xcode 4.2 和 iOS 5,未捕获的异常似乎不再显示在控制台中。我建议添加以下内容或修改您现有的未捕获异常处理程序,为您转储异常调用堆栈。

#ifdef DEBUG
void eHandler(NSException *);

void eHandler(NSException *exception) {
    NSLog(@"%@", exception);
    NSLog(@"%@", [exception callStackSymbols]);
}
#endif

int main(int argc, char *argv[]) {

#ifdef DEBUG
    NSSetUncaughtExceptionHandler(&eHandler);
#endif

...rest of your main function here...

}

回答by Mohammad Sadiq

The easiest way for this kind of crashes which are occuring during development is to add exception break points. You can add exception breakpoint like below

对于在开发过程中发生的这种崩溃,最简单的方法是添加异常断点。您可以添加如下异常断点

  1. Select the break points option in left menu in XCode
  1. 在 XCode 的左侧菜单中选择断点选项

 Select the break points option in left menu

 在左侧菜单中选择断点选项

  1. Add the exception break point
  1. 添加异常断点

enter image description here

在此处输入图片说明

  1. Add breakpoint for all the exceptions
  1. 为所有异常添加断点

enter image description here

在此处输入图片说明

  1. Run the app. In most of the cases when exception occurs XCode will stop the execution and show you the line which caused the exception.
  1. 运行应用程序。在发生异常的大多数情况下,XCode 将停止执行并显示导致异常的行。